Qt 4.8
Classes | Public Types | Public Functions | Static Public Functions | Properties | List of all members
QFontEngineQPA Class Reference

#include <qfontengine_qpa_p.h>

Inheritance diagram for QFontEngineQPA:
QFontEngine QObject

Classes

struct  Block
 
struct  Glyph
 
struct  Header
 
struct  Tag
 

Public Types

enum  { CurrentMajorVersion = 2, CurrentMinorVersion = 0 }
 
enum  BlockTag { CMapBlock, GMapBlock, GlyphBlock }
 
enum  GlyphFormat { BitmapGlyphs = 1, AlphamapGlyphs = 8 }
 
enum  HeaderTag {
  Tag_FontName, Tag_FileName, Tag_FileIndex, Tag_FontRevision,
  Tag_FreeText, Tag_Ascent, Tag_Descent, Tag_Leading,
  Tag_XHeight, Tag_AverageCharWidth, Tag_MaxCharWidth, Tag_LineThickness,
  Tag_MinLeftBearing, Tag_MinRightBearing, Tag_UnderlinePosition, Tag_GlyphFormat,
  Tag_PixelSize, Tag_Weight, Tag_Style, Tag_EndOfHeader,
  Tag_WritingSystems, NumTags
}
 
enum  TagType {
  StringType, FixedType, UInt8Type, UInt32Type,
  BitFieldType
}
 
- 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 Functions

void addOutlineToPath (qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
 
QImage alphaMapForGlyph (glyph_t t)
 
QFixed ascent () const
 
glyph_metrics_t boundingBox (const QGlyphLayout &glyphs)
 
glyph_metrics_t boundingBox (glyph_t glyph)
 
bool canRender (const QChar *string, int len)
 
QFixed descent () const
 
FaceId faceId () const
 
const GlyphfindGlyph (glyph_t g) const
 
bool getSfntTableData (uint tag, uchar *buffer, uint *length) const
 
virtual int glyphCount () const
 
bool isValid () const
 
QFixed leading () const
 
QFixed lineThickness () const
 
qreal maxCharWidth () const
 
qreal minLeftBearing () const
 
qreal minRightBearing () const
 
const char * name () const
 
 QFontEngineQPA (const QFontDef &def, const QByteArray &data)
 
void recalcAdvances (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
bool stringToCMap (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
 
Type type () const
 
QFixed underlinePosition () const
 
 ~QFontEngineQPA ()
 
- Public Functions inherited from QFontEngine
void addBitmapFontToPath (qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)
 
virtual void addGlyphsToPath (glyph_t *glyphs, QFixedPoint *positions, int nglyphs, QPainterPath *path, QTextItem::RenderFlags flags)
 
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, const QTransform &t)
 
virtual QImage alphaMapForGlyph (glyph_t, QFixed subPixelPosition, const QTransform &t)
 
virtual QImage alphaRGBMapForGlyph (glyph_t, QFixed subPixelPosition, int margin, const QTransform &t)
 
virtual QFixed averageCharWidth () const
 
virtual glyph_metrics_t boundingBox (glyph_t glyph, const QTransform &matrix)
 
virtual QFontEnginecloneWithSize (qreal) const
 
virtual void doKerning (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
virtual QFixed emSquareSize () 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
 
HB_Face harfbuzzFace () const
 
HB_Font harfbuzzFont () const
 
void loadKerningPairs (QFixed scalingFactor)
 
virtual Properties properties () const
 
 QFontEngine ()
 
virtual void removeGlyphFromCache (glyph_t)
 
void setGlyphCache (void *key, QFontEngineGlyphCache *data)
 
virtual bool supportsSubPixelPositions () const
 
virtual int synthesized () const
 
glyph_metrics_t tightBoundingBox (const QGlyphLayout &glyphs)
 
virtual QFixed xHeight () 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...
 

Static Public Functions

static QVariant extractHeaderField (const uchar *data, HeaderTag tag)
 
static bool verifyHeader (const uchar *data, int size)
 
- 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)
 

Properties

quint32 cmapOffset
 
int cmapSize
 
int dataSize
 
QString encodedFileName
 
const ucharexternalCMap
 
FaceId face_id
 
const ucharfontData
 
QByteArray freetypeCMapTable
 
quint32 glyphDataOffset
 
quint32 glyphDataSize
 
quint32 glyphMapEntries
 
quint32 glyphMapOffset
 
QString internalFileName
 
bool kerning_pairs_loaded
 
bool readOnly
 

Additional Inherited Members

- 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...
 
- 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 72 of file qfontengine_qpa_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
CurrentMajorVersion 
CurrentMinorVersion 

Definition at line 122 of file qfontengine_qpa_p.h.

◆ BlockTag

Enumerator
CMapBlock 
GMapBlock 
GlyphBlock 

Definition at line 130 of file qfontengine_qpa_p.h.

◆ GlyphFormat

Enumerator
BitmapGlyphs 
AlphamapGlyphs 

Definition at line 117 of file qfontengine_qpa_p.h.

◆ HeaderTag

Enumerator
Tag_FontName 
Tag_FileName 
Tag_FileIndex 
Tag_FontRevision 
Tag_FreeText 
Tag_Ascent 
Tag_Descent 
Tag_Leading 
Tag_XHeight 
Tag_AverageCharWidth 
Tag_MaxCharWidth 
Tag_LineThickness 
Tag_MinLeftBearing 
Tag_MinRightBearing 
Tag_UnderlinePosition 
Tag_GlyphFormat 
Tag_PixelSize 
Tag_Weight 
Tag_Style 
Tag_EndOfHeader 
Tag_WritingSystems 
NumTags 

Definition at line 77 of file qfontengine_qpa_p.h.

77  {
78  Tag_FontName, // 0 string
79  Tag_FileName, // 1 string
80  Tag_FileIndex, // 2 quint32
81  Tag_FontRevision, // 3 quint32
82  Tag_FreeText, // 4 string
83  Tag_Ascent, // 5 QFixed
84  Tag_Descent, // 6 QFixed
85  Tag_Leading, // 7 QFixed
86  Tag_XHeight, // 8 QFixed
87  Tag_AverageCharWidth, // 9 QFixed
88  Tag_MaxCharWidth, // 10 QFixed
89  Tag_LineThickness, // 11 QFixed
90  Tag_MinLeftBearing, // 12 QFixed
91  Tag_MinRightBearing, // 13 QFixed
92  Tag_UnderlinePosition, // 14 QFixed
93  Tag_GlyphFormat, // 15 quint8
94  Tag_PixelSize, // 16 quint8
95  Tag_Weight, // 17 quint8
96  Tag_Style, // 18 quint8
97  Tag_EndOfHeader, // 19 string
98  Tag_WritingSystems, // 20 bitfield
99 
100  NumTags
101  };

◆ TagType

Enumerator
StringType 
FixedType 
UInt8Type 
UInt32Type 
BitFieldType 

Definition at line 103 of file qfontengine_qpa_p.h.

Constructors and Destructors

◆ QFontEngineQPA()

QFontEngineQPA::QFontEngineQPA ( const QFontDef def,
const QByteArray data 
)

Definition at line 237 of file qfontengine_qpa.cpp.

238  : fontData(reinterpret_cast<const uchar *>(data.constData())), dataSize(data.size())
239 {
240  fontDef = def;
241  cache_cost = 100;
242  externalCMap = 0;
243  cmapOffset = 0;
244  cmapSize = 0;
245  glyphMapOffset = 0;
246  glyphMapEntries = 0;
247  glyphDataOffset = 0;
248  glyphDataSize = 0;
249  kerning_pairs_loaded = false;
250  readOnly = true;
251 
252 #if defined(DEBUG_FONTENGINE)
253  qDebug() << "QFontEngineQPA::QFontEngineQPA( fd =" << fd << ", renderingFontEngine =" << renderingFontEngine << ')';
254 #endif
255 
256  if (!verifyHeader(fontData, dataSize)) {
257 #if defined(DEBUG_FONTENGINE)
258  qDebug() << "verifyHeader failed!";
259 #endif
260  return;
261  }
262 
263  const Header *header = reinterpret_cast<const Header *>(fontData);
264 
265  readOnly = (header->lock == 0xffffffff);
266 
267  const uchar *imgData = fontData + sizeof(Header) + qFromBigEndian<quint16>(header->dataSize);
268  const uchar *endPtr = fontData + dataSize;
269  while (imgData <= endPtr - 8) {
270  quint16 blockTag = readValue<quint16>(imgData);
271  imgData += 2; // skip padding
272  quint32 blockSize = readValue<quint32>(imgData);
273 
274  if (blockTag == CMapBlock) {
275  cmapOffset = imgData - fontData;
277  } else if (blockTag == GMapBlock) {
278  glyphMapOffset = imgData - fontData;
279  glyphMapEntries = blockSize / 4;
280  } else if (blockTag == GlyphBlock) {
281  glyphDataOffset = imgData - fontData;
283  }
284 
285  imgData += blockSize;
286  }
287 
290 
291  // get the real cmap
292  if (cmapOffset) {
293  int tableSize = cmapSize;
294  const uchar *cmapPtr = getCMap(fontData + cmapOffset, tableSize, &symbol, &cmapSize);
295  if (cmapPtr)
296  cmapOffset = cmapPtr - fontData;
297  else
298  cmapOffset = 0;
299  } else if (externalCMap) {
300  int tableSize = cmapSize;
301  externalCMap = getCMap(externalCMap, tableSize, &symbol, &cmapSize);
302  }
303 
304  // verify all the positions in the glyphMap
305  if (glyphMapOffset) {
306  const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset);
307  for (uint i = 0; i < glyphMapEntries; ++i) {
308  quint32 glyphDataPos = qFromBigEndian<quint32>(gmapPtr[i]);
309  if (glyphDataPos == 0xffffffff)
310  continue;
311  if (glyphDataPos >= glyphDataSize) {
312  // error
313  glyphMapOffset = 0;
314  glyphMapEntries = 0;
315  break;
316  }
317  }
318  }
319 
320 #if defined(DEBUG_FONTENGINE)
321  if (!isValid())
322  qDebug() << "fontData" << fontData << "dataSize" << dataSize
323  << "externalCMap" << externalCMap << "cmapOffset" << cmapOffset
324  << "glyphMapOffset" << glyphMapOffset << "glyphDataOffset" << glyphDataOffset
325  << "fd" << fd << "glyphDataSize" << glyphDataSize;
326 #endif
327 }
const int blockSize
static const uchar * getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize)
quint32 qFromBigEndian< quint32 >(const uchar *src)
Definition: qendian.h:239
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
static QString toString(Register *reg, int type, bool *ok=0)
const uchar * externalCMap
unsigned short quint16
Definition: qglobal.h:936
unsigned int uint
Definition: qglobal.h:996
quint16 qFromBigEndian< quint16 >(const uchar *src)
Definition: qendian.h:249
bool isValid() const
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static bool verifyHeader(const uchar *data, int size)
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
QFontDef fontDef
const uchar * fontData

◆ ~QFontEngineQPA()

QFontEngineQPA::~QFontEngineQPA ( )

Definition at line 329 of file qfontengine_qpa.cpp.

330 {
331 }

Functions

◆ addOutlineToPath()

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

Reimplemented from QFontEngine.

Definition at line 415 of file qfontengine_qpa.cpp.

416 {
417  addBitmapFontToPath(x, y, glyphs, path, flags);
418 }
void addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags)

◆ alphaMapForGlyph()

QImage QFontEngineQPA::alphaMapForGlyph ( glyph_t  glyph)
virtual

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 402 of file qfontengine_qpa.cpp.

403 {
404  const Glyph *glyph = findGlyph(g);
405  if (!glyph)
406  return QImage();
407 
408  const uchar *bits = ((const uchar *) glyph) + sizeof(Glyph);
409 
410  QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Indexed8);
411 
412  return image;
413 }
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
const Glyph * findGlyph(glyph_t g) const

◆ ascent()

QFixed QFontEngineQPA::ascent ( ) const
virtual

Implements QFontEngine.

Definition at line 462 of file qfontengine_qpa.cpp.

Referenced by boundingBox().

463 {
464  return QFixed::fromReal(extractHeaderField(fontData, Tag_Ascent).value<qreal>());
465 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData

◆ boundingBox() [1/2]

glyph_metrics_t QFontEngineQPA::boundingBox ( const QGlyphLayout glyphs)
virtual

Implements QFontEngine.

Definition at line 420 of file qfontengine_qpa.cpp.

421 {
422  glyph_metrics_t overall;
423  // initialize with line height, we get the same behaviour on all platforms
424  overall.y = -ascent();
425  overall.height = ascent() + descent() + 1;
426 
427  QFixed ymax = 0;
428  QFixed xmax = 0;
429  for (int i = 0; i < glyphs.numGlyphs; i++) {
430  const Glyph *g = findGlyph(glyphs.glyphs[i]);
431  if (!g)
432  continue;
433 
434  QFixed x = overall.xoff + glyphs.offsets[i].x + g->x;
435  QFixed y = overall.yoff + glyphs.offsets[i].y + g->y;
436  overall.x = qMin(overall.x, x);
437  overall.y = qMin(overall.y, y);
438  xmax = qMax(xmax, x + g->width);
439  ymax = qMax(ymax, y + g->height);
440  overall.xoff += g->advance;
441  }
442  overall.height = qMax(overall.height, ymax - overall.y);
443  overall.width = xmax - overall.x;
444 
445  return overall;
446 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
HB_Glyph * glyphs
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QFixed y
Definition: qfixed_p.h:191
QFixed descent() const
QFixed x
Definition: qfixed_p.h:190
const Glyph * findGlyph(glyph_t g) const
QFixed ascent() const
QFixedPoint * offsets

◆ boundingBox() [2/2]

glyph_metrics_t QFontEngineQPA::boundingBox ( glyph_t  glyph)
virtual

Implements QFontEngine.

Definition at line 448 of file qfontengine_qpa.cpp.

449 {
450  glyph_metrics_t overall;
451  const Glyph *g = findGlyph(glyph);
452  if (!g)
453  return overall;
454  overall.x = g->x;
455  overall.y = g->y;
456  overall.width = g->width;
457  overall.height = g->height;
458  overall.xoff = g->advance;
459  return overall;
460 }
const Glyph * findGlyph(glyph_t g) const

◆ canRender()

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

Implements QFontEngine.

Definition at line 507 of file qfontengine_qpa.cpp.

508 {
510 
511  if (symbol) {
512  for (int i = 0; i < len; ++i) {
513  unsigned int uc = getChar(string, i, len);
514  glyph_t g = getTrueTypeGlyphIndex(cmap, uc);
515  if(!g && uc < 0x100)
516  g = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
517  if (!g)
518  return false;
519  }
520  } else {
521  for (int i = 0; i < len; ++i) {
522  unsigned int uc = getChar(string, i, len);
523  if (!getTrueTypeGlyphIndex(cmap, uc))
524  return false;
525  }
526  }
527  return true;
528 }
static QColor cmap[256]
Definition: qgl_mac.mm:760
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
unsigned char uchar
Definition: qglobal.h:994
const uchar * externalCMap
static unsigned int getChar(const QChar *str, int &i, const int len)
const uchar * fontData
unsigned int glyph_t

◆ descent()

QFixed QFontEngineQPA::descent ( ) const
virtual

Implements QFontEngine.

Definition at line 467 of file qfontengine_qpa.cpp.

Referenced by boundingBox().

468 {
469  return QFixed::fromReal(extractHeaderField(fontData, Tag_Descent).value<qreal>());
470 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData

◆ extractHeaderField()

QVariant QFontEngineQPA::extractHeaderField ( const uchar data,
HeaderTag  tag 
)
static

Definition at line 194 of file qfontengine_qpa.cpp.

Referenced by ascent(), descent(), leading(), lineThickness(), maxCharWidth(), minLeftBearing(), minRightBearing(), QFontEngineQPA(), QPlatformFontDatabase::registerQPF2Font(), and underlinePosition().

195 {
196  const Header *header = reinterpret_cast<const Header *>(data);
197  const uchar *tagPtr = data + sizeof(Header);
198  const uchar *endPtr = tagPtr + qFromBigEndian<quint16>(header->dataSize);
199  while (tagPtr < endPtr - 3) {
200  quint16 tag = readValue<quint16>(tagPtr);
201  quint16 length = readValue<quint16>(tagPtr);
202  if (tag == requestedTag) {
203  switch (tagTypes[requestedTag]) {
204  case StringType:
205  return QVariant(QString::fromUtf8(reinterpret_cast<const char *>(tagPtr), length));
206  case UInt32Type:
207  return QVariant(readValue<quint32>(tagPtr));
208  case UInt8Type:
209  return QVariant(uint(*tagPtr));
210  case FixedType:
211  return QVariant(QFixed::fromFixed(readValue<quint32>(tagPtr)).toReal());
212  case BitFieldType:
213  return QVariant(QByteArray(reinterpret_cast<const char *>(tagPtr), length));
214  }
215  return QVariant();
216  } else if (tag == Tag_EndOfHeader) {
217  break;
218  }
219  tagPtr += length;
220  }
221 
222  return QVariant();
223 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QFixed fromFixed(int fixed)
Definition: qfixed_p.h:71
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
unsigned char uchar
Definition: qglobal.h:994
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
static QFontEngineQPA::TagType tagTypes[QFontEngineQPA::NumTags]
quint16 qFromBigEndian< quint16 >(const uchar *src)
Definition: qendian.h:249
static qreal toReal(Register *reg, int type, bool *ok=0)

◆ faceId()

FaceId QFontEngineQPA::faceId ( ) const
inlinevirtual

Reimplemented from QFontEngine.

Definition at line 165 of file qfontengine_qpa_p.h.

165 { return face_id; }

◆ findGlyph()

const QFontEngineQPA::Glyph * QFontEngineQPA::findGlyph ( glyph_t  g) const

Definition at line 151 of file qfontengine_qpa.cpp.

Referenced by alphaMapForGlyph(), boundingBox(), recalcAdvances(), and stringToCMap().

152 {
153  if (!g || g >= glyphMapEntries)
154  return 0;
155  const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset);
156  quint32 glyphPos = qFromBigEndian<quint32>(gmapPtr[g]);
157  if (glyphPos > glyphDataSize) {
158  if (glyphPos == 0xffffffff)
159  return 0;
160 #if defined(DEBUG_FONTENGINE)
161  qDebug() << "glyph" << g << "outside of glyphData, remapping font file";
162 #endif
163  if (glyphPos > glyphDataSize)
164  return 0;
165  }
166  return reinterpret_cast<const Glyph *>(fontData + glyphDataOffset + glyphPos);
167 }
quint32 qFromBigEndian< quint32 >(const uchar *src)
Definition: qendian.h:239
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned int quint32
Definition: qglobal.h:938
const uchar * fontData

◆ getSfntTableData()

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

Reimplemented from QFontEngine.

Definition at line 333 of file qfontengine_qpa.cpp.

334 {
335  Q_UNUSED(tag);
336  Q_UNUSED(buffer);
337  *length = 0;
338  return false;
339 }
#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

◆ glyphCount()

virtual int QFontEngineQPA::glyphCount ( ) const
inlinevirtual

Reimplemented from QFontEngine.

Definition at line 191 of file qfontengine_qpa_p.h.

Referenced by QPAGenerator::writeGMap().

191 { return glyphMapEntries; }

◆ isValid()

bool QFontEngineQPA::isValid ( ) const

Definition at line 530 of file qfontengine_qpa.cpp.

Referenced by QFontEngineQPA().

531 {
532  return fontData && dataSize && (cmapOffset || externalCMap)
534 }
const uchar * externalCMap
const uchar * fontData

◆ leading()

QFixed QFontEngineQPA::leading ( ) const
virtual

Implements QFontEngine.

Definition at line 472 of file qfontengine_qpa.cpp.

473 {
474  return QFixed::fromReal(extractHeaderField(fontData, Tag_Leading).value<qreal>());
475 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData

◆ lineThickness()

QFixed QFontEngineQPA::lineThickness ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 497 of file qfontengine_qpa.cpp.

498 {
500 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData

◆ maxCharWidth()

qreal QFontEngineQPA::maxCharWidth ( ) const
virtual

Implements QFontEngine.

Definition at line 477 of file qfontengine_qpa.cpp.

478 {
480 }
double qreal
Definition: qglobal.h:1193
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332

◆ minLeftBearing()

qreal QFontEngineQPA::minLeftBearing ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 482 of file qfontengine_qpa.cpp.

483 {
485 }
double qreal
Definition: qglobal.h:1193
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332

◆ minRightBearing()

qreal QFontEngineQPA::minRightBearing ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 487 of file qfontengine_qpa.cpp.

488 {
490 }
double qreal
Definition: qglobal.h:1193
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332

◆ name()

const char* QFontEngineQPA::name ( ) const
inlinevirtual

Implements QFontEngine.

Definition at line 189 of file qfontengine_qpa_p.h.

189 { return "QPF2"; }

◆ recalcAdvances()

void QFontEngineQPA::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 389 of file qfontengine_qpa.cpp.

Referenced by stringToCMap().

390 {
391  for (int i = 0; i < glyphs->numGlyphs; ++i) {
392  const Glyph *g = findGlyph(glyphs->glyphs[i]);
393  if (!g) {
394  glyphs->glyphs[i] = 0;
395  continue;
396  }
397  glyphs->advances_x[i] = g->advance;
398  glyphs->advances_y[i] = 0;
399  }
400 }
const Glyph * findGlyph(glyph_t g) const

◆ stringToCMap()

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

Implements QFontEngine.

Definition at line 341 of file qfontengine_qpa.cpp.

342 {
343  if (*nglyphs < len) {
344  *nglyphs = len;
345  return false;
346  }
347 
348 #if defined(DEBUG_FONTENGINE)
349  QSet<QChar> seenGlyphs;
350 #endif
351 
353 
354  bool mirrored = flags & QTextEngine::RightToLeft;
355  int glyph_pos = 0;
356  if (symbol) {
357  for (int i = 0; i < len; ++i) {
358  unsigned int uc = getChar(str, i, len);
359  if (mirrored)
360  uc = QChar::mirroredChar(uc);
361  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
362  if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
363  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
364  ++glyph_pos;
365  }
366  } else {
367  for (int i = 0; i < len; ++i) {
368  unsigned int uc = getChar(str, i, len);
369  if (mirrored)
370  uc = QChar::mirroredChar(uc);
371  glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
372 #if 0 && defined(DEBUG_FONTENGINE)
373  QChar c(uc);
374  if (!findGlyph(glyphs[glyph_pos].glyph) && !seenGlyphs.contains(c))
375  qDebug() << "glyph for character" << c << '/' << hex << uc << "is" << dec << glyphs[glyph_pos].glyph;
376 
377  seenGlyphs.insert(c);
378 #endif
379  ++glyph_pos;
380  }
381  }
382 
383  *nglyphs = glyph_pos;
384  glyphs->numGlyphs = glyph_pos;
385  recalcAdvances(glyphs, flags);
386  return true;
387 }
unsigned char c[8]
Definition: qnumeric_p.h:62
HB_Glyph * glyphs
static QColor cmap[256]
Definition: qgl_mac.mm:760
void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, uint unicode)
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
bool contains(const T &value) const
Definition: qset.h:91
const uchar * externalCMap
QChar mirroredChar() const
Returns the mirrored character if this character is a mirrored character; otherwise returns the chara...
Definition: qchar.cpp:1016
const_iterator insert(const T &value)
Definition: qset.h:179
const Glyph * findGlyph(glyph_t g) const
static unsigned int getChar(const QChar *str, int &i, const int len)
const uchar * fontData

◆ type()

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

Implements QFontEngine.

Definition at line 502 of file qfontengine_qpa.cpp.

503 {
504  return QFontEngine::QPF2;
505 }

◆ underlinePosition()

QFixed QFontEngineQPA::underlinePosition ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 492 of file qfontengine_qpa.cpp.

493 {
495 }
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
const uchar * fontData

◆ verifyHeader()

bool QFontEngineQPA::verifyHeader ( const uchar data,
int  size 
)
static

Definition at line 169 of file qfontengine_qpa.cpp.

Referenced by QFontEngineQPA(), and QPlatformFontDatabase::registerQPF2Font().

170 {
171  VERIFY(size >= int(sizeof(Header)));
172  const Header *header = reinterpret_cast<const Header *>(data);
173  if (header->magic[0] != 'Q'
174  || header->magic[1] != 'P'
175  || header->magic[2] != 'F'
176  || header->magic[3] != '2')
177  return false;
178 
179  VERIFY(header->majorVersion <= CurrentMajorVersion);
180  const quint16 dataSize = qFromBigEndian<quint16>(header->dataSize);
181  VERIFY(size >= int(sizeof(Header)) + dataSize);
182 
183  const uchar *tagPtr = data + sizeof(Header);
184  const uchar *tagEndPtr = tagPtr + dataSize;
185  while (tagPtr < tagEndPtr - 3) {
186  tagPtr = verifyTag(tagPtr, tagEndPtr);
187  VERIFY(tagPtr);
188  }
189 
190  VERIFY(tagPtr <= tagEndPtr);
191  return true;
192 }
static const uchar * verifyTag(const uchar *tagPtr, const uchar *endPtr)
unsigned char uchar
Definition: qglobal.h:994
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
quint16 qFromBigEndian< quint16 >(const uchar *src)
Definition: qendian.h:249
#define VERIFY(condition)

Properties

◆ cmapOffset

quint32 QFontEngineQPA::cmapOffset
private

Definition at line 205 of file qfontengine_qpa_p.h.

Referenced by canRender(), isValid(), QFontEngineQPA(), and stringToCMap().

◆ cmapSize

int QFontEngineQPA::cmapSize
private

Definition at line 206 of file qfontengine_qpa_p.h.

Referenced by QFontEngineQPA().

◆ dataSize

int QFontEngineQPA::dataSize
private

Definition at line 203 of file qfontengine_qpa_p.h.

Referenced by isValid(), QFontEngineQPA(), and verifyHeader().

◆ encodedFileName

QString QFontEngineQPA::encodedFileName
private

Definition at line 212 of file qfontengine_qpa_p.h.

◆ externalCMap

const uchar* QFontEngineQPA::externalCMap
private

Definition at line 204 of file qfontengine_qpa_p.h.

Referenced by canRender(), isValid(), QFontEngineQPA(), and stringToCMap().

◆ face_id

FaceId QFontEngineQPA::face_id
private

Definition at line 215 of file qfontengine_qpa_p.h.

Referenced by QFontEngineQPA().

◆ fontData

const uchar* QFontEngineQPA::fontData
private

◆ freetypeCMapTable

QByteArray QFontEngineQPA::freetypeCMapTable
private

Definition at line 216 of file qfontengine_qpa_p.h.

◆ glyphDataOffset

quint32 QFontEngineQPA::glyphDataOffset
private

Definition at line 209 of file qfontengine_qpa_p.h.

Referenced by findGlyph(), isValid(), and QFontEngineQPA().

◆ glyphDataSize

quint32 QFontEngineQPA::glyphDataSize
private

Definition at line 210 of file qfontengine_qpa_p.h.

Referenced by findGlyph(), isValid(), and QFontEngineQPA().

◆ glyphMapEntries

quint32 QFontEngineQPA::glyphMapEntries
private

Definition at line 208 of file qfontengine_qpa_p.h.

Referenced by findGlyph(), and QFontEngineQPA().

◆ glyphMapOffset

quint32 QFontEngineQPA::glyphMapOffset
private

Definition at line 207 of file qfontengine_qpa_p.h.

Referenced by findGlyph(), isValid(), and QFontEngineQPA().

◆ internalFileName

QString QFontEngineQPA::internalFileName
private

Definition at line 211 of file qfontengine_qpa_p.h.

◆ kerning_pairs_loaded

bool QFontEngineQPA::kerning_pairs_loaded
mutableprivate

Definition at line 217 of file qfontengine_qpa_p.h.

Referenced by QFontEngineQPA().

◆ readOnly

bool QFontEngineQPA::readOnly
private

Definition at line 213 of file qfontengine_qpa_p.h.

Referenced by QFontEngineQPA().


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