Qt 4.8
Classes | Macros | Functions | Variables
qfontengine_ft.cpp File Reference
#include "qdir.h"
#include "qmetatype.h"
#include "qtextstream.h"
#include "qvariant.h"
#include "qfontengine_ft_p.h"
#include "qfile.h"
#include "qabstractfileengine.h"
#include "qthreadstorage.h"
#include <qmath.h>
#include <private/qharfbuzz_p.h>
#include <ft2build.h>
#include <FT_FREETYPE_H>
#include <FT_OUTLINE_H>
#include <FT_SYNTHESIS_H>
#include <FT_TRUETYPE_TABLES_H>
#include <FT_TYPE1_TABLES_H>
#include <FT_GLYPH_H>

Go to the source code of this file.

Classes

class  QtFreetypeData
 

Macros

#define CEIL(x)   (((x)+63) & -64)
 
#define FLOOR(x)   ((x) & -64)
 
#define Q_FT_GLYPHSLOT_EMBOLDEN(slot)
 
#define QT_MAX_CACHED_GLYPH_SIZE   64
 
#define ROUND(x)   (((x)+32) & -64)
 
#define TRUNC(x)   ((x) >> 6)
 
#define X_SIZE(face, i)   ((face)->available_sizes[i].width << 6)
 
#define Y_SIZE(face, i)   ((face)->available_sizes[i].height << 6)
 

Functions

static void convertRGBToARGB (const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter)
 
static void convertRGBToARGB_V (const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter)
 
static void convoluteBitmap (const uchar *src, uchar *dst, int width, int height, int pitch)
 
static uint filterPixel (uint red, uint green, uint blue, bool legacyFilter)
 
static unsigned int getChar (const QChar *str, int &i, const int len)
 
static HB_Error hb_getSFntTable (void *font, HB_Tag tableTag, HB_Byte *buffer, HB_UInt *length)
 
void qt_addBitmapToPath (qreal x0, qreal y0, const uchar *image_data, int bpl, int w, int h, QPainterPath *path)
 
FT_Library qt_getFreetype ()
 
QtFreetypeDataqt_getFreetypeData ()
 
static void scaleOutline (FT_Face face, FT_GlyphSlot g, FT_Fixed x_scale, FT_Fixed y_scale)
 

Variables

static const ushort char_table []
 
static const int char_table_entries = sizeof(char_table)/sizeof(ushort)
 
static const uint subpixel_filter [3][3]
 

Macro Definition Documentation

◆ CEIL

#define CEIL (   x)    (((x)+63) & -64)

◆ FLOOR

#define FLOOR (   x)    ((x) & -64)

◆ Q_FT_GLYPHSLOT_EMBOLDEN

#define Q_FT_GLYPHSLOT_EMBOLDEN (   slot)

Definition at line 104 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::loadGlyph().

◆ QT_MAX_CACHED_GLYPH_SIZE

#define QT_MAX_CACHED_GLYPH_SIZE   64

◆ ROUND

#define ROUND (   x)    (((x)+32) & -64)

◆ TRUNC

#define TRUNC (   x)    ((x) >> 6)

◆ X_SIZE

#define X_SIZE (   face,
 
)    ((face)->available_sizes[i].width << 6)

◆ Y_SIZE

#define Y_SIZE (   face,
 
)    ((face)->available_sizes[i].height << 6)

Function Documentation

◆ convertRGBToARGB()

static void convertRGBToARGB ( const uchar src,
uint dst,
int  width,
int  height,
int  src_pitch,
bool  bgr,
bool  legacyFilter 
)
static

Definition at line 569 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::loadGlyph().

570 {
571  int h = height;
572  const int offs = bgr ? -1 : 1;
573  const int w = width * 3;
574  while (h--) {
575  uint *dd = dst;
576  for (int x = 0; x < w; x += 3) {
577  uint red = src[x+1-offs];
578  uint green = src[x+1];
579  uint blue = src[x+1+offs];
580  *dd = filterPixel(red, green, blue, legacyFilter);
581  ++dd;
582  }
583  dst += width;
584  src += src_pitch;
585  }
586 }
unsigned int uint
Definition: qglobal.h:996
static uint filterPixel(uint red, uint green, uint blue, bool legacyFilter)

◆ convertRGBToARGB_V()

static void convertRGBToARGB_V ( const uchar src,
uint dst,
int  width,
int  height,
int  src_pitch,
bool  bgr,
bool  legacyFilter 
)
static

Definition at line 588 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::loadGlyph().

589 {
590  int h = height;
591  const int offs = bgr ? -src_pitch : src_pitch;
592  while (h--) {
593  for (int x = 0; x < width; x++) {
594  uint red = src[x+src_pitch-offs];
595  uint green = src[x+src_pitch];
596  uint blue = src[x+src_pitch+offs];
597  dst[x] = filterPixel(red, green, blue, legacyFilter);
598  }
599  dst += width;
600  src += 3*src_pitch;
601  }
602 }
unsigned int uint
Definition: qglobal.h:996
static uint filterPixel(uint red, uint green, uint blue, bool legacyFilter)

◆ convoluteBitmap()

static void convoluteBitmap ( const uchar src,
uchar dst,
int  width,
int  height,
int  pitch 
)
static

Definition at line 604 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::loadGlyph().

605 {
606  // convolute the bitmap with a triangle filter to get rid of color fringes
607  // If we take account for a gamma value of 2, we end up with
608  // weights of 1, 4, 9, 4, 1. We use an approximation of 1, 3, 8, 3, 1 here,
609  // as this nicely sums up to 16 :)
610  int h = height;
611  while (h--) {
612  dst[0] = dst[1] = 0;
613  //
614  for (int x = 2; x < width - 2; ++x) {
615  uint sum = src[x-2] + 3*src[x-1] + 8*src[x] + 3*src[x+1] + src[x+2];
616  dst[x] = (uchar) (sum >> 4);
617  }
618  dst[width - 2] = dst[width - 1] = 0;
619  src += pitch;
620  dst += pitch;
621  }
622 }
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996

◆ filterPixel()

static uint filterPixel ( uint  red,
uint  green,
uint  blue,
bool  legacyFilter 
)
inlinestatic

Definition at line 554 of file qfontengine_ft.cpp.

Referenced by convertRGBToARGB(), and convertRGBToARGB_V().

555 {
556  uint res;
557  if (legacyFilter) {
558  uint high = (red*subpixel_filter[0][0] + green*subpixel_filter[0][1] + blue*subpixel_filter[0][2]) >> 8;
559  uint mid = (red*subpixel_filter[1][0] + green*subpixel_filter[1][1] + blue*subpixel_filter[1][2]) >> 8;
560  uint low = (red*subpixel_filter[2][0] + green*subpixel_filter[2][1] + blue*subpixel_filter[2][2]) >> 8;
561  res = (mid << 24) + (high << 16) + (mid << 8) + low;
562  } else {
563  uint alpha = green;
564  res = (alpha << 24) + (red << 16) + (green << 8) + blue;
565  }
566  return res;
567 }
static const uint subpixel_filter[3][3]
unsigned int uint
Definition: qglobal.h:996

◆ getChar()

static unsigned int getChar ( const QChar str,
int &  i,
const int  len 
)
inlinestatic

Definition at line 1423 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::canRender(), QTextStreamPrivate::getNumber(), QTextStreamPrivate::getReal(), QXmlStreamReaderPrivate::parse(), QFontEngineFT::stringToCMap(), and QIODevice::write().

1424 {
1425  uint ucs4 = str[i].unicode();
1426  if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
1427  ++i;
1428  ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
1429  }
1430  return ucs4;
1431 }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
unsigned int uint
Definition: qglobal.h:996
static uint surrogateToUcs4(ushort high, ushort low)
Converts a UTF16 surrogate pair with the given high and low values to its UCS-4 code point...
Definition: qchar.h:297

◆ hb_getSFntTable()

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

Definition at line 112 of file qfontengine_ft.cpp.

Referenced by QFreetypeFace::getFace().

113 {
114 #if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) > 20103
115  FT_Face face = (FT_Face)font;
116  FT_ULong ftlen = *length;
117  FT_Error error = 0;
118 
119  if ( !FT_IS_SFNT(face) )
120  return HB_Err_Invalid_Argument;
121 
122  error = FT_Load_Sfnt_Table(face, tableTag, 0, buffer, &ftlen);
123  *length = ftlen;
124  return (HB_Error)error;
125 #else
126  return HB_Err_Invalid_Argument;
127 #endif
128 }
#define error(msg)
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50

◆ qt_addBitmapToPath()

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)

◆ qt_getFreetype()

FT_Library qt_getFreetype ( )

Definition at line 162 of file qfontengine_ft.cpp.

Referenced by QBasicUnixFontDatabase::addTTFile(), QFontDatabasePrivate::addTTFile(), QFontEngineFT::loadGlyph(), and queryFont().

163 {
164  QtFreetypeData *freetypeData = qt_getFreetypeData();
165  if (!freetypeData->library)
166  FT_Init_FreeType(&freetypeData->library);
167  return freetypeData->library;
168 }
FT_Library library
QtFreetypeData * qt_getFreetypeData()

◆ qt_getFreetypeData()

QtFreetypeData* qt_getFreetypeData ( )

Definition at line 153 of file qfontengine_ft.cpp.

Referenced by QFreetypeFace::getFace(), qt_getFreetype(), and QFreetypeFace::release().

154 {
155  QtFreetypeData *&freetypeData = theFreetypeData()->localData();
156  if (!freetypeData)
157  freetypeData = new QtFreetypeData;
158  return freetypeData;
159 }

◆ scaleOutline()

static void scaleOutline ( FT_Face  face,
FT_GlyphSlot  g,
FT_Fixed  x_scale,
FT_Fixed  y_scale 
)
static

Definition at line 436 of file qfontengine_ft.cpp.

Referenced by QFreetypeFace::addGlyphToPath().

437 {
438  x_scale = FT_MulDiv(x_scale, 1 << 10, face->units_per_EM);
439  y_scale = FT_MulDiv(y_scale, 1 << 10, face->units_per_EM);
440  FT_Vector *p = g->outline.points;
441  const FT_Vector *e = p + g->outline.n_points;
442  while (p < e) {
443  p->x = FT_MulFix(p->x, x_scale);
444  p->y = FT_MulFix(p->y, y_scale);
445  ++p;
446  }
447 }

Variable Documentation

◆ char_table

const ushort char_table[]
static
Initial value:
= {
40,
67,
70,
75,
86,
88,
89,
91,
102,
114,
124,
127,
205,
645,
884,
922,
1070,
12386
}

Definition at line 1215 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::minRightBearing().

◆ char_table_entries

const int char_table_entries = sizeof(char_table)/sizeof(ushort)
static

Definition at line 1236 of file qfontengine_ft.cpp.

Referenced by QFontEngineFT::minRightBearing().

◆ subpixel_filter

const uint subpixel_filter[3][3]
static
Initial value:
= {
{ 180, 60, 16 },
{ 38, 180, 38 },
{ 16, 60, 180 }
}

Definition at line 548 of file qfontengine_ft.cpp.

Referenced by filterPixel().