From 244adb53b0308f121ede4dfafd2a7953914e55a6 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 22 Mar 2021 11:27:31 +0000 Subject: convert calloc/free into std::vector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iecbbc58b52d393840b9e68764de276594a86aa4b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112882 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- vcl/source/fontsubset/sft.cxx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'vcl/source/fontsubset') diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index bc4db89582d0..61ff497cbde4 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -1116,7 +1116,6 @@ bool withinBounds(sal_uInt32 tdoffset, sal_uInt32 moreoffset, sal_uInt32 len, sa AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName, const FontCharMapRef xCharMap) : m_pFileName(nullptr) , m_nGlyphs(0xFFFFFFFF) - , m_pGlyphOffsets(nullptr) , m_nHorzMetrics(0) , m_nVertMetrics(0) , m_nUnitsPerEm(0) @@ -1129,7 +1128,6 @@ AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName, const FontChar AbstractTrueTypeFont::~AbstractTrueTypeFont() { free(m_pFileName); - free(m_pGlyphOffsets); } TrueTypeFont::TrueTypeFont(const char* pFileName, const FontCharMapRef xCharMap) @@ -1160,6 +1158,11 @@ TrueTypeFont::~TrueTypeFont() void CloseTTFont(TrueTypeFont* ttf) { delete ttf; } +sal_uInt32 AbstractTrueTypeFont::glyphOffset(sal_uInt32 glyphID) const +{ + return m_aGlyphOffsets[glyphID]; +} + SFErrCodes AbstractTrueTypeFont::indexGlyphData() { if (!(hasTable(O_maxp) && hasTable(O_head) && hasTable(O_name) && hasTable(O_cmap))) @@ -1185,12 +1188,10 @@ SFErrCodes AbstractTrueTypeFont::indexGlyphData() if (k < static_cast(m_nGlyphs)) /* Hack for broken Chinese fonts */ m_nGlyphs = k; - free(m_pGlyphOffsets); - m_pGlyphOffsets = static_cast(calloc(m_nGlyphs + 1, sizeof(sal_uInt32))); - assert(m_pGlyphOffsets != nullptr); - + m_aGlyphOffsets.clear(); + m_aGlyphOffsets.reserve(m_nGlyphs + 1); for (int i = 0; i <= static_cast(m_nGlyphs); ++i) - m_pGlyphOffsets[i] = indexfmt ? GetUInt32(table, i << 2) : static_cast(GetUInt16(table, i << 1)) << 1; + m_aGlyphOffsets.push_back(indexfmt ? GetUInt32(table, i << 2) : static_cast(GetUInt16(table, i << 1)) << 1); } else if (this->table(O_CFF, table_size)) /* PS-OpenType */ { @@ -1198,17 +1199,15 @@ SFErrCodes AbstractTrueTypeFont::indexGlyphData() if (k < static_cast(m_nGlyphs)) m_nGlyphs = k; - free(m_pGlyphOffsets); - m_pGlyphOffsets = static_cast(calloc(m_nGlyphs + 1, sizeof(sal_uInt32))); + m_aGlyphOffsets.clear(); + m_aGlyphOffsets.resize(m_nGlyphs + 1, 0); /* TODO: implement to get subsetting */ - assert(m_pGlyphOffsets != nullptr); } else { // Bitmap font, accept for now. - free(m_pGlyphOffsets); - m_pGlyphOffsets = static_cast(calloc(m_nGlyphs + 1, sizeof(sal_uInt32))); + m_aGlyphOffsets.clear(); + m_aGlyphOffsets.resize(m_nGlyphs + 1, 0); /* TODO: implement to get subsetting */ - assert(m_pGlyphOffsets != nullptr); } table = this->table(O_hhea, table_size); -- cgit v1.2.3