Skip to content

Commit a3d2936

Browse files
authored
Merge pull request #111 from virxkane/font-render-fixes
Font render fixes
2 parents 802ae13 + fd1eabb commit a3d2936

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+7546
-5610
lines changed

android/app/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ set(CRENGINE_SRC_FILES
6363
${CR3_ROOT}/crengine/src/lvbmpbuf.cpp
6464
${CR3_ROOT}/crengine/src/lvfnt.cpp
6565
${CR3_ROOT}/crengine/src/hyphman.cpp
66+
${CR3_ROOT}/crengine/src/lvfont.cpp
67+
${CR3_ROOT}/crengine/src/lvembeddedfont.cpp
6668
${CR3_ROOT}/crengine/src/lvfntman.cpp
6769
${CR3_ROOT}/crengine/src/lvimg.cpp
6870
${CR3_ROOT}/crengine/src/crskin.cpp
@@ -74,6 +76,12 @@ set(CRENGINE_SRC_FILES
7476
${CR3_ROOT}/crengine/src/wolutil.cpp
7577
${CR3_ROOT}/crengine/src/crconcurrent.cpp
7678
${CR3_ROOT}/crengine/src/hist.cpp
79+
${CR3_ROOT}/crengine/src/private/lvfontglyphcache.cpp
80+
${CR3_ROOT}/crengine/src/private/lvfontboldtransform.cpp
81+
${CR3_ROOT}/crengine/src/private/lvfontcache.cpp
82+
${CR3_ROOT}/crengine/src/private/lvfontdef.cpp
83+
${CR3_ROOT}/crengine/src/private/lvfreetypeface.cpp
84+
${CR3_ROOT}/crengine/src/private/lvfreetypefontman.cpp
7785
${CR3_ROOT}/crengine/fc-lang/fc-lang-cat.c
7886
)
7987
# ${CR3_ROOT}/crengine/src/cri18n.cpp

cr3qt/src/cr3.rc

100755100644
File mode changed.

cr3qt/src/cr3widget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ CR3View::CR3View( QWidget *parent)
343343
updateDefProps();
344344
setMouseTracking(true);
345345
setFocusPolicy(Qt::StrongFocus);
346+
setMinimumSize(SCREEN_SIZE_MIN, SCREEN_SIZE_MIN);
346347
}
347348

348349
void CR3View::updateDefProps()
@@ -749,6 +750,11 @@ void CR3View::refreshPropFromView( const char * propName )
749750
_data->_props->setString( propName, _docview->propsGetCurrent()->getStringDef( propName, "" ) );
750751
}
751752

753+
QSize CR3View::minimumSizeHint() const
754+
{
755+
return QSize(SCREEN_SIZE_MIN, SCREEN_SIZE_MIN);
756+
}
757+
752758
void CR3View::zoomIn()
753759
{
754760
doCommand( DCMD_ZOOM_IN, 1 );

cr3qt/src/cr3widget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class CR3View : public QWidget, public LVDocViewCallback
158158
virtual void mousePressEvent ( QMouseEvent * event );
159159
virtual void mouseReleaseEvent ( QMouseEvent * event );
160160
virtual void refreshPropFromView( const char * propName );
161+
virtual QSize minimumSizeHint() const;
161162

162163
private slots:
163164

cr3qt/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ bool InitCREngine( const char * exename, lString16Collection & fontDirs )
421421
// fonts are in files font1.lbf, font2.lbf, ... font32.lbf
422422
// use fontconfig
423423

424+
#if USE_FREETYPE==1
424425
lString16Collection fontExt;
425426
fontExt.add(cs16(".ttf"));
426427
fontExt.add(cs16(".otf"));
@@ -441,6 +442,7 @@ bool InitCREngine( const char * exename, lString16Collection & fontDirs )
441442
}
442443
}
443444
//}
445+
#endif // USE_FREETYPE==1
444446

