summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2018-09-15 21:14:33 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-09-19 10:09:33 +0200
commitd469dca492e55798251c7f570bb730a38c32e893 (patch)
tree808c559f6dc8f7887dfd27eef318607e2df5f6ba /vcl
parent21614aadc2b7a7bb6d2e00a5a081d8d233e4384b (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')
-rw-r--r--vcl/inc/sft.hxx7
-rw-r--r--vcl/quartz/salgdi.cxx6
-rw-r--r--vcl/quartz/salgdicommon.cxx12
-rw-r--r--vcl/source/fontsubset/sft.cxx22
-rw-r--r--vcl/unx/generic/fontmanager/fontmanager.cxx12
-rw-r--r--vcl/win/gdi/salfont.cxx18
6 files changed, 33 insertions, 44 deletions
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index c09834adeaef..00cf119a4ca4 100644
--- a/vcl/inc/sft.hxx
+++ b/vcl/inc/sft.hxx
@@ -49,6 +49,7 @@
#include <vcl/fontcapabilities.hxx>
#include <i18nlangtag/lang.h>
+#include <memory>
#include <vector>
#include <cstdint>
@@ -113,7 +114,7 @@ namespace vcl
OVERLAP_COMPOUND = 1<<10
};
-/** Structure used by GetTTSimpleGlyphMetrics() and GetTTSimpleCharMetrics() functions */
+/** Structure used by GetTTSimpleCharMetrics() functions */
typedef struct {
sal_uInt16 adv; /**< advance width or height */
sal_Int16 sb; /**< left or top sidebearing */
@@ -377,7 +378,7 @@ namespace vcl
int nGlyphs);
/**
- * Queries glyph metrics. Allocates an array of TTSimpleGlyphMetrics structs and returns it.
+ * Queries glyph metrics. Allocates an array of advance width/height values and returns it.
*
* @param ttf pointer to the TrueTypeFont structure
* @param glyphArray pointer to an array of glyphs that are to be extracted from ttf
@@ -386,7 +387,7 @@ namespace vcl
* @ingroup sft
*
*/
- 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);
#if defined(_WIN32) || defined(MACOSX) || defined(IOS)
/**
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index db595a5aa37b..43ca506220c9 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -756,15 +756,15 @@ void AquaSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFontData, bool bV
aGlyphIds[i] = static_cast<sal_uInt16>(i);
}
- const TTSimpleGlyphMetrics* pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, &aGlyphIds[0],
+ std::unique_ptr<sal_uInt16[]> pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, &aGlyphIds[0],
nGlyphCount, bVertical );
if( pGlyphMetrics )
{
for( int i = 0; i < nGlyphCount; ++i )
{
- rGlyphWidths[i] = pGlyphMetrics[i].adv;
+ rGlyphWidths[i] = pGlyphMetrics[i];
}
- free( const_cast<TTSimpleGlyphMetrics *>(pGlyphMetrics) );
+ pGlyphMetrics.reset();
}
rtl::Reference<CoreTextFontFace> rCTFontData(new CoreTextFontFace(*pFontData, pFontData->GetFontId()));
diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx
index 59d836506b52..2d952244847e 100644
--- a/vcl/quartz/salgdicommon.cxx
+++ b/vcl/quartz/salgdicommon.cxx
@@ -302,21 +302,21 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile,
// fill the pGlyphWidths array
// while making sure that the NotDef glyph is at index==0
- TTSimpleGlyphMetrics* pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, aShortIDs,
+ std::unique_ptr<sal_uInt16[]> pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, aShortIDs,
nGlyphCount, bVertical );
if( !pGlyphMetrics )
{
return false;
}
- sal_uInt16 nNotDefAdv = pGlyphMetrics[0].adv;
- pGlyphMetrics[0].adv = pGlyphMetrics[nNotDef].adv;
- pGlyphMetrics[nNotDef].adv = nNotDefAdv;
+ sal_uInt16 nNotDefAdv = pGlyphMetrics[0];
+ pGlyphMetrics[0] = pGlyphMetrics[nNotDef];
+ pGlyphMetrics[nNotDef] = nNotDefAdv;
for( int i = 0; i < nOrigCount; ++i )
{
- pGlyphWidths[i] = pGlyphMetrics[i].adv;
+ pGlyphWidths[i] = pGlyphMetrics[i];
}
- free( pGlyphMetrics );
+ pGlyphMetrics.reset();
// write subset into destination file
nRC = ::CreateTTFromTTGlyphs( pSftFont, aToFile.getStr(), aShortIDs,
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;
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index 8b6ad13471a0..abd2c6c30232 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -1078,15 +1078,15 @@ bool PrintFontManager::createFontSubset(
rInfo.m_nCapHeight = yMax; // Well ...
// fill in glyph advance widths
- TTSimpleGlyphMetrics* pMetrics = GetTTSimpleGlyphMetrics( pTTFont,
+ std::unique_ptr<sal_uInt16[]> pMetrics = GetTTSimpleGlyphMetrics( pTTFont,
pGID,
nGlyphs,
false/*bVertical*/ );
if( pMetrics )
{
for( int i = 0; i < nGlyphs; i++ )
- pWidths[pOldIndex[i]] = pMetrics[i].adv;
- free( pMetrics );
+ pWidths[pOldIndex[i]] = pMetrics[i];
+ pMetrics.reset();
}
else
{
@@ -1123,15 +1123,15 @@ void PrintFontManager::getGlyphWidths( fontID nFont,
std::vector<sal_uInt16> aGlyphIds(nGlyphs);
for (int i = 0; i < nGlyphs; i++)
aGlyphIds[i] = sal_uInt16(i);
- TTSimpleGlyphMetrics* pMetrics = GetTTSimpleGlyphMetrics(pTTFont,
+ std::unique_ptr<sal_uInt16[]> pMetrics = GetTTSimpleGlyphMetrics(pTTFont,
&aGlyphIds[0],
nGlyphs,
bVertical);
if (pMetrics)
{
for (int i = 0; i< nGlyphs; i++)
- rWidths[i] = pMetrics[i].adv;
- free(pMetrics);
+ rWidths[i] = pMetrics[i];
+ pMetrics.reset();
rUnicodeEnc.clear();
}
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index fdffffecd037..d49040201cd7 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1737,16 +1737,16 @@ bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
SAL_WARN_IF( nGlyphCount >= 257, "vcl", "too many glyphs for subsetting" );
// fill pWidth array
- TTSimpleGlyphMetrics* pMetrics =
+ std::unique_ptr<sal_uInt16[]> pMetrics =
::GetTTSimpleGlyphMetrics( aSftTTF.get(), aShortIDs, nGlyphCount, aIFSD.mbVertical );
if( !pMetrics )
return FALSE;
- sal_uInt16 nNotDefAdv = pMetrics[0].adv;
- pMetrics[0].adv = pMetrics[nNotDef].adv;
- pMetrics[nNotDef].adv = nNotDefAdv;
+ sal_uInt16 nNotDefAdv = pMetrics[0];
+ pMetrics[0] = pMetrics[nNotDef];
+ pMetrics[nNotDef] = nNotDefAdv;
for( i = 0; i < nOrigCount; ++i )
- pGlyphWidths[i] = pMetrics[i].adv;
- free( pMetrics );
+ pGlyphWidths[i] = pMetrics[i];
+ pMetrics.reset();
// write subset into destination file
nRC = ::CreateTTFromTTGlyphs( aSftTTF.get(), aToFile.getStr(), aShortIDs,
@@ -1819,15 +1819,15 @@ void WinSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
std::vector<sal_uInt16> aGlyphIds(nGlyphs);
for( int i = 0; i < nGlyphs; i++ )
aGlyphIds[i] = sal_uInt16(i);
- TTSimpleGlyphMetrics* pMetrics = ::GetTTSimpleGlyphMetrics( aSftTTF.get(),
+ std::unique_ptr<sal_uInt16[]> pMetrics = ::GetTTSimpleGlyphMetrics( aSftTTF.get(),
&aGlyphIds[0],
nGlyphs,
bVertical );
if( pMetrics )
{
for( int i = 0; i< nGlyphs; i++ )
- rWidths[i] = pMetrics[i].adv;
- free( pMetrics );
+ rWidths[i] = pMetrics[i];
+ pMetrics.reset();
rUnicodeEnc.clear();
}
const WinFontFace* pWinFont = static_cast<const WinFontFace*>(pFont);