diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2018-09-15 21:14:33 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-19 10:09:33 +0200 |
commit | d469dca492e55798251c7f570bb730a38c32e893 (patch) | |
tree | 808c559f6dc8f7887dfd27eef318607e2df5f6ba /vcl/source/fontsubset | |
parent | 21614aadc2b7a7bb6d2e00a5a081d8d233e4384b (diff) |
loplugin:useuniqueptr in GetTTSimpleGlyphMetrics
and only return the advance, we don't use the other field
Change-Id: I956033dac97763caea2b27404fe9f099da809899
Reviewed-on: https://gerrit.libreoffice.org/60703
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/fontsubset')
-rw-r--r-- | vcl/source/fontsubset/sft.cxx | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 40a5e0bf0999..1f3634b38320 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -2306,7 +2306,7 @@ bool GetSfntTable( TrueTypeFont const * ttf, int nSubtableIndex, return bOk; } -TTSimpleGlyphMetrics *GetTTSimpleGlyphMetrics(TrueTypeFont const *ttf, const sal_uInt16 *glyphArray, int nGlyphs, bool vertical) +std::unique_ptr<sal_uInt16[]> GetTTSimpleGlyphMetrics(TrueTypeFont const *ttf, const sal_uInt16 *glyphArray, int nGlyphs, bool vertical) { const sal_uInt8* pTable; sal_uInt32 n; @@ -2325,36 +2325,24 @@ TTSimpleGlyphMetrics *GetTTSimpleGlyphMetrics(TrueTypeFont const *ttf, const sal if (!nGlyphs || !glyphArray) return nullptr; /* invalid parameters */ if (!n || !pTable) return nullptr; /* the font does not contain the requested metrics */ - TTSimpleGlyphMetrics* res = static_cast<TTSimpleGlyphMetrics*>(calloc(nGlyphs, sizeof(TTSimpleGlyphMetrics))); - assert(res != nullptr); + std::unique_ptr<sal_uInt16[]> res(new sal_uInt16[nGlyphs]); const int UPEm = ttf->unitsPerEm; for( int i = 0; i < nGlyphs; ++i) { - int nAdvOffset, nLsbOffset; + int nAdvOffset; sal_uInt16 glyphID = glyphArray[i]; if (glyphID < n) { nAdvOffset = 4 * glyphID; - nLsbOffset = nAdvOffset + 2; } else { nAdvOffset = 4 * (n - 1); - if( glyphID < ttf->nglyphs ) - nLsbOffset = 4 * n + 2 * (glyphID - n); - else /* font is broken -> use lsb of last hmetrics */ - nLsbOffset = nAdvOffset + 2; } if( nAdvOffset >= nTableSize) - res[i].adv = 0; /* better than a crash for buggy fonts */ + res[i] = 0; /* better than a crash for buggy fonts */ else - res[i].adv = static_cast<sal_uInt16>( + res[i] = static_cast<sal_uInt16>( XUnits( UPEm, GetUInt16( pTable, nAdvOffset) ) ); - - if( nLsbOffset >= nTableSize) - res[i].sb = 0; /* better than a crash for buggy fonts */ - else - res[i].sb = static_cast<sal_Int16>( - XUnits( UPEm, GetInt16( pTable, nLsbOffset) ) ); } return res; |