[Libreoffice-commits] core.git: vcl/inc vcl/quartz vcl/source vcl/win

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Tue Sep 15 04:42:59 UTC 2020


 vcl/inc/salgdi.hxx              |   13 +++++++++
 vcl/quartz/salgdi.cxx           |   46 --------------------------------
 vcl/source/gdi/salgdilayout.cxx |   56 ++++++++++++++++++++++++++++++++++++++++
 vcl/win/gdi/salfont.cxx         |   39 ---------------------------
 4 files changed, 71 insertions(+), 83 deletions(-)

New commits:
commit a88c9752c6251dceb77c809b4592f2516e10f3e6
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Fri Sep 11 17:24:59 2020 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Tue Sep 15 06:42:13 2020 +0200

    WIN OSX unify GetGlyphWidths code
    
    Now that GetFontChatMap is a member of PhysicalFontFace, we can
    copy the common part of both architectures into a SalGraphics
    helper function.
    
    Change-Id: Iad379ea690a1c5346b69b5042188506ccf575cc2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102684
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index d2b92c65110f..2e83e558a3c7 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -54,6 +54,11 @@ namespace basegfx {
     class B2DPolyPolygon;
 }
 
+namespace vcl
+{
+class AbstractTrueTypeFont;
+}
+
 typedef sal_Unicode sal_Ucs; // TODO: use sal_UCS4 instead of sal_Unicode
 typedef std::map< sal_Ucs, sal_uInt32 >   Ucs2UIntMap;
 
@@ -613,6 +618,14 @@ protected:
 
     std::unique_ptr<vcl::WidgetDrawInterface> m_pWidgetDraw;
     vcl::WidgetDrawInterface* forWidget() { return m_pWidgetDraw ? m_pWidgetDraw.get() : this; }
+
+#if defined(_WIN32) || defined(MACOSX) || defined(IOS)
+    static void GetGlyphWidths(const vcl::TrueTypeFont& rTTF,
+#else
+    static void GetGlyphWidths(const vcl::AbstractTrueTypeFont& rTTF,
+#endif
+                               const PhysicalFontFace& rFontFace, bool bVertical,
+                               std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc);
 };
 
 bool SalGraphics::IsNativeControlSupported(ControlType eType, ControlPart ePart)
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 4cab7731eca5..2c1fdff16eec 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -763,51 +763,7 @@ void AquaSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFontData, bool bV
     if( nRC != SFErrCodes::Ok )
         return;
 
-    const int nGlyphCount = pSftFont->glyphCount();
-    if( nGlyphCount > 0 )
-    {
-        // get glyph metrics
-        rGlyphWidths.resize(nGlyphCount);
-        std::vector<sal_uInt16> aGlyphIds(nGlyphCount);
-        for( int i = 0; i < nGlyphCount; i++ )
-        {
-            aGlyphIds[i] = static_cast<sal_uInt16>(i);
-        }
-
-        std::unique_ptr<sal_uInt16[]> pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, aGlyphIds.data(),
-                                                                               nGlyphCount, bVertical );
-        if( pGlyphMetrics )
-        {
-            for( int i = 0; i < nGlyphCount; ++i )
-            {
-                rGlyphWidths[i] = pGlyphMetrics[i];
-            }
-            pGlyphMetrics.reset();
-        }
-
-        rtl::Reference<CoreTextFontFace> rCTFontData(new CoreTextFontFace(*pFontData, pFontData->GetFontId()));
-        FontCharMapRef xFCMap = rCTFontData->GetFontCharMap();
-        SAL_WARN_IF( !xFCMap.is() || !xFCMap->GetCharCount(), "vcl", "no charmap" );
-
-        // get unicode<->glyph encoding
-        // TODO? avoid sft mapping by using the xFCMap itself
-        int nCharCount = xFCMap->GetCharCount();
-        sal_uInt32 nChar = xFCMap->GetFirstChar();
-        for( ; --nCharCount >= 0; nChar = xFCMap->GetNextChar( nChar ) )
-        {
-            if( nChar > 0xFFFF ) // TODO: allow UTF-32 chars
-                break;
-
-            sal_Ucs nUcsChar = static_cast<sal_Ucs>(nChar);
-            sal_uInt32 nGlyph = ::MapChar( pSftFont, nUcsChar );
-            if( nGlyph > 0 )
-            {
-                rUnicodeEnc[ nUcsChar ] = nGlyph;
-            }
-        }
-
-        xFCMap = nullptr;
-    }
+    SalGraphics::GetGlyphWidths(*pSftFont, *pFontData, bVertical, rGlyphWidths, rUnicodeEnc);
 
     ::CloseTTFont( pSftFont );
 }
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 21844bff732a..63c3c8b8dc7d 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -28,8 +28,10 @@
 #include <svsys.h>
 #endif
 #endif
+#include <PhysicalFontFace.hxx>
 #include <salgdi.hxx>
 #include <salframe.hxx>
+#include <sft.hxx>
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <FileDefinitionWidgetDraw.hxx>
@@ -894,4 +896,58 @@ OUString SalGraphics::getRenderBackendName() const
     return OUString();
 }
 
+#if defined(_WIN32) || defined(MACOSX) || defined(IOS)
+void SalGraphics::GetGlyphWidths(const vcl::TrueTypeFont& rTTF,
+#else
+void SalGraphics::GetGlyphWidths(const vcl::AbstractTrueTypeFont& rTTF,
+#endif
+                                 const PhysicalFontFace& rFontFace, const bool bVertical,
+                                 std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc)
+{
+    rWidths.clear();
+    rUnicodeEnc.clear();
+
+    const int nGlyphCount = rTTF.glyphCount();
+    if (nGlyphCount <= 0)
+        return;
+
+    FontCharMapRef xFCMap = rFontFace.GetFontCharMap();
+    if (!xFCMap.is() || !xFCMap->GetCharCount())
+    {
+        SAL_WARN("vcl.fonts", "no charmap");
+        return;
+    }
+
+    rWidths.resize(nGlyphCount);
+    std::vector<sal_uInt16> aGlyphIds(nGlyphCount);
+    for (int i = 0; i < nGlyphCount; i++)
+        aGlyphIds[i] = static_cast<sal_uInt16>(i);
+
+    std::unique_ptr<sal_uInt16[]> pGlyphMetrics
+        = GetTTSimpleGlyphMetrics(&rTTF, aGlyphIds.data(), nGlyphCount, bVertical);
+    if (pGlyphMetrics)
+    {
+        for (int i = 0; i < nGlyphCount; ++i)
+            rWidths[i] = pGlyphMetrics[i];
+        pGlyphMetrics.reset();
+    }
+
+    int nCharCount = xFCMap->GetCharCount();
+    sal_uInt32 nChar = xFCMap->GetFirstChar();
+    for (; --nCharCount >= 0; nChar = xFCMap->GetNextChar(nChar))
+    {
+        if (nChar > 0xFFFF)
+            continue;
+
+        sal_Ucs nUcsChar = static_cast<sal_Ucs>(nChar);
+#if defined(_WIN32) || defined(MACOSX) || defined(IOS)
+        sal_uInt32 nGlyph = MapChar(&rTTF, nUcsChar);
+#else
+        sal_uInt32 nGlyph = xFCMap->GetGlyphIndex(nUcsChar);
+#endif
+        if (nGlyph > 0)
+            rUnicodeEnc[nUcsChar] = nGlyph;
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 4dac58aaafb2..f5f69f3eab33 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1749,44 +1749,7 @@ void WinSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
     if( nRC != SFErrCodes::Ok )
         return;
 
-    int nGlyphs = aSftTTF->glyphCount();
-    if( nGlyphs > 0 )
-    {
-        rWidths.resize(nGlyphs);
-        std::vector<sal_uInt16> aGlyphIds(nGlyphs);
-        for( int i = 0; i < nGlyphs; i++ )
-            aGlyphIds[i] = sal_uInt16(i);
-        std::unique_ptr<sal_uInt16[]> pMetrics = ::GetTTSimpleGlyphMetrics( aSftTTF.get(),
-                                                                    aGlyphIds.data(),
-                                                                    nGlyphs,
-                                                                    bVertical );
-        if( pMetrics )
-        {
-            for( int i = 0; i< nGlyphs; i++ )
-                rWidths[i] = pMetrics[i];
-            pMetrics.reset();
-            rUnicodeEnc.clear();
-        }
-        const WinFontFace* pWinFont = static_cast<const WinFontFace*>(pFont);
-        FontCharMapRef xFCMap = pWinFont->GetFontCharMap();
-        SAL_WARN_IF( !xFCMap.is() || !xFCMap->GetCharCount(), "vcl", "no map" );
-
-        int nCharCount = xFCMap->GetCharCount();
-        sal_uInt32 nChar = xFCMap->GetFirstChar();
-        for( int i = 0; i < nCharCount; i++ )
-        {
-            if( nChar < 0x00010000 )
-            {
-                sal_uInt16 nGlyph = ::MapChar( aSftTTF.get(),
-                                               static_cast<sal_Ucs>(nChar));
-                if( nGlyph )
-                    rUnicodeEnc[ static_cast<sal_Unicode>(nChar) ] = nGlyph;
-            }
-            nChar = xFCMap->GetNextChar( nChar );
-        }
-
-        xFCMap = nullptr;
-    }
+    SalGraphics::GetGlyphWidths(*aSftTTF.get(), *pFont, bVertical, rWidths, rUnicodeEnc);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list