summaryrefslogtreecommitdiff
path: root/vcl/source/fontsubset/sft.cxx
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 /vcl/source/fontsubset/sft.cxx
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>
Diffstat (limited to 'vcl/source/fontsubset/sft.cxx')
-rw-r--r--vcl/source/fontsubset/sft.cxx101
1 files changed, 82 insertions, 19 deletions
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();