vcl/source/fontsubset/sft.cxx | 47 ++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 31 deletions(-)
New commits: commit fd49a057c9d0fc3a184097f4f3bcb6835eb70edb Author: Noel Grandin <[email protected]> AuthorDate: Tue Sep 20 21:27:09 2022 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Wed Sep 21 10:19:28 2022 +0200 use more unique_ptr Change-Id: I7836a1b1813d16db53ca0d6cc2b2ff2ae95e70cb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140267 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 3cf0ccf4735c..b96d924b2253 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -53,6 +53,7 @@ #include <unotools/tempfile.hxx> #include <fontsubset.hxx> #include <algorithm> +#include <memory> namespace vcl { @@ -126,9 +127,8 @@ private: class GlyphOffsets { public: GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen); - ~GlyphOffsets(); sal_uInt32 nGlyphs; /* number of glyphs in the font + 1 */ - sal_uInt32 *offs; /* array of nGlyphs offsets */ + std::unique_ptr<sal_uInt32[]> offs; /* array of nGlyphs offsets */ }; } @@ -1964,7 +1964,7 @@ GlyphOffsets::GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen) this->nGlyphs = locaLen / ((indexToLocFormat == 1) ? 4 : 2); assert(this->nGlyphs != 0); - this->offs = static_cast<sal_uInt32*>(scalloc(this->nGlyphs, sizeof(sal_uInt32))); + this->offs = std::make_unique<sal_uInt32[]>(this->nGlyphs); for (sal_uInt32 i = 0; i < this->nGlyphs; i++) { if (indexToLocFormat == 1) { @@ -1975,11 +1975,6 @@ GlyphOffsets::GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen) } } -GlyphOffsets::~GlyphOffsets() -{ - free(this->offs); -} - static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) { if (sfntLen < 12) commit 4df352d39602c1b45c5cf156d9dee2c148418dc0 Author: Noel Grandin <[email protected]> AuthorDate: Tue Sep 20 21:20:12 2022 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Wed Sep 21 10:19:14 2022 +0200 convert GlyphOffsets to a C++ class Change-Id: If693a5d0a94da666fd0361d45a3047890d9dec8e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140265 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 9794cc23f118..3cf0ccf4735c 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -123,20 +123,16 @@ private: int total = 0; }; -struct GlyphOffsets { +class GlyphOffsets { +public: + GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen); + ~GlyphOffsets(); sal_uInt32 nGlyphs; /* number of glyphs in the font + 1 */ sal_uInt32 *offs; /* array of nGlyphs offsets */ }; } -static void *smalloc(size_t size) -{ - void *res = malloc(size); - assert(res != nullptr); - return res; -} - static void *scalloc(size_t n, size_t size) { void *res = calloc(n, size); @@ -1929,9 +1925,8 @@ bool CreateCFFfontSubset(const unsigned char* pFontBytes, int nByteLength, return bRet; } -static GlyphOffsets *GlyphOffsetsNew(sal_uInt8 *sfntP, sal_uInt32 sfntLen) +GlyphOffsets::GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen) { - GlyphOffsets* res = static_cast<GlyphOffsets*>(smalloc(sizeof(GlyphOffsets))); sal_uInt8 *loca = nullptr; sal_uInt16 numTables = GetUInt16(sfntP, 4); sal_uInt32 locaLen = 0; @@ -1967,26 +1962,22 @@ static GlyphOffsets *GlyphOffsetsNew(sal_uInt8 *sfntP, sal_uInt32 sfntLen) } } - res->nGlyphs = locaLen / ((indexToLocFormat == 1) ? 4 : 2); - assert(res->nGlyphs != 0); - res->offs = static_cast<sal_uInt32*>(scalloc(res->nGlyphs, sizeof(sal_uInt32))); + this->nGlyphs = locaLen / ((indexToLocFormat == 1) ? 4 : 2); + assert(this->nGlyphs != 0); + this->offs = static_cast<sal_uInt32*>(scalloc(this->nGlyphs, sizeof(sal_uInt32))); - for (sal_uInt32 i = 0; i < res->nGlyphs; i++) { + for (sal_uInt32 i = 0; i < this->nGlyphs; i++) { if (indexToLocFormat == 1) { - res->offs[i] = GetUInt32(loca, i * 4); + this->offs[i] = GetUInt32(loca, i * 4); } else { - res->offs[i] = GetUInt16(loca, i * 2) << 1; + this->offs[i] = GetUInt16(loca, i * 2) << 1; } } - return res; } -static void GlyphOffsetsDispose(GlyphOffsets *_this) +GlyphOffsets::~GlyphOffsets() { - if (_this) { - free(_this->offs); - free(_this); - } + free(this->offs); } static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) @@ -2004,7 +1995,7 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) HexFmt h(outf); sal_uInt16 i, numTables = GetUInt16(sfntP, 4); - GlyphOffsets *go = GlyphOffsetsNew(sfntP, sfntLen); + GlyphOffsets go(sfntP, sfntLen); sal_uInt8 const pad[] = {0,0,0,0}; /* zeroes */ if (numTables > nMaxPossibleTables) @@ -2060,9 +2051,9 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) { sal_uInt8 *glyf = pRecordStart; sal_uInt8 *eof = pRecordStart + nMaxLenPossible; - for (sal_uInt32 j = 0; j < go->nGlyphs - 1; j++) + for (sal_uInt32 j = 0; j < go.nGlyphs - 1; j++) { - sal_uInt32 nStartOffset = go->offs[j]; + sal_uInt32 nStartOffset = go.offs[j]; sal_uInt8 *pSubRecordStart = glyf + nStartOffset; if (pSubRecordStart > eof) { @@ -2071,7 +2062,7 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) break; } - sal_uInt32 nEndOffset = go->offs[j + 1]; + sal_uInt32 nEndOffset = go.offs[j + 1]; sal_uInt8 *pSubRecordEnd = glyf + nEndOffset; if (pSubRecordEnd > eof) { @@ -2088,7 +2079,6 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) } h.CloseString(); fputs("] def\n", outf); - GlyphOffsetsDispose(go); free(offs); }
