vcl/inc/impfontmetricdata.hxx                  |    5 +---
 vcl/inc/sft.hxx                                |    4 +--
 vcl/qt5/Qt5Graphics_Text.cxx                   |    8 ------
 vcl/quartz/ctfonts.cxx                         |   18 ---------------
 vcl/source/font/fontmetric.cxx                 |   21 +++++++++++++----
 vcl/source/fontsubset/sft.cxx                  |   30 ++++++++++++-------------
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx |   10 --------
 vcl/win/gdi/salfont.cxx                        |   10 --------
 8 files changed, 39 insertions(+), 67 deletions(-)

New commits:
commit f01125c01298148b93f0783c01806c6a6ff4c3e2
Author:     Khaled Hosny <khaledho...@eglug.org>
AuthorDate: Sun Aug 25 14:12:15 2019 +0200
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Wed Mar 24 16:20:04 2021 +0100

    Consolidate ImplCalcLineSpacing()
    
    Move getting UPEM and font tables to the functions and use HarfBuzz API
    to get them. In the future we might stop reading the tables ourselves
    and use HarfBuzz metrics API instead.
    
    Change-Id: I3f4511628fd33200bae94cdcd96479ba3e6d2fba
    Reviewed-on: https://gerrit.libreoffice.org/78081
    Tested-by: Jenkins
    Reviewed-by: Khaled Hosny <khaledho...@eglug.org>
    (cherry picked from commit 60d4be99383b6fe13ca55572c43fd022bdc73ce8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112484
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Aron Budea <aron.bu...@collabora.com>

diff --git a/vcl/inc/impfontmetricdata.hxx b/vcl/inc/impfontmetricdata.hxx
index 1c9b14a5098f..2093b18c53e8 100644
--- a/vcl/inc/impfontmetricdata.hxx
+++ b/vcl/inc/impfontmetricdata.hxx
@@ -32,6 +32,7 @@ typedef tools::SvRef<ImplFontMetricData> 
ImplFontMetricDataRef;
 
 class OutputDevice;
 class FontSelectPattern;
+class LogicalFontInstance;
 
 class VCL_DLLPUBLIC ImplFontMetricData : public FontAttributes, public 
SvRefBase
 {
@@ -92,9 +93,7 @@ public:
     void            ImplInitTextLineSize( const OutputDevice* pDev );
     void            ImplInitAboveTextLineSize();
     void            ImplInitFlags( const OutputDevice* pDev );
-    void            ImplCalcLineSpacing(const std::vector<uint8_t>& rHhea,
-                                        const std::vector<uint8_t>& rOS_2,
-                                        int nUPEM);
+    void            ImplCalcLineSpacing(LogicalFontInstance *pFontInstance);
 
 private:
     bool            ShouldUseWinMetrics(vcl::TTGlobalFontInfo& rInfo);
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index 95fbcadb0d8d..06d214b8d391 100644
--- a/vcl/inc/sft.hxx
+++ b/vcl/inc/sft.hxx
@@ -423,8 +423,8 @@ namespace vcl
  * @ingroup sft
  *
  */
- void GetTTFontMetrics(const std::vector<uint8_t>& hhea,
-                       const std::vector<uint8_t>& os2,
+ void GetTTFontMetrics(const uint8_t *pHhea, size_t nHhea,
+                       const uint8_t *pOs2, size_t nOs2,
                        TTGlobalFontInfo *info);
 
 /**
diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx
index 67cef5962dad..849987187ee9 100644
--- a/vcl/qt5/Qt5Graphics_Text.cxx
+++ b/vcl/qt5/Qt5Graphics_Text.cxx
@@ -59,13 +59,7 @@ void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef& rFMD, 
int nFallbackLevel)
     QRawFont aRawFont(QRawFont::fromFont(*m_pTextStyle[nFallbackLevel]));
     Qt5FontFace::fillAttributesFromQFont(*m_pTextStyle[nFallbackLevel], *rFMD);
 
-    QByteArray aHheaTable = aRawFont.fontTable("hhea");
-    std::vector<uint8_t> rHhea(aHheaTable.data(), aHheaTable.data() + 
aHheaTable.size());
-
-    QByteArray aOs2Table = aRawFont.fontTable("OS/2");
-    std::vector<uint8_t> rOS2(aOs2Table.data(), aOs2Table.data() + 
aOs2Table.size());
-
-    rFMD->ImplCalcLineSpacing(rHhea, rOS2, aRawFont.unitsPerEm());
+    rFMD->ImplCalcLineSpacing(m_pTextStyle[nFallbackLevel].get());
 
     rFMD->SetSlant(0);
     rFMD->SetWidth(aRawFont.averageCharWidth());
diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx
index 03582bf9cf3d..755de2148e71 100644
--- a/vcl/quartz/ctfonts.cxx
+++ b/vcl/quartz/ctfonts.cxx
@@ -110,24 +110,8 @@ void CoreTextStyle::GetFontMetric( ImplFontMetricDataRef 
const & rxFontMetric )
     // get the matching CoreText font handle
     // TODO: is it worth it to cache the CTFontRef in SetFont() and reuse it 
here?
     CTFontRef aCTFontRef = static_cast<CTFontRef>(CFDictionaryGetValue( 
mpStyleDict, kCTFontAttributeName ));
-    const CoreTextFontFace* mpFontData = static_cast<const 
CoreTextFontFace*>(GetFontFace());
 
-    int nBufSize = 0;
-
-    nBufSize = mpFontData->GetFontTable("hhea", nullptr);
-    uint8_t* pHheaBuf = new uint8_t[nBufSize];
-    nBufSize = mpFontData->GetFontTable("hhea", pHheaBuf);
-    std::vector<uint8_t> rHhea(pHheaBuf, pHheaBuf + nBufSize);
-
-    nBufSize = mpFontData->GetFontTable("OS/2", nullptr);
-    uint8_t* pOS2Buf = new uint8_t[nBufSize];
-    nBufSize = mpFontData->GetFontTable("OS/2", pOS2Buf);
-    std::vector<uint8_t> rOS2(pOS2Buf, pOS2Buf + nBufSize);
-
-    rxFontMetric->ImplCalcLineSpacing(rHhea, rOS2, 
CTFontGetUnitsPerEm(aCTFontRef));
-
-    delete[] pHheaBuf;
-    delete[] pOS2Buf;
+    rxFontMetric->ImplCalcLineSpacing(this);
 
     // since ImplFontMetricData::mnWidth is only used for stretching/squeezing 
fonts
     // setting this width to the pixel height of the fontsize is good enough
diff --git a/vcl/source/font/fontmetric.cxx b/vcl/source/font/fontmetric.cxx
index 4dd3cf88abcd..ee76c98cd23b 100644
--- a/vcl/source/font/fontmetric.cxx
+++ b/vcl/source/font/fontmetric.cxx
@@ -434,17 +434,28 @@ bool 
ImplFontMetricData::ShouldUseWinMetrics(vcl::TTGlobalFontInfo& rInfo)
  *   - Use Win metrics if available.
  *   - Unless USE_TYPO_METRICS flag is set, in which case use Typo metrics.
 */
-void ImplFontMetricData::ImplCalcLineSpacing(const std::vector<uint8_t>& 
rHheaData,
-        const std::vector<uint8_t>& rOS2Data, int nUPEM)
+void ImplFontMetricData::ImplCalcLineSpacing(LogicalFontInstance 
*pFontInstance)
 {
     mnAscent = mnDescent = mnExtLeading = mnIntLeading = 0;
 
-    double fScale = static_cast<double>(mnHeight) / nUPEM;
-    double fAscent = 0, fDescent = 0, fExtLeading = 0;
+    hb_font_t* pHbFont = pFontInstance->GetHbFont();
+    hb_face_t* pHbFace = hb_font_get_face(pHbFont);
+
+    hb_blob_t* pHhea = hb_face_reference_table(pHbFace, HB_TAG('h', 'h', 'e', 
'a'));
+    hb_blob_t* pOS2 = hb_face_reference_table(pHbFace, HB_TAG('O', 'S', '/', 
'2'));
 
     vcl::TTGlobalFontInfo rInfo;
     memset(&rInfo, 0, sizeof(vcl::TTGlobalFontInfo));
-    GetTTFontMetrics(rHheaData, rOS2Data, &rInfo);
+    GetTTFontMetrics(reinterpret_cast<const uint8_t*>(hb_blob_get_data(pHhea, 
nullptr)), hb_blob_get_length(pHhea),
+                     reinterpret_cast<const uint8_t*>(hb_blob_get_data(pOS2, 
nullptr)), hb_blob_get_length(pOS2),
+                     &rInfo);
+
+    hb_blob_destroy(pHhea);
+    hb_blob_destroy(pOS2);
+
+    double nUPEM = hb_face_get_upem(pHbFace);
+    double fScale = mnHeight / nUPEM;
+    double fAscent = 0, fDescent = 0, fExtLeading = 0;
 
     // Try hhea table first.
     // tdf#107605: Some fonts have weird values here, so check that ascender is
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 802453ae7446..a689f15937d1 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -2351,8 +2351,8 @@ std::unique_ptr<sal_uInt16[]> 
GetTTSimpleGlyphMetrics(TrueTypeFont const *ttf, c
 }
 
 // TODO, clean up table parsing and re-use it elsewhere in this file.
-void GetTTFontMetrics(const std::vector<uint8_t>& hhea,
-                      const std::vector<uint8_t>& os2,
+void GetTTFontMetrics(const uint8_t *pHhea, size_t nHhea,
+                      const uint8_t *pOs2, size_t nOs2,
                       TTGlobalFontInfo *info)
 {
     /* There are 3 different versions of OS/2 table: original (68 bytes long),
@@ -2362,20 +2362,20 @@ void GetTTFontMetrics(const std::vector<uint8_t>& hhea,
      * FIXME: horribly outdated comment and horrible code that uses hard-coded
      * offsets to read the table.
      */
-    if (os2.size() >= 76 + 2)
+    if (nOs2 >= 76 + 2)
     {
-        info->fsSelection   = GetUInt16(os2.data(), 62);
-        info->typoAscender  = GetInt16(os2.data(),  68);
-        info->typoDescender = GetInt16(os2.data(),  70);
-        info->typoLineGap   = GetInt16(os2.data(),  72);
-        info->winAscent     = GetUInt16(os2.data(), 74);
-        info->winDescent    = GetUInt16(os2.data(), 76);
-    }
-
-    if (hhea.size() >= 8 + 2) {
-        info->ascender      = GetInt16(hhea.data(), 4);
-        info->descender     = GetInt16(hhea.data(), 6);
-        info->linegap       = GetInt16(hhea.data(), 8);
+        info->fsSelection   = GetUInt16(pOs2, 62);
+        info->typoAscender  = GetInt16(pOs2,  68);
+        info->typoDescender = GetInt16(pOs2,  70);
+        info->typoLineGap   = GetInt16(pOs2,  72);
+        info->winAscent     = GetUInt16(pOs2, 74);
+        info->winDescent    = GetUInt16(pOs2, 76);
+    }
+
+    if (nHhea >= 8 + 2) {
+        info->ascender      = GetInt16(pHhea, 4);
+        info->descender     = GetInt16(pHhea, 6);
+        info->linegap       = GetInt16(pHhea, 8);
     }
 }
 
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx 
b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 002e503ac657..3d1b6966d0df 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -557,15 +557,7 @@ void FreetypeFont::GetFontMetric(ImplFontMetricDataRef 
const & rxTo) const
 
     FT_Activate_Size( maSizeFT );
 
-    sal_uLong nHhea = 0;
-    const uint8_t* pHheaBuf = mpFontInfo->GetTable("hhea", &nHhea);
-    const std::vector<uint8_t> rHhea(pHheaBuf, pHheaBuf + nHhea);
-
-    sal_uLong nOS2 = 0;
-    const uint8_t* pOS2Buf = mpFontInfo->GetTable("OS/2", &nOS2);
-    const std::vector<uint8_t> rOS2(pOS2Buf, pOS2Buf + nOS2);
-
-    rxTo->ImplCalcLineSpacing(rHhea, rOS2, maFaceFT->units_per_EM);
+    rxTo->ImplCalcLineSpacing(mpFontInstance.get());
 
     rxTo->SetSlant( 0 );
     rxTo->SetWidth( mnWidth );
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 155c08e962fb..2aedd1529591 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -957,12 +957,8 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& 
rxFontMetric, int nFa
     if( GetTextFaceW( getHDC(), SAL_N_ELEMENTS(aFaceName), aFaceName ) )
         rxFontMetric->SetFamilyName(o3tl::toU(aFaceName));
 
-    const DWORD nHheaTag = CalcTag("hhea");
-    const DWORD nOS2Tag = CalcTag("OS/2");
-    const RawFontData aHheaRawData(getHDC(), nHheaTag);
-    const RawFontData aOS2RawData(getHDC(), nOS2Tag);
-
     rxFontMetric->SetMinKashida(pFontInstance->GetKashidaWidth());
+    rxFontMetric->ImplCalcLineSpacing(pFontInstance.get());
 
     // get the font metric
     OUTLINETEXTMETRICW aOutlineMetric;
@@ -984,10 +980,6 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& 
rxFontMetric, int nFa
 
     // transformation dependent font metrics
     rxFontMetric->SetWidth(static_cast<int>(pFontInstance->GetScale() * 
aWinMetric.tmAveCharWidth));
-
-    const std::vector<uint8_t> rHhea(aHheaRawData.get(), aHheaRawData.get() + 
aHheaRawData.size());
-    const std::vector<uint8_t> rOS2(aOS2RawData.get(), aOS2RawData.get() + 
aOS2RawData.size());
-    rxFontMetric->ImplCalcLineSpacing(rHhea, rOS2, aOutlineMetric.otmEMSquare);
 }
 
 const FontCharMapRef WinSalGraphics::GetFontCharMap() const
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to