Qt 4.8
Public Functions | Public Variables | Private Functions | List of all members
QFontEngineWin Class Reference

#include <qfontengine_win_p.h>

Inheritance diagram for QFontEngineWin:
QFontEngine QObject

Public Functions

virtual void addGlyphsToPath (glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
 
virtual void addOutlineToPath (qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
 
virtual QImage alphaMapForGlyph (glyph_t t)
 
virtual QImage alphaMapForGlyph (glyph_t, const QTransform &xform)
 
virtual QImage alphaRGBMapForGlyph (glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
 
virtual QFixed ascent () const
 
virtual QFixed averageCharWidth () const
 
virtual glyph_metrics_t boundingBox (const QGlyphLayout &glyphs)
 
virtual glyph_metrics_t boundingBox (glyph_t g)
 
virtual glyph_metrics_t boundingBox (glyph_t g, const QTransform &t)
 
bool canRender (const QChar *string, int len)
 
virtual QFontEnginecloneWithSize (qreal pixelSize) const
 
virtual QFixed descent () const
 
virtual QFixed emSquareSize () const
 
virtual FaceId faceId () const
 
void getCMap ()
 
virtual void getGlyphBearings (glyph_t glyph, qreal *leftBearing=0, qreal *rightBearing=0)
 
int getGlyphIndexes (const QChar *ch, int numChars, QGlyphLayout *glyphs, bool mirrored) const
 
virtual bool getSfntTableData (uint tag, uchar *buffer, uint *length) const
 
virtual void getUnscaledGlyph (glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
 
virtual QFixed leading () const
 
virtual QFixed lineThickness () const
 
virtual qreal maxCharWidth () const
 
virtual qreal minLeftBearing () const
 
virtual qreal minRightBearing () const
 
virtual const char * name () const
 
virtual Properties properties () const
 
 QFontEngineWin (const QString &name, HFONT, bool, LOGFONT)
 
virtual void recalcAdvances (QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
 
HGDIOBJ selectDesignFont () const
 
virtual bool stringToCMap (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
 
virtual int synthesized () const
 
Type type () const
 
virtual QFixed xHeight () const
 
 ~QFontEngineWin ()
 
- Public Functions inherited from QFontEngine
void addBitmapFontToPath (qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)
 
virtual glyph_metrics_t alphaMapBoundingBox (glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat)
 
virtual QImage alphaMapForGlyph (glyph_t glyph, QFixed subPixelPosition)
 
virtual QImage alphaMapForGlyph (glyph_t, QFixed subPixelPosition, const QTransform &t)
 
virtual void doKerning (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
void getGlyphPositions (const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
 
virtual HB_Error getPointInOutline (HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
 
QByteArray getSfntTable (uint) const
 
QFontEngineGlyphCacheglyphCache (void *key, QFontEngineGlyphCache::Type type, const QTransform &transform) const
 
virtual int glyphCount () const
 
HB_Face harfbuzzFace () const
 
HB_Font harfbuzzFont () const
 
void loadKerningPairs (QFixed scalingFactor)
 
 QFontEngine ()
 
virtual void removeGlyphFromCache (glyph_t)
 
void setGlyphCache (void *key, QFontEngineGlyphCache *data)
 
virtual bool supportsSubPixelPositions () const
 
glyph_metrics_t tightBoundingBox (const QGlyphLayout &glyphs)
 
virtual QFixed underlinePosition () const
 
virtual ~QFontEngine ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

FaceId _faceId
 
QString _name
 
const unsigned char * cmap
 
QByteArray cmapTable
 
QFixeddesignAdvances
 
int designAdvancesSize
 
QFixed designToDevice
 
uint hasOutline: 1
 
HFONT hfont
 
qreal lbearing
 
QFixed lineWidth
 
LOGFONT logfont
 
int lw
 
qreal rbearing
 
uint stockFont: 1
 
int synthesized_flags
 
TEXTMETRIC tm
 
uint ttf: 1
 
QString uniqueFamilyName
 
int unitsPerEm
 
unsigned char * widthCache
 
uint widthCacheSize
 
QFixed x_height
 
- Public Variables inherited from QFontEngine
uint cache_cost
 
int cache_count
 
QFontDef fontDef
 
uint fsType: 16
 
int glyphFormat
 
HB_Face hbFace
 
HB_FontRec hbFont
 
QVector< KernPairkerning_pairs
 
QAtomicInt ref
 
bool symbol
 

Private Functions

QNativeImagedrawGDIGlyph (HFONT font, glyph_t, int margin, const QTransform &xform, QImage::Format mask_format)
 

Additional Inherited Members

- Public Types inherited from QFontEngine
enum  GlyphFormat {
  Format_None, Format_Render = Format_None, Format_Mono, Format_A8,
  Format_A32
}
 
enum  SynthesizedFlags { SynthesizedItalic = 0x1, SynthesizedBold = 0x2, SynthesizedStretch = 0x4 }
 
enum  Type {
  Box, Multi, XLFD, Win,
  Mac, Freetype, QPF1, QPF2,
  Proxy, S60FontEngine, DirectWrite, TestFontEngine = 0x1000
}
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QFontEngine
static QByteArray convertToPostscriptFontFamilyName (const QByteArray &fontFamily)
 
static const uchargetCMap (const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
 
static quint32 getTrueTypeGlyphIndex (const uchar *cmap, uint unicode)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QFontEngine
QFixed lastRightBearing (const QGlyphLayout &glyphs, bool round=false)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Static Protected Functions inherited from QFontEngine
static const QVector< QRgb > & grayPalette ()
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 62 of file qfontengine_win_p.h.

Constructors and Destructors

◆ QFontEngineWin()

QFontEngineWin::QFontEngineWin ( const QString name,
HFONT  _hfont,
bool  stockFont,
LOGFONT  lf 
)

Definition at line 314 of file qfontengine_win.cpp.

315 {
316  //qDebug("regular windows font engine created: font='%s', size=%d", name, lf.lfHeight);
317 
318  _name = name;
319 
320  cmap = 0;
321  hfont = _hfont;
322  logfont = lf;
323  HDC hdc = shared_dc();
324  SelectObject(hdc, hfont);
325  this->stockFont = stockFont;
326  fontDef.pixelSize = -lf.lfHeight;
327 
328  lbearing = SHRT_MIN;
329  rbearing = SHRT_MIN;
330  synthesized_flags = -1;
331  lineWidth = -1;
332  x_height = -1;
333 
334  BOOL res = GetTextMetrics(hdc, &tm);
335  fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
336  if (!res) {
337  qErrnoWarning("QFontEngineWin: GetTextMetrics failed");
338  ZeroMemory(&tm, sizeof(TEXTMETRIC));
339  }
340 
341  cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000;
342  getCMap();
343 
344  widthCache = 0;
345  widthCacheSize = 0;
346  designAdvances = 0;
347  designAdvancesSize = 0;
348 
349 #ifndef Q_WS_WINCE
350  if (!resolvedGetCharWidthI)
351  resolveGetCharWidthI();
352 #endif
353 }
uint fixedPitch
Definition: qfont_p.h:96
const unsigned char * cmap
virtual const char * name() const
unsigned char * widthCache
qreal pixelSize
Definition: qfont_p.h:90
HDC shared_dc()
QFontDef fontDef
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ ~QFontEngineWin()

QFontEngineWin::~QFontEngineWin ( )

Definition at line 355 of file qfontengine_win.cpp.

356 {
357  if (designAdvances)
358  free(designAdvances);
359 
360  if (widthCache)
361  free(widthCache);
362 
363  // make sure we aren't by accident still selected
364  SelectObject(shared_dc(), (HFONT)GetStockObject(SYSTEM_FONT));
365 
366  if (!stockFont) {
367  if (!DeleteObject(hfont))
368  qErrnoWarning("QFontEngineWin: failed to delete non-stock font...");
369  }
370 }
unsigned char * widthCache
HDC shared_dc()
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

Functions

◆ addGlyphsToPath()

void QFontEngineWin::addGlyphsToPath ( glyph_t glyphs,
QFixedPoint positions,
int  nglyphs,
QPainterPath path,
QTextItem::RenderFlags  flags 
)
virtual

Reimplemented from QFontEngine.

Definition at line 944 of file qfontengine_win.cpp.

946 {
947  LOGFONT lf = logfont;
948  // The sign must be negative here to make sure we match against character height instead of
949  // hinted cell height. This ensures that we get linear matching, and we need this for
950  // paths since we later on apply a scaling transform to the glyph outline to get the
951  // font at the correct pixel size.
952  lf.lfHeight = -unitsPerEm;
953  lf.lfWidth = 0;
954  HFONT hf = CreateFontIndirect(&lf);
955  HDC hdc = shared_dc();
956  HGDIOBJ oldfont = SelectObject(hdc, hf);
957 
958  for(int i = 0; i < nglyphs; ++i) {
959  if (!addGlyphToPath(glyphs[i], positions[i], hdc, path, ttf, /*metric*/0,
961  // Some windows fonts, like "Modern", are vector stroke
962  // fonts, which are reported as TMPF_VECTOR but do not
963  // support GetGlyphOutline, and thus we set this bit so
964  // that addOutLineToPath can check it and return safely...
965  hasOutline = false;
966  break;
967  }
968  }
969  DeleteObject(SelectObject(hdc, oldfont));
970 }
double qreal
Definition: qglobal.h:1193
qreal pixelSize
Definition: qfont_p.h:90
HDC shared_dc()
static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc, QPainterPath *path, bool ttf, glyph_metrics_t *metric=0, qreal scale=1)
QFontDef fontDef

◆ addOutlineToPath()

void QFontEngineWin::addOutlineToPath ( qreal  x,
qreal  y,
const QGlyphLayout glyphs,
QPainterPath path,
QTextItem::RenderFlags  flags 
)
virtual

Reimplemented from QFontEngine.

Definition at line 972 of file qfontengine_win.cpp.

974 {
975 #if !defined(Q_WS_WINCE)
976  if(tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) {
977  hasOutline = true;
978  QFontEngine::addOutlineToPath(x, y, glyphs, path, flags);
979  if (hasOutline) {
980  // has_outline is set to false if addGlyphToPath gets
981  // false from GetGlyphOutline, meaning its not an outline
982  // font.
983  return;
984  }
985  }
986 #endif
987  QFontEngine::addBitmapFontToPath(x, y, glyphs, path, flags);
988 }
virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags)
void addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)

◆ alphaMapForGlyph() [1/2]

virtual QImage QFontEngineWin::alphaMapForGlyph ( glyph_t  glyph)
inlinevirtual

Create a qimage with the alpha values for the glyph. Returns an image indexed_8 with index values ranging from 0=fully transparent to 255=opaque

Reimplemented from QFontEngine.

Definition at line 105 of file qfontengine_win_p.h.

Referenced by alphaMapForGlyph().

105 { return alphaMapForGlyph(t, QTransform()); }
virtual QImage alphaMapForGlyph(glyph_t t)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ alphaMapForGlyph() [2/2]

QImage QFontEngineWin::alphaMapForGlyph ( glyph_t  glyph,
const QTransform xform 
)
virtual

Reimplemented from QFontEngine.

Definition at line 1193 of file qfontengine_win.cpp.

1194 {
1195  HFONT font = hfont;
1196  if (qt_cleartype_enabled) {
1197  LOGFONT lf = logfont;
1198  lf.lfQuality = ANTIALIASED_QUALITY;
1199  font = CreateFontIndirect(&lf);
1200  }
1202 #ifndef Q_OS_WINCE
1203  mask_format = QImage::Format_RGB32;
1204 #endif
1205 
1206  QNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform, mask_format);
1207  if (mask == 0)
1208  return QImage();
1209 
1210  QImage indexed(mask->width(), mask->height(), QImage::Format_Indexed8);
1211 
1212  // ### This part is kinda pointless, but we'll crash later if we don't because some
1213  // code paths expects there to be colortables for index8-bit...
1214  QVector<QRgb> colors(256);
1215  for (int i=0; i<256; ++i)
1216  colors[i] = qRgba(0, 0, 0, i);
1217  indexed.setColorTable(colors);
1218 
1219  // Copy data... Cannot use QPainter here as GDI has messed up the
1220  // Alpha channel of the ni.image pixels...
1221  for (int y=0; y<mask->height(); ++y) {
1222  uchar *dest = indexed.scanLine(y);
1223  if (mask->image.format() == QImage::Format_RGB16) {
1224  const qint16 *src = (qint16 *) ((const QImage &) mask->image).scanLine(y);
1225  for (int x=0; x<mask->width(); ++x)
1226  dest[x] = 255 - qGray(src[x]);
1227  } else {
1228  const uint *src = (uint *) ((const QImage &) mask->image).scanLine(y);
1229  for (int x=0; x<mask->width(); ++x) {
1230 #ifdef Q_OS_WINCE
1231  dest[x] = 255 - qGray(src[x]);
1232 #else
1234  dest[x] = 255 - qGray(src[x]);
1235  else
1236  dest[x] = 255 - (qt_pow_gamma[qGray(src[x])] * 255. / 2047.);
1237 #endif
1238  }
1239  }
1240  }
1241 
1242  // Cleanup...
1243  delete mask;
1244  if (qt_cleartype_enabled) {
1245  DeleteObject(font);
1246  }
1247 
1248  return indexed;
1249 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
static QImage::Format systemFormat()
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
unsigned char uchar
Definition: qglobal.h:994
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
Definition: qrgb.h:72
int width() const
QNativeImage * drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform, QImage::Format mask_format)
short qint16
Definition: qglobal.h:935
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
uint qt_pow_gamma[256]
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
int height() const
bool qt_cleartype_enabled

◆ alphaRGBMapForGlyph()

QImage QFontEngineWin::alphaRGBMapForGlyph ( glyph_t  t,
QFixed  subPixelPosition,
int  margin,
const QTransform xform 
)
virtual

Reimplemented from QFontEngine.

Definition at line 1254 of file qfontengine_win.cpp.

Referenced by alphaMapForGlyph().

1255 {
1256  HFONT font = hfont;
1257 
1258  int contrast;
1259  SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &contrast, 0);
1260  SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, (void *) 1000, 0);
1261 
1262  QNativeImage *mask = drawGDIGlyph(font, glyph, margin, t, QImage::Format_RGB32);
1263  SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, (void *) contrast, 0);
1264 
1265  if (mask == 0)
1266  return QImage();
1267 
1268  // Gracefully handle the odd case when the display is 16-bit
1269  const QImage source = mask->image.depth() == 32
1270  ? mask->image
1272 
1273  QImage rgbMask(mask->width(), mask->height(), QImage::Format_RGB32);
1274  for (int y=0; y<mask->height(); ++y) {
1275  uint *dest = (uint *) rgbMask.scanLine(y);
1276  const uint *src = (uint *) source.scanLine(y);
1277  for (int x=0; x<mask->width(); ++x) {
1278  dest[x] = 0xffffffff - (0x00ffffff & src[x]);
1279  }
1280  }
1281 
1282  delete mask;
1283 
1284  return rgbMask;
1285 }
#define SPI_SETFONTSMOOTHINGCONTRAST
int width() const
QNativeImage * drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform, QImage::Format mask_format)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
#define SPI_GETFONTSMOOTHINGCONTRAST
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ ascent()

QFixed QFontEngineWin::ascent ( ) const
virtual

Implements QFontEngine.

Definition at line 596 of file qfontengine_win.cpp.

Referenced by boundingBox().

597 {
598  return tm.tmAscent;
599 }

◆ averageCharWidth()

QFixed QFontEngineWin::averageCharWidth ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 621 of file qfontengine_win.cpp.

Referenced by boundingBox().

622 {
623  return tm.tmAveCharWidth;
624 }

◆ boundingBox() [1/3]

glyph_metrics_t QFontEngineWin::boundingBox ( const QGlyphLayout glyphs)
virtual

Implements QFontEngine.

Definition at line 480 of file qfontengine_win.cpp.

Referenced by boundingBox().

481 {
482  if (glyphs.numGlyphs == 0)
483  return glyph_metrics_t();
484 
485  QFixed w = 0;
486  for (int i = 0; i < glyphs.numGlyphs; ++i)
487  w += glyphs.effectiveAdvance(i);
488 
489  return glyph_metrics_t(0, -tm.tmAscent, w - lastRightBearing(glyphs), tm.tmHeight, w, 0);
490 }
QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round=false)
QFixed effectiveAdvance(int item) const

◆ boundingBox() [2/3]

virtual glyph_metrics_t QFontEngineWin::boundingBox ( glyph_t  g)
inlinevirtual

Implements QFontEngine.

Definition at line 86 of file qfontengine_win_p.h.

Referenced by boundingBox().

86 { return boundingBox(g, QTransform()); }
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ boundingBox() [3/3]

glyph_metrics_t QFontEngineWin::boundingBox ( glyph_t  g,
const QTransform t 
)
virtual

Reimplemented from QFontEngine.

Definition at line 546 of file qfontengine_win.cpp.

547 {
548 #ifndef Q_WS_WINCE
549  HDC hdc = shared_dc();
550  SelectObject(hdc, hfont);
551 
552  glyph_metrics_t glyphMetrics;
553  bool success = getOutlineMetrics(glyph, t, &glyphMetrics);
554 
555  if (!ttf && !success) {
556  // Bitmap fonts
557  wchar_t ch = glyph;
558  ABCFLOAT abc;
559  GetCharABCWidthsFloat(hdc, ch, ch, &abc);
560  int width = qRound(abc.abcfB);
561 
562  return glyph_metrics_t(QFixed::fromReal(abc.abcfA), -tm.tmAscent, width, tm.tmHeight, width, 0).transformed(t);
563  }
564 
565  return glyphMetrics;
566 #else
567  HDC hdc = shared_dc();
568  HGDIOBJ oldFont = SelectObject(hdc, hfont);
569 
570  ABC abc;
571  int width;
572  int advance;
573 #ifdef GWES_MGTT // true type fonts
574  if (GetCharABCWidths(hdc, glyph, glyph, &abc)) {
575  width = qAbs(abc.abcA) + abc.abcB + qAbs(abc.abcC);
576  advance = abc.abcA + abc.abcB + abc.abcC;
577  }
578  else
579 #endif
580 #if defined(GWES_MGRAST) || defined(GWES_MGRAST2) // raster fonts
581  if (GetCharWidth32(hdc, glyph, glyph, &width)) {
582  advance = width;
583  }
584  else
585 #endif
586  { // fallback
587  width = tm.tmMaxCharWidth;
588  advance = width;
589  }
590 
591  SelectObject(hdc, oldFont);
592  return glyph_metrics_t(0, -tm.tmAscent, width, tm.tmHeight, advance, 0).transformed(t);
593 #endif
594 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
glyph_metrics_t transformed(const QTransform &xform) const
HDC shared_dc()
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ canRender()

bool QFontEngineWin::canRender ( const QChar string,
int  len 
)
virtual

Implements QFontEngine.

Definition at line 791 of file qfontengine_win.cpp.

Referenced by boundingBox().

792 {
793  if (symbol) {
794  for (int i = 0; i < len; ++i) {
795  unsigned int uc = getChar(string, i, len);
796  if (getTrueTypeGlyphIndex(cmap, uc) == 0) {
797  if (uc < 0x100) {
798  if (getTrueTypeGlyphIndex(cmap, uc + 0xf000) == 0)
799  return false;
800  } else {
801  return false;
802  }
803  }
804  }
805  } else if (ttf) {
806  for (int i = 0; i < len; ++i) {
807  unsigned int uc = getChar(string, i, len);
808  if (getTrueTypeGlyphIndex(cmap, uc) == 0)
809  return false;
810  }
811  } else {
812  while(len--) {
813  if (tm.tmFirstChar > string->unicode() || tm.tmLastChar < string->unicode())
814  return false;
815  }
816  }
817  return true;
818 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
const unsigned char * cmap
unsigned int getChar(const QChar *str, int &i, const int len)

◆ cloneWithSize()

QFontEngine * QFontEngineWin::cloneWithSize ( qreal  pixelSize) const
virtual

Reimplemented from QFontEngine.

Definition at line 1289 of file qfontengine_win.cpp.

Referenced by alphaMapForGlyph().

1290 {
1291  QFontDef request = fontDef;
1292  QString actualFontName = request.family;
1293  if (!uniqueFamilyName.isEmpty())
1294  request.family = uniqueFamilyName;
1295  request.pixelSize = pixelSize;
1296 
1297  QFontEngine *fontEngine = qt_load_font_engine_win(request);
1298  if (fontEngine != NULL)
1299  fontEngine->fontDef.family = actualFontName;
1300 
1301  return fontEngine;
1302 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
qreal pixelSize
Definition: qfont_p.h:90
QFontEngine * qt_load_font_engine_win(const QFontDef &request)
QFontDef fontDef
QString family
Definition: qfont_p.h:82

◆ descent()

QFixed QFontEngineWin::descent ( ) const
virtual

Implements QFontEngine.

Definition at line 601 of file qfontengine_win.cpp.

Referenced by boundingBox().

602 {
603  // ### we substract 1 to even out the historical +1 in QFontMetrics's
604  // ### height=asc+desc+1 equation. Fix in Qt5.
605  return tm.tmDescent - 1;
606 }

◆ drawGDIGlyph()

QNativeImage * QFontEngineWin::drawGDIGlyph ( HFONT  font,
glyph_t  glyph,
int  margin,
const QTransform xform,
QImage::Format  mask_format 
)
private

Definition at line 1090 of file qfontengine_win.cpp.

1092 {
1093  Q_UNUSED(mask_format)
1094  glyph_metrics_t gm = boundingBox(glyph);
1095 
1096 // printf(" -> for glyph %4x\n", glyph);
1097 
1098  int gx = gm.x.toInt();
1099  int gy = gm.y.toInt();
1100  int iw = gm.width.toInt();
1101  int ih = gm.height.toInt();
1102 
1103  if (iw <= 0 || iw <= 0)
1104  return 0;
1105 
1106  bool has_transformation = t.type() > QTransform::TxTranslate;
1107 
1108 #ifndef Q_WS_WINCE
1109  unsigned int options = ttf ? ETO_GLYPH_INDEX : 0;
1110  XFORM xform;
1111 
1112  if (has_transformation) {
1113  xform.eM11 = t.m11();
1114  xform.eM12 = t.m12();
1115  xform.eM21 = t.m21();
1116  xform.eM22 = t.m22();
1117  xform.eDx = margin;
1118  xform.eDy = margin;
1119 
1120  QtHDC qthdc;
1121  HDC hdc = qthdc.hdc();
1122 
1123  SetGraphicsMode(hdc, GM_ADVANCED);
1124  SetWorldTransform(hdc, &xform);
1125  HGDIOBJ old_font = SelectObject(hdc, font);
1126 
1127  int ggo_options = GGO_METRICS | (ttf ? GGO_GLYPH_INDEX : 0);
1128  GLYPHMETRICS tgm;
1129  MAT2 mat;
1130  memset(&mat, 0, sizeof(mat));
1131  mat.eM11.value = mat.eM22.value = 1;
1132 
1133  if (GetGlyphOutline(hdc, glyph, ggo_options, &tgm, 0, 0, &mat) == GDI_ERROR) {
1134  qWarning("QWinFontEngine: unable to query transformed glyph metrics...");
1135  return 0;
1136  }
1137 
1138  iw = tgm.gmBlackBoxX;
1139  ih = tgm.gmBlackBoxY;
1140 
1141  xform.eDx -= tgm.gmptGlyphOrigin.x;
1142  xform.eDy += tgm.gmptGlyphOrigin.y;
1143 
1144  SetGraphicsMode(hdc, GM_COMPATIBLE);
1145  SelectObject(hdc, old_font);
1146  }
1147 #else // else winc
1148  unsigned int options = 0;
1149 #ifdef DEBUG
1150  Q_ASSERT(!has_transformation);
1151 #else
1152  Q_UNUSED(has_transformation);
1153 #endif
1154 #endif
1155 
1156  QNativeImage *ni = new QNativeImage(iw + 2 * margin + 4,
1157  ih + 2 * margin + 4,
1159 
1160  /*If cleartype is enabled we use the standard system format even on Windows CE
1161  and not the special textbuffer format we have to use if cleartype is disabled*/
1162 
1163  ni->image.fill(0xffffffff);
1164 
1165  HDC hdc = ni->hdc;
1166 
1167  SelectObject(hdc, GetStockObject(NULL_BRUSH));
1168  SelectObject(hdc, GetStockObject(BLACK_PEN));
1169  SetTextColor(hdc, RGB(0,0,0));
1170  SetBkMode(hdc, TRANSPARENT);
1171  SetTextAlign(hdc, TA_BASELINE);
1172 
1173  HGDIOBJ old_font = SelectObject(hdc, font);
1174 
1175 #ifndef Q_OS_WINCE
1176  if (has_transformation) {
1177  SetGraphicsMode(hdc, GM_ADVANCED);
1178  SetWorldTransform(hdc, &xform);
1179  ExtTextOut(hdc, 0, 0, options, 0, (LPCWSTR) &glyph, 1, 0);
1180  } else
1181 #endif
1182  {
1183  ExtTextOut(hdc, -gx + margin, -gy + margin, options, 0, (LPCWSTR) &glyph, 1, 0);
1184  }
1185 
1186  SelectObject(hdc, old_font);
1187  return ni;
1188 }
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
#define ETO_GLYPH_INDEX
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
static QImage::Format systemFormat()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
HDC hdc() const
Q_CORE_EXPORT void qWarning(const char *,...)
int toInt() const
Definition: qfixed_p.h:76
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define GGO_GLYPH_INDEX
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
bool qt_cleartype_enabled

◆ emSquareSize()

QFixed QFontEngineWin::emSquareSize ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 1023 of file qfontengine_win.cpp.

1024 {
1025  return unitsPerEm;
1026 }

◆ faceId()

QFontEngine::FaceId QFontEngineWin::faceId ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 990 of file qfontengine_win.cpp.

991 {
992  return _faceId;
993 }

◆ getCMap()

void QFontEngineWin::getCMap ( )

Definition at line 193 of file qfontengine_win.cpp.

Referenced by alphaMapForGlyph().

194 {
195  ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE);
196  HDC hdc = shared_dc();
197  SelectObject(hdc, hfont);
198  bool symb = false;
199  if (ttf) {
200  cmapTable = getSfntTable(qbswap<quint32>(MAKE_TAG('c', 'm', 'a', 'p')));
201  int size = 0;
202  cmap = QFontEngine::getCMap(reinterpret_cast<const uchar *>(cmapTable.constData()),
203  cmapTable.size(), &symb, &size);
204  }
205  if (!cmap) {
206  ttf = false;
207  symb = false;
208  }
209  symbol = symb;
210  designToDevice = 1;
211  _faceId.index = 0;
212  if(cmap) {
213  OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc);
214  designToDevice = QFixed((int)otm->otmEMSquare)/int(otm->otmTextMetrics.tmHeight);
215  unitsPerEm = otm->otmEMSquare;
216  x_height = (int)otm->otmsXHeight;
218  _faceId.filename = QString::fromWCharArray((wchar_t *)((char *)otm + (quintptr)otm->otmpFullName)).toLatin1();
219  lineWidth = otm->otmsUnderscoreSize;
220  fsType = otm->otmfsType;
221  free(otm);
222  } else {
223  unitsPerEm = tm.tmHeight;
224  }
225 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
static const uchar * getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
#define MAKE_TAG(ch1, ch2, ch3, ch4)
const unsigned char * cmap
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
HDC shared_dc()
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static OUTLINETEXTMETRIC * getOutlineTextMetric(HDC hdc)
void loadKerningPairs(QFixed scalingFactor)
quint32 qbswap< quint32 >(quint32 source)
Definition: qendian.h:302
QByteArray getSfntTable(uint) const
QByteArray cmapTable

◆ getGlyphBearings()

void QFontEngineWin::getGlyphBearings ( glyph_t  glyph,
qreal leftBearing = 0,
qreal rightBearing = 0 
)
virtual

Reimplemented from QFontEngine.

Definition at line 657 of file qfontengine_win.cpp.

Referenced by alphaMapForGlyph().

658 {
659  HDC hdc = shared_dc();
660  SelectObject(hdc, hfont);
661 
662 #ifndef Q_WS_WINCE
663  if (ttf)
664 #endif
665 
666  {
667  ABC abcWidths;
668  GetCharABCWidthsI(hdc, glyph, 1, 0, &abcWidths);
669  if (leftBearing)
670  *leftBearing = abcWidths.abcA;
671  if (rightBearing)
672  *rightBearing = abcWidths.abcC;
673  }
674 
675 #ifndef Q_WS_WINCE
676  else {
677  QFontEngine::getGlyphBearings(glyph, leftBearing, rightBearing);
678  }
679 #endif
680 }
virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing=0, qreal *rightBearing=0)
HDC shared_dc()

◆ getGlyphIndexes()

int QFontEngineWin::getGlyphIndexes ( const QChar ch,
int  numChars,
QGlyphLayout glyphs,
bool  mirrored 
) const

Definition at line 238 of file qfontengine_win.cpp.

Referenced by alphaMapForGlyph().

239 {
240  int i = 0;
241  int glyph_pos = 0;
242  if (mirrored) {
243 #if defined(Q_WS_WINCE)
244  {
245 #else
246  if (symbol) {
247  for (; i < numChars; ++i, ++glyph_pos) {
248  unsigned int uc = getChar(str, i, numChars);
249  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
250  if (!glyphs->glyphs[glyph_pos] && uc < 0x100)
251  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
252  }
253  } else if (ttf) {
254  for (; i < numChars; ++i, ++glyph_pos) {
255  unsigned int uc = getChar(str, i, numChars);
256  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, QChar::mirroredChar(uc));
257  }
258  } else {
259 #endif
260  wchar_t first = tm.tmFirstChar;
261  wchar_t last = tm.tmLastChar;
262 
263  for (; i < numChars; ++i, ++glyph_pos) {
264  uint ucs = QChar::mirroredChar(getChar(str, i, numChars));
265  if (
266 #ifdef Q_WS_WINCE
267  tm.tmFirstChar > 60000 || // see line 375
268 #endif
269  ucs >= first && ucs <= last)
270  glyphs->glyphs[glyph_pos] = ucs;
271  else
272  glyphs->glyphs[glyph_pos] = 0;
273  }
274  }
275  } else {
276 #if defined(Q_WS_WINCE)
277  {
278 #else
279  if (symbol) {
280  for (; i < numChars; ++i, ++glyph_pos) {
281  unsigned int uc = getChar(str, i, numChars);
282  glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc);
283  if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
284  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
285  }
286  } else if (ttf) {
287  for (; i < numChars; ++i, ++glyph_pos) {
288  unsigned int uc = getChar(str, i, numChars);
289  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
290  }
291  } else {
292 #endif
293  wchar_t first = tm.tmFirstChar;
294  wchar_t last = tm.tmLastChar;
295 
296  for (; i < numChars; ++i, ++glyph_pos) {
297  uint uc = getChar(str, i, numChars);
298  if (
299 #ifdef Q_WS_WINCE
300  tm.tmFirstChar > 60000 || // see comment in QFontEngineWin
301 #endif
302  uc >= first && uc <= last)
303  glyphs->glyphs[glyph_pos] = uc;
304  else
305  glyphs->glyphs[glyph_pos] = 0;
306  }
307  }
308  }
309  glyphs->numGlyphs = glyph_pos;
310  return glyph_pos;
311 }
HB_Glyph * glyphs
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
QChar mirroredChar() const
Returns the mirrored character if this character is a mirrored character; otherwise returns the chara...
Definition: qchar.cpp:1016
const unsigned char * cmap
unsigned int uint
Definition: qglobal.h:996
unsigned int getChar(const QChar *str, int &i, const int len)
#define Q_WS_WINCE
Definition: qglobal.h:895

◆ getSfntTableData()

bool QFontEngineWin::getSfntTableData ( uint  tag,
uchar buffer,
uint length 
) const
virtual

Reimplemented from QFontEngine.

Definition at line 1073 of file qfontengine_win.cpp.

1074 {
1075  if (!ttf)
1076  return false;
1077  HDC hdc = shared_dc();
1078  SelectObject(hdc, hfont);
1079  DWORD t = qbswap<quint32>(tag);
1080  *length = GetFontData(hdc, t, 0, buffer, *length);
1081  return *length != GDI_ERROR;
1082 }
HDC shared_dc()
quint32 qbswap< quint32 >(quint32 source)
Definition: qendian.h:302

◆ getUnscaledGlyph()

void QFontEngineWin::getUnscaledGlyph ( glyph_t  glyph,
QPainterPath path,
glyph_metrics_t metrics 
)
virtual

Reimplemented from QFontEngine.

Definition at line 1055 of file qfontengine_win.cpp.

1056 {
1057  LOGFONT lf = logfont;
1058  lf.lfHeight = unitsPerEm;
1059  int flags = synthesized();
1060  if(flags & SynthesizedItalic)
1061  lf.lfItalic = false;
1062  lf.lfWidth = 0;
1063  HFONT hf = CreateFontIndirect(&lf);
1064  HDC hdc = shared_dc();
1065  HGDIOBJ oldfont = SelectObject(hdc, hf);
1066  QFixedPoint p;
1067  p.x = 0;
1068  p.y = 0;
1069  addGlyphToPath(glyph, p, hdc, path, ttf, metrics);
1070  DeleteObject(SelectObject(hdc, oldfont));
1071 }
QFixed y
Definition: qfixed_p.h:191
HDC shared_dc()
QFixed x
Definition: qfixed_p.h:190
static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc, QPainterPath *path, bool ttf, glyph_metrics_t *metric=0, qreal scale=1)
virtual int synthesized() const

◆ leading()

QFixed QFontEngineWin::leading ( ) const
virtual

Implements QFontEngine.

Definition at line 608 of file qfontengine_win.cpp.

Referenced by boundingBox().

609 {
610  return tm.tmExternalLeading;
611 }

◆ lineThickness()

QFixed QFontEngineWin::lineThickness ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 176 of file qfontengine_win.cpp.

177 {
178  if(lineWidth > 0)
179  return lineWidth;
180 
182 }
virtual QFixed lineThickness() const

◆ maxCharWidth()

qreal QFontEngineWin::maxCharWidth ( ) const
virtual

Implements QFontEngine.

Definition at line 626 of file qfontengine_win.cpp.

Referenced by boundingBox().

627 {
628  return tm.tmMaxCharWidth;
629 }

◆ minLeftBearing()

qreal QFontEngineWin::minLeftBearing ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 683 of file qfontengine_win.cpp.

Referenced by boundingBox().

684 {
685  if (lbearing == SHRT_MIN)
686  minRightBearing(); // calculates both
687 
688  return lbearing;
689 }
virtual qreal minRightBearing() const

◆ minRightBearing()

qreal QFontEngineWin::minRightBearing ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 691 of file qfontengine_win.cpp.

Referenced by boundingBox().

692 {
693 #ifdef Q_WS_WINCE
694  if (rbearing == SHRT_MIN) {
695  int ml = 0;
696  int mr = 0;
697  HDC hdc = shared_dc();
698  SelectObject(hdc, hfont);
699  if (ttf) {
700  ABC *abc = 0;
701  int n = tm.tmLastChar - tm.tmFirstChar;
702  if (n <= max_font_count) {
703  abc = new ABC[n+1];
704  GetCharABCWidths(hdc, tm.tmFirstChar, tm.tmLastChar, abc);
705  } else {
706  abc = new ABC[char_table_entries+1];
707  for(int i = 0; i < char_table_entries; i++)
708  GetCharABCWidths(hdc, char_table[i], char_table[i], abc+i);
709  n = char_table_entries;
710  }
711  ml = abc[0].abcA;
712  mr = abc[0].abcC;
713  for (int i = 1; i < n; i++) {
714  if (abc[i].abcA + abc[i].abcB + abc[i].abcC != 0) {
715  ml = qMin(ml,abc[i].abcA);
716  mr = qMin(mr,abc[i].abcC);
717  }
718  }
719  delete [] abc;
720  }
721  lbearing = ml;
722  rbearing = mr;
723  }
724 
725  return rbearing;
726 #else
727  if (rbearing == SHRT_MIN) {
728  int ml = 0;
729  int mr = 0;
730  HDC hdc = shared_dc();
731  SelectObject(hdc, hfont);
732  if (ttf) {
733  ABC *abc = 0;
734  int n = tm.tmLastChar - tm.tmFirstChar;
735  if (n <= max_font_count) {
736  abc = new ABC[n+1];
737  GetCharABCWidths(hdc, tm.tmFirstChar, tm.tmLastChar, abc);
738  } else {
739  abc = new ABC[char_table_entries+1];
740  for(int i = 0; i < char_table_entries; i++)
741  GetCharABCWidths(hdc, char_table[i], char_table[i], abc + i);
742  n = char_table_entries;
743  }
744  ml = abc[0].abcA;
745  mr = abc[0].abcC;
746  for (int i = 1; i < n; i++) {
747  if (abc[i].abcA + abc[i].abcB + abc[i].abcC != 0) {
748  ml = qMin(ml,abc[i].abcA);
749  mr = qMin(mr,abc[i].abcC);
750  }
751  }
752  delete [] abc;
753  } else {
754  ABCFLOAT *abc = 0;
755  int n = tm.tmLastChar - tm.tmFirstChar+1;
756  if (n <= max_font_count) {
757  abc = new ABCFLOAT[n];
758  GetCharABCWidthsFloat(hdc, tm.tmFirstChar, tm.tmLastChar, abc);
759  } else {
760  abc = new ABCFLOAT[char_table_entries];
761  for(int i = 0; i < char_table_entries; i++)
762  GetCharABCWidthsFloat(hdc, char_table[i], char_table[i], abc+i);
763  n = char_table_entries;
764  }
765  float fml = abc[0].abcfA;
766  float fmr = abc[0].abcfC;
767  for (int i=1; i<n; i++) {
768  if (abc[i].abcfA + abc[i].abcfB + abc[i].abcfC != 0) {
769  fml = qMin(fml,abc[i].abcfA);
770  fmr = qMin(fmr,abc[i].abcfC);
771  }
772  }
773  ml = int(fml - 0.9999);
774  mr = int(fmr - 0.9999);
775  delete [] abc;
776  }
777  lbearing = ml;
778  rbearing = mr;
779  }
780 
781  return rbearing;
782 #endif
783 }
static const ushort char_table[]
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static const int char_table_entries
HDC shared_dc()

◆ name()

const char * QFontEngineWin::name ( ) const
virtual

Implements QFontEngine.

Definition at line 786 of file qfontengine_win.cpp.

Referenced by boundingBox().

787 {
788  return 0;
789 }

◆ properties()

QFontEngine::Properties QFontEngineWin::properties ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 1028 of file qfontengine_win.cpp.

1029 {
1030  LOGFONT lf = logfont;
1031  lf.lfHeight = unitsPerEm;
1032  HFONT hf = CreateFontIndirect(&lf);
1033  HDC hdc = shared_dc();
1034  HGDIOBJ oldfont = SelectObject(hdc, hf);
1035  OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc);
1036  Properties p;
1037  p.emSquare = unitsPerEm;
1038  p.italicAngle = otm->otmItalicAngle;
1039  p.postscriptName = QString::fromWCharArray((wchar_t *)((char *)otm + (quintptr)otm->otmpFamilyName)).toLatin1();
1040  p.postscriptName += QString::fromWCharArray((wchar_t *)((char *)otm + (quintptr)otm->otmpStyleName)).toLatin1();
1041  p.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(p.postscriptName);
1042  p.boundingBox = QRectF(otm->otmrcFontBox.left, -otm->otmrcFontBox.top,
1043  otm->otmrcFontBox.right - otm->otmrcFontBox.left,
1044  otm->otmrcFontBox.top - otm->otmrcFontBox.bottom);
1045  p.ascent = otm->otmAscent;
1046  p.descent = -otm->otmDescent;
1047  p.leading = (int)otm->otmLineGap;
1048  p.capHeight = 0;
1049  p.lineWidth = otm->otmsUnderscoreSize;
1050  free(otm);
1051  DeleteObject(SelectObject(hdc, oldfont));
1052  return p;
1053 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
HDC shared_dc()
static QByteArray convertToPostscriptFontFamilyName(const QByteArray &fontFamily)
static OUTLINETEXTMETRIC * getOutlineTextMetric(HDC hdc)

◆ recalcAdvances()

void QFontEngineWin::recalcAdvances ( QGlyphLayout ,
QTextEngine::ShaperFlags   
) const
virtual

This is a callback from harfbuzz. The font engine uses the font-system in use to find out the advances of each glyph and set it on the layout.

Reimplemented from QFontEngine.

Definition at line 406 of file qfontengine_win.cpp.

407 {
408  HGDIOBJ oldFont = 0;
409  HDC hdc = shared_dc();
410  if (ttf && (flags & QTextEngine::DesignMetrics)) {
411  for(int i = 0; i < glyphs->numGlyphs; i++) {
412  unsigned int glyph = glyphs->glyphs[i];
413  if(int(glyph) >= designAdvancesSize) {
414  int newSize = (glyph + 256) >> 8 << 8;
416  newSize*sizeof(QFixed)));
417  for(int i = designAdvancesSize; i < newSize; ++i)
418  designAdvances[i] = -1000000;
419  designAdvancesSize = newSize;
420  }
421  if (designAdvances[glyph] < -999999) {
422  if (!oldFont)
423  oldFont = selectDesignFont();
424 
425  int width = 0;
426  calculateTTFGlyphWidth(hdc, glyph, width);
427  designAdvances[glyph] = QFixed(width) / designToDevice;
428  }
429  glyphs->advances_x[i] = designAdvances[glyph];
430  glyphs->advances_y[i] = 0;
431  }
432  if(oldFont)
433  DeleteObject(SelectObject(hdc, oldFont));
434  } else {
435  for(int i = 0; i < glyphs->numGlyphs; i++) {
436  unsigned int glyph = glyphs->glyphs[i];
437 
438  glyphs->advances_y[i] = 0;
439 
440  if (glyph >= widthCacheSize) {
441  int newSize = (glyph + 256) >> 8 << 8;
442  widthCache = q_check_ptr((unsigned char *)realloc(widthCache,
443  newSize*sizeof(QFixed)));
444  memset(widthCache + widthCacheSize, 0, newSize - widthCacheSize);
445  widthCacheSize = newSize;
446  }
447  glyphs->advances_x[i] = widthCache[glyph];
448  // font-width cache failed
449  if (glyphs->advances_x[i] == 0) {
450  int width = 0;
451  if (!oldFont)
452  oldFont = SelectObject(hdc, hfont);
453 
454  if (!ttf) {
455  QChar ch[2] = { ushort(glyph), 0 };
456  int chrLen = 1;
457  if (glyph > 0xffff) {
458  ch[0] = QChar::highSurrogate(glyph);
459  ch[1] = QChar::lowSurrogate(glyph);
460  ++chrLen;
461  }
462  SIZE size = {0, 0};
463  GetTextExtentPoint32(hdc, (wchar_t *)ch, chrLen, &size);
464  width = size.cx;
465  } else {
466  calculateTTFGlyphWidth(hdc, glyph, width);
467  }
468  glyphs->advances_x[i] = width;
469  // if glyph's within cache range, store it for later
470  if (width > 0 && width < 0x100)
471  widthCache[glyph] = width;
472  }
473  }
474 
475  if (oldFont)
476  SelectObject(hdc, oldFont);
477  }
478 }
T * q_check_ptr(T *p)
Definition: qglobal.h:1857
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
#define SIZE(large, small, mini)
HGDIOBJ selectDesignFont() const
static ushort highSurrogate(uint ucs4)
Returns the high surrogate value of a ucs4 code point.
Definition: qchar.h:303
static ushort lowSurrogate(uint ucs4)
Returns the low surrogate value of a ucs4 code point.
Definition: qchar.h:306
unsigned char * widthCache
void calculateTTFGlyphWidth(HDC hdc, UINT glyph, int &width)
HDC shared_dc()
unsigned short ushort
Definition: qglobal.h:995

◆ selectDesignFont()

HGDIOBJ QFontEngineWin::selectDesignFont ( ) const

Definition at line 372 of file qfontengine_win.cpp.

373 {
374  LOGFONT f = logfont;
375  f.lfHeight = unitsPerEm;
376  HFONT designFont = CreateFontIndirect(&f);
377  return SelectObject(shared_dc(), designFont);
378 }
HDC shared_dc()

◆ stringToCMap()

bool QFontEngineWin::stringToCMap ( const QChar str,
int  len,
QGlyphLayout glyphs,
int *  nglyphs,
QTextEngine::ShaperFlags  flags 
) const
virtual

Implements QFontEngine.

Definition at line 380 of file qfontengine_win.cpp.

381 {
382  if (*nglyphs < len) {
383  *nglyphs = len;
384  return false;
385  }
386 
387  *nglyphs = getGlyphIndexes(str, len, glyphs, flags & QTextEngine::RightToLeft);
388 
389  if (flags & QTextEngine::GlyphIndicesOnly)
390  return true;
391 
392  recalcAdvances(glyphs, flags);
393  return true;
394 }
virtual void recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs, bool mirrored) const

◆ synthesized()

int QFontEngineWin::synthesized ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 999 of file qfontengine_win.cpp.

1000 {
1001  if(synthesized_flags == -1) {
1002  synthesized_flags = 0;
1003  if(ttf) {
1004  const DWORD HEAD = MAKE_TAG('h', 'e', 'a', 'd');
1005  HDC hdc = shared_dc();
1006  SelectObject(hdc, hfont);
1007  uchar data[4];
1008  GetFontData(hdc, HEAD, 44, &data, 4);
1009  USHORT macStyle = getUShort(data);
1010  if (tm.tmItalic && !(macStyle & 2))
1012  if (fontDef.stretch != 100 && ttf)
1014  if (tm.tmWeight >= 500 && !(macStyle & 1))
1016  //qDebug() << "font is" << _name <<
1017  // "it=" << (macStyle & 2) << fontDef.style << "flags=" << synthesized_flags;
1018  }
1019  }
1020  return synthesized_flags;
1021 }
static quint16 getUShort(unsigned char *p)
unsigned char uchar
Definition: qglobal.h:994
#define MAKE_TAG(ch1, ch2, ch3, ch4)
static const char * data(const QByteArray &arr)
HDC shared_dc()
uint stretch
Definition: qfont_p.h:98
QFontDef fontDef

◆ type()

QFontEngine::Type QFontEngineWin::type ( ) const
virtual

Implements QFontEngine.

Definition at line 820 of file qfontengine_win.cpp.

Referenced by boundingBox().

821 {
822  return QFontEngine::Win;
823 }

◆ xHeight()

QFixed QFontEngineWin::xHeight ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 614 of file qfontengine_win.cpp.

Referenced by boundingBox().

615 {
616  if(x_height >= 0)
617  return x_height;
618  return QFontEngine::xHeight();
619 }
virtual QFixed xHeight() const

Properties

◆ _faceId

FaceId QFontEngineWin::_faceId

Definition at line 138 of file qfontengine_win_p.h.

◆ _name

QString QFontEngineWin::_name

Definition at line 122 of file qfontengine_win_p.h.

◆ cmap

const unsigned char* QFontEngineWin::cmap

Definition at line 131 of file qfontengine_win_p.h.

◆ cmapTable

QByteArray QFontEngineWin::cmapTable

Definition at line 132 of file qfontengine_win_p.h.

◆ designAdvances

QFixed* QFontEngineWin::designAdvances
mutable

Definition at line 144 of file qfontengine_win_p.h.

◆ designAdvancesSize

int QFontEngineWin::designAdvancesSize
mutable

Definition at line 145 of file qfontengine_win_p.h.

◆ designToDevice

QFixed QFontEngineWin::designToDevice

Definition at line 135 of file qfontengine_win_p.h.

◆ hasOutline

uint QFontEngineWin::hasOutline

Definition at line 128 of file qfontengine_win_p.h.

◆ hfont

HFONT QFontEngineWin::hfont

◆ lbearing

qreal QFontEngineWin::lbearing
mutable

Definition at line 133 of file qfontengine_win_p.h.

◆ lineWidth

QFixed QFontEngineWin::lineWidth
mutable

Definition at line 141 of file qfontengine_win_p.h.

◆ logfont

LOGFONT QFontEngineWin::logfont

Definition at line 125 of file qfontengine_win_p.h.

Referenced by QWin32PrintEngine::drawTextItem().

◆ lw

int QFontEngineWin::lw

Definition at line 130 of file qfontengine_win_p.h.

◆ rbearing

qreal QFontEngineWin::rbearing
mutable

Definition at line 134 of file qfontengine_win_p.h.

◆ stockFont

uint QFontEngineWin::stockFont

Definition at line 126 of file qfontengine_win_p.h.

◆ synthesized_flags

int QFontEngineWin::synthesized_flags
mutable

Definition at line 140 of file qfontengine_win_p.h.

◆ tm

TEXTMETRIC QFontEngineWin::tm

◆ ttf

uint QFontEngineWin::ttf

Definition at line 127 of file qfontengine_win_p.h.

Referenced by draw_text_item_win().

◆ uniqueFamilyName

QString QFontEngineWin::uniqueFamilyName

Definition at line 123 of file qfontengine_win_p.h.

◆ unitsPerEm

int QFontEngineWin::unitsPerEm

Definition at line 136 of file qfontengine_win_p.h.

◆ widthCache

unsigned char* QFontEngineWin::widthCache
mutable

Definition at line 142 of file qfontengine_win_p.h.

◆ widthCacheSize

uint QFontEngineWin::widthCacheSize
mutable

Definition at line 143 of file qfontengine_win_p.h.

◆ x_height

QFixed QFontEngineWin::x_height

Definition at line 137 of file qfontengine_win_p.h.


The documentation for this class was generated from the following files: