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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Jul 4 04:44:06 UTC 2016


 vcl/win/gdi/salfont.cxx   |    8 ++++++++
 vcl/win/gdi/winlayout.cxx |   14 +++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit b5cd1220b849a9759dd4446032a7e1affbf151f2
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Jul 4 09:21:13 2016 +0800

    tdf#98710 check the font is bound, substitute FON fonts
    
    If we can't bind the font then we can't proceed with rendering
    and caching of the glyphs. This may avoid the crash but the font
    won't be drawn. This happens for old Windows 3.1 bitmap fonts in
    FON format which Direct Write doesn't support. So in addition
    substitute "Script" and "Roman" FON fonts with "Times New Roman".
    
    Change-Id: I16b480399b47989738a703ad84c0398493f9f4e3
    Reviewed-on: https://gerrit.libreoffice.org/26885
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 5aa4aa4..331f519 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1373,6 +1373,14 @@ HFONT WinSalGraphics::ImplDoSetFont( FontSelectPattern* i_pFont, float& o_rFontS
     && (ImplSalWICompareAscii( aLogFont.lfFaceName, "Courier" ) == 0) )
         lstrcpynW( aLogFont.lfFaceName, L"Courier New", 12 );
 
+    // Script and Roman are Win 3.1 bitmap fonts using "FON" font format
+    // which is not supported with "Direct Write" so let's substitute them
+    // with a font that is supported and always available.
+    if (ImplSalWICompareAscii(aLogFont.lfFaceName, "Script") == 0)
+        wcscpy(aLogFont.lfFaceName, L"Times New Roman");
+    if (ImplSalWICompareAscii(aLogFont.lfFaceName, "Roman") == 0)
+        wcscpy(aLogFont.lfFaceName, L"Times New Roman");
+
     // #i47675# limit font requests to MAXFONTHEIGHT
     // TODO: share MAXFONTHEIGHT font instance
     if( (-aLogFont.lfHeight <= MAXFONTHEIGHT)
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 5ceec06..d0f0b9a 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -276,6 +276,7 @@ class D2DWriteTextOutRenderer : public TextOutRenderer
 {
     typedef HRESULT(WINAPI *pD2D1CreateFactory_t)(D2D1_FACTORY_TYPE,
         REFIID, const D2D1_FACTORY_OPTIONS *, void **);
+
     typedef HRESULT(WINAPI *pDWriteCreateFactory_t)(DWRITE_FACTORY_TYPE,
         REFIID, IUnknown **);
 
@@ -379,7 +380,12 @@ bool WinFontInstance::CacheGlyphToAtlas(bool bRealGlyphIndices, int nGlyphIndex,
     if (!pTxt)
         return false;
 
-    pTxt->BindFont(hDC);
+    if (!pTxt->BindFont(hDC))
+    {
+        SAL_WARN("vcl.gdi", "Binding of font failed. The font might not be supported by Direct Write.");
+        DeleteDC(hDC);
+        return false;
+    }
 
     // Bail for non-horizontal text.
     {
@@ -405,6 +411,11 @@ bool WinFontInstance::CacheGlyphToAtlas(bool bRealGlyphIndices, int nGlyphIndex,
     // Fetch the ink boxes and calculate the size of the atlas.
     if (!bRealGlyphIndices)
     {
+        if (!pTxt->GetFontFace())
+        {
+            SAL_WARN("vcl.gdi", "Font face is not available.");
+            return false;
+        }
         if (!SUCCEEDED(pTxt->GetFontFace()->GetGlyphIndices(aCodePointsOrGlyphIndices.data(), aCodePointsOrGlyphIndices.size(), aGlyphIndices.data())))
         {
             pTxt->ReleaseFont();
@@ -415,6 +426,7 @@ bool WinFontInstance::CacheGlyphToAtlas(bool bRealGlyphIndices, int nGlyphIndex,
     {
         aGlyphIndices[0] = aCodePointsOrGlyphIndices[0];
     }
+
     Rectangle bounds(0, 0, 0, 0);
     auto aInkBoxes = pTxt->GetGlyphInkBoxes(aGlyphIndices.data(), aGlyphIndices.data() + 1);
     for (auto &box : aInkBoxes)


More information about the Libreoffice-commits mailing list