Kaydet (Commit) d469dca4 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 21614aad
......@@ -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)
/**
......
......@@ -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()));
......
......@@ -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,
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment