summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-07-04 09:21:13 +0800
committerCaolán McNamara <caolanm@redhat.com>2016-07-06 09:51:21 +0000
commit3a9fb7a6bf34c7ad5647c4b84a91f43a41826dcd (patch)
tree3dabccd188db233447884a681e864b78abb67982
parent9a9e1e6fdd5f0a2553d98818c31627be077deca9 (diff)
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@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit b5cd1220b849a9759dd4446032a7e1affbf151f2) Reviewed-on: https://gerrit.libreoffice.org/26969 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/win/gdi/salfont.cxx8
-rw-r--r--vcl/win/gdi/winlayout.cxx14
2 files changed, 21 insertions, 1 deletions
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index ba922479cf97..df406d4c4f88 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 7133a7cea00c..41b01c3bbb29 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -278,6 +278,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 **);
@@ -381,7 +382,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.
{
@@ -407,6 +413,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();
@@ -417,6 +428,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)