Skip to content

Commit 19f8b8e

Browse files
Eskil Abrahamsen Blomfeldtashkulz
authored andcommitted
Make distance fields rendering work with Opentype CFF fonts
If the font has a CFF table, GDI will not label it as TMPF_TRUETYPE, however, we can still use GetFontData to get the SFNT tables. This is required to get the maxp table which contains the glyph count, which is required to use the font with the distance-field renderer. Task-number: QTBUG-28746 Reviewed-by: Konstantin Ritt <[email protected]> Change-Id: I1e084f7e9dbd0bccb9b1ff4de2eaf65d6a5f9f1e (cherry picked from qtbase/dde09c429ae8b7ad0df4e4b36b8459d2b85a1219) Reviewed-by: Oswald Buddenhagen <[email protected]>
1 parent 3985dfb commit 19f8b8e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/gui/text/qfontengine_win.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,20 @@ static OUTLINETEXTMETRIC *getOutlineTextMetric(HDC hdc)
190190
return otm;
191191
}
192192

193+
bool QFontEngineWin::hasCFFTable() const
194+
{
195+
HDC hdc = shared_dc();
196+
SelectObject(hdc, hfont);
197+
return GetFontData(hdc, MAKE_TAG('C', 'F', 'F', ' '), 0, 0, 0) != GDI_ERROR;
198+
}
199+
193200
void QFontEngineWin::getCMap()
194201
{
195202
ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE);
203+
204+
// TMPF_TRUETYPE is not set for fonts with CFF tables
205+
cffTable = !ttf && hasCFFTable();
206+
196207
HDC hdc = shared_dc();
197208
SelectObject(hdc, hfont);
198209
bool symb = false;
@@ -1072,7 +1083,7 @@ void QFontEngineWin::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_m
10721083

10731084
bool QFontEngineWin::getSfntTableData(uint tag, uchar *buffer, uint *length) const
10741085
{
1075-
if (!ttf)
1086+
if (!ttf && !cffTable)
10761087
return false;
10771088
HDC hdc = shared_dc();
10781089
SelectObject(hdc, hfont);

src/gui/text/qfontengine_win_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class QFontEngineWin : public QFontEngine
126126
uint stockFont : 1;
127127
uint ttf : 1;
128128
uint hasOutline : 1;
129+
uint cffTable : 1;
129130
TEXTMETRIC tm;
130131
int lw;
131132
const unsigned char *cmap;
@@ -145,6 +146,7 @@ class QFontEngineWin : public QFontEngine
145146
mutable int designAdvancesSize;
146147

147148
private:
149+
bool hasCFFTable() const;
148150
QNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform,
149151
QImage::Format mask_format);
150152

0 commit comments

Comments
 (0)