Skip to content

Commit 6b83c1d

Browse files
committed
Function prototypes LVFont::getGlyphInfo() LVFont::getGlyph() were changed to exclude
integer overflow when passing arguments, including characters with codes greater than 0xFFFF.
1 parent a349a57 commit 6b83c1d

File tree

9 files changed

+31
-30
lines changed

9 files changed

+31
-30
lines changed

crengine/include/lvfont.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ class LVFont : public LVRefCounter {
6767
virtual int getVisualAligmentWidth();
6868

6969
/** \brief get glyph info
70+
\param code is unicode character code
7071
\param glyph is pointer to glyph_info_t struct to place retrieved info
7172
\return true if glyh was found
7273
*/
73-
virtual bool getGlyphInfo(lUInt16 code, glyph_info_t *glyph, lChar16 def_char = 0) = 0;
74+
virtual bool getGlyphInfo(lUInt32 code, glyph_info_t *glyph, lChar16 def_char = 0) = 0;
7475

7576
/** \brief measure text
7677
\param text is text string pointer
@@ -104,12 +105,12 @@ class LVFont : public LVRefCounter {
104105
// \param buf is buffer [width*height] to place glyph data
105106
// \return true if glyph was found
106107
// */
107-
// virtual bool getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char=0) = 0;
108+
// virtual bool getGlyphImage(lUInt32 code, lUInt8 * buf, lChar16 def_char=0) = 0;
108109
/** \brief get glyph item
109-
\param code is unicode character
110+
\param code is unicode character code
110111
\return glyph pointer if glyph was found, NULL otherwise
111112
*/
112-
virtual LVFontGlyphCacheItem *getGlyph(lUInt16 ch, lChar16 def_char = 0) = 0;
113+
virtual LVFontGlyphCacheItem *getGlyph(lUInt32 ch, lChar16 def_char = 0) = 0;
113114

114115
/// returns font baseline offset
115116
virtual int getBaseline() = 0;

crengine/src/private/lvbitmapfont.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LVFontRef LoadFontFromFile( const char * fname )
3232
return ref;
3333
}
3434

35-
bool LBitmapFont::getGlyphInfo( lUInt16 code, LVFont::glyph_info_t * glyph, lChar16 def_char )
35+
bool LBitmapFont::getGlyphInfo( lUInt32 code, LVFont::glyph_info_t * glyph, lChar16 def_char )
3636
{
3737
const lvfont_glyph_t * ptr = lvfontGetGlyph( m_font, code );
3838
if (!ptr)
@@ -110,7 +110,7 @@ int LBitmapFont::getItalic() const
110110
return hdr->flgItalic;
111111
}
112112
/*
113-
bool LBitmapFont::getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char)
113+
bool LBitmapFont::getGlyphImage(lUInt32 code, lUInt8 * buf, lChar16 def_char)
114114
{
115115
const lvfont_glyph_t * ptr = lvfontGetGlyph( m_font, code );
116116
if (!ptr)
@@ -122,7 +122,7 @@ bool LBitmapFont::getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char)
122122
return true;
123123
}
124124
*/
125-
LVFontGlyphCacheItem *LBitmapFont::getGlyph(lUInt16 ch, lChar16 def_char) {
125+
LVFontGlyphCacheItem *LBitmapFont::getGlyph(lUInt32 ch, lChar16 def_char) {
126126
// TODO:
127127
return NULL;
128128
}

crengine/src/private/lvbitmapfont.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LBitmapFont : public LVBaseFont {
3030
public:
3131
LBitmapFont() : m_font(NULL) {}
3232

33-
virtual bool getGlyphInfo(lUInt16 code, LVFont::glyph_info_t *glyph, lChar16 def_char = 0);
33+
virtual bool getGlyphInfo(lUInt32 code, LVFont::glyph_info_t *glyph, lChar16 def_char = 0);
3434

3535
virtual lUInt16
3636
measureText(const lChar16 *text, int len, lUInt16 *widths, lUInt8 *flags, int max_width,
@@ -60,9 +60,9 @@ class LBitmapFont : public LVBaseFont {
6060
/// returns italic flag
6161
virtual int getItalic() const;
6262

63-
//virtual bool getGlyphImage(lUInt16 code, lUInt8 *buf, lChar16 def_char = 0);
63+
//virtual bool getGlyphImage(lUInt32 code, lUInt8 *buf, lChar16 def_char = 0);
6464

65-
virtual LVFontGlyphCacheItem *getGlyph(lUInt16 ch, lChar16 def_char = 0);
65+
virtual LVFontGlyphCacheItem *getGlyph(lUInt32 ch, lChar16 def_char = 0);
6666

6767
/// returns char width
6868
virtual int getCharWidth(lChar16 ch, lChar16 def_char = 0) {

crengine/src/private/lvfontboldtransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int LVFontBoldTransform::getHyphenWidth() {
3939
}
4040

4141
bool
42-
LVFontBoldTransform::getGlyphInfo(lUInt16 code, LVFont::glyph_info_t *glyph, lChar16 def_char) {
42+
LVFontBoldTransform::getGlyphInfo(lUInt32 code, LVFont::glyph_info_t *glyph, lChar16 def_char) {
4343
bool res = _baseFont->getGlyphInfo(code, glyph, def_char);
4444
if (!res)
4545
return res;
@@ -91,7 +91,7 @@ lUInt32 LVFontBoldTransform::getTextWidth(const lChar16 *text, int len) {
9191
return 0;
9292
}
9393

94-
LVFontGlyphCacheItem *LVFontBoldTransform::getGlyph(lUInt16 ch, lChar16 def_char) {
94+
LVFontGlyphCacheItem *LVFontBoldTransform::getGlyph(lUInt32 ch, lChar16 def_char) {
9595

9696
LVFontGlyphCacheItem *item = _glyph_cache.get(ch);
9797
if (item)

crengine/src/private/lvfontboldtransform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LVFontBoldTransform : public LVFont {
5050
\param glyph is pointer to glyph_info_t struct to place retrieved info
5151
\return true if glyh was found
5252
*/
53-
virtual bool getGlyphInfo(lUInt16 code, glyph_info_t *glyph, lChar16 def_char = 0);
53+
virtual bool getGlyphInfo(lUInt32 code, glyph_info_t *glyph, lChar16 def_char = 0);
5454

5555
/** \brief measure text
5656
\param text is text string pointer
@@ -83,7 +83,7 @@ class LVFontBoldTransform : public LVFont {
8383
\param code is unicode character
8484
\return glyph pointer if glyph was found, NULL otherwise
8585
*/
86-
virtual LVFontGlyphCacheItem *getGlyph(lUInt16 ch, lChar16 def_char = 0);
86+
virtual LVFontGlyphCacheItem *getGlyph(lUInt32 ch, lChar16 def_char = 0);
8787

8888
/** \brief get glyph image in 1 byte per pixel format
8989
\param code is unicode character

crengine/src/private/lvfreetypeface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ bool LVFreeTypeFace::hbCalcCharWidth(LVCharPosInfo *posInfo, const LVCharTriplet
636636

637637
#endif // USE_HARFBUZZ==1
638638

639-
FT_UInt LVFreeTypeFace::getCharIndex(lChar16 code, lChar16 def_char) {
639+
FT_UInt LVFreeTypeFace::getCharIndex(lUInt32 code, lChar16 def_char) {
640640
if (code == '\t')
641641
code = ' ';
642642
FT_UInt ch_glyph_index = FT_Get_Char_Index(_face, code);
@@ -650,7 +650,7 @@ FT_UInt LVFreeTypeFace::getCharIndex(lChar16 code, lChar16 def_char) {
650650
return ch_glyph_index;
651651
}
652652

653-
bool LVFreeTypeFace::getGlyphInfo(lUInt16 code, LVFont::glyph_info_t *glyph, lChar16 def_char) {
653+
bool LVFreeTypeFace::getGlyphInfo(lUInt32 code, LVFont::glyph_info_t *glyph, lChar16 def_char) {
654654
//FONT_GUARD
655655
int glyph_index = getCharIndex(code, 0);
656656
if (glyph_index == 0) {
@@ -1022,7 +1022,7 @@ void LVFreeTypeFace::updateTransform() {
10221022
// }
10231023
}
10241024

1025-
LVFontGlyphCacheItem *LVFreeTypeFace::getGlyph(lUInt16 ch, lChar16 def_char) {
1025+
LVFontGlyphCacheItem *LVFreeTypeFace::getGlyph(lUInt32 ch, lChar16 def_char) {
10261026
//FONT_GUARD
10271027
FT_UInt ch_glyph_index = getCharIndex(ch, 0);
10281028
if (ch_glyph_index == 0) {

crengine/src/private/lvfreetypeface.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,11 @@ class LVFreeTypeFace : public LVFont {
194194

195195
#endif // USE_HARFBUZZ==1
196196

197-
FT_UInt getCharIndex(lChar16 code, lChar16 def_char);
198-
199197
/** \brief get glyph info
200198
\param glyph is pointer to glyph_info_t struct to place retrieved info
201199
\return true if glyh was found
202200
*/
203-
virtual bool getGlyphInfo(lUInt16 code, glyph_info_t *glyph, lChar16 def_char = 0);
201+
virtual bool getGlyphInfo(lUInt32 code, glyph_info_t *glyph, lChar16 def_char = 0);
204202
/*
205203
// USE GET_CHAR_FLAGS instead
206204
inline int calcCharFlags( lChar16 ch )
@@ -258,7 +256,7 @@ class LVFreeTypeFace : public LVFont {
258256
\param code is unicode character
259257
\return glyph pointer if glyph was found, NULL otherwise
260258
*/
261-
virtual LVFontGlyphCacheItem *getGlyph(lUInt16 ch, lChar16 def_char = 0);
259+
virtual LVFontGlyphCacheItem *getGlyph(lUInt32 ch, lChar16 def_char = 0);
262260

263261
#if USE_HARFBUZZ == 1
264262

@@ -340,6 +338,8 @@ class LVFreeTypeFace : public LVFont {
340338
}
341339

342340
virtual void Clear();
341+
protected:
342+
FT_UInt getCharIndex(lUInt32 code, lChar16 def_char);
343343
};
344344

345345
#endif // (USE_FREETYPE==1)

crengine/src/private/lvwin32font.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool LVBaseWin32Font::Create(int size, int weight, bool italic, css_font_family_
118118
\param glyph is pointer to glyph_info_t struct to place retrieved info
119119
\return true if glyh was found
120120
*/
121-
bool LVWin32DrawFont::getGlyphInfo( lUInt16 code, glyph_info_t * glyph, lChar16 def_char )
121+
bool LVWin32DrawFont::getGlyphInfo( lUInt32 code, glyph_info_t * glyph, lChar16 def_char )
122122
{
123123
return false;
124124
}
@@ -356,7 +356,7 @@ void LVWin32DrawFont::DrawTextString( LVDrawBuf * buf, int x, int y,
356356
\param buf is buffer [width*height] to place glyph data
357357
\return true if glyph was found
358358
*/
359-
bool LVWin32DrawFont::getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char)
359+
bool LVWin32DrawFont::getGlyphImage(lUInt32 code, lUInt8 * buf, lChar16 def_char)
360360
{
361361
return false;
362362
}
@@ -505,7 +505,7 @@ glyph_t * LVWin32Font::GetGlyphRec( lChar16 ch )
505505
\param glyph is pointer to glyph_info_t struct to place retrieved info
506506
\return true if glyh was found
507507
*/
508-
bool LVWin32Font::getGlyphInfo( lUInt16 code, glyph_info_t * glyph, lChar16 def_char )
508+
bool LVWin32Font::getGlyphInfo( lUInt32 code, glyph_info_t * glyph, lChar16 def_char )
509509
{
510510
if (_hfont==NULL)
511511
return false;
@@ -618,7 +618,7 @@ lUInt16 LVWin32Font::measureText(
618618
\param buf is buffer [width*height] to place glyph data
619619
\return true if glyph was found
620620
*/
621-
bool LVWin32Font::getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char)
621+
bool LVWin32Font::getGlyphImage(lUInt32 code, lUInt8 * buf, lChar16 def_char)
622622
{
623623
if (_hfont==NULL)
624624
return false;

crengine/src/private/lvwin32font.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class LVBaseWin32Font : public LVBaseFont
104104
return css_ff_inherit;
105105
}
106106

107-
virtual LVFontGlyphCacheItem * getGlyph(lUInt16 ch, lChar16 def_char=0) {
107+
virtual LVFontGlyphCacheItem * getGlyph(lUInt32 ch, lChar16 def_char=0) {
108108
return NULL;
109109
}
110110

@@ -127,7 +127,7 @@ class LVWin32DrawFont : public LVBaseWin32Font
127127
\param glyph is pointer to glyph_info_t struct to place retrieved info
128128
\return true if glyh was found
129129
*/
130-
virtual bool getGlyphInfo( lUInt16 code, glyph_info_t * glyph, lChar16 def_char=0 );
130+
virtual bool getGlyphInfo( lUInt32 code, glyph_info_t * glyph, lChar16 def_char=0 );
131131

132132
/** \brief measure text
133133
\param glyph is pointer to glyph_info_t struct to place retrieved info
@@ -164,7 +164,7 @@ class LVWin32DrawFont : public LVBaseWin32Font
164164
\param buf is buffer [width*height] to place glyph data
165165
\return true if glyph was found
166166
*/
167-
virtual bool getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char=0);
167+
virtual bool getGlyphImage(lUInt32 code, lUInt8 * buf, lChar16 def_char=0);
168168

169169
};
170170

@@ -302,7 +302,7 @@ class LVWin32Font : public LVBaseWin32Font
302302
\param glyph is pointer to glyph_info_t struct to place retrieved info
303303
\return true if glyh was found
304304
*/
305-
virtual bool getGlyphInfo( lUInt16 code, glyph_info_t * glyph, lChar16 def_char=0 );
305+
virtual bool getGlyphInfo( lUInt32 code, glyph_info_t * glyph, lChar16 def_char=0 );
306306

307307
/** \brief measure text
308308
\param glyph is pointer to glyph_info_t struct to place retrieved info
@@ -331,7 +331,7 @@ class LVWin32Font : public LVBaseWin32Font
331331
\param buf is buffer [width*height] to place glyph data
332332
\return true if glyph was found
333333
*/
334-
virtual bool getGlyphImage(lUInt16 code, lUInt8 * buf, lChar16 def_char=0);
334+
virtual bool getGlyphImage(lUInt32 code, lUInt8 * buf, lChar16 def_char=0);
335335

336336
virtual void Clear();
337337

0 commit comments

Comments
 (0)