Qt 4.8
Macros | Enumerations | Functions | Variables
qfontengine.cpp File Reference
#include <qdebug.h>
#include <private/qfontengine_p.h>
#include "qbitmap.h"
#include "qpainter.h"
#include "qpainterpath.h"
#include "qvarlengtharray.h"
#include <qmath.h>
#include <qendian.h>
#include <private/qharfbuzz_p.h>

Go to the source code of this file.

Macros

#define GRID(x, y)   grid[(y)*(w+1) + (x)]
 
#define SET(x, y)   (*(image_data + (y)*bpl + ((x) >> 3)) & (0x80 >> ((x) & 7)))
 

Enumerations

enum  { EdgeRight = 0x1, EdgeDown = 0x2, EdgeLeft = 0x4, EdgeUp = 0x8 }
 

Functions

static void collectSingleContour (qreal x0, qreal y0, uint *grid, int x, int y, int w, int h, QPainterPath *path)
 
static HB_Bool hb_canRender (HB_Font font, const HB_UChar16 *string, hb_uint32 length)
 
static void hb_getAdvances (HB_Font font, const HB_Glyph *glyphs, hb_uint32 numGlyphs, HB_Fixed *advances, int flags)
 
static HB_Fixed hb_getFontMetric (HB_Font font, HB_FontMetric metric)
 
static void hb_getGlyphMetrics (HB_Font font, HB_Glyph glyph, HB_GlyphMetrics *metrics)
 
static HB_Error hb_getPointInOutline (HB_Font font, HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
 
static HB_Error hb_getSFntTable (void *font, HB_Tag tableTag, HB_Byte *buffer, HB_UInt *length)
 
static HB_Bool hb_stringToGlyphs (HB_Font font, const HB_UChar16 *string, hb_uint32 length, HB_Glyph *glyphs, hb_uint32 *numGlyphs, HB_Bool rightToLeft)
 
static uchar highByte (glyph_t glyph)
 
static QFixed kerning (int left, int right, const QFontEngine::KernPair *pairs, int numPairs)
 
 Q_GLOBAL_STATIC_WITH_INITIALIZER (QVector< QRgb >, qt_grayPalette, { x->resize(256);QRgb *it=x->data();for(int i=0;i< x->size();++i,++it) *it=0xff000000|i|(i<< 8)|(i<< 16);}) const QVector< QRgb > &QFontEngine
 
Q_GUI_EXPORT void qt_addBitmapToPath (qreal x0, qreal y0, const uchar *image_data, int bpl, int w, int h, QPainterPath *path)
 
static bool qtransform_equals_no_translate (const QTransform &a, const QTransform &b)
 
static glyph_t stripped (glyph_t glyph)
 

Variables

static const HB_FontClass hb_fontClass
 

Macro Definition Documentation

◆ GRID

#define GRID (   x,
 
)    grid[(y)*(w+1) + (x)]

Definition at line 432 of file qfontengine.cpp.

Referenced by collectSingleContour(), and qt_addBitmapToPath().

◆ SET

#define SET (   x,
 
)    (*(image_data + (y)*bpl + ((x) >> 3)) & (0x80 >> ((x) & 7)))

Definition at line 433 of file qfontengine.cpp.

Referenced by qt_addBitmapToPath().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
EdgeRight 
EdgeDown 
EdgeLeft 
EdgeUp 

Definition at line 435 of file qfontengine.cpp.

435  { EdgeRight = 0x1,
436  EdgeDown = 0x2,
437  EdgeLeft = 0x4,
438  EdgeUp = 0x8
439 };

Function Documentation

◆ collectSingleContour()

static void collectSingleContour ( qreal  x0,
qreal  y0,
uint grid,
int  x,
int  y,
int  w,
int  h,
QPainterPath path 
)
static

Definition at line 441 of file qfontengine.cpp.

Referenced by qt_addBitmapToPath().

