summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-07-04 09:21:13 +0800
committerTomaž Vajngerl <quikee@gmail.com>2016-07-04 04:43:37 +0000
commitb5cd1220b849a9759dd4446032a7e1affbf151f2 (patch)
tree40deafdcd092f31ca43bfb3654bb8c5bb8e3fbbb
parent21a3d78cf080dc4d86edab2a7378055a2d848bfe (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>
-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 5aa4aa493b41..331f51996dd4 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 5ceec063d483..d0f0b9a10b83 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)