vcl/inc/font/LogicalFontInstance.hxx    |    2 ++
 vcl/source/font/LogicalFontInstance.cxx |   21 +++++++++++++--------
 vcl/source/gdi/CommonSalLayout.cxx      |   13 +++++--------
 vcl/source/gdi/pdfwriter_impl.cxx       |    9 +++------
 4 files changed, 23 insertions(+), 22 deletions(-)

New commits:
commit e34d6e017ccfa2279f7e855eb6fd5fbbbd056714
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Wed Sep 7 11:10:11 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Thu Sep 8 03:34:28 2022 +0200

    vcl: Add LogicalFontInstance::GetGlyphIndex()
    
    And use it in a few places, particularly where we get glyph ID from
    FontCharMap. We want to get the glyph indices from HarfBuzz like we do
    for shaping, to avoid any potential discrepancy (e.g. a new “cmap”
    subtable that our ParseCMAP() would not automatically support).
    
    Change-Id: Ie80993b35f0586d8567b6bda0ea56ba453316e81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139578
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/vcl/inc/font/LogicalFontInstance.hxx 
b/vcl/inc/font/LogicalFontInstance.hxx
index c08e3e5bc937..d1f19760a9a3 100644
--- a/vcl/inc/font/LogicalFontInstance.hxx
+++ b/vcl/inc/font/LogicalFontInstance.hxx
@@ -100,6 +100,8 @@ public: // TODO: make data members private
     bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
     virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) 
const = 0;
 
+    sal_GlyphId GetGlyphIndex(uint32_t, uint32_t = 0) const;
+
     double GetGlyphWidth(sal_GlyphId, bool = false, bool = false) const;
 
     int GetKashidaWidth() const;
diff --git a/vcl/source/font/LogicalFontInstance.cxx 
b/vcl/source/font/LogicalFontInstance.cxx
index 611c84f44610..ce6ea99ee8f3 100644
--- a/vcl/source/font/LogicalFontInstance.cxx
+++ b/vcl/source/font/LogicalFontInstance.cxx
@@ -66,14 +66,10 @@ hb_font_t* LogicalFontInstance::InitHbFont()
 
 int LogicalFontInstance::GetKashidaWidth() const
 {
-    hb_font_t* pHbFont = const_cast<LogicalFontInstance*>(this)->GetHbFont();
-    hb_position_t nWidth = 0;
-    hb_codepoint_t nIndex = 0;
-
-    if (hb_font_get_glyph(pHbFont, 0x0640, 0, &nIndex))
-        nWidth = std::ceil(GetGlyphWidth(nIndex));
-
-    return nWidth;
+    sal_GlyphId nGlyph = GetGlyphIndex(0x0640);
+    if (nGlyph)
+        return std::ceil(GetGlyphWidth(nGlyph));
+    return 0;
 }
 
 void LogicalFontInstance::GetScale(double* nXScale, double* nYScale) const
@@ -146,6 +142,15 @@ bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId 
nID, tools::Rectangle& r
     return res;
 }
 
+sal_GlyphId LogicalFontInstance::GetGlyphIndex(uint32_t nUnicode, uint32_t 
nVariationSelector) const
+{
+    auto* pHbFont = const_cast<LogicalFontInstance*>(this)->GetHbFont();
+    sal_GlyphId nGlyph = 0;
+    if (hb_font_get_glyph(pHbFont, nUnicode, nVariationSelector, &nGlyph))
+        return nGlyph;
+    return 0;
+}
+
 double LogicalFontInstance::GetGlyphWidth(sal_GlyphId nGlyph, bool bVertical, 
bool bPDF) const
 {
     auto* pHbFont = const_cast<LogicalFontInstance*>(this)->GetHbFont();
diff --git a/vcl/source/gdi/CommonSalLayout.cxx 
b/vcl/source/gdi/CommonSalLayout.cxx
index db5575fb8c82..aab404ebe73f 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -221,14 +221,13 @@ void GenericSalLayout::DrawText(SalGraphics& 
rSalGraphics) const
 // script/language then we want to always treat it as upright glyph.
 bool GenericSalLayout::HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 
aVariationSelector)
 {
-    hb_codepoint_t nGlyphIndex = 0;
-    hb_font_t *pHbFont = GetFont().GetHbFont();
-    if (!hb_font_get_glyph(pHbFont, aChar, aVariationSelector, &nGlyphIndex))
+    sal_GlyphId nGlyphIndex = GetFont().GetGlyphIndex(aChar, 
aVariationSelector);
+    if (!nGlyphIndex)
         return false;
 
     if (!mpVertGlyphs)
     {
-        hb_face_t* pHbFace = hb_font_get_face(pHbFont);
+        hb_face_t* pHbFace = hb_font_get_face(GetFont().GetHbFont());
         mpVertGlyphs = hb_set_create();
 
         // Find all GSUB lookups for “vert” feature.
@@ -850,10 +849,8 @@ void GenericSalLayout::ApplyDXArray(const double* 
pDXArray, const sal_Bool* pKas
         return;
 
     // Find Kashida glyph width and index.
-    double nKashidaWidth = 0;
-    hb_codepoint_t nKashidaIndex = 0;
-    if (hb_font_get_glyph(GetFont().GetHbFont(), 0x0640, 0, &nKashidaIndex))
-        nKashidaWidth = GetFont().GetKashidaWidth();
+    sal_GlyphId nKashidaIndex = GetFont().GetGlyphIndex(0x0640);
+    double nKashidaWidth = GetFont().GetKashidaWidth();
 
     if (nKashidaWidth <= 0)
     {
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 3e01a6c76b9d..1f032c25a79e 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2335,12 +2335,11 @@ std::map< sal_Int32, sal_Int32 > 
PDFWriterImpl::emitSystemFont( const vcl::font:
     OUString aTmpName;
     osl_createTempFile( nullptr, nullptr, &aTmpName.pData );
 
-    sal_Int32 pWidths[256] = {};
-    FontCharMapRef xFontCharMap = pFont->GetFontCharMap();
+    sal_Int32 pWidths[256] = { 0 };
     const LogicalFontInstance* pFontInstance = rEmbed.m_pFontInstance;
     for( sal_Ucs c = 32; c < 256; c++ )
     {
-        sal_GlyphId nGlyph = xFontCharMap->GetGlyphIndex(c);
+        sal_GlyphId nGlyph = pFontInstance->GetGlyphIndex(c);
         pWidths[c] = pFontInstance->GetGlyphWidth(nGlyph, false, true);
     }
 
@@ -3890,15 +3889,13 @@ void PDFWriterImpl::createDefaultCheckBoxAppearance( 
PDFWidget& rBox, const PDFW
     // reasons require even the standard PS fonts to be embedded!
     Push();
     SetFont( Font( OUString( "OpenSymbol" ), aFont.GetFontSize() ) );
-    FontCharMapRef pMap;
-    GetFontCharMap(pMap);
     const LogicalFontInstance* pFontInstance = GetFontInstance();
     const vcl::font::PhysicalFontFace* pDevFont = pFontInstance->GetFontFace();
     Pop();
 
     // make sure OpenSymbol is embedded, and includes our checkmark
     const sal_Unicode cMark=0x2713;
-    const GlyphItem aItem(0, 0, pMap->GetGlyphIndex(cMark),
+    const GlyphItem aItem(0, 0, pFontInstance->GetGlyphIndex(cMark),
                           DevicePoint(), GlyphItemFlags::NONE, 0, 0, 0);
     const std::vector<sal_Ucs> aCodeUnits={ cMark };
     auto nGlyphWidth = pFontInstance->GetGlyphWidth(aItem.glyphId(), 
aItem.IsVertical(), true);

Reply via email to