442 {
443  Q_UNUSED(h);
444 
445  path->moveTo(x + x0, y + y0);
446  while (GRID(x, y)) {
447  if (GRID(x, y) & EdgeRight) {
448  while (GRID(x, y) & EdgeRight) {
449  GRID(x, y) &= ~EdgeRight;
450  ++x;
451  }
452  Q_ASSERT(x <= w);
453  path->lineTo(x + x0, y + y0);
454  continue;
455  }
456  if (GRID(x, y) & EdgeDown) {
457  while (GRID(x, y) & EdgeDown) {
458  GRID(x, y) &= ~EdgeDown;
459  ++y;
460  }
461  Q_ASSERT(y <= h);
462  path->lineTo(x + x0, y + y0);
463  continue;
464  }
465  if (GRID(x, y) & EdgeLeft) {
466  while (GRID(x, y) & EdgeLeft) {
467  GRID(x, y) &= ~EdgeLeft;
468  --x;
469  }
470  Q_ASSERT(x >= 0);
471  path->lineTo(x + x0, y + y0);
472  continue;
473  }
474  if (GRID(x, y) & EdgeUp) {
475  while (GRID(x, y) & EdgeUp) {
476  GRID(x, y) &= ~EdgeUp;
477  --y;
478  }
479  Q_ASSERT(y >= 0);
480  path->lineTo(x + x0, y + y0);
481  continue;
482  }
483  }
484  path->closeSubpath();
485 }
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
#define GRID(x, y)
#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

◆ hb_canRender()

static HB_Bool hb_canRender ( HB_Font  font,
const HB_UChar16 *  string,
hb_uint32  length 
)
static

Definition at line 111 of file qfontengine.cpp.

112 {
113  QFontEngine *fe = (QFontEngine *)font->userData;
114  return fe->canRender(reinterpret_cast<const QChar *>(string), length);
115 }
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
virtual bool canRender(const QChar *string, int len)=0

◆ hb_getAdvances()

static void hb_getAdvances ( HB_Font  font,
const HB_Glyph *  glyphs,
hb_uint32  numGlyphs,
HB_Fixed *  advances,
int  flags 
)
static

Definition at line 96 of file qfontengine.cpp.

97 {
98  QFontEngine *fe = (QFontEngine *)font->userData;
99 
100  QVarLengthGlyphLayoutArray qglyphs(numGlyphs);
101 
102  for (hb_uint32 i = 0; i < numGlyphs; ++i)
103  qglyphs.glyphs[i] = glyphs[i];
104 
105  fe->recalcAdvances(&qglyphs, flags & HB_ShaperFlag_UseDesignMetrics ? QFlags<QTextEngine::ShaperFlag>(QTextEngine::DesignMetrics) : QFlags<QTextEngine::ShaperFlag>(0));
106 
107  for (hb_uint32 i = 0; i < numGlyphs; ++i)
108  advances[i] = qglyphs.advances_x[i].value();
109 }
HB_Glyph * glyphs
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313

◆ hb_getFontMetric()

static HB_Fixed hb_getFontMetric ( HB_Font  font,
HB_FontMetric  metric 
)
static

Definition at line 129 of file qfontengine.cpp.

130 {
131  QFontEngine *fe = (QFontEngine *)font->userData;
132  switch (metric) {
133  case HB_FontAscent:
134  return fe->ascent().value();
135  break;
136  case HB_FontDescent:
137  return fe->descent().value();
138  break;
139  default:
140  return 0;
141  }
142 }
int value() const
Definition: qfixed_p.h:73
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
virtual QFixed ascent() const =0
virtual QFixed descent() const =0

◆ hb_getGlyphMetrics()

static void hb_getGlyphMetrics ( HB_Font  font,
HB_Glyph  glyph,
HB_GlyphMetrics *  metrics 
)
static

Definition at line 117 of file qfontengine.cpp.

118 {
119  QFontEngine *fe = (QFontEngine *)font->userData;
120  glyph_metrics_t m = fe->boundingBox(glyph);
121  metrics->x = m.x.value();
122  metrics->y = m.y.value();
123  metrics->width = m.width.value();
124  metrics->height = m.height.value();
125  metrics->xOffset = m.xoff.value();
126  metrics->yOffset = m.yoff.value();
127 }
int value() const
Definition: qfixed_p.h:73
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0