445447
// init hyphenation manager
446448
//char hyphfn[1024];

cr3qt/src/settings.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,13 @@ void SettingsDlg::on_buttonBox_rejected()
329329
void SettingsDlg::on_cbFontKerning_stateChanged(int s)
330330
{
331331
setCheck( PROP_FONT_KERNING_ENABLED, s );
332+
updateStyleSample();
332333
}
333334

334335
void SettingsDlg::on_cbLigatures_stateChanged(int s)
335336
{
336337
setCheck( PROP_FONT_LIGATURES_ENABLED, s );
338+
updateStyleSample();
337339
}
338340

339341
void SettingsDlg::on_buttonBox_accepted()
@@ -944,11 +946,13 @@ void SettingsDlg::on_cbPageSkin_currentIndexChanged(int index)
944946
void SettingsDlg::on_cbFloatingPunctuation_stateChanged(int s)
945947
{
946948
setCheck( PROP_FLOATING_PUNCTUATION, s );
949+
updateStyleSample();
947950
}
948951

949952
void SettingsDlg::on_cbFontGamma_currentIndexChanged(QString s)
950953
{
951954
m_props->setString( PROP_FONT_GAMMA, s );
955+
updateStyleSample();
952956
}
953957

954958
void SettingsDlg::on_cbStyleName_currentIndexChanged(int index)
@@ -1015,6 +1019,7 @@ void SettingsDlg::on_cbDefFontColor_currentIndexChanged(int index)
10151019
void SettingsDlg::on_cbFontHinting_currentIndexChanged(int index)
10161020
{
10171021
m_props->setInt(PROP_FONT_HINTING, index);
1022+
updateStyleSample();
10181023
}
10191024

10201025
void SettingsDlg::on_cbFallbackFontFace_currentIndexChanged(const QString &s)

crengine/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ if ( NOT ${GUI} STREQUAL FB2PROPS )
2727
SET (CRENGINE_SOURCES ${CRENGINE_SOURCES}
2828
src/lvbmpbuf.cpp
2929
src/lvfnt.cpp
30-
src/hyphman.cpp
30+
src/hyphman.cpp
31+
src/lvembeddedfont.cpp
32+
src/lvfont.cpp
3133
src/lvfntman.cpp
3234
src/crgui.cpp
3335
src/lvimg.cpp
@@ -44,6 +46,17 @@ if ( NOT ${GUI} STREQUAL FB2PROPS )
4446
src/pdbfmt.cpp
4547
src/wordfmt.cpp
4648
src/crconcurrent.cpp
49+
src/private/lvbasefont.cpp
50+
src/private/lvbitmapfont.cpp
51+
src/private/lvbitmapfontman.cpp
52+
src/private/lvfontglyphcache.cpp
53+
src/private/lvfontcache.cpp
54+
src/private/lvfontboldtransform.cpp
55+
src/private/lvfontdef.cpp
56+
src/private/lvwin32font.cpp
57+
src/private/lvwin32fontman.cpp
58+
src/private/lvfreetypeface.cpp
59+
src/private/lvfreetypefontman.cpp
4760
#src/xutils.cpp
4861
)
4962
endif (NOT ${GUI} STREQUAL FB2PROPS)

