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

#include <qfontengine_x11_p.h>

Inheritance diagram for QFontEngineXLFD:
QFontEngine QObject

Public Functions

virtual void addOutlineToPath (qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags)
 
virtual QImage alphaMapForGlyph (glyph_t)
 
virtual QFixed ascent () const
 
virtual glyph_metrics_t boundingBox (const QGlyphLayout &glyphs)
 
virtual glyph_metrics_t boundingBox (glyph_t glyph)
 
virtual bool canRender (const QChar *string, int len)
 
virtual QFixed descent () const
 
virtual QFontEngine::FaceId faceId () const
 
XFontStruct * fontStruct () const
 
virtual bool getSfntTableData (uint tag, uchar *buffer, uint *length) const
 
virtual void getUnscaledGlyph (glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
 
glyph_t glyphIndexToFreetypeGlyphIndex (glyph_t g) const
 
virtual QFixed leading () const
 
virtual qreal maxCharWidth () const
 
virtual qreal minLeftBearing () const
 
virtual qreal minRightBearing () const
 
virtual const char * name () const
 
FT_Face non_locked_face () const
 
QFontEngine::Properties properties () const
 
 QFontEngineXLFD (XFontStruct *f, const QByteArray &name, int mib)
 
virtual void recalcAdvances (QGlyphLayout *, QTextEngine::ShaperFlags) const
 
virtual bool stringToCMap (const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
 
virtual int synthesized () const
 
uint toUnicode (glyph_t g) const
 
virtual Type type () const
 
 ~QFontEngineXLFD ()
 
- 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
 
QFontEngineGlyphCacheglyphCache (void *key, QFontEngineGlyphCache::Type type, const QTransform &transform) const
 
virtual int glyphCount () const
 
HB_Face harfbuzzFace () const
 
HB_Font harfbuzzFont () const
 
virtual QFixed lineThickness () 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 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...
 

Private Functions

QBitmap bitmapForGlyphs (const QGlyphLayout &glyphs, const glyph_metrics_t &metrics, QTextItem::RenderFlags flags=0)
 

Properties

int _cmap
 
QTextCodec_codec
 
XFontStruct * _fs
 
QByteArray _name
 
QFontEngine::FaceId face_id
 
QFreetypeFacefreetype
 
int lbearing
 
int rbearing
 
int synth
 

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

Warning
This function is not part of the public interface. The font engine for X Logical Font Description (XLFD) fonts, which is for X11 systems without freetype.

Definition at line 82 of file qfontengine_x11_p.h.

Constructors and Destructors

◆ QFontEngineXLFD()

QFontEngineXLFD::QFontEngineXLFD ( XFontStruct *  f,
const QByteArray name,
int  mib 
)

Definition at line 323 of file qfontengine_x11.cpp.

324  : _fs(fs), _name(name), _codec(0), _cmap(mib)
325 {
327 
328  cache_cost = (((fs->max_byte1 - fs->min_byte1) *
329  (fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1)) +
330  fs->max_char_or_byte2 - fs->min_char_or_byte2);
331  cache_cost = ((fs->max_bounds.ascent + fs->max_bounds.descent) *
332  (fs->max_bounds.width * cache_cost / 8));
333  lbearing = SHRT_MIN;
334  rbearing = SHRT_MIN;
335  face_id.index = -1;
336  freetype = 0;
337  synth = 0;
338 }
XFontStruct * _fs
QFreetypeFace * freetype
int mib
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
QTextCodec * _codec
QFontEngine::FaceId face_id

◆ ~QFontEngineXLFD()

QFontEngineXLFD::~QFontEngineXLFD ( )

Definition at line 340 of file qfontengine_x11.cpp.

341 {
342  XFreeFont(QX11Info::display(), _fs);
343  _fs = 0;
344 #ifndef QT_NO_FREETYPE
345  if (freetype)
347 #endif
348 }
XFontStruct * _fs
QFreetypeFace * freetype
QFontEngine::FaceId face_id
void release(const QFontEngine::FaceId &face_id)
static Display * display()
Returns the default display for the application.

Functions

◆ addOutlineToPath()

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

Reimplemented from QFontEngine.

Definition at line 667 of file qfontengine_x11.cpp.

668 {
669  // cannot use QFontEngine::addBitmapFontToPath(), since we don't
670  // have direct access to the glyph bitmaps, so we have to draw
671  // onto a QBitmap, then convert to QImage, then to path
672  glyph_metrics_t metrics = boundingBox(glyphs);
673 
674  QImage image = bitmapForGlyphs(glyphs, metrics, flags).toImage();
675  if (image.isNull())
676  return;
677 
678  image = image.convertToFormat(QImage::Format_Mono);
679  const uchar *image_data = image.bits();
680  uint bpl = image.bytesPerLine();
681  // from qfontengine.cpp
682  extern void qt_addBitmapToPath(qreal x0, qreal y0, const uchar *image_data,
683  int bpl, int w, int h, QPainterPath *path);
684  qt_addBitmapToPath(x, y + metrics.y.toReal(), image_data, bpl, image.width(), image.height(), path);
685 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
Q_GUI_EXPORT void qt_addBitmapToPath(qreal x0, qreal y0, const uchar *image_data, int bpl, int w, int h, QPainterPath *path)
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
unsigned int uint
Definition: qglobal.h:996
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
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
qreal toReal() const
Definition: qfixed_p.h:77
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
QBitmap bitmapForGlyphs(const QGlyphLayout &glyphs, const glyph_metrics_t &metrics, QTextItem::RenderFlags flags=0)

◆ alphaMapForGlyph()

QImage QFontEngineXLFD::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 787 of file qfontengine_x11.cpp.

788 {
789  glyph_metrics_t metrics = boundingBox(glyph);
790 
791 /*
792  printf("a) w=%.2f, h=%.2f, xoff=%.2f, yoff=%.2f, x=%.2f, y=%.2f\n",
793  metrics.width.toReal(),
794  metrics.height.toReal(),
795  metrics.xoff.toReal(),
796  metrics.yoff.toReal(),
797  metrics.x.toReal(),
798  metrics.y.toReal());
799 */
800 
801  QGlyphLayoutArray<1> glyphs;
802  glyphs.glyphs[0] = glyph;
803 
804  QImage image = bitmapForGlyphs(glyphs, metrics).toImage();
805 //image.save(QString::fromLatin1("x11cache-%1.png").arg((int)glyph));
806 
808  QVector<QRgb> colors(256);
809  for (int i = 0; i < 256; ++i)
810  colors[i] = qRgba(0, 0, 0, i);
811  image.setColorTable(colors);
812 
813  int width = image.width();
814  int height = image.height();
815  for (int y = 0; y < height; ++y) {
816  uchar *bits = image.scanLine(y);
817  for (int x = 0; x < width; ++x)
818  bits[x] = ~(bits[x]-1);
819  }
820 
821  return image;
822 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
void setColorTable(const QVector< QRgb > colors)
Sets the color table used to translate color indexes to QRgb values, to the specified colors...
Definition: qimage.cpp:1744
HB_Glyph * glyphs
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)
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
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
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
Returns the height of the image.
Definition: qimage.cpp:1572
QBitmap bitmapForGlyphs(const QGlyphLayout &glyphs, const glyph_metrics_t &metrics, QTextItem::RenderFlags flags=0)
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ ascent()

QFixed QFontEngineXLFD::ascent ( ) const
virtual

Implements QFontEngine.

Definition at line 524 of file qfontengine_x11.cpp.

Referenced by boundingBox().

525 {
526  return _fs->ascent;
527 }
XFontStruct * _fs

◆ bitmapForGlyphs()

QBitmap QFontEngineXLFD::bitmapForGlyphs ( const QGlyphLayout glyphs,
const glyph_metrics_t metrics,
QTextItem::RenderFlags  flags = 0 
)
private

Definition at line 635 of file qfontengine_x11.cpp.

Referenced by addOutlineToPath(), and alphaMapForGlyph().

636 {
637  int w = metrics.width.toInt();
638  int h = metrics.height.toInt();
639  if (w <= 0 || h <= 0)
640  return QBitmap();
641 
643  data->resize(w, h);
644  QPixmap bm(data);
645  QPainter p(&bm);
646  p.fillRect(0, 0, w, h, Qt::color0);
647  p.setPen(Qt::color1);
648 
649  QTextItemInt item;
650  item.flags = flags;
651  item.ascent = -metrics.y;
652  item.descent = metrics.height - item.ascent;
653  item.width = metrics.width;
654  item.chars = 0;
655  item.num_chars = 0;
656  item.logClusters = 0;
657  item.glyphs = glyphs;
658  item.fontEngine = this;
659  item.f = 0;
660 
661  p.drawTextItem(QPointF(-metrics.x.toReal(), item.ascent.toReal()), item);
662  p.end();
663 
664  return QBitmap(bm);
665 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QFontEngine * fontEngine
const QChar * chars
RenderFlags flags
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void resize(int width, int height)=0
const unsigned short * logClusters
QGlyphLayout glyphs
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
Internal QTextItem.
int toInt() const
Definition: qfixed_p.h:76
static const char * data(const QByteArray &arr)
qreal toReal() const
Definition: qfixed_p.h:77
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
const QFont * f

◆ boundingBox() [1/2]

glyph_metrics_t QFontEngineXLFD::boundingBox ( const QGlyphLayout glyphs)
virtual

Implements QFontEngine.

Definition at line 472 of file qfontengine_x11.cpp.

Referenced by addOutlineToPath(), and alphaMapForGlyph().

473 {
474  int i;
475 
476  glyph_metrics_t overall;
477  // initialize with line height, we get the same behaviour on all platforms
478  overall.y = -ascent();
479  overall.height = ascent() + descent() + 1;
480  QFixed ymax;
481  QFixed xmax;
482  for (i = 0; i < glyphs.numGlyphs; i++) {
483  XCharStruct *xcs = charStruct(_fs, glyphs.glyphs[i]);
484  if (xcs) {
485  QFixed x = overall.xoff + glyphs.offsets[i].x + xcs->lbearing;
486  QFixed y = overall.yoff + glyphs.offsets[i].y - xcs->ascent;
487  overall.x = qMin(overall.x, x);
488  overall.y = qMin(overall.y, y);
489  // XCharStruct::rbearing is defined as distance from left edge to rightmost pixel
490  xmax = qMax(xmax, overall.xoff + glyphs.offsets[i].x + xcs->rbearing);
491  ymax = qMax(ymax, y + xcs->ascent + xcs->descent);
492  overall.xoff += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
493  } else {
494  QFixed size = _fs->ascent;
495  overall.x = qMin(overall.x, overall.xoff);
496  overall.y = qMin(overall.y, overall.yoff - size);
497  ymax = qMax(ymax, overall.yoff);
498  overall.xoff += size;
499  xmax = qMax(xmax, overall.xoff);
500  }
501  }
502  overall.height = qMax(overall.height, ymax - overall.y);
503  overall.width = xmax - overall.x;
504 
505  return overall;
506 }
QGlyphJustification * justifications
static QFixed fromFixed(int fixed)
Definition: qfixed_p.h:71
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QFixed * advances_x
HB_Glyph * glyphs
XFontStruct * _fs
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static XCharStruct * charStruct(XFontStruct *xfs, uint ch)
QFixed y
Definition: qfixed_p.h:191
QFixed x
Definition: qfixed_p.h:190
virtual QFixed descent() const
QFixedPoint * offsets
virtual QFixed ascent() const

◆ boundingBox() [2/2]

glyph_metrics_t QFontEngineXLFD::boundingBox ( glyph_t  glyph)
virtual

Implements QFontEngine.

Definition at line 508 of file qfontengine_x11.cpp.

509 {
510  glyph_metrics_t gm;
511  XCharStruct *xcs = charStruct(_fs, glyph);
512  if (xcs) {
513  // XCharStruct::rbearing is defined as distance from left edge to rightmost pixel
514  // XCharStruct::width is defined as the advance
515  gm = glyph_metrics_t(xcs->lbearing, -xcs->ascent, xcs->rbearing- xcs->lbearing, xcs->ascent + xcs->descent,
516  xcs->width, 0);
517  } else {
518  QFixed size = ascent();
519  gm = glyph_metrics_t(0, size, size, size, size, 0);
520  }
521  return gm;
522 }
XFontStruct * _fs
static XCharStruct * charStruct(XFontStruct *xfs, uint ch)
virtual QFixed ascent() const

◆ canRender()

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

Implements QFontEngine.

Definition at line 615 of file qfontengine_x11.cpp.

616 {
617  QVarLengthGlyphLayoutArray glyphs(len);
618  int nglyphs = len;
619  if (stringToCMap(string, len, &glyphs, &nglyphs, 0) == false) {
620  glyphs.resize(nglyphs);
621  stringToCMap(string, len, &glyphs, &nglyphs, 0);
622  }
623 
624  bool allExist = true;
625  for (int i = 0; i < nglyphs; i++) {
626  if (!glyphs.glyphs[i] || !charStruct(_fs, glyphs.glyphs[i])) {
627  allExist = false;
628  break;
629  }
630  }
631 
632  return allExist;
633 }
XFontStruct * _fs
static XCharStruct * charStruct(XFontStruct *xfs, uint ch)
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const

◆ descent()

QFixed QFontEngineXLFD::descent ( ) const
virtual

Implements QFontEngine.

Definition at line 529 of file qfontengine_x11.cpp.

Referenced by boundingBox().

530 {
531  return (_fs->descent-1);
532 }
XFontStruct * _fs

◆ faceId()

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

Reimplemented from QFontEngine.

Definition at line 687 of file qfontengine_x11.cpp.

688 {
689 #ifndef QT_NO_FREETYPE
690  if (face_id.index == -1) {
692  if (_codec)
694  if (freetype) {
695  const_cast<QFontEngineXLFD *>(this)->fsType = freetype->fsType();
696  } else {
697  face_id.index = 0;
699  }
700  }
701 #endif
702 
703  return face_id;
704 }
QFreetypeFace * freetype
static QFontEngine::FaceId fontFile(const QByteArray &_xname, QFreetypeFace **freetype, int *synth)
virtual int mibEnum() const =0
Subclasses of QTextCodec must reimplement this function.
QTextCodec * _codec
QFontEngine::FaceId face_id
virtual Properties properties() const
int fsType() const

◆ fontStruct()

XFontStruct* QFontEngineXLFD::fontStruct ( ) const
inline

Definition at line 116 of file qfontengine_x11_p.h.

Referenced by QX11PaintEngine::drawXLFD().

117  { return _fs; }
XFontStruct * _fs

◆ getSfntTableData()

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

Reimplemented from QFontEngine.

Definition at line 766 of file qfontengine_x11.cpp.

767 {
768 #ifndef QT_NO_FREETYPE
769  if (face_id.index == -1)
770  (void)faceId();
771  if (!freetype)
772  return false;
773  return freetype->getSfntTable(tag, buffer, length);
774 #else
775  Q_UNUSED(tag);
776  Q_UNUSED(buffer);
777  Q_UNUSED(length);
778  return false;
779 #endif
780 }
bool getSfntTable(uint tag, uchar *buffer, uint *length) const
QFreetypeFace * freetype
QFontEngine::FaceId face_id
#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
virtual QFontEngine::FaceId faceId() const

◆ getUnscaledGlyph()

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

Reimplemented from QFontEngine.

Definition at line 718 of file qfontengine_x11.cpp.

719 {
720  if (face_id.index == -1)
721  (void)faceId();
722 #ifndef QT_NO_FREETYPE
723  if (!freetype)
724 #endif
725  {
726  QFontEngine::getUnscaledGlyph(glyph, path, metrics);
727  return;
728  }
729 
730 #ifndef QT_NO_FREETYPE
731  freetype->lock();
732 
733  FT_Face face = freetype->face;
734  FT_Set_Char_Size(face, face->units_per_EM << 6, face->units_per_EM << 6, 0, 0);
735  freetype->xsize = face->units_per_EM << 6;
736  freetype->ysize = face->units_per_EM << 6;
737  FT_Set_Transform(face, 0, 0);
738  glyph = glyphIndexToFreetypeGlyphIndex(glyph);
739  FT_Load_Glyph(face, glyph, FT_LOAD_NO_BITMAP);
740 
741  int left = face->glyph->metrics.horiBearingX;
742  int right = face->glyph->metrics.horiBearingX + face->glyph->metrics.width;
743  int top = face->glyph->metrics.horiBearingY;
744  int bottom = face->glyph->metrics.horiBearingY - face->glyph->metrics.height;
745 
746  QFixedPoint p;
747  p.x = 0;
748  p.y = 0;
749  metrics->width = QFixed::fromFixed(right-left);
750  metrics->height = QFixed::fromFixed(top-bottom);
751  metrics->x = QFixed::fromFixed(left);
752  metrics->y = QFixed::fromFixed(-top);
753  metrics->xoff = QFixed::fromFixed(face->glyph->advance.x);
754 
755  if (!FT_IS_SCALABLE(freetype->face))
756  QFreetypeFace::addBitmapToPath(face->glyph, p, path);
757  else
758  QFreetypeFace::addGlyphToPath(face, face->glyph, p, path, face->units_per_EM << 6, face->units_per_EM << 6);
759 
760  FT_Set_Transform(face, &freetype->matrix, 0);
761  freetype->unlock();
762 #endif // QT_NO_FREETYPE
763 }
static QFixed fromFixed(int fixed)
Definition: qfixed_p.h:71
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
glyph_t glyphIndexToFreetypeGlyphIndex(glyph_t g) const
static void addGlyphToPath(FT_Face face, FT_GlyphSlot g, const QFixedPoint &point, QPainterPath *path, FT_Fixed x_scale, FT_Fixed y_scale)
QFixed y
Definition: qfixed_p.h:191
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
QFreetypeFace * freetype
static void addBitmapToPath(FT_GlyphSlot slot, const QFixedPoint &point, QPainterPath *path, bool=false)
virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
QFontEngine::FaceId face_id
QFixed x
Definition: qfixed_p.h:190
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
virtual QFontEngine::FaceId faceId() const

◆ glyphIndexToFreetypeGlyphIndex()

glyph_t QFontEngineXLFD::glyphIndexToFreetypeGlyphIndex ( glyph_t  g) const

Definition at line 852 of file qfontengine_x11.cpp.

853 {
854  return FT_Get_Char_Index(freetype->face, toUnicode(g));
855 }
QFreetypeFace * freetype
uint toUnicode(glyph_t g) const

◆ leading()

QFixed QFontEngineXLFD::leading ( ) const
virtual

Implements QFontEngine.

Definition at line 534 of file qfontengine_x11.cpp.

535 {
536  QFixed l = QFixed(qMin<int>(_fs->ascent, _fs->max_bounds.ascent)
537  + qMin<int>(_fs->descent, _fs->max_bounds.descent)) * QFixed::fromReal(0.15);
538  return l.ceil();
539 }
XFontStruct * _fs
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
QFactoryLoader * l
QFixed ceil() const
Definition: qfixed_p.h:82

◆ maxCharWidth()

qreal QFontEngineXLFD::maxCharWidth ( ) const
virtual

Implements QFontEngine.

Definition at line 541 of file qfontengine_x11.cpp.

542 {
543  return _fs->max_bounds.width;
544 }
XFontStruct * _fs

◆ minLeftBearing()

qreal QFontEngineXLFD::minLeftBearing ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 554 of file qfontengine_x11.cpp.

555 {
556  if (lbearing == SHRT_MIN) {
557  if (_fs->per_char) {
558  XCharStruct *cs = _fs->per_char;
559  int nc = maxIndex(_fs) + 1;
560  int mx = cs->lbearing;
561 
562  for (int c = 1; c < nc; c++) {
563  // ignore the bearings for characters whose ink is
564  // completely outside the normal bounding box
565  if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) ||
566  (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width))
567  continue;
568 
569  int nmx = cs[c].lbearing;
570 
571  if (nmx < mx)
572  mx = nmx;
573  }
574 
575  ((QFontEngineXLFD *)this)->lbearing = mx;
576  } else
577  ((QFontEngineXLFD *)this)->lbearing = _fs->min_bounds.lbearing;
578  }
579  return lbearing;
580 }
unsigned char c[8]
Definition: qnumeric_p.h:62
XFontStruct * _fs
static int maxIndex(XFontStruct *f)

◆ minRightBearing()

qreal QFontEngineXLFD::minRightBearing ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 582 of file qfontengine_x11.cpp.

583 {
584  if (rbearing == SHRT_MIN) {
585  if (_fs->per_char) {
586  XCharStruct *cs = _fs->per_char;
587  int nc = maxIndex(_fs) + 1;
588  int mx = cs->rbearing;
589 
590  for (int c = 1; c < nc; c++) {
591  // ignore the bearings for characters whose ink is
592  // completely outside the normal bounding box
593  if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) ||
594  (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width))
595  continue;
596 
597  int nmx = cs[c].rbearing;
598 
599  if (nmx < mx)
600  mx = nmx;
601  }
602 
603  ((QFontEngineXLFD *)this)->rbearing = mx;
604  } else
605  ((QFontEngineXLFD *)this)->rbearing = _fs->min_bounds.rbearing;
606  }
607  return rbearing;
608 }
unsigned char c[8]
Definition: qnumeric_p.h:62
XFontStruct * _fs
static int maxIndex(XFontStruct *f)

◆ name()

const char * QFontEngineXLFD::name ( ) const
virtual

Implements QFontEngine.

Definition at line 610 of file qfontengine_x11.cpp.

611 {
612  return _name;
613 }

◆ non_locked_face()

FT_Face QFontEngineXLFD::non_locked_face ( ) const

Definition at line 826 of file qfontengine_x11.cpp.

Referenced by ft_face(), and qt_x11_set_fallback_font_family().

827 {
828  return freetype ? freetype->face : 0;
829 }
QFreetypeFace * freetype

◆ properties()

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

Reimplemented from QFontEngine.

Definition at line 706 of file qfontengine_x11.cpp.

707 {
708  if (face_id.index == -1)
709  (void)faceId();
710 
711 #ifndef QT_NO_FREETYPE
712  if (freetype)
713  return freetype->properties();
714 #endif
715  return QFontEngine::properties();
716 }
QFreetypeFace * freetype
QFontEngine::FaceId face_id
QFontEngine::Properties properties() const
virtual Properties properties() const
virtual QFontEngine::FaceId faceId() const

◆ recalcAdvances()

void QFontEngineXLFD::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 426 of file qfontengine_x11.cpp.

Referenced by stringToCMap().

427 {
428  int i = glyphs->numGlyphs;
429  XCharStruct *xcs;
430  // inlined for better performance
431  if (!_fs->per_char) {
432  xcs = &_fs->min_bounds;
433  while (i != 0) {
434  --i;
435  const unsigned char r = glyphs->glyphs[i] >> 8;
436  const unsigned char c = glyphs->glyphs[i] & 0xff;
437  if (r >= _fs->min_byte1 &&
438  r <= _fs->max_byte1 &&
439  c >= _fs->min_char_or_byte2 &&
440  c <= _fs->max_char_or_byte2) {
441  glyphs->advances_x[i] = xcs->width;
442  } else {
443  glyphs->glyphs[i] = 0;
444  }
445  }
446  }
447  else if (!_fs->max_byte1) {
448  XCharStruct *base = _fs->per_char - _fs->min_char_or_byte2;
449  while (i != 0) {
450  unsigned int gl = glyphs->glyphs[--i];
451  xcs = (gl >= _fs->min_char_or_byte2 && gl <= _fs->max_char_or_byte2) ?
452  base + gl : 0;
453  if (!xcs || (!xcs->width && !xcs->ascent && !xcs->descent)) {
454  glyphs->glyphs[i] = 0;
455  } else {
456  glyphs->advances_x[i] = xcs->width;
457  }
458  }
459  }
460  else {
461  while (i != 0) {
462  xcs = charStruct(_fs, glyphs->glyphs[--i]);
463  if (!xcs) {
464  glyphs->glyphs[i] = 0;
465  } else {
466  glyphs->advances_x[i] = xcs->width;
467  }
468  }
469  }
470 }
unsigned char c[8]
Definition: qnumeric_p.h:62
XFontStruct * _fs
static const uint base
Definition: qurl.cpp:268
static XCharStruct * charStruct(XFontStruct *xfs, uint ch)

◆ stringToCMap()

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

Implements QFontEngine.

Definition at line 350 of file qfontengine_x11.cpp.

Referenced by canRender().

351 {
352  if (*nglyphs < len) {
353  *nglyphs = len;
354  return false;
355  }
356 
357  // filter out surrogates, we can't handle them anyway with XLFD fonts
358  QVarLengthArray<ushort> _s(len);
359  QChar *str = (QChar *)_s.data();
360  for (int i = 0; i < len; ++i) {
361  if (s[i].isHighSurrogate() && i < len-1 && s[i+1].isLowSurrogate()) {
362  *str = QChar();
363  ++i;
364  } else {
365  *str = s[i];
366  }
367  ++str;
368  }
369 
370  len = str - (QChar *)_s.data();
371  str = (QChar *)_s.data();
372 
373  bool mirrored = flags & QTextEngine::RightToLeft;
374  if (_codec) {
375  bool haveNbsp = false;
376  for (int i = 0; i < len; i++)
377  if (str[i].unicode() == 0xa0) {
378  haveNbsp = true;
379  break;
380  }
381 
383  QChar *chars = (QChar *)ch.data();
384  if (haveNbsp || mirrored) {
385  for (int i = 0; i < len; i++)
386  chars[i] = (str[i].unicode() == 0xa0 ? 0x20 :
387  (mirrored ? QChar::mirroredChar(str[i].unicode()) : str[i].unicode()));
388  } else {
389  for (int i = 0; i < len; i++)
390  chars[i] = str[i].unicode();
391  }
394  QByteArray ba = _codec->fromUnicode(chars, len, &state);
395  if (ba.length() == 2*len) {
396  // double byte encoding
397  const uchar *data = (const uchar *)ba.constData();
398  for (int i = 0; i < len; i++) {
399  glyphs->glyphs[i] = ((ushort)data[0] << 8) + data[1];
400  data += 2;
401  }
402  } else {
403  const uchar *data = (const uchar *)ba.constData();
404  for (int i = 0; i < len; i++)
405  glyphs->glyphs[i] = (ushort)data[i];
406  }
407  } else {
408  int i = len;
409  const QChar *c = str + len;
410  if (mirrored) {
411  while (c != str)
412  glyphs->glyphs[--i] = (--c)->unicode() == 0xa0 ? 0x20 : QChar::mirroredChar(c->unicode());
413  } else {
414  while (c != str)
415  glyphs->glyphs[--i] = (--c)->unicode() == 0xa0 ? 0x20 : c->unicode();
416  }
417  }
418  *nglyphs = len;
419  glyphs->numGlyphs = len;
420 
421  if (!(flags & QTextEngine::GlyphIndicesOnly))
422  recalcAdvances(glyphs, flags);
423  return true;
424 }
unsigned char c[8]
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
HB_Glyph * glyphs
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
unsigned char uchar
Definition: qglobal.h:994
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
QChar mirroredChar() const
Returns the mirrored character if this character is a mirrored character; otherwise returns the chara...
Definition: qchar.cpp:1016
static const char * data(const QByteArray &arr)
QTextCodec * _codec
int length() const
Same as size().
Definition: qbytearray.h:356
ConversionFlags flags
Definition: qtextcodec.h:106
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
unsigned short ushort
Definition: qglobal.h:995

◆ synthesized()

int QFontEngineXLFD::synthesized ( ) const
virtual

Reimplemented from QFontEngine.

Definition at line 782 of file qfontengine_x11.cpp.

783 {
784  return synth;
785 }

◆ toUnicode()

uint QFontEngineXLFD::toUnicode ( glyph_t  g) const

Definition at line 831 of file qfontengine_x11.cpp.

Referenced by glyphIndexToFreetypeGlyphIndex().

832 {
833  if (_codec) {
836  uchar data[2];
837  int l = 1;
838  if (g > 255) {
839  data[0] = (g >> 8);
840  data[1] = (g & 255);
841  l = 2;
842  } else {
843  data[0] = g;
844  }
845  QString s = _codec->toUnicode((char *)data, l, &state);
846  Q_ASSERT(s.length() == 1);
847  g = s.at(0).unicode();
848  }
849  return g;
850 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned char uchar
Definition: qglobal.h:994
static const char * data(const QByteArray &arr)
QTextCodec * _codec
ConversionFlags flags
Definition: qtextcodec.h:106
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QFactoryLoader * l

◆ type()

virtual Type QFontEngineXLFD::type ( ) const
inlinevirtual

Implements QFontEngine.

Definition at line 110 of file qfontengine_x11_p.h.

Properties

◆ _cmap

int QFontEngineXLFD::_cmap
private

Definition at line 131 of file qfontengine_x11_p.h.

Referenced by QFontEngineXLFD().

◆ _codec

QTextCodec* QFontEngineXLFD::_codec
private

Definition at line 130 of file qfontengine_x11_p.h.

Referenced by faceId(), QFontEngineXLFD(), stringToCMap(), and toUnicode().

◆ _fs

XFontStruct* QFontEngineXLFD::_fs
private

◆ _name

QByteArray QFontEngineXLFD::_name
private

Definition at line 129 of file qfontengine_x11_p.h.

Referenced by faceId(), and name().

◆ face_id

QFontEngine::FaceId QFontEngineXLFD::face_id
mutableprivate

◆ freetype

QFreetypeFace* QFontEngineXLFD::freetype
mutableprivate

◆ lbearing

int QFontEngineXLFD::lbearing
private

Definition at line 132 of file qfontengine_x11_p.h.

Referenced by minLeftBearing(), minRightBearing(), and QFontEngineXLFD().

◆ rbearing

int QFontEngineXLFD::rbearing
private

Definition at line 132 of file qfontengine_x11_p.h.

Referenced by minLeftBearing(), minRightBearing(), and QFontEngineXLFD().

◆ synth

int QFontEngineXLFD::synth
mutableprivate

Definition at line 135 of file qfontengine_x11_p.h.

Referenced by faceId(), QFontEngineXLFD(), and synthesized().


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