◆ hb_getPointInOutline()

static HB_Error hb_getPointInOutline ( HB_Font  font,
HB_Glyph  glyph,
int  flags,
hb_uint32  point,
HB_Fixed *  xpos,
HB_Fixed *  ypos,
hb_uint32 *  nPoints 
)
static

Definition at line 155 of file qfontengine.cpp.

156 {
157  QFontEngine *fe = (QFontEngine *)font->userData;
158  return fe->getPointInOutline(glyph, flags, point, xpos, ypos, nPoints);
159 }
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
virtual HB_Error getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)

◆ hb_getSFntTable()

static HB_Error hb_getSFntTable ( void *  font,
HB_Tag  tableTag,
HB_Byte *  buffer,
HB_UInt *  length 
)
static

Definition at line 166 of file qfontengine.cpp.

Referenced by QFontEngine::harfbuzzFace().

167 {
168  QFontEngine *fe = (QFontEngine *)font;
169  if (!fe->getSfntTableData(tableTag, buffer, length))
170  return HB_Err_Invalid_Argument;
171  return HB_Err_Ok;
172 }
virtual bool getSfntTableData(uint, uchar *, uint *) const

◆ hb_stringToGlyphs()

static HB_Bool hb_stringToGlyphs ( HB_Font  font,
const HB_UChar16 *  string,
hb_uint32  length,
HB_Glyph *  glyphs,
hb_uint32 *  numGlyphs,
HB_Bool  rightToLeft 
)
static

Definition at line 74 of file qfontengine.cpp.

75 {
76  QFontEngine *fe = (QFontEngine *)font->userData;
77 
78  QVarLengthGlyphLayoutArray qglyphs(*numGlyphs);
79 
80  QTextEngine::ShaperFlags shaperFlags(QTextEngine::GlyphIndicesOnly);
81  if (rightToLeft)
82  shaperFlags |= QTextEngine::RightToLeft;
83 
84  int nGlyphs = *numGlyphs;
85  bool result = fe->stringToCMap(reinterpret_cast<const QChar *>(string), length, &qglyphs, &nGlyphs, shaperFlags);
86  *numGlyphs = nGlyphs;
87  if (!result)
88  return false;
89 
90  for (hb_uint32 i = 0; i < *numGlyphs; ++i)
91  glyphs[i] = qglyphs.glyphs[i];
92 
93  return true;
94 }
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0

◆ highByte()

static uchar highByte ( glyph_t  glyph)
inlinestatic

◆ kerning()

static QFixed kerning ( int  left,
int  right,
const QFontEngine::KernPair pairs,
int  numPairs 
)
inlinestatic

Definition at line 766 of file qfontengine.cpp.

Referenced by QFontEngine::doKerning().

767 {
768  uint left_right = (left << 16) + right;
769 
770  left = 0, right = numPairs - 1;
771  while (left <= right) {
772  int middle = left + ( ( right - left ) >> 1 );
773 
774  if(pairs[middle].left_right == left_right)
775  return pairs[middle].adjust;
776 
777  if (pairs[middle].left_right < left_right)
778  left = middle + 1;
779  else
780  right = middle - 1;
781  }
782  return 0;
783 }
QTextStream & right(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream...
unsigned int uint
Definition: qglobal.h:996
QTextStream & left(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream...

◆ Q_GLOBAL_STATIC_WITH_INITIALIZER()

Q_GLOBAL_STATIC_WITH_INITIALIZER ( QVector< QRgb ,
qt_grayPalette  ,
{ x->resize(256);QRgb *it=x->data();for(int i=0;i< x->size();++i,++it) *it=0xff000000|i|(i<< 8)|(i<< 16);}   
) const &

Definition at line 1121 of file qfontengine.cpp.

1121  {
1122  x->resize(256);
1123  QRgb *it = x->data();
1124  for (int i = 0; i < x->size(); ++i, ++it)
1125  *it = 0xff000000 | i | (i<<8) | (i<<16);
1126 })
1127 
1129 {
1130  return *qt_grayPalette();
1131 }
unsigned int QRgb
Definition: qrgb.h:53
#define it(className, varName)
static const QVector< QRgb > & grayPalette()

◆ qt_addBitmapToPath()

Q_GUI_EXPORT void qt_addBitmapToPath ( qreal  x0,
qreal  y0,
const uchar image_data,
int  bpl,
int  w,
int  h,
QPainterPath path 
)

Definition at line 487 of file qfontengine.cpp.

Referenced by QFontEngine::addBitmapFontToPath(), QFreetypeFace::addBitmapToPath(), QFreetypeFace::addGlyphToPath(), and QFontEngineXLFD::addOutlineToPath().

488 {
489  uint *grid = new uint[(w+1)*(h+1)];
490  // set up edges
491  for (int y = 0; y <= h; ++y) {
492  for (int x = 0; x <= w; ++x) {
493  bool topLeft = (x == 0)|(y == 0) ? false : SET(x - 1, y - 1);
494  bool topRight = (x == w)|(y == 0) ? false : SET(x, y - 1);
495  bool bottomLeft = (x == 0)|(y == h) ? false : SET(x - 1, y);
496  bool bottomRight = (x == w)|(y == h) ? false : SET(x, y);
497 
498  GRID(x, y) = 0;
499  if ((!topRight) & bottomRight)
500  GRID(x, y) |= EdgeRight;
501  if ((!bottomRight) & bottomLeft)
502  GRID(x, y) |= EdgeDown;
503  if ((!bottomLeft) & topLeft)
504  GRID(x, y) |= EdgeLeft;
505  if ((!topLeft) & topRight)
506  GRID(x, y) |= EdgeUp;
507  }
508  }
509 
510  // collect edges
511  for (int y = 0; y < h; ++y) {
512  for (int x = 0; x < w; ++x) {
513  if (!GRID(x, y))
514  continue;
515  // found start of a contour, follow it
516  collectSingleContour(x0, y0, grid, x, y, w, h, path);
517  }
518  }
519  delete [] grid;
520 }
unsigned int uint
Definition: qglobal.h:996
static void collectSingleContour(qreal x0, qreal y0, uint *grid, int x, int y, int w, int h, QPainterPath *path)
#define GRID(x, y)
#define SET(x, y)

◆ qtransform_equals_no_translate()

static bool qtransform_equals_no_translate ( const QTransform a,
const QTransform b 
)
inlinestatic

Definition at line 55 of file qfontengine.cpp.

Referenced by QFontEngine::glyphCache().

56 {
58  return true;
59  } else {
60  // We always use paths for perspective text anyway, so no
61  // point in checking the full matrix...
64 
65  return a.m11() == b.m11()
66  && a.m12() == b.m12()
67  && a.m21() == b.m21()
68  && a.m22() == b.m22();
69  }
70 }
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
TransformationType type() const
Returns the transformation type of this matrix.
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ stripped()

static glyph_t stripped ( glyph_t  glyph)
inlinestatic

Variable Documentation

◆ hb_fontClass

const HB_FontClass hb_fontClass
static
Initial value:
= {
}
static HB_Error hb_getPointInOutline(HB_Font font, HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints)
static void hb_getAdvances(HB_Font font, const HB_Glyph *glyphs, hb_uint32 numGlyphs, HB_Fixed *advances, int flags)
Definition: qfontengine.cpp:96
static void hb_getGlyphMetrics(HB_Font font, HB_Glyph glyph, HB_GlyphMetrics *metrics)
static HB_Bool hb_canRender(HB_Font font, const HB_UChar16 *string, hb_uint32 length)
static HB_Fixed hb_getFontMetric(HB_Font font, HB_FontMetric metric)
static HB_Bool hb_stringToGlyphs(HB_Font font, const HB_UChar16 *string, hb_uint32 length, HB_Glyph *glyphs, hb_uint32 *numGlyphs, HB_Bool rightToLeft)
Definition: qfontengine.cpp:74

Definition at line 161 of file qfontengine.cpp.

Referenced by QFontEngine::QFontEngine().