crengine/Tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ add_subdirectory(GammaGen)
77
add_subdirectory(HyphConv)
88
add_subdirectory(langstat)
99
add_subdirectory(langstat2)
10+
add_subdirectory(glyphcache_bench)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
set(SRC_LIST
3+
main.cpp
4+
lvfontglyphcache_a.cpp
5+
lvfontglyphcache_b.cpp
6+
)
7+
8+
if(WIN32)
9+
add_definitions(-DWIN32 -D_CONSOLE)
10+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole")
11+
endif(WIN32)
12+
13+
add_executable(glyphcache_bench ${SRC_LIST})
14+
#target_link_libraries(glyphcache_bench)
15+
16+
configure_file(valgrind_check.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/valgrind_check.sh)
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/** @file lvfontglyphcache.cpp
2+
@brief font glyph cache implementation
3+
4+
CoolReader Engine
5+
6+
7+
(c) Vadim Lopatin, 2000-2006
8+
This source code is distributed under the terms of
9+
GNU General Public License.
10+
11+
See LICENSE file for details.
12+
13+
*/
14+
15+
// This file contains copy of class LVFontLocalGlyphCacheA from cr3.2.31
16+
17+
#include "lvfontglyphcache_a.h"
18+
//#include "../../include/crlocks.h"
19+
20+
21+
void LVFontLocalGlyphCacheA::clear() {
22+
//FONT_LOCAL_GLYPH_CACHE_GUARD
23+
while (head) {
24+
LVFontGlyphCacheItemA *ptr = head;
25+
remove(ptr);
26+
global_cache->remove(ptr);
27+
LVFontGlyphCacheItemA::freeItem(ptr);
28+
}
29+
}
30+
31+
LVFontGlyphCacheItemA *LVFontLocalGlyphCacheA::getByChar(lChar16 ch) {
32+
//FONT_LOCAL_GLYPH_CACHE_GUARD
33+
LVFontGlyphCacheItemA *ptr = head;
34+
for (; ptr; ptr = ptr->next_local) {
35+
if (ptr->data.ch == ch) {
36+
global_cache->refresh(ptr);
37+
return ptr;
38+
}
39+
}
40+
return NULL;
41+
}
42+
43+
#if USE_HARFBUZZ==1
44+
LVFontGlyphCacheItemA* LVFontLocalGlyphCacheA::getByIndex(lUInt32 index)
45+
{
46+
//FONT_LOCAL_GLYPH_CACHE_GUARD
47+
LVFontGlyphCacheItemA *ptr = head;
48+
for (; ptr; ptr = ptr->next_local) {
49+
if (ptr->data.gindex == index) {
50+
global_cache->refresh(ptr);
51+
return ptr;
52+
}
53+
}
54+
return NULL;
55+
}
56+
#endif
57+
58+
void LVFontLocalGlyphCacheA::put(LVFontGlyphCacheItemA *item) {
59+
//FONT_LOCAL_GLYPH_CACHE_GUARD
60+
global_cache->put(item);
61+
item->next_local = head;
62+
if (head)
63+
head->prev_local = item;
64+
if (!tail)
65+
tail = item;
66+
head = item;
67+
}
68+
69+
/// remove from list, but don't delete
70+
void LVFontLocalGlyphCacheA::remove(LVFontGlyphCacheItemA *item) {
71+
//FONT_LOCAL_GLYPH_CACHE_GUARD
72+
if (item == head)
73+
head = item->next_local;
74+
if (item == tail)
75+
tail = item->prev_local;
76+
if (!head || !tail)
77+
return;
78+
if (item->prev_local)
79+
item->prev_local->next_local = item->next_local;
80+
if (item->next_local)
81+
item->next_local->prev_local = item->prev_local;
82+
item->next_local = NULL;
83+
item->prev_local = NULL;
84+
}
85+
86+
void LVFontGlobalGlyphCacheA::refresh(LVFontGlyphCacheItemA *item) {
87+
//FONT_GLYPH_CACHE_GUARD
88+
if (tail != item) {
89+
//move to head
90+
removeNoLock(item);
91+
putNoLock(item);
92+
}
93+
}
94+
95+
void LVFontGlobalGlyphCacheA::put(LVFontGlyphCacheItemA *item) {
96+
//FONT_GLYPH_CACHE_GUARD
97+
putNoLock(item);
98+
}
99+
100+
void LVFontGlobalGlyphCacheA::putNoLock(LVFontGlyphCacheItemA *item) {
101+
int sz = item->getSize();
102+
// remove extra items from tail
103+
while (sz + size > max_size) {
104+
LVFontGlyphCacheItemA *removed_item = tail;
105+
if (!removed_item)
106+
break;
107+
removeNoLock(removed_item);
108+
removed_item->local_cache->remove(removed_item);
109+
LVFontGlyphCacheItemA::freeItem(removed_item);
110+
}
111+
// add new item to head
112+
item->next_global = head;
113+
if (head)
114+
head->prev_global = item;
115+
head = item;
116+
if (!tail)
117+
tail = item;
118+
size += sz;
119+
}
120+
121+
void LVFontGlobalGlyphCacheA::remove(LVFontGlyphCacheItemA *item) {
122+
//FONT_GLYPH_CACHE_GUARD
123+
removeNoLock(item);
124+
}
125+
126+
void LVFontGlobalGlyphCacheA::removeNoLock(LVFontGlyphCacheItemA *item) {
127+
if (item == head)
128+
head = item->next_global;
129+
if (item == tail)
130+
tail = item->prev_global;
131+
if (!head || !tail)
132+
return;
133+
if (item->prev_global)
134+
item->prev_global->next_global = item->next_global;
135+
if (item->next_global)
136+
item->next_global->prev_global = item->prev_global;
137+
item->next_global = NULL;
138+
item->prev_global = NULL;
139+
size -= item->getSize();
140+
}
141+
142+
void LVFontGlobalGlyphCacheA::clear() {
143+
//FONT_GLYPH_CACHE_GUARD
144+
while (head) {
145+
LVFontGlyphCacheItemA *ptr = head;
146+
remove(ptr);
147+
ptr->local_cache->remove(ptr);
148+
LVFontGlyphCacheItemA::freeItem(ptr);
149+
}
150+
}
151+
152+
LVFontGlyphCacheItemA *LVFontGlyphCacheItemA::newItem(LVFontLocalGlyphCacheA *local_cache, lChar16 ch, int w, int h) {
153+
LVFontGlyphCacheItemA *item = (LVFontGlyphCacheItemA *) malloc(sizeof(LVFontGlyphCacheItemA)
154+
+ (w * h - 1) * sizeof(lUInt8));
155+
if (item) {
156+
item->data.ch = ch;
157+
item->bmp_width = (lUInt16) w;
158+
item->bmp_height = (lUInt16) h;
159+
item->origin_x = 0;
160+
item->origin_y = 0;
161+
item->advance = 0;
162+
item->prev_global = NULL;
163+
item->next_global = NULL;
164+
item->prev_local = NULL;
165+
item->next_local = NULL;
166+
item->local_cache = local_cache;
167+
}
168+
return item;
169+
}
170+
171+
#if USE_HARFBUZZ==1
172+
LVFontGlyphCacheItemA *LVFontGlyphCacheItemA::newItem(LVFontLocalGlyphCacheA* local_cache, lUInt32 glyph_index, int w, int h)
173+
{
174+
LVFontGlyphCacheItemA *item = (LVFontGlyphCacheItemA *) malloc(sizeof(LVFontGlyphCacheItemA)
175+
+ (w * h - 1) * sizeof(lUInt8));
176+
if (item) {
177+
item->data.gindex = glyph_index;
178+
item->bmp_width = (lUInt16) w;
179+
item->bmp_height = (lUInt16) h;
180+
item->origin_x = 0;
181+
item->origin_y = 0;
182+
item->advance = 0;
183+
item->prev_global = NULL;
184+
item->next_global = NULL;
185+
item->prev_local = NULL;
186+
item->next_local = NULL;
187+
item->local_cache = local_cache;
188+
}
189+
return item;
190+
}
191+
#endif // USE_HARFBUZZ==1
192+
193+
void LVFontGlyphCacheItemA::freeItem(LVFontGlyphCacheItemA *item) {
194+
if (item)
195+
::free(item);
196+
}

0 commit comments

Comments
 (0)