summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-09-11 01:23:16 +0200
committerخالد حسني <khaled@aliftype.com>2022-09-11 09:51:53 +0200
commit4286e745bccc7393ecd8b06346306d13d23316b5 (patch)
treea3ee27126cf59c27eaa549c9c3e3a70e9860812f
parentaa0a71b5cec118d4a4a922f6833ff20d7e4ba8ba (diff)
vcl: Add a PhysicalFontFace-backed TrueTypeFont
This is mainly to be able to get the font table data from the PhysicalFontFace so that an actual font file or full font data are not required (since they are not always available, e.g. with CoreText fonts). This is slightly based on QtTrueTypeFont that this code replaces. Change-Id: I6926706dfc6765076100ac0314a30f9ff970ddb6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139760 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r--vcl/inc/sft.hxx35
-rw-r--r--vcl/qt5/QtGraphics_Text.cxx127
-rw-r--r--vcl/quartz/salgdicommon.cxx25
-rw-r--r--vcl/source/fontsubset/sft.cxx101
-rw-r--r--vcl/unx/generic/fontmanager/fontmanager.cxx19
-rw-r--r--vcl/win/gdi/salfont.cxx72
6 files changed, 146 insertions, 233 deletions
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index 75af2af8044e..88fa729fe6b8 100644
--- a/vcl/inc/sft.hxx
+++ b/vcl/inc/sft.hxx
@@ -50,6 +50,8 @@
#include <vector>
#include <cstdint>
+#include "font/PhysicalFontFace.hxx"
+
namespace vcl
{
@@ -450,6 +452,7 @@ constexpr sal_uInt32 T_CFF = 0x43464620;
class AbstractTrueTypeFont;
class TrueTypeFont;
+class TrueTypeFace;
/**
* @defgroup sft Sun Font Tools Exported Functions
@@ -664,7 +667,7 @@ class TrueTypeFont;
* @ingroup sft
*
*/
- VCL_DLLPUBLIC void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info);
+ VCL_DLLPUBLIC void GetTTGlobalFontInfo(AbstractTrueTypeFont *ttf, TTGlobalFontInfo *info);
/**
* Returns part of the head table info, normally collected by GetTTGlobalFontInfo.
@@ -736,6 +739,8 @@ public:
AbstractTrueTypeFont(const char* fileName = nullptr, const FontCharMapRef xCharMap = nullptr);
virtual ~AbstractTrueTypeFont();
+ SFErrCodes initialize();
+
std::string const & fileName() const { return m_sFileName; }
sal_uInt32 glyphCount() const { return m_nGlyphs; }
sal_uInt32 glyphOffset(sal_uInt32 glyphID) const;
@@ -746,6 +751,12 @@ public:
virtual bool hasTable(sal_uInt32 ord) const = 0;
virtual const sal_uInt8* table(sal_uInt32 ord, sal_uInt32& size) const = 0;
+
+ char *psname;
+ char *family;
+ sal_Unicode *ufamily;
+ char *subfamily;
+ sal_Unicode *usubfamily;
};
class TrueTypeFont final : public AbstractTrueTypeFont
@@ -761,13 +772,6 @@ class TrueTypeFont final : public AbstractTrueTypeFont
public:
sal_Int32 fsize;
sal_uInt8 *ptr;
-
- char *psname;
- char *family;
- sal_Unicode *ufamily;
- char *subfamily;
- sal_Unicode *usubfamily;
-
sal_uInt32 ntables;
TrueTypeFont(const char* pFileName = nullptr, const FontCharMapRef xCharMap = nullptr);
@@ -792,6 +796,21 @@ const sal_uInt8* TrueTypeFont::table(sal_uInt32 ord, sal_uInt32& size) const
return rTable.pData;
}
+class VCL_DLLPUBLIC TrueTypeFace final : public AbstractTrueTypeFont
+{
+ const font::PhysicalFontFace& m_rFace;
+ mutable std::array<font::RawFontData, NUM_TAGS> m_aTableList;
+
+ static sal_uInt32 TableTag(sal_uInt32);
+
+public:
+ TrueTypeFace(const font::PhysicalFontFace&);
+ ~TrueTypeFace() override;
+
+ bool hasTable(sal_uInt32) const override;
+ const sal_uInt8* table(sal_uInt32, sal_uInt32&) const override;
+};
+
} // namespace vcl
#endif // INCLUDED_VCL_INC_SFT_HXX
diff --git a/vcl/qt5/QtGraphics_Text.cxx b/vcl/qt5/QtGraphics_Text.cxx
index c8c59bc48cc3..69828ea82cc0 100644
--- a/vcl/qt5/QtGraphics_Text.cxx
+++ b/vcl/qt5/QtGraphics_Text.cxx
@@ -137,94 +137,7 @@ bool QtGraphics::AddTempDevFont(vcl::font::PhysicalFontCollection*, const OUStri
return false;
}
-namespace
-{
-class QtTrueTypeFont : public vcl::AbstractTrueTypeFont
-{
- const QRawFont& m_aRawFont;
- mutable QByteArray m_aFontTable[vcl::NUM_TAGS];
-
-public:
- QtTrueTypeFont(const QtFontFace& aFontFace, const QRawFont& aRawFont);
-
- bool hasTable(sal_uInt32 ord) const override;
- const sal_uInt8* table(sal_uInt32 ord, sal_uInt32& size) const override;
-};
-
-QtTrueTypeFont::QtTrueTypeFont(const QtFontFace& aFontFace, const QRawFont& aRawFont)
- : vcl::AbstractTrueTypeFont(nullptr, aFontFace.GetFontCharMap())
- , m_aRawFont(aRawFont)
-{
- indexGlyphData();
-}
-
-const char* vclFontTableAsChar(sal_uInt32 ord)
-{
- switch (ord)
- {
- case vcl::O_maxp:
- return "maxp";
- case vcl::O_glyf:
- return "glyf";
- case vcl::O_head:
- return "head";
- case vcl::O_loca:
- return "loca";
- case vcl::O_name:
- return "name";
- case vcl::O_hhea:
- return "hhea";
- case vcl::O_hmtx:
- return "hmtx";
- case vcl::O_cmap:
- return "cmap";
- case vcl::O_vhea:
- return "vhea";
- case vcl::O_vmtx:
- return "vmtx";
- case vcl::O_OS2:
- return "OS/2";
- case vcl::O_post:
- return "post";
- case vcl::O_cvt:
- return "cvt ";
- case vcl::O_prep:
- return "prep";
- case vcl::O_fpgm:
- return "fpgm";
- case vcl::O_gsub:
- return "gsub";
- case vcl::O_CFF:
- return "CFF ";
- default:
- return nullptr;
- }
-}
-
-bool QtTrueTypeFont::hasTable(sal_uInt32 ord) const
-{
- const char* table_char = vclFontTableAsChar(ord);
- if (!table_char)
- return false;
- if (m_aFontTable[ord].isEmpty())
- m_aFontTable[ord] = m_aRawFont.fontTable(table_char);
- return !m_aFontTable[ord].isEmpty();
-}
-
-const sal_uInt8* QtTrueTypeFont::table(sal_uInt32 ord, sal_uInt32& size) const
-{
- const char* table_char = vclFontTableAsChar(ord);
- if (!table_char)
- return nullptr;
- if (m_aFontTable[ord].isEmpty())
- m_aFontTable[ord] = m_aRawFont.fontTable(table_char);
- size = m_aFontTable[ord].size();
- return reinterpret_cast<const sal_uInt8*>(m_aFontTable[ord].data());
-}
-}
-
-bool QtGraphics::CreateFontSubset(const OUString& rToFile,
- const vcl::font::PhysicalFontFace* pFontFace,
+bool QtGraphics::CreateFontSubset(const OUString& rToFile, const vcl::font::PhysicalFontFace* pFace,
const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
int nGlyphCount, FontSubsetInfo& rInfo)
{
@@ -232,32 +145,26 @@ bool QtGraphics::CreateFontSubset(const OUString& rToFile,
if (osl_File_E_None != osl_getSystemPathFromFileURL(rToFile.pData, &aSysPath.pData))
return false;
- // get the raw-bytes from the font to be subset
- const QtFontFace* pQtFontFace = static_cast<const QtFontFace*>(pFontFace);
- const QFont aFont = pQtFontFace->CreateFont();
- const QRawFont aRawFont(QRawFont::fromFont(aFont));
const OString aToFile(OUStringToOString(aSysPath, osl_getThreadTextEncoding()));
// handle CFF-subsetting
- QByteArray aCFFtable = aRawFont.fontTable("CFF ");
- if (!aCFFtable.isEmpty())
- return SalGraphics::CreateCFFfontSubset(
- reinterpret_cast<const sal_uInt8*>(aCFFtable.data()), aCFFtable.size(), aToFile,
- pGlyphIds, pEncoding, nGlyphCount, rInfo);
-
- // fill details about the subsetted font
- rInfo.m_nFontType = FontType::SFNT_TTF;
- rInfo.m_aPSName = toOUString(aRawFont.familyName());
- rInfo.m_nCapHeight = aRawFont.capHeight();
- rInfo.m_nAscent = aRawFont.ascent();
- rInfo.m_nDescent = aRawFont.descent();
-
- QtTrueTypeFont aTTF(*pQtFontFace, aRawFont);
- int nXmin, nYmin, nXmax, nYmax;
- sal_uInt16 nMacStyleFlags;
- if (GetTTGlobalFontHeadInfo(&aTTF, nXmin, nYmin, nXmax, nYmax, nMacStyleFlags))
- rInfo.m_aFontBBox = tools::Rectangle(Point(nXmin, nYmin), Point(nXmax, nYmax));
+ auto aData = pFace->GetRawFontData(vcl::T_CFF);
+ if (!aData.empty())
+ return SalGraphics::CreateCFFfontSubset(aData.data(), aData.size(), aToFile, pGlyphIds,
+ pEncoding, nGlyphCount, rInfo);
+
+ // prepare data for psprint's font subsetter
+ vcl::TrueTypeFace aTTF(*pFace);
+ if (aTTF.initialize() != vcl::SFErrCodes::Ok)
+ return false;
+
+ // get details about the subsetted font
+ vcl::TTGlobalFontInfo aTTInfo;
+ vcl::GetTTGlobalFontInfo(&aTTF, &aTTInfo);
+ OUString aPSName(aTTInfo.psname, std::strlen(aTTInfo.psname), RTL_TEXTENCODING_UTF8);
+ FillFontSubsetInfo(aTTInfo, aPSName, rInfo);
+ // write subset into destination file
return SalGraphics::CreateTTFfontSubset(aTTF, aToFile, pGlyphIds, pEncoding, nGlyphCount);
}
diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx
index d9ca95d997a0..26ba9e86a4c7 100644
--- a/vcl/quartz/salgdicommon.cxx
+++ b/vcl/quartz/salgdicommon.cxx
@@ -47,7 +47,7 @@
using namespace vcl;
bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile,
- const vcl::font::PhysicalFontFace* pFontData,
+ const vcl::font::PhysicalFontFace* pFace,
const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
const int nGlyphCount,
FontSubsetInfo& rInfo )
@@ -59,18 +59,14 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile,
if( osl_File_E_None != osl_getSystemPathFromFileURL( rToFile.pData, &aSysPath.pData ) )
return false;
- // get the raw-bytes from the font to be subset
- std::vector<unsigned char> aBuffer;
- bool bCffOnly = false;
- if( !GetRawFontData( pFontData, aBuffer, &bCffOnly ) )
- return false;
const OString aToFile( OUStringToOString( aSysPath,
osl_getThreadTextEncoding()));
// handle CFF-subsetting
// NOTE: assuming that all glyphids requested on Aqua are fully translated
- if (bCffOnly)
- return SalGraphics::CreateCFFfontSubset(aBuffer.data(), aBuffer.size(), aToFile, pGlyphIds,
+ auto aData = pFace->GetRawFontData(T_CFF);
+ if (!aData.empty())
+ return SalGraphics::CreateCFFfontSubset(aData.data(), aData.size(), aToFile, pGlyphIds,
pEncoding, nGlyphCount, rInfo);
// TODO: modernize psprint's horrible fontsubset C-API
@@ -78,23 +74,18 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile,
// that can preserve change history after file renames
// prepare data for psprint's font subsetter
- TrueTypeFont* pSftFont = nullptr;
- if (::OpenTTFontBuffer( static_cast<void*>(aBuffer.data()), aBuffer.size(), 0, &pSftFont, pFontData->GetFontCharMap())
- != SFErrCodes::Ok)
+ TrueTypeFace aSftFont(*pFace);
+ if (aSftFont.initialize() != SFErrCodes::Ok)
return false;
// get details about the subsetted font
TTGlobalFontInfo aTTInfo;
- ::GetTTGlobalFontInfo( pSftFont, &aTTInfo );
+ ::GetTTGlobalFontInfo(&aSftFont, &aTTInfo);
OUString aPSName(aTTInfo.psname, std::strlen(aTTInfo.psname), RTL_TEXTENCODING_UTF8);
FillFontSubsetInfo(aTTInfo, aPSName, rInfo);
// write subset into destination file
- bool bRet
- = SalGraphics::CreateTTFfontSubset(*pSftFont, aToFile,
- pGlyphIds, pEncoding, nGlyphCount);
- ::CloseTTFont(pSftFont);
- return bRet;
+ return SalGraphics::CreateTTFfontSubset(aSftFont, aToFile, pGlyphIds, pEncoding, nGlyphCount);
}
#ifndef IOS
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 710172fbd8de..f5c857e83de4 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -963,7 +963,7 @@ static int findname( const sal_uInt8 *name, sal_uInt16 n, sal_uInt16 platformID,
* Fix: change algorithm, and use (1, 0, *) if both standard Mac and MS strings are not found
*/
-static void GetNames(TrueTypeFont *t)
+static void GetNames(AbstractTrueTypeFont *t)
{
sal_uInt32 nTableSize;
const sal_uInt8* table = t->table(O_name, nTableSize);
@@ -1201,6 +1201,11 @@ AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName, const FontChar
, m_nUnitsPerEm(0)
, m_xCharMap(xCharMap)
, m_bIsSymbolFont(false)
+ , psname(nullptr)
+ , family(nullptr)
+ , ufamily(nullptr)
+ , subfamily(nullptr)
+ , usubfamily(nullptr)
{
if (pFileName)
m_sFileName = pFileName;
@@ -1208,17 +1213,17 @@ AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName, const FontChar
AbstractTrueTypeFont::~AbstractTrueTypeFont()
{
+ free(psname);
+ free(family);
+ free(ufamily);
+ free(subfamily);
+ free(usubfamily);
}
TrueTypeFont::TrueTypeFont(const char* pFileName, const FontCharMapRef xCharMap)
: AbstractTrueTypeFont(pFileName, xCharMap)
, fsize(-1)
, ptr(nullptr)
- , psname(nullptr)
- , family(nullptr)
- , ufamily(nullptr)
- , subfamily(nullptr)
- , usubfamily(nullptr)
, ntables(0)
{
}
@@ -1229,15 +1234,79 @@ TrueTypeFont::~TrueTypeFont()
if (!fileName().empty())
munmap(ptr, fsize);
#endif
- free(psname);
- free(family);
- free(ufamily);
- free(subfamily);
- free(usubfamily);
+}
+
+TrueTypeFace::TrueTypeFace(const font::PhysicalFontFace& rFace)
+ : AbstractTrueTypeFont(nullptr, rFace.GetFontCharMap())
+ , m_rFace(rFace)
+{
+}
+
+TrueTypeFace::~TrueTypeFace()
+{
+}
+
+sal_uInt32 TrueTypeFace::TableTag(sal_uInt32 nIdx)
+{
+ switch (nIdx)
+ {
+ case O_cmap: return T_cmap;
+ case O_cvt: return T_cvt;
+ case O_fpgm: return T_fpgm;
+ case O_glyf: return T_glyf;
+ case O_gsub: return T_gsub;
+ case O_head: return T_head;
+ case O_hhea: return T_hhea;
+ case O_hmtx: return T_hmtx;
+ case O_loca: return T_loca;
+ case O_maxp: return T_maxp;
+ case O_name: return T_name;
+ case O_post: return T_post;
+ case O_prep: return T_prep;
+ case O_vhea: return T_vhea;
+ case O_vmtx: return T_vmtx;
+ case O_OS2: return T_OS2;
+ case O_CFF: return T_CFF;
+ default:
+ assert(false);
+ return 0;
+ }
+}
+
+bool TrueTypeFace::hasTable(sal_uInt32 nIdx) const
+{
+ uint32_t nTag = TableTag(nIdx);
+ if (!nTag)
+ return false;
+ if (m_aTableList[nIdx].empty())
+ m_aTableList[nIdx] = std::move(m_rFace.GetRawFontData(nTag));
+ return !m_aTableList[nIdx].empty();
+}
+
+const sal_uInt8* TrueTypeFace::table(sal_uInt32 nIdx, sal_uInt32& nSize) const
+{
+ uint32_t nTag = TableTag(nIdx);
+ if (!nTag)
+ return nullptr;
+ if (m_aTableList[nIdx].empty())
+ m_aTableList[nIdx] = std::move(m_rFace.GetRawFontData(nTag));
+ nSize = m_aTableList[nIdx].size();
+ return reinterpret_cast<const sal_uInt8*>(m_aTableList[nIdx].data());
}
void CloseTTFont(TrueTypeFont* ttf) { delete ttf; }
+SFErrCodes AbstractTrueTypeFont::initialize()
+{
+ SFErrCodes ret = indexGlyphData();
+ if (ret != SFErrCodes::Ok)
+ return ret;
+
+ GetNames(this);
+
+ return SFErrCodes::Ok;
+}
+
sal_uInt32 AbstractTrueTypeFont::glyphOffset(sal_uInt32 glyphID) const
{
if (m_aGlyphOffsets.empty()) // the O_CFF and Bitmap cases
@@ -1445,13 +1514,7 @@ SFErrCodes TrueTypeFont::open(sal_uInt32 facenum)
/* At this point TrueTypeFont is constructed, now need to verify the font format
and read the basic font properties */
- SFErrCodes ret = indexGlyphData();
- if (ret != SFErrCodes::Ok)
- return ret;
-
- GetNames(this);
-
- return SFErrCodes::Ok;
+ return AbstractTrueTypeFont::initialize();
}
int GetTTGlyphPoints(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, ControlPoint **pointArray)
@@ -2159,7 +2222,7 @@ bool GetTTGlobalFontHeadInfo(const AbstractTrueTypeFont *ttf, int& xMin, int& yM
return true;
}
-void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info)
+void GetTTGlobalFontInfo(AbstractTrueTypeFont *ttf, TTGlobalFontInfo *info)
{
int UPEm = ttf->unitsPerEm();
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index 33ccb9987dad..1aed1a37d1d4 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -984,12 +984,8 @@ bool PrintFontManager::createFontSubset(
}
nGlyphs = nChar; // either input value or increased by one
- // prepare system name for read access for subset source file
- // TODO: since this file is usually already mmapped there is no need to open it again
- const OString aFromFile = getFontFile( *pFont );
-
- TrueTypeFont* pTTFont = nullptr; // TODO: rename to SfntFont
- if( OpenTTFontFile( aFromFile.getStr(), pFont->m_nCollectionEntry, &pTTFont, pFace->GetFontCharMap() ) != SFErrCodes::Ok )
+ TrueTypeFace aSftFont(*pFace);
+ if (aSftFont.initialize() != SFErrCodes::Ok)
return false;
// prepare system name for write access for subset file target
@@ -1001,7 +997,7 @@ bool PrintFontManager::createFontSubset(
// do CFF subsetting if possible
sal_uInt32 nCffLength = 0;
- const sal_uInt8* pCffBytes = pTTFont->table(vcl::O_CFF, nCffLength);
+ const sal_uInt8* pCffBytes = aSftFont.table(vcl::O_CFF, nCffLength);
if (pCffBytes)
{
rInfo.LoadFont( FontType::CFF_FONT, pCffBytes, nCffLength );
@@ -1013,10 +1009,7 @@ bool PrintFontManager::createFontSubset(
// create subset file at requested path
FILE* pOutFile = fopen( aToFile.getStr(), "wb" );
if (!pOutFile)
- {
- CloseTTFont( pTTFont );
return false;
- }
// create font subset
const char* const pGlyphSetName = nullptr; // TODO: better name?
const bool bOK = rInfo.CreateFontSubset(
@@ -1031,8 +1024,6 @@ bool PrintFontManager::createFontSubset(
rInfo.m_nAscent = aFontInfo.m_nAscend;
rInfo.m_nDescent = -aFontInfo.m_nDescend;
}
- // cleanup before early return
- CloseTTFont( pTTFont );
return bOK;
}
@@ -1051,13 +1042,11 @@ bool PrintFontManager::createFontSubset(
rInfo.m_aFontBBox = tools::Rectangle( Point( xMin, yMin ), Size( xMax-xMin, yMax-yMin ) );
rInfo.m_nCapHeight = yMax; // Well ...
- bool bSuccess = ( SFErrCodes::Ok == CreateTTFromTTGlyphs( pTTFont,
+ bool bSuccess = ( SFErrCodes::Ok == CreateTTFromTTGlyphs(&aSftFont,
aToFile.getStr(),
pGID,
pEnc,
nGlyphs ) );
- CloseTTFont( pTTFont );
-
return bSuccess;
}
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 3cc5f3bedd32..e116ad049449 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1491,57 +1491,12 @@ private:
HFONT m_hOrigFont;
};
-class ScopedTrueTypeFont
-{
-public:
- ScopedTrueTypeFont(): m_pFont(nullptr) {}
-
- ~ScopedTrueTypeFont();
-
- SFErrCodes open(void const * pBuffer, sal_uInt32 nLen, sal_uInt32 nFaceNum, const FontCharMapRef xCharMap = nullptr);
-
- TrueTypeFont * get() const { return m_pFont; }
-
-private:
- TrueTypeFont * m_pFont;
-};
-
-}
-
-ScopedTrueTypeFont::~ScopedTrueTypeFont()
-{
- if (m_pFont != nullptr)
- CloseTTFont(m_pFont);
-}
-
-SFErrCodes ScopedTrueTypeFont::open(void const * pBuffer, sal_uInt32 nLen,
- sal_uInt32 nFaceNum, const FontCharMapRef xCharMap)
-{
- OSL_ENSURE(m_pFont == nullptr, "already open");
- return OpenTTFontBuffer(pBuffer, nLen, nFaceNum, &m_pFont, xCharMap);
}
-static DWORD CalcTag( const char p[5]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); }
-
bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
- const vcl::font::PhysicalFontFace* pFont, const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
+ const vcl::font::PhysicalFontFace* pFace, const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
int nGlyphCount, FontSubsetInfo& rInfo )
{
- ScopedFontHDC aScopedFontHDC(*this, *pFont);
- HDC hDC = aScopedFontHDC.hdc();
- if (!hDC)
- return false;
-
-#if OSL_DEBUG_LEVEL > 1
- // get font metrics
- TEXTMETRICW aWinMetric;
- if (!::GetTextMetricsW(hDC, &aWinMetric))
- return false;
-
- SAL_WARN_IF( (aWinMetric.tmPitchAndFamily & TMPF_DEVICE), "vcl", "cannot subset device font" );
- SAL_WARN_IF( !(aWinMetric.tmPitchAndFamily & TMPF_TRUETYPE), "vcl", "can only subset TT font" );
-#endif
-
OUString aSysPath;
if( osl_File_E_None != osl_getSystemPathFromFileURL( rToFile.pData, &aSysPath.pData ) )
return false;
@@ -1549,35 +1504,24 @@ bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
const OString aToFile(OUStringToOString(aSysPath, aThreadEncoding));
// check if the font has a CFF-table
- const DWORD nCffTag = CalcTag( "CFF " );
- const RawFontData aRawCffData(hDC, nCffTag);
- if (aRawCffData.get())
- return SalGraphics::CreateCFFfontSubset(aRawCffData.get(), aRawCffData.size(), aToFile,
+ auto aData = pFace->GetRawFontData(T_CFF);
+ if (!aData.empty())
+ return SalGraphics::CreateCFFfontSubset(aData.data(), aData.size(), aToFile,
pGlyphIds, pEncoding, nGlyphCount,
rInfo);
- // get raw font file data
- const RawFontData xRawFontData(hDC, 0);
- if( !xRawFontData.get() )
- return false;
-
// open font file
- sal_uInt32 nFaceNum = 0;
- if( !*xRawFontData.get() ) // TTC candidate
- nFaceNum = ~0U; // indicate "TTC font extracts only"
-
- ScopedTrueTypeFont aSftTTF;
- SFErrCodes nRC = aSftTTF.open( xRawFontData.get(), xRawFontData.size(), nFaceNum, pFont->GetFontCharMap());
- if( nRC != SFErrCodes::Ok )
+ TrueTypeFace aSftTTF(*pFace);
+ if (aSftTTF.initialize() != SFErrCodes::Ok)
return false;
TTGlobalFontInfo aTTInfo;
- ::GetTTGlobalFontInfo( aSftTTF.get(), &aTTInfo );
+ ::GetTTGlobalFontInfo(&aSftTTF, &aTTInfo);
OUString aPSName = ImplSalGetUniString(aTTInfo.psname);
FillFontSubsetInfo(aTTInfo, aPSName, rInfo);
// write subset into destination file
- return SalGraphics::CreateTTFfontSubset(*aSftTTF.get(), aToFile,
+ return SalGraphics::CreateTTFfontSubset(aSftTTF, aToFile,
pGlyphIds, pEncoding, nGlyphCount);
}