[Libreoffice-commits] core.git: vcl/inc vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 4 11:45:54 UTC 2019


 vcl/inc/unx/glyphcache.hxx                     |    7 +++++++
 vcl/unx/generic/gdi/cairotextrender.cxx        |   20 ++++++++++++++++++++
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx |   20 ++++++++++++++++++++
 3 files changed, 47 insertions(+)

New commits:
commit df4a6f977843dbf4eb8bb5998b090d92c454611b
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Sep 4 10:57:06 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Sep 4 13:45:10 2019 +0200

    tdf#127189 FreeType <= 2.8 will fail to render stretched horizontal brace...
    
    glyphs in starmath at a fairly low stretch ratio. The failure will set
    CAIRO_STATUS_FREETYPE_ERROR on the surface which cannot be cleared, so all
    further painting to the surface fails.
    
    This appears fixed in 2.9 with
    https://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=91015cb41d8f56777f93394f5a60914bc0c0f330
    "Improve complex rendering at high ppem"
    
    Change-Id: I8cbf8347ccd29beda4057b14f2e68678f6030bf4
    Reviewed-on: https://gerrit.libreoffice.org/78587
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/inc/unx/glyphcache.hxx b/vcl/inc/unx/glyphcache.hxx
index 0331d7e9f86e..ccb25cab87e2 100644
--- a/vcl/inc/unx/glyphcache.hxx
+++ b/vcl/inc/unx/glyphcache.hxx
@@ -117,6 +117,13 @@ public:
     FreetypeFontInstance*   GetFontInstance() const { return mpFontInstance.get(); }
 
     void                    SetFontVariationsOnHBFont(hb_font_t* pHbFace) const;
+
+    // tdf#127189 FreeType <= 2.8 will fail to render stretched horizontal brace glyphs
+    // in starmath at a fairly low stretch ratio. This appears fixed in 2.9 with
+    // https://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=91015cb41d8f56777f93394f5a60914bc0c0f330
+    // "Improve complex rendering at high ppem"
+    static bool             AlmostHorizontalDrainsRenderingPool();
+
 private:
     friend class GlyphCache;
     friend class FreetypeFontInstance;
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 8b55ab6da58d..0b24cbf32d63 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -204,6 +204,22 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG
     if (nWidth == 0 || nHeight == 0)
         return;
 
+    int nRatio = nWidth * 10 / nHeight;
+    if (nRatio > 100 && rFSD.maTargetName == "OpenSymbol" && FreetypeFont::AlmostHorizontalDrainsRenderingPool())
+    {
+        // tdf#127189 FreeType <= 2.8 will fail to render stretched horizontal
+        // brace glyphs in starmath at a fairly low stretch ratio. The failure
+        // will set CAIRO_STATUS_FREETYPE_ERROR on the surface which cannot be
+        // cleared, so all further painting to the surface fails.
+
+        // This appears fixed in >= freetype 2.9
+
+        // Restrict this bodge to a stretch ratio > ~10 of the OpenSymbol font
+        // where it has been seen in practice.
+        SAL_WARN("vcl", "rendering text would fail with stretch ratio of: " << nRatio << ", with FreeType <= 2.8");
+        return;
+    }
+
     /*
      * It might be ideal to cache surface and cairo context between calls and
      * only destroy it when the drawable changes, but to do that we need to at
@@ -330,6 +346,10 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG
 
         cairo_set_font_matrix(cr, &m);
         cairo_show_glyphs(cr, &cairo_glyphs[nStartIndex], nLen);
+        if (cairo_status(cr) != CAIRO_STATUS_SUCCESS)
+        {
+            SAL_WARN("vcl", "rendering text failed with stretch ratio of: " << nRatio << ", " << cairo_status_to_string(cairo_status(cr)));
+        }
 
 #if OSL_DEBUG_LEVEL > 2
         //draw origin
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 1b3532ceee1b..525da6e52b43 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -324,6 +324,26 @@ void GlyphCache::InitFreetype()
     (void)vclFontFileList::get();
 }
 
+namespace
+{
+    bool DoesAlmostHorizontalDrainRenderingPool()
+    {
+        FT_Int nMajor, nMinor, nPatch;
+        FT_Library_Version(aLibFT, &nMajor, &nMinor, &nPatch);
+        if (nMajor > 2)
+            return false;
+        if (nMajor == 2 && nMinor <= 8)
+            return true;
+        return false;
+    }
+}
+
+bool FreetypeFont::AlmostHorizontalDrainsRenderingPool()
+{
+    static bool bAlmostHorizontalDrainsRenderingPool = DoesAlmostHorizontalDrainRenderingPool();
+    return bAlmostHorizontalDrainsRenderingPool;
+}
+
 FT_Face FreetypeFont::GetFtFace() const
 {
     FT_Activate_Size( maSizeFT );


More information about the Libreoffice-commits mailing list