From 0c14a586bd13f19ffbf6cd94da4b766254c74821 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 27 Jun 2013 21:21:47 +0000 Subject: [PATCH] (svn r25493) -Codechange: support for the safer variant of ICU's getFontTable --- src/fontcache.cpp | 23 ++++++++++++++--------- src/fontcache.h | 3 ++- src/gfx_layout.cpp | 8 +++++++- src/gfx_layout.h | 1 + 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/fontcache.cpp b/src/fontcache.cpp index a8dd71c757..5b66c3b7a4 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -77,7 +77,7 @@ public: virtual uint GetGlyphWidth(GlyphID key); virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key) { return SPRITE_GLYPH | key; } - virtual const void *GetFontTable(uint32 tag) { return NULL; } + virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return NULL; } }; /** @@ -191,7 +191,8 @@ class FreeTypeFontCache : public FontCache { private: FT_Face face; ///< The font face associated with this font. - SmallMap font_tables; ///< Cached font tables. + typedef SmallMap> FontTable; ///< Table with font table cache + FontTable font_tables; ///< Cached font tables. /** Container for information about a glyph. */ struct GlyphEntry { @@ -229,7 +230,7 @@ public: virtual uint GetGlyphWidth(GlyphID key); virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key); - virtual const void *GetFontTable(uint32 tag); + virtual const void *GetFontTable(uint32 tag, size_t &length); }; FT_Library _library = NULL; @@ -363,8 +364,8 @@ FreeTypeFontCache::~FreeTypeFontCache() FT_Done_Face(this->face); this->ClearFontCache(); - for (SmallPair *iter = this->font_tables.Begin(); iter != this->font_tables.End(); iter++) { - free(iter->second); + for (FontTable::iterator iter = this->font_tables.Begin(); iter != this->font_tables.End(); iter++) { + free(iter->second.second); } } @@ -552,10 +553,13 @@ GlyphID FreeTypeFontCache::MapCharToGlyph(WChar key) return FT_Get_Char_Index(this->face, key); } -const void *FreeTypeFontCache::GetFontTable(uint32 tag) +const void *FreeTypeFontCache::GetFontTable(uint32 tag, size_t &length) { - const SmallPair *iter = this->font_tables.Find(tag); - if (iter != this->font_tables.End()) return iter->second; + const FontTable::iterator iter = this->font_tables.Find(tag); + if (iter != this->font_tables.End()) { + length = iter->second.first; + return iter->second.second; + } FT_ULong len = 0; FT_Byte *result = NULL; @@ -566,8 +570,9 @@ const void *FreeTypeFontCache::GetFontTable(uint32 tag) result = MallocT(len); FT_Load_Sfnt_Table(this->face, tag, 0, result, &len); } + length = len; - this->font_tables.Insert(tag, result); + this->font_tables.Insert(tag, SmallPair(length, result)); return result; } diff --git a/src/fontcache.h b/src/fontcache.h index 6e4d18b3b6..1f52ddcdc4 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -114,9 +114,10 @@ public: /** * Read a font table from the font. * @param tag The of the table to load. + * @param length The length of the read data. * @return The loaded table data. */ - virtual const void *GetFontTable(uint32 tag) = 0; + virtual const void *GetFontTable(uint32 tag, size_t &length) = 0; /** * Get the font cache of a given font size. diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 9dc9212672..69b3077f27 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -76,7 +76,13 @@ float Font::getScaleFactorY() const const void *Font::getFontTable(LETag tableTag) const { - return this->fc->GetFontTable(tableTag); + size_t length; + return this->getFontTable(tableTag, length); +} + +const void *Font::getFontTable(LETag tableTag, size_t &length) const +{ + return this->fc->GetFontTable(tableTag, length); } LEGlyphID Font::mapCharToGlyph(LEUnicode32 ch) const diff --git a/src/gfx_layout.h b/src/gfx_layout.h index dbeccd4296..0fadd51263 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -45,6 +45,7 @@ public: float getScaleFactorX() const; float getScaleFactorY() const; const void *getFontTable(LETag tableTag) const; + const void *getFontTable(LETag tableTag, size_t &length) const; LEGlyphID mapCharToGlyph(LEUnicode32 ch) const; void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const; le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;