vcl/inc/salgdi.hxx                   |   15 -----
 vcl/inc/sft.hxx                      |   15 +++++
 vcl/source/font/PhysicalFontFace.cxx |    8 +-
 vcl/source/fontsubset/sft.cxx        |   96 +++++++++++++++++++++++++++++++++
 vcl/source/gdi/salgdilayout.cxx      |   99 -----------------------------------
 5 files changed, 115 insertions(+), 118 deletions(-)

New commits:
commit 1bf6acf0fe438194d76e7fb2f605ed26c7914f55
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Sun Sep 11 16:07:34 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Tue Sep 13 15:28:12 2022 +0200

    vcl: Move subsetting helper functions to sft.cxx
    
    No functional change.
    
    Change-Id: I8de9117c1b1b1fef251e2711287dbdadaccc4d74
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139799
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index 4521785e3971..a0f8a22df7b3 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -44,7 +44,6 @@ namespace vcl::font {
 }
 class SalLayout;
 namespace tools { class Rectangle; }
-class FontSubsetInfo;
 class OutputDevice;
 class FreetypeFont;
 struct SystemGraphicsData;
@@ -630,20 +629,6 @@ protected:
 
     std::unique_ptr<vcl::WidgetDrawInterface> m_pWidgetDraw;
     vcl::WidgetDrawInterface* forWidget() { return m_pWidgetDraw ? 
m_pWidgetDraw.get() : this; }
-
-public:
-    static bool CreateTTFfontSubset(vcl::AbstractTrueTypeFont& aTTF, const 
OString& rSysPath,
-                                    const sal_GlyphId* pGlyphIds,
-                                    const sal_uInt8* pEncoding,
-                                    int nGlyphCount);
-
-    static bool CreateCFFfontSubset(const unsigned char* pFontBytes, int 
nByteLength,
-                                    const OString& rSysPath, const 
sal_GlyphId* pGlyphIds,
-                                    const sal_uInt8* pEncoding,
-                                    int nGlyphCount, FontSubsetInfo& rInfo);
-
-    static void FillFontSubsetInfo(const vcl::TTGlobalFontInfo& rTTInfo, const 
OUString& pPSName,
-                                   FontSubsetInfo& rInfo);
 };
 
 bool SalGraphics::IsNativeControlSupported(ControlType eType, ControlPart 
ePart)
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index 88fa729fe6b8..ccadaeb8d0b5 100644
--- a/vcl/inc/sft.hxx
+++ b/vcl/inc/sft.hxx
@@ -619,6 +619,21 @@ class TrueTypeFace;
                               sal_uInt8 const *encoding,
                               int            nGlyphs);
 
+    VCL_DLLPUBLIC bool CreateTTFfontSubset(AbstractTrueTypeFont& aTTF,
+                              const OString& rSysPath,
+                              const sal_GlyphId* pGlyphIds,
+                              const sal_uInt8* pEncoding,
+                              int nGlyphCount);
+
+    VCL_DLLPUBLIC bool CreateCFFfontSubset(const unsigned char* pFontBytes,
+                              int nByteLength,
+                              const OString& rSysPath, const sal_GlyphId* 
pGlyphIds,
+                              const sal_uInt8* pEncoding,
+                              int nGlyphCount, FontSubsetInfo& rInfo);
+
+    VCL_DLLPUBLIC void FillFontSubsetInfo(const TTGlobalFontInfo& rTTInfo,
+                              const OUString& pPSName,
+                              FontSubsetInfo& rInfo);
 /**
  * Generates a new PostScript Type42 font and dumps it to <b>outf</b> file.
  * This function substitutes glyph 0 for all glyphIDs that are not found in 
the font.
diff --git a/vcl/source/font/PhysicalFontFace.cxx 
b/vcl/source/font/PhysicalFontFace.cxx
index 10a1048dcf79..245eab3ed88e 100644
--- a/vcl/source/font/PhysicalFontFace.cxx
+++ b/vcl/source/font/PhysicalFontFace.cxx
@@ -298,8 +298,8 @@ bool PhysicalFontFace::CreateFontSubset(const OUString& 
rToFile, const sal_Glyph
     // Shortcut for CFF-subsetting.
     auto aData = GetRawFontData(T_CFF);
     if (!aData.empty())
-        return SalGraphics::CreateCFFfontSubset(aData.data(), aData.size(), 
aToFile, pGlyphIds,
-                                                pEncoding, nGlyphCount, rInfo);
+        return CreateCFFfontSubset(aData.data(), aData.size(), aToFile, 
pGlyphIds, pEncoding,
+                                   nGlyphCount, rInfo);
 
     // Prepare data for font subsetter.
     TrueTypeFace aSftFont(*this);
@@ -310,10 +310,10 @@ bool PhysicalFontFace::CreateFontSubset(const OUString& 
rToFile, const sal_Glyph
     TTGlobalFontInfo aTTInfo;
     GetTTGlobalFontInfo(&aSftFont, &aTTInfo);
     OUString aPSName(aTTInfo.psname, std::strlen(aTTInfo.psname), 
RTL_TEXTENCODING_UTF8);
-    SalGraphics::FillFontSubsetInfo(aTTInfo, aPSName, rInfo);
+    FillFontSubsetInfo(aTTInfo, aPSName, rInfo);
 
     // write subset into destination file
-    return SalGraphics::CreateTTFfontSubset(aSftFont, aToFile, pGlyphIds, 
pEncoding, nGlyphCount);
+    return CreateTTFfontSubset(aSftFont, aToFile, pGlyphIds, pEncoding, 
nGlyphCount);
 }
 }
 
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index f5c857e83de4..1e270805fb90 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -1860,6 +1860,79 @@ SFErrCodes CreateTTFromTTGlyphs(AbstractTrueTypeFont  
*ttf,
     return res;
 }
 
+bool CreateTTFfontSubset(vcl::AbstractTrueTypeFont& rTTF, const OString& 
rSysPath,
+                         const sal_GlyphId* pGlyphIds, const sal_uInt8* 
pEncoding,
+                         const int nOrigGlyphCount)
+{
+    // Multiple questions:
+    // - Why is there a glyph limit?
+    //   MacOS used to handle 257 glyphs...
+    //   Also the much more complex PrintFontManager variant has this limit.
+    //   Also the very first implementation has the limit in
+    //   commit 8789ed701e98031f2a1657ea0dfd6f7a0b050992
+    // - Why doesn't the PrintFontManager care about the fake glyph? It
+    //   is used on all unx platforms to create the subset font.
+    // - Should the SAL_WARN actually be asserts, like on MacOS?
+    if (nOrigGlyphCount > 256)
+    {
+        SAL_WARN("vcl.fonts", "too many glyphs for subsetting");
+        return false;
+    }
+
+    int nGlyphCount = nOrigGlyphCount;
+    sal_uInt16 aShortIDs[256];
+    sal_uInt8 aTempEncs[256];
+
+    // handle the undefined / first font glyph
+    int nNotDef = -1, i;
+    for (i = 0; i < nGlyphCount; ++i)
+    {
+        aTempEncs[i] = pEncoding[i];
+        aShortIDs[i] = static_cast<sal_uInt16>(pGlyphIds[i]);
+        if (!aShortIDs[i])
+            if (nNotDef < 0)
+                nNotDef = i;
+    }
+
+    // nNotDef glyph must be in pos 0 => swap glyphids
+    if (nNotDef != 0)
+    {
+        if (nNotDef < 0)
+        {
+            if (nGlyphCount == 256)
+            {
+                SAL_WARN("vcl.fonts", "too many glyphs for subsetting");
+                return false;
+            }
+            nNotDef = nGlyphCount++;
+        }
+
+        aShortIDs[nNotDef] = aShortIDs[0];
+        aTempEncs[nNotDef] = aTempEncs[0];
+        aShortIDs[0] = 0;
+        aTempEncs[0] = 0;
+    }
+
+    // write subset into destination file
+    return (CreateTTFromTTGlyphs(&rTTF, rSysPath.getStr(), aShortIDs, 
aTempEncs, nGlyphCount)
+            == vcl::SFErrCodes::Ok);
+}
+
+bool CreateCFFfontSubset(const unsigned char* pFontBytes, int nByteLength,
+                         const OString& rSysPath, const sal_GlyphId* pGlyphIds,
+                         const sal_uInt8* pEncoding, int nGlyphCount,
+                         FontSubsetInfo& rInfo)
+{
+    FILE* pOutFile = fopen(rSysPath.getStr(), "wb");
+    if (!pOutFile)
+        return false;
+    rInfo.LoadFont(FontType::CFF_FONT, pFontBytes, nByteLength);
+    bool bRet = rInfo.CreateFontSubset(FontType::TYPE1_PFB, pOutFile, nullptr, 
pGlyphIds, pEncoding,
+                                       nGlyphCount);
+    fclose(pOutFile);
+    return bRet;
+}
+
 static GlyphOffsets *GlyphOffsetsNew(sal_uInt8 *sfntP, sal_uInt32 sfntLen)
 {
     GlyphOffsets* res = 
static_cast<GlyphOffsets*>(smalloc(sizeof(GlyphOffsets)));
@@ -2275,6 +2348,29 @@ void GetTTGlobalFontInfo(AbstractTrueTypeFont *ttf, 
TTGlobalFontInfo *info)
     }
 }
 
+void FillFontSubsetInfo(const vcl::TTGlobalFontInfo& rTTInfo, const OUString& 
pPSName,
+                        FontSubsetInfo& rInfo)
+{
+    rInfo.m_aPSName = pPSName;
+    rInfo.m_nFontType = FontType::SFNT_TTF;
+    rInfo.m_aFontBBox
+        = tools::Rectangle(Point(rTTInfo.xMin, rTTInfo.yMin), 
Point(rTTInfo.xMax, rTTInfo.yMax));
+    rInfo.m_nCapHeight = rTTInfo.yMax; // Well ...
+    rInfo.m_nAscent = rTTInfo.winAscent;
+    rInfo.m_nDescent = rTTInfo.winDescent;
+
+    // mac fonts usually do not have an OS2-table
+    // => get valid ascent/descent values from other tables
+    if (!rInfo.m_nAscent)
+        rInfo.m_nAscent = +rTTInfo.typoAscender;
+    if (!rInfo.m_nAscent)
+        rInfo.m_nAscent = +rTTInfo.ascender;
+    if (!rInfo.m_nDescent)
+        rInfo.m_nDescent = +rTTInfo.typoDescender;
+    if (!rInfo.m_nDescent)
+        rInfo.m_nDescent = -rTTInfo.descender;
+}
+
 GlyphData *GetTTRawGlyphData(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID)
 {
     if (glyphID >= ttf->glyphCount())
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 5bb6e43c3420..07757614b087 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -23,10 +23,8 @@
 #include <config_features.h>
 #include <sal/log.hxx>
 #include <font/PhysicalFontFace.hxx>
-#include <fontsubset.hxx>
 #include <salgdi.hxx>
 #include <salframe.hxx>
-#include <sft.hxx>
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <FileDefinitionWidgetDraw.hxx>
@@ -928,101 +926,4 @@ OUString SalGraphics::getRenderBackendName() const
     return OUString();
 }
 
-bool SalGraphics::CreateTTFfontSubset(vcl::AbstractTrueTypeFont& rTTF, const 
OString& rSysPath,
-                                   const sal_GlyphId* pGlyphIds,
-                                   const sal_uInt8* pEncoding,
-                                   const int nOrigGlyphCount)
-{
-    // Multiple questions:
-    // - Why is there a glyph limit?
-    //   MacOS used to handle 257 glyphs...
-    //   Also the much more complex PrintFontManager variant has this limit.
-    //   Also the very first implementation has the limit in
-    //   commit 8789ed701e98031f2a1657ea0dfd6f7a0b050992
-    // - Why doesn't the PrintFontManager care about the fake glyph? It
-    //   is used on all unx platforms to create the subset font.
-    // - Should the SAL_WARN actually be asserts, like on MacOS?
-    if (nOrigGlyphCount > 256)
-    {
-        SAL_WARN("vcl.fonts", "too many glyphs for subsetting");
-        return false;
-    }
-
-    int nGlyphCount = nOrigGlyphCount;
-    sal_uInt16 aShortIDs[256];
-    sal_uInt8 aTempEncs[256];
-
-    // handle the undefined / first font glyph
-    int nNotDef = -1, i;
-    for (i = 0; i < nGlyphCount; ++i)
-    {
-        aTempEncs[i] = pEncoding[i];
-        aShortIDs[i] = static_cast<sal_uInt16>(pGlyphIds[i]);
-        if (!aShortIDs[i])
-            if (nNotDef < 0)
-                nNotDef = i;
-    }
-
-    // nNotDef glyph must be in pos 0 => swap glyphids
-    if (nNotDef != 0)
-    {
-        if (nNotDef < 0)
-        {
-            if (nGlyphCount == 256)
-            {
-                SAL_WARN("vcl.fonts", "too many glyphs for subsetting");
-                return false;
-            }
-            nNotDef = nGlyphCount++;
-        }
-
-        aShortIDs[nNotDef] = aShortIDs[0];
-        aTempEncs[nNotDef] = aTempEncs[0];
-        aShortIDs[0] = 0;
-        aTempEncs[0] = 0;
-    }
-
-    // write subset into destination file
-    return (CreateTTFromTTGlyphs(&rTTF, rSysPath.getStr(), aShortIDs, 
aTempEncs, nGlyphCount)
-            == vcl::SFErrCodes::Ok);
-}
-
-bool SalGraphics::CreateCFFfontSubset(const unsigned char* pFontBytes, int 
nByteLength,
-                                      const OString& rSysPath, const 
sal_GlyphId* pGlyphIds,
-                                      const sal_uInt8* pEncoding,
-                                      int nGlyphCount, FontSubsetInfo& rInfo)
-{
-    FILE* pOutFile = fopen(rSysPath.getStr(), "wb");
-    if (!pOutFile)
-        return false;
-    rInfo.LoadFont(FontType::CFF_FONT, pFontBytes, nByteLength);
-    bool bRet = rInfo.CreateFontSubset(FontType::TYPE1_PFB, pOutFile, nullptr, 
pGlyphIds, pEncoding,
-                                       nGlyphCount);
-    fclose(pOutFile);
-    return bRet;
-}
-
-void SalGraphics::FillFontSubsetInfo(const vcl::TTGlobalFontInfo& rTTInfo, 
const OUString& pPSName,
-                                     FontSubsetInfo& rInfo)
-{
-    rInfo.m_aPSName = pPSName;
-    rInfo.m_nFontType = FontType::SFNT_TTF;
-    rInfo.m_aFontBBox
-        = tools::Rectangle(Point(rTTInfo.xMin, rTTInfo.yMin), 
Point(rTTInfo.xMax, rTTInfo.yMax));
-    rInfo.m_nCapHeight = rTTInfo.yMax; // Well ...
-    rInfo.m_nAscent = rTTInfo.winAscent;
-    rInfo.m_nDescent = rTTInfo.winDescent;
-
-    // mac fonts usually do not have an OS2-table
-    // => get valid ascent/descent values from other tables
-    if (!rInfo.m_nAscent)
-        rInfo.m_nAscent = +rTTInfo.typoAscender;
-    if (!rInfo.m_nAscent)
-        rInfo.m_nAscent = +rTTInfo.ascender;
-    if (!rInfo.m_nDescent)
-        rInfo.m_nDescent = +rTTInfo.typoDescender;
-    if (!rInfo.m_nDescent)
-        rInfo.m_nDescent = -rTTInfo.descender;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to