From 5a8d870c018db33ee63dad821a260939e1b2fbd0 Mon Sep 17 00:00:00 2001 From: Ashish Kulkarni Date: Thu, 10 Jul 2014 22:09:27 +0530 Subject: [PATCH] improvements in the rendering of OpenType fonts on Windows This is essentially porting of the following commits from Qt 5: qtproject/qtbase@51998eb4f65b92640176973ba0e0ed14adee561d qtproject/qtbase@dde09c429ae8b7ad0df4e4b36b8459d2b85a1219 qtproject/qtbase@0a170be576153b84ee6249f1a2b7cbce1ef10d84 --- src/gui/text/qfontengine_win.cpp | 21 +++++++++++++++++++-- src/gui/text/qfontengine_win_p.h | 3 +++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index 66a741c1d56..8b097887290 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -190,9 +190,25 @@ static OUTLINETEXTMETRIC *getOutlineTextMetric(HDC hdc) return otm; } +bool QFontEngineWin::hasCFFTable() const +{ + HDC hdc = shared_dc(); + SelectObject(hdc, hfont); + return GetFontData(hdc, MAKE_TAG('C', 'F', 'F', ' '), 0, 0, 0) != GDI_ERROR; +} + +bool QFontEngineWin::hasCMapTable() const +{ + HDC hdc = shared_dc(); + SelectObject(hdc, hfont); + return GetFontData(hdc, MAKE_TAG('c', 'm', 'a', 'p'), 0, 0, 0) != GDI_ERROR; +} + void QFontEngineWin::getCMap() { - ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE); + ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE) || hasCMapTable(); + cffTable = hasCFFTable(); + HDC hdc = shared_dc(); SelectObject(hdc, hfont); bool symb = false; @@ -373,6 +389,7 @@ HGDIOBJ QFontEngineWin::selectDesignFont() const { LOGFONT f = logfont; f.lfHeight = unitsPerEm; + f.lfWidth = 0; HFONT designFont = CreateFontIndirect(&f); return SelectObject(shared_dc(), designFont); } @@ -1072,7 +1089,7 @@ void QFontEngineWin::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_m bool QFontEngineWin::getSfntTableData(uint tag, uchar *buffer, uint *length) const { - if (!ttf) + if (!ttf && !cffTable) return false; HDC hdc = shared_dc(); SelectObject(hdc, hfont); diff --git a/src/gui/text/qfontengine_win_p.h b/src/gui/text/qfontengine_win_p.h index 2b5ad4ef332..ba6aa020db6 100644 --- a/src/gui/text/qfontengine_win_p.h +++ b/src/gui/text/qfontengine_win_p.h @@ -126,6 +126,7 @@ class QFontEngineWin : public QFontEngine uint stockFont : 1; uint ttf : 1; uint hasOutline : 1; + uint cffTable : 1; TEXTMETRIC tm; int lw; const unsigned char *cmap; @@ -145,6 +146,8 @@ class QFontEngineWin : public QFontEngine mutable int designAdvancesSize; private: + bool hasCFFTable() const; + bool hasCMapTable() const; QNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform, QImage::Format mask_format);