Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
QFontEngineDirectWrite Class Reference

#include <qfontenginedirectwrite_p.h>

Inheritance diagram for QFontEngineDirectWrite:
QFontEngine QObject

Public Functions

void addGlyphsToPath (glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
 
glyph_metrics_t alphaMapBoundingBox (glyph_t glyph, QFixed subPixelPosition, const QTransform &matrix, GlyphFormat format)
 
QImage alphaMapForGlyph (glyph_t, QFixed subPixelPosition, const QTransform &t)
 
QImage alphaRGBMapForGlyph (glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
 
QFixed ascent () const
 
glyph_metrics_t boundingBox (const QGlyphLayout &glyphs)
 
glyph_metrics_t boundingBox (glyph_t g)
 
bool canRender (const QChar *string, int len)
 
QFontEnginecloneWithSize (qreal pixelSize) const
 
QFixed descent () const
 
QFixed emSquareSize () const
 
bool getSfntTableData (uint tag, uchar *buffer, uint *length) const
 
QFixed leading () const
 
QFixed lineThickness () const
 
qreal maxCharWidth () const
 
const char * name () const
 
 QFontEngineDirectWrite (IDWriteFactory *directWriteFactory, IDWriteFontFace *directWriteFontFace, qreal pixelSize)
 
void recalcAdvances (QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
 
bool stringToCMap (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
 
bool supportsSubPixelPositions () const
 
Type type () const
 
QFixed xHeight () const
 
 ~QFontEngineDirectWrite ()
 
- Public Functions inherited from QFontEngine
void addBitmapFontToPath (qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)
 
virtual void addOutlineToPath (qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags)
 
virtual QImage alphaMapForGlyph (glyph_t)
 
virtual QImage alphaMapForGlyph (glyph_t glyph, QFixed subPixelPosition)
 
virtual QImage alphaMapForGlyph (glyph_t, const QTransform &t)
 
virtual QFixed averageCharWidth () const
 
virtual glyph_metrics_t boundingBox (glyph_t glyph, const QTransform &matrix)
 
virtual void doKerning (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
virtual FaceId faceId () const
 
virtual void getGlyphBearings (glyph_t glyph, qreal *leftBearing=0, qreal *rightBearing=0)
 
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
 
virtual void getUnscaledGlyph (glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
 
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)
 
virtual qreal minLeftBearing () const
 
virtual qreal minRightBearing () const
 
virtual Properties properties () const
 
 QFontEngine ()
 
virtual void removeGlyphFromCache (glyph_t)
 
void setGlyphCache (void *key, QFontEngineGlyphCache *data)
 
virtual int synthesized () 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...
 

Private Functions

void collectMetrics ()
 
QImage imageForGlyph (glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
 

Properties

QFixed m_ascent
 
QFixed m_descent
 
IDWriteBitmapRenderTarget * m_directWriteBitmapRenderTarget
 
IDWriteFactory * m_directWriteFactory
 
IDWriteFontFace * m_directWriteFontFace
 
FaceId m_faceId
 
QFixed m_lineGap
 
QFixed m_lineThickness
 
int m_unitsPerEm
 
QFixed m_xHeight
 

Friends

class QRawFontPrivate
 

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)
 
- 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
 
- 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 68 of file qfontenginedirectwrite_p.h.

Constructors and Destructors

◆ QFontEngineDirectWrite()

QFontEngineDirectWrite::QFontEngineDirectWrite ( IDWriteFactory *  directWriteFactory,
IDWriteFontFace *  directWriteFontFace,
qreal  pixelSize 
)
explicit

Definition at line 173 of file qfontenginedirectwrite.cpp.

Referenced by cloneWithSize().

176  : m_directWriteFontFace(directWriteFontFace)
177  , m_directWriteFactory(directWriteFactory)
179  , m_lineThickness(-1)
180  , m_unitsPerEm(-1)
181  , m_ascent(-1)
182  , m_descent(-1)
183  , m_xHeight(-1)
184  , m_lineGap(-1)
185 {
186  m_directWriteFactory->AddRef();
187  m_directWriteFontFace->AddRef();
188 
190  collectMetrics();
191 }
IDWriteFontFace * m_directWriteFontFace
IDWriteBitmapRenderTarget * m_directWriteBitmapRenderTarget
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
qreal pixelSize
Definition: qfont_p.h:90
QFontDef fontDef

◆ ~QFontEngineDirectWrite()

QFontEngineDirectWrite::~QFontEngineDirectWrite ( )

Definition at line 193 of file qfontenginedirectwrite.cpp.

194 {
195  m_directWriteFactory->Release();
196  m_directWriteFontFace->Release();
197 
200 }
IDWriteFontFace * m_directWriteFontFace
IDWriteBitmapRenderTarget * m_directWriteBitmapRenderTarget

Functions

◆ addGlyphsToPath()

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

Reimplemented from QFontEngine.

Definition at line 341 of file qfontenginedirectwrite.cpp.

343 {
344  if (m_directWriteFontFace == 0)
345  return;
346 
347  QVarLengthArray<UINT16> glyphIndices(nglyphs);
348  QVarLengthArray<DWRITE_GLYPH_OFFSET> glyphOffsets(nglyphs);
349  QVarLengthArray<FLOAT> glyphAdvances(nglyphs);
350 
351  for (int i=0; i<nglyphs; ++i) {
352  glyphIndices[i] = glyphs[i];
353  glyphOffsets[i].advanceOffset = positions[i].x.toReal();
354  glyphOffsets[i].ascenderOffset = -positions[i].y.toReal();
355  glyphAdvances[i] = 0.0;
356  }
357 
358  GeometrySink geometrySink(path);
359  HRESULT hr = m_directWriteFontFace->GetGlyphRunOutline(
361  glyphIndices.data(),
362  glyphAdvances.data(),
363  glyphOffsets.data(),
364  nglyphs,
365  false,
366  flags & QTextItem::RightToLeft,
367  &geometrySink
368  );
369 
370  if (FAILED(hr))
371  qErrnoWarning("QFontEngineDirectWrite::addGlyphsToPath: GetGlyphRunOutline failed");
372 }
IDWriteFontFace * m_directWriteFontFace
QFixed y
Definition: qfixed_p.h:191
qreal pixelSize
Definition: qfont_p.h:90
QFixed x
Definition: qfixed_p.h:190
long HRESULT
qreal toReal() const
Definition: qfixed_p.h:77
QFontDef fontDef
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ alphaMapBoundingBox()

glyph_metrics_t QFontEngineDirectWrite::alphaMapBoundingBox ( glyph_t  glyph,
QFixed  subPixelPosition,
const QTransform matrix,
GlyphFormat  format 
)
virtual

Reimplemented from QFontEngine.

Definition at line 390 of file qfontenginedirectwrite.cpp.

393 {
394  glyph_metrics_t bbox = QFontEngine::boundingBox(glyph, matrix); // To get transformed advance
395 
396  UINT16 glyphIndex = glyph;
397  FLOAT glyphAdvance = 0;
398 
399  DWRITE_GLYPH_OFFSET glyphOffset;
400  glyphOffset.advanceOffset = 0;
401  glyphOffset.ascenderOffset = 0;
402 
403  DWRITE_GLYPH_RUN glyphRun;
404  glyphRun.fontFace = m_directWriteFontFace;
405  glyphRun.fontEmSize = fontDef.pixelSize;
406  glyphRun.glyphCount = 1;
407  glyphRun.glyphIndices = &glyphIndex;
408  glyphRun.glyphAdvances = &glyphAdvance;
409  glyphRun.isSideways = false;
410  glyphRun.bidiLevel = 0;
411  glyphRun.glyphOffsets = &glyphOffset;
412 
413  DWRITE_MATRIX transform;
414  transform.dx = subPixelPosition.toReal();
415  transform.dy = 0;
416  transform.m11 = matrix.m11();
417  transform.m12 = matrix.m12();
418  transform.m21 = matrix.m21();
419  transform.m22 = matrix.m22();
420 
421  IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
422  HRESULT hr = m_directWriteFactory->CreateGlyphRunAnalysis(
423  &glyphRun,
424  1.0f,
425  &transform,
426  DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
427  DWRITE_MEASURING_MODE_NATURAL,
428  0.0, 0.0,
429  &glyphAnalysis
430  );
431 
432  if (SUCCEEDED(hr)) {
433  RECT rect;
434  glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
435  glyphAnalysis->Release();
436 
437  return glyph_metrics_t(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
438  bbox.xoff, bbox.yoff);
439  } else {
440  return glyph_metrics_t();
441  }
442 }
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
IDWriteFontFace * m_directWriteFontFace
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
qreal pixelSize
Definition: qfont_p.h:90
long HRESULT
qreal toReal() const
Definition: qfixed_p.h:77
QFontDef fontDef
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ alphaMapForGlyph()

QImage QFontEngineDirectWrite::alphaMapForGlyph ( glyph_t  glyph,
QFixed  subPixelPosition,
const QTransform t 
)
virtual

Reimplemented from QFontEngine.

Definition at line 513 of file qfontenginedirectwrite.cpp.

515 {
516  QImage im = imageForGlyph(glyph, subPixelPosition, 0, xform);
517 
518  QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
519  QVector<QRgb> colors(256);
520  for (int i=0; i<256; ++i)
521  colors[i] = qRgba(0, 0, 0, i);
522  indexed.setColorTable(colors);
523 
524  for (int y=0; y<im.height(); ++y) {
525  uint *src = (uint*) im.scanLine(y);
526  uchar *dst = indexed.scanLine(y);
527  for (int x=0; x<im.width(); ++x) {
528  *dst = 255 - (qt_pow_gamma[qGray(0xffffffff - *src)] * 255. / 2047.);
529  ++dst;
530  ++src;
531  }
532  }
533 
534  return indexed;
535 }
QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
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
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
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
uint qt_pow_gamma[256]
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ alphaRGBMapForGlyph()

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

Reimplemented from QFontEngine.

Definition at line 640 of file qfontenginedirectwrite.cpp.

644 {
645  QImage mask = imageForGlyph(t, subPixelPosition, margin, xform);
646  return mask.depth() == 32
647  ? mask
649 }
QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
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

◆ ascent()

QFixed QFontEngineDirectWrite::ascent ( ) const
virtual

Implements QFontEngine.

Definition at line 477 of file qfontenginedirectwrite.cpp.

478 {
480  ? m_ascent.round()
481  : m_ascent;
482 }
QFixed round() const
Definition: qfixed_p.h:80
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92

◆ boundingBox() [1/2]

glyph_metrics_t QFontEngineDirectWrite::boundingBox ( const QGlyphLayout glyphs)
virtual

Implements QFontEngine.

Definition at line 374 of file qfontenginedirectwrite.cpp.

375 {
376  if (glyphs.numGlyphs == 0)
377  return glyph_metrics_t();
378 
380 
381  QFixed w = 0;
382  for (int i = 0; i < glyphs.numGlyphs; ++i) {
383  w += round ? glyphs.effectiveAdvance(i).round() : glyphs.effectiveAdvance(i);
384 
385  }
386 
387  return glyph_metrics_t(0, -m_ascent, w - lastRightBearing(glyphs), m_ascent + m_descent, w, 0);
388 }
QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round=false)
QFixed round() const
Definition: qfixed_p.h:80
QFixed effectiveAdvance(int item) const
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92

◆ boundingBox() [2/2]

glyph_metrics_t QFontEngineDirectWrite::boundingBox ( glyph_t  g)
virtual

Implements QFontEngine.

Definition at line 444 of file qfontenginedirectwrite.cpp.

445 {
446  if (m_directWriteFontFace == 0)
447  return glyph_metrics_t();
448 
449  UINT16 glyphIndex = g;
450 
451  DWRITE_GLYPH_METRICS glyphMetrics;
452  HRESULT hr = m_directWriteFontFace->GetDesignGlyphMetrics(&glyphIndex, 1, &glyphMetrics);
453  if (SUCCEEDED(hr)) {
454  QFixed advanceWidth = DESIGN_TO_LOGICAL(glyphMetrics.advanceWidth);
455  QFixed leftSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.leftSideBearing);
456  QFixed rightSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.rightSideBearing);
457  QFixed advanceHeight = DESIGN_TO_LOGICAL(glyphMetrics.advanceHeight);
458  QFixed verticalOriginY = DESIGN_TO_LOGICAL(glyphMetrics.verticalOriginY);
459 
461  advanceWidth = advanceWidth.round();
462  advanceHeight = advanceHeight.round();
463  }
464 
465  QFixed width = advanceWidth - leftSideBearing - rightSideBearing;
466 
467  return glyph_metrics_t(-leftSideBearing, -verticalOriginY,
468  width, m_ascent + m_descent,
469  advanceWidth, advanceHeight);
470  } else {
471  qErrnoWarning("QFontEngineDirectWrite::boundingBox: GetDesignGlyphMetrics failed");
472  }
473 
474  return glyph_metrics_t();
475 }
IDWriteFontFace * m_directWriteFontFace
QFixed round() const
Definition: qfixed_p.h:80
#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE)
long HRESULT
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ canRender()

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

Implements QFontEngine.

Definition at line 656 of file qfontenginedirectwrite.cpp.

657 {
658  QVarLengthArray<UINT32> codePoints(len);
659  int actualLength = 0;
660  for (int i=0; i<len; ++i, actualLength++)
661  codePoints[actualLength] = getChar(string, i, len);
662 
663  QVarLengthArray<UINT16> glyphIndices(actualLength);
664  HRESULT hr = m_directWriteFontFace->GetGlyphIndices(codePoints.data(), actualLength,
665  glyphIndices.data());
666  if (FAILED(hr)) {
667  qErrnoWarning(hr, "QFontEngineDirectWrite::canRender: GetGlyphIndices failed");
668  return false;
669  } else {
670  for (int i=0; i<glyphIndices.size(); ++i) {
671  if (glyphIndices.at(i) == 0)
672  return false;
673  }
674 
675  return true;
676  }
677 }
unsigned int getChar(const QChar *str, int &i, const int len)
IDWriteFontFace * m_directWriteFontFace
long HRESULT
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ cloneWithSize()

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

Reimplemented from QFontEngine.

Definition at line 684 of file qfontenginedirectwrite.cpp.

685 {
687  pixelSize);
688 
689  fontEngine->fontDef = fontDef;
690  fontEngine->fontDef.pixelSize = pixelSize;
691 
692  return fontEngine;
693 }
IDWriteFontFace * m_directWriteFontFace
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
qreal pixelSize
Definition: qfont_p.h:90
QFontEngineDirectWrite(IDWriteFactory *directWriteFactory, IDWriteFontFace *directWriteFontFace, qreal pixelSize)
QFontDef fontDef

◆ collectMetrics()

void QFontEngineDirectWrite::collectMetrics ( )
private

Definition at line 202 of file qfontenginedirectwrite.cpp.

Referenced by QFontEngineDirectWrite().

203 {
204  if (m_directWriteFontFace != 0) {
205  DWRITE_FONT_METRICS metrics;
206 
207  m_directWriteFontFace->GetMetrics(&metrics);
208  m_unitsPerEm = metrics.designUnitsPerEm;
209 
210  m_lineThickness = DESIGN_TO_LOGICAL(metrics.underlineThickness);
211  m_ascent = DESIGN_TO_LOGICAL(metrics.ascent);
212  m_descent = DESIGN_TO_LOGICAL(metrics.descent);
213  m_xHeight = DESIGN_TO_LOGICAL(metrics.xHeight);
214  m_lineGap = DESIGN_TO_LOGICAL(metrics.lineGap);
215  }
216 }
IDWriteFontFace * m_directWriteFontFace
#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE)

◆ descent()

QFixed QFontEngineDirectWrite::descent ( ) const
virtual

Implements QFontEngine.

Definition at line 484 of file qfontenginedirectwrite.cpp.

485 {
487  ? (m_descent - 1).round()
488  : (m_descent - 1);
489 }
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92

◆ emSquareSize()

QFixed QFontEngineDirectWrite::emSquareSize ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 262 of file qfontenginedirectwrite.cpp.

263 {
264  if (m_unitsPerEm > 0)
265  return m_unitsPerEm;
266  else
267  return QFontEngine::emSquareSize();
268 }
virtual QFixed emSquareSize() const

◆ getSfntTableData()

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

Reimplemented from QFontEngine.

Definition at line 226 of file qfontenginedirectwrite.cpp.

227 {
228  if (m_directWriteFontFace) {
229  DWORD t = qbswap<quint32>(tag);
230 
231  const void *tableData = 0;
232  void *tableContext = 0;
233  UINT32 tableSize;
234  BOOL exists;
235  HRESULT hr = m_directWriteFontFace->TryGetFontTable(
236  t, &tableData, &tableSize, &tableContext, &exists
237  );
238 
239  if (SUCCEEDED(hr)) {
240  if (!exists)
241  return false;
242 
243  if (buffer == 0) {
244  *length = tableSize;
245  return true;
246  } else if (*length < tableSize) {
247  return false;
248  }
249 
250  qMemCopy(buffer, tableData, tableSize);
251  m_directWriteFontFace->ReleaseFontTable(tableContext);
252 
253  return true;
254  } else {
255  qErrnoWarning("QFontEngineDirectWrite::getSfntTableData: TryGetFontTable failed");
256  }
257  }
258 
259  return false;
260 }
IDWriteFontFace * m_directWriteFontFace
void * qMemCopy(void *dest, const void *src, size_t n)
Definition: qglobal.cpp:2508
long HRESULT
quint32 qbswap< quint32 >(quint32 source)
Definition: qendian.h:302
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ imageForGlyph()

QImage QFontEngineDirectWrite::imageForGlyph ( glyph_t  t,
QFixed  subPixelPosition,
int  margin,
const QTransform xform 
)
private

Definition at line 542 of file qfontenginedirectwrite.cpp.

Referenced by alphaMapForGlyph(), and alphaRGBMapForGlyph().

546 {
547  UINT16 glyphIndex = t;
548  FLOAT glyphAdvance = 0;
549 
550  DWRITE_GLYPH_OFFSET glyphOffset;
551  glyphOffset.advanceOffset = 0;
552  glyphOffset.ascenderOffset = 0;
553 
554  DWRITE_GLYPH_RUN glyphRun;
555  glyphRun.fontFace = m_directWriteFontFace;
556  glyphRun.fontEmSize = fontDef.pixelSize;
557  glyphRun.glyphCount = 1;
558  glyphRun.glyphIndices = &glyphIndex;
559  glyphRun.glyphAdvances = &glyphAdvance;
560  glyphRun.isSideways = false;
561  glyphRun.bidiLevel = 0;
562  glyphRun.glyphOffsets = &glyphOffset;
563 
564  DWRITE_MATRIX transform;
565  transform.dx = subPixelPosition.toReal();
566  transform.dy = 0;
567  transform.m11 = xform.m11();
568  transform.m12 = xform.m12();
569  transform.m21 = xform.m21();
570  transform.m22 = xform.m22();
571 
572  IDWriteGlyphRunAnalysis *glyphAnalysis = NULL;
573  HRESULT hr = m_directWriteFactory->CreateGlyphRunAnalysis(
574  &glyphRun,
575  1.0f,
576  &transform,
577  DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
578  DWRITE_MEASURING_MODE_NATURAL,
579  0.0, 0.0,
580  &glyphAnalysis
581  );
582 
583  if (SUCCEEDED(hr)) {
584  RECT rect;
585  glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect);
586 
587  rect.left -= margin;
588  rect.top -= margin;
589  rect.right += margin;
590  rect.bottom += margin;
591 
592  int width = rect.right - rect.left;
593  int height = rect.bottom - rect.top;
594 
595  int size = width * height * 3;
596  if (size > 0) {
597  BYTE *alphaValues = new BYTE[size];
598  qMemSet(alphaValues, size, 0);
599 
600  hr = glyphAnalysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1,
601  &rect,
602  alphaValues,
603  size);
604 
605  if (SUCCEEDED(hr)) {
606  QImage img(width, height, QImage::Format_RGB32);
607  img.fill(0xffffffff);
608 
609  for (int y=0; y<height; ++y) {
610  uint *dest = reinterpret_cast<uint *>(img.scanLine(y));
611  BYTE *src = alphaValues + width * 3 * y;
612 
613  for (int x=0; x<width; ++x) {
614  dest[x] = *(src) << 16
615  | *(src + 1) << 8
616  | *(src + 2);
617 
618  src += 3;
619  }
620  }
621 
622  delete[] alphaValues;
623  glyphAnalysis->Release();
624 
625  return img;
626  } else {
627  delete[] alphaValues;
628  glyphAnalysis->Release();
629 
630  qErrnoWarning("QFontEngineDirectWrite::imageForGlyph: CreateAlphaTexture failed");
631  }
632  }
633  } else {
634  qErrnoWarning("QFontEngineDirectWrite::imageForGlyph: CreateGlyphRunAnalysis failed");
635  }
636 
637  return QImage();
638 }
#define BYTE
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
IDWriteFontFace * m_directWriteFontFace
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
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
qreal pixelSize
Definition: qfont_p.h:90
long HRESULT
void * qMemSet(void *dest, int c, size_t n)
Definition: qglobal.cpp:2509
qreal toReal() const
Definition: qfixed_p.h:77
QFontDef fontDef
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ leading()

QFixed QFontEngineDirectWrite::leading ( ) const
virtual

Implements QFontEngine.

Definition at line 491 of file qfontenginedirectwrite.cpp.

492 {
494  ? m_lineGap.round()
495  : m_lineGap;
496 }
QFixed round() const
Definition: qfixed_p.h:80
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92

◆ lineThickness()

QFixed QFontEngineDirectWrite::lineThickness ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 218 of file qfontenginedirectwrite.cpp.

219 {
220  if (m_lineThickness > 0)
221  return m_lineThickness;
222  else
224 }
virtual QFixed lineThickness() const

◆ maxCharWidth()

qreal QFontEngineDirectWrite::maxCharWidth ( ) const
virtual

Implements QFontEngine.

Definition at line 505 of file qfontenginedirectwrite.cpp.

506 {
507  // ###
508  return 0;
509 }

◆ name()

const char * QFontEngineDirectWrite::name ( ) const
virtual

Implements QFontEngine.

Definition at line 651 of file qfontenginedirectwrite.cpp.

652 {
653  return 0;
654 }

◆ recalcAdvances()

void QFontEngineDirectWrite::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 314 of file qfontenginedirectwrite.cpp.

Referenced by stringToCMap().

315 {
316  if (m_directWriteFontFace == 0)
317  return;
318 
319  QVarLengthArray<UINT16> glyphIndices(glyphs->numGlyphs);
320 
321  // ### Caching?
322  for(int i=0; i<glyphs->numGlyphs; i++)
323  glyphIndices[i] = UINT16(glyphs->glyphs[i]);
324 
325  QVarLengthArray<DWRITE_GLYPH_METRICS> glyphMetrics(glyphIndices.size());
326  HRESULT hr = m_directWriteFontFace->GetDesignGlyphMetrics(glyphIndices.data(),
327  glyphIndices.size(),
328  glyphMetrics.data());
329  if (SUCCEEDED(hr)) {
330  for (int i=0; i<glyphs->numGlyphs; ++i) {
331  glyphs->advances_x[i] = DESIGN_TO_LOGICAL(glyphMetrics[i].advanceWidth);
333  glyphs->advances_x[i] = glyphs->advances_x[i].round();
334  glyphs->advances_y[i] = 0;
335  }
336  } else {
337  qErrnoWarning("QFontEngineDirectWrite::recalcAdvances: GetDesignGlyphMetrics failed");
338  }
339 }
IDWriteFontFace * m_directWriteFontFace
#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE)
long HRESULT
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ stringToCMap()

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

Implements QFontEngine.

Definition at line 280 of file qfontenginedirectwrite.cpp.

282 {
283  if (m_directWriteFontFace != 0) {
284  QVarLengthArray<UINT32> codePoints(len);
285  for (int i=0; i<len; ++i) {
286  codePoints[i] = getChar(str, i, len);
287  if (flags & QTextEngine::RightToLeft)
288  codePoints[i] = QChar::mirroredChar(codePoints[i]);
289  }
290 
291  QVarLengthArray<UINT16> glyphIndices(len);
292  HRESULT hr = m_directWriteFontFace->GetGlyphIndicesW(codePoints.data(),
293  len,
294  glyphIndices.data());
295 
296  if (SUCCEEDED(hr)) {
297  for (int i=0; i<len; ++i)
298  glyphs->glyphs[i] = glyphIndices[i];
299 
300  *nglyphs = len;
301 
302  if (!(flags & QTextEngine::GlyphIndicesOnly))
303  recalcAdvances(glyphs, 0);
304 
305  return true;
306  } else {
307  qErrnoWarning("QFontEngineDirectWrite::stringToCMap: GetGlyphIndicesW failed");
308  }
309  }
310 
311  return false;
312 }
HB_Glyph * glyphs
unsigned int getChar(const QChar *str, int &i, const int len)
IDWriteFontFace * m_directWriteFontFace
void recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const
QChar mirroredChar() const
Returns the mirrored character if this character is a mirrored character; otherwise returns the chara...
Definition: qchar.cpp:1016
long HRESULT
if(void) toggleToolbarShown
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ supportsSubPixelPositions()

bool QFontEngineDirectWrite::supportsSubPixelPositions ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 537 of file qfontenginedirectwrite.cpp.

538 {
539  return true;
540 }

◆ type()

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

Implements QFontEngine.

Definition at line 679 of file qfontenginedirectwrite.cpp.

◆ xHeight()

QFixed QFontEngineDirectWrite::xHeight ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 498 of file qfontenginedirectwrite.cpp.

499 {
501  ? m_xHeight.round()
502  : m_xHeight;
503 }
QFixed round() const
Definition: qfixed_p.h:80
QFontDef fontDef
uint styleStrategy
Definition: qfont_p.h:92

Friends and Related Functions

◆ QRawFontPrivate

friend class QRawFontPrivate
friend

Definition at line 114 of file qfontenginedirectwrite_p.h.

Properties

◆ m_ascent

QFixed QFontEngineDirectWrite::m_ascent
private

Definition at line 125 of file qfontenginedirectwrite_p.h.

Referenced by ascent(), boundingBox(), and collectMetrics().

◆ m_descent

QFixed QFontEngineDirectWrite::m_descent
private

Definition at line 126 of file qfontenginedirectwrite_p.h.

Referenced by boundingBox(), collectMetrics(), and descent().

◆ m_directWriteBitmapRenderTarget

IDWriteBitmapRenderTarget* QFontEngineDirectWrite::m_directWriteBitmapRenderTarget
private

Definition at line 121 of file qfontenginedirectwrite_p.h.

Referenced by ~QFontEngineDirectWrite().

◆ m_directWriteFactory

IDWriteFactory* QFontEngineDirectWrite::m_directWriteFactory
private

◆ m_directWriteFontFace

IDWriteFontFace* QFontEngineDirectWrite::m_directWriteFontFace
private

◆ m_faceId

FaceId QFontEngineDirectWrite::m_faceId
private

Definition at line 129 of file qfontenginedirectwrite_p.h.

◆ m_lineGap

QFixed QFontEngineDirectWrite::m_lineGap
private

Definition at line 128 of file qfontenginedirectwrite_p.h.

Referenced by collectMetrics(), and leading().

◆ m_lineThickness

QFixed QFontEngineDirectWrite::m_lineThickness
private

Definition at line 123 of file qfontenginedirectwrite_p.h.

Referenced by collectMetrics(), and lineThickness().

◆ m_unitsPerEm

int QFontEngineDirectWrite::m_unitsPerEm
private

Definition at line 124 of file qfontenginedirectwrite_p.h.

Referenced by collectMetrics(), and emSquareSize().

◆ m_xHeight

QFixed QFontEngineDirectWrite::m_xHeight
private

Definition at line 127 of file qfontenginedirectwrite_p.h.

Referenced by collectMetrics(), and xHeight().


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