10#include "private/qfontdatabase_p.h"
11#include "private/qimage_p.h"
12#include <private/qstringiterator_p.h>
13#include <qguiapplication.h>
15#include <qpa/qplatformscreen.h>
16#include <QtCore/QUuid>
17#include <QtCore/QLoggingCategory>
18#include <QtGui/QPainterPath>
24#include <qscopedvaluerollback.h>
28#include <private/qcolrpaintgraphrenderer_p.h>
35#include FT_SYNTHESIS_H
36#include FT_TRUETYPE_TABLES_H
37#include FT_TYPE1_TABLES_H
40#include FT_LCD_FILTER_H
41#include FT_MULTIPLE_MASTERS_H
43#if defined(FT_CONFIG_OPTIONS_H)
44#include FT_CONFIG_OPTIONS_H
47#if defined(FT_FONT_FORMATS_H)
48#include FT_FONT_FORMATS_H
55#if !defined(QT_MAX_CACHED_GLYPH_SIZE)
56# define QT_MAX_CACHED_GLYPH_SIZE 64
61using namespace Qt::StringLiterals;
63#define FLOOR(x) ((x) & -64
)
64#define CEIL(x) (((x)+63
) & -64
)
65#define TRUNC(x) ((x) >> 6
)
66#define ROUND(x) (((x)+32
) & -64
)
68static bool ft_getSfntTable(
void *user_data, uint tag, uchar *buffer, uint *length)
70 FT_Face face = (FT_Face)user_data;
73 if (FT_IS_SFNT(face)) {
74 FT_ULong len = *length;
75 result = FT_Load_Sfnt_Table(face, tag, 0, buffer, &len) == FT_Err_Ok;
77 Q_ASSERT(!result ||
int(*length) > 0);
87 QFontEngineFT::HintFull;
89 QFontEngineFT::HintNone;
120 for (
auto iter = faces.cbegin(); iter != faces.cend(); ++iter) {
121 iter.value()->cleanup();
122 if (!iter.value()->ref.deref())
127 for (
auto iter = staleFaces.cbegin(); iter != staleFaces.cend(); ++iter) {
129 if (!(*iter)->ref.deref())
134 FT_Done_FreeType(library);
140 return style1.faceFileName == style2.faceFileName && style1.styleName == style2.styleName;
145 return qHashMulti(seed, style.faceFileName, style.styleName);
155 if (!freetypeData->library) {
156 FT_Init_FreeType(&freetypeData->library);
157#if defined(FT_FONT_FORMATS_H)
159 FT_Bool no_darkening =
false;
160 FT_Property_Set(freetypeData->library,
"cff",
"no-stem-darkening", &no_darkening);
169 Q_ASSERT(freetypeData->library);
170 return freetypeData->library;
173int QFreetypeFace::fsType()
const
176 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);
178 fsType = os2->fsType;
182int QFreetypeFace::getPointInOutline(glyph_t glyph,
int flags, quint32 point, QFixed *xpos, QFixed *ypos, quint32 *nPoints)
184 if (
int error = FT_Load_Glyph(face, glyph, flags))
187 if (face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)
188 return Err_Invalid_SubTable;
190 *nPoints = face->glyph->outline.n_points;
194 if (point > *nPoints)
195 return Err_Invalid_SubTable;
197 *xpos = QFixed::fromFixed(face->glyph->outline.points[point].x);
198 *ypos = QFixed::fromFixed(face->glyph->outline.points[point].y);
203bool QFreetypeFace::isScalableBitmap()
const
206 return !FT_IS_SCALABLE(face) && FT_HAS_COLOR(face);
215
216
217
218
219
220
221QFreetypeFace *QFreetypeFace::getFace(
const QFontEngine::FaceId &face_id,
222 const QByteArray &fontData)
224 if (face_id.filename.isEmpty() && fontData.isEmpty())
227 QtFreetypeData *freetypeData = qt_getFreetypeData();
230 for (
auto it = freetypeData->staleFaces.constBegin(); it != freetypeData->staleFaces.constEnd(); ) {
231 if ((*it)->ref.loadRelaxed() == 1) {
234 it = freetypeData->staleFaces.erase(it);
240 QFreetypeFace *freetype =
nullptr;
241 auto it = freetypeData->faces.find(face_id);
242 if (it != freetypeData->faces.end()) {
245 Q_ASSERT(freetype->ref.loadRelaxed() > 0);
246 if (freetype->ref.loadRelaxed() == 1) {
253 freetypeData->faces.erase(it);
262 const auto deleter = [](QFreetypeFace *f) {
delete f; };
263 std::unique_ptr<QFreetypeFace,
decltype(deleter)> newFreetype(
new QFreetypeFace, deleter);
266 if (!face_id.filename.isEmpty()) {
267 QString fileName = QFile::decodeName(face_id.filename);
268 if (
const char *prefix =
":qmemoryfonts/"; face_id.filename.startsWith(prefix)) {
270 QByteArray idx = face_id.filename;
271 idx.remove(0, strlen(prefix));
273 newFreetype->fontData = qt_fontdata_from_index(idx.toInt(&ok));
275 newFreetype->fontData = QByteArray();
276 }
else if (!QFileInfo(fileName).isNativePath()) {
277 QFile file(fileName);
278 if (!file.open(QIODevice::ReadOnly)) {
281 newFreetype->fontData = file.readAll();
284 newFreetype->fontData = fontData;
287 FT_Int major, minor, patch;
288 FT_Library_Version(qt_getFreetype(), &major, &minor, &patch);
289 const bool goodVersion = major > 2 || (major == 2 && minor > 13) || (major == 2 && minor == 13 && patch > 2);
291 if (!newFreetype->fontData.isEmpty()) {
292 if (FT_New_Memory_Face(freetypeData->library,
293 (
const FT_Byte *)newFreetype->fontData.constData(),
294 newFreetype->fontData.size(),
304 if (FT_Reference_Face(face))
306 }
else if (!FT_HAS_MULTIPLE_MASTERS(face)
307 || FT_New_Memory_Face(freetypeData->library,
308 (
const FT_Byte *)newFreetype->fontData.constData(),
309 newFreetype->fontData.size(),
311 &tmpFace) != FT_Err_Ok) {
315 if (FT_New_Face(freetypeData->library, face_id.filename, face_id.index, &face))
322 if (FT_Reference_Face(face))
324 }
else if (!FT_HAS_MULTIPLE_MASTERS(face)
325 || FT_New_Face(freetypeData->library, face_id.filename, face_id.index, &tmpFace) != FT_Err_Ok) {
330#if (FREETYPE_MAJOR*10000
+ FREETYPE_MINOR*100
+ FREETYPE_PATCH) >= 20900
331 if (face_id.instanceIndex >= 0) {
333 <<
"Selecting named instance" << (face_id.instanceIndex)
334 <<
"in" << face_id.filename;
335 FT_Set_Named_Instance(face, face_id.instanceIndex + 1);
343 if (tmpFace !=
nullptr) {
345 if (FT_Get_MM_Var(tmpFace, &var) == FT_Err_Ok) {
346 for (FT_UInt i = 0; i < var->num_axis; ++i) {
347 FT_Var_Axis *axis = var->axis + i;
349 QFontVariableAxis fontVariableAxis;
350 if (
const auto tag = QFont::Tag::fromValue(axis->tag)) {
351 fontVariableAxis.setTag(*tag);
353 qWarning() <<
"QFreetypeFace::getFace: Invalid variable axis tag encountered"
357 fontVariableAxis.setMinimumValue(axis->minimum / 65536.0);
358 fontVariableAxis.setMaximumValue(axis->maximum / 65536.0);
359 fontVariableAxis.setDefaultValue(axis->def / 65536.0);
360 fontVariableAxis.setName(QString::fromUtf8(axis->name));
362 newFreetype->variableAxisList.append(fontVariableAxis);
365 if (!face_id.variableAxes.isEmpty()) {
366 QVarLengthArray<FT_Fixed, 16> coords(var->num_axis);
367 FT_Get_Var_Design_Coordinates(face, var->num_axis, coords.data());
368 for (qsizetype i = 0; i < newFreetype->variableAxisList.size(); ++i) {
369 const QFontVariableAxis &axis = newFreetype->variableAxisList.at(i);
370 if (axis.tag().isValid()) {
371 const auto it = face_id.variableAxes.constFind(axis.tag());
372 if (it != face_id.variableAxes.constEnd())
373 coords[i] = FT_Fixed(*it * 65536);
376 FT_Set_Var_Design_Coordinates(face, var->num_axis, coords.data());
379 FT_Done_MM_Var(qt_getFreetype(), var);
382 FT_Done_Face(tmpFace);
385 newFreetype->face = face;
386 newFreetype->mm_var =
nullptr;
387 if (FT_IS_NAMED_INSTANCE(newFreetype->face)) {
389 ftresult = FT_Get_MM_Var(face, &newFreetype->mm_var);
390 if (ftresult != FT_Err_Ok)
391 newFreetype->mm_var =
nullptr;
394 newFreetype->ref.storeRelaxed(1);
395 newFreetype->xsize = 0;
396 newFreetype->ysize = 0;
397 newFreetype->matrix.xx = 0x10000;
398 newFreetype->matrix.yy = 0x10000;
399 newFreetype->matrix.xy = 0;
400 newFreetype->matrix.yx = 0;
401 newFreetype->unicode_map =
nullptr;
402 newFreetype->symbol_map =
nullptr;
404 memset(newFreetype->cmapCache, 0,
sizeof(newFreetype->cmapCache));
406 for (
int i = 0; i < newFreetype->face->num_charmaps; ++i) {
407 FT_CharMap cm = newFreetype->face->charmaps[i];
408 switch(cm->encoding) {
409 case FT_ENCODING_UNICODE:
410 newFreetype->unicode_map = cm;
412 case FT_ENCODING_APPLE_ROMAN:
413 case FT_ENCODING_ADOBE_LATIN_1:
414 if (!newFreetype->unicode_map || newFreetype->unicode_map->encoding != FT_ENCODING_UNICODE)
415 newFreetype->unicode_map = cm;
417 case FT_ENCODING_ADOBE_CUSTOM:
418 case FT_ENCODING_MS_SYMBOL:
419 if (!newFreetype->symbol_map)
420 newFreetype->symbol_map = cm;
427 if (!FT_IS_SCALABLE(newFreetype->face) && newFreetype->face->num_fixed_sizes == 1)
428 FT_Set_Char_Size(face, newFreetype->face->available_sizes[0].x_ppem, newFreetype->face->available_sizes[0].y_ppem, 0, 0);
430 FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map);
433 freetypeData->faces.insert(face_id, newFreetype.get());
435 newFreetype.release()->release(face_id);
439 freetype = newFreetype.release();
445void QFreetypeFace::cleanup()
449 FT_Done_MM_Var(qt_getFreetype(), mm_var);
455void QFreetypeFace::release(
const QFontEngine::FaceId &face_id)
458 bool deleteThis = !ref.deref();
464 if (face && ref.loadRelaxed() == 1) {
465 QtFreetypeData *freetypeData = qt_getFreetypeData();
467 for (
auto it = freetypeData->staleFaces.constBegin(); it != freetypeData->staleFaces.constEnd(); ) {
468 if ((*it)->ref.loadRelaxed() == 1) {
474 it = freetypeData->staleFaces.erase(it);
480 for (
auto it = freetypeData->faces.constBegin();
481 it != freetypeData->faces.constEnd();
482 it = freetypeData->faces.erase(it)) {
483 if (it.value()->ref.loadRelaxed() == 1) {
484 it.value()->cleanup();
485 if (it.value() ==
this)
490 freetypeData->staleFaces.append(it.value());
494 if (freetypeData->faces.isEmpty() && freetypeData->staleFaces.isEmpty()) {
495 FT_Done_FreeType(freetypeData->library);
496 freetypeData->library =
nullptr;
506 FT_Library library = qt_getFreetype();
514 FT_Error error = FT_New_Face(library, faceFileName.toUtf8().constData(), faceIndex, &face);
515 if (error != FT_Err_Ok) {
516 qDebug() <<
"FT_New_Face failed for face index" << faceIndex <<
':' << Qt::hex << error;
520 const bool found = QLatin1StringView(face->style_name) == styleName;
521 numFaces = face->num_faces;
527 }
while (++faceIndex < numFaces);
533int QFreetypeFace::getFaceIndexByStyleName(
const QString &faceFileName,
const QString &styleName)
535 QtFreetypeData *freetypeData = qt_getFreetypeData();
538 QtFreetypeData::FaceStyle faceStyle(faceFileName, styleName);
539 int faceIndex = freetypeData->faceIndices.value(faceStyle, -1);
544 faceIndex = computeFaceIndex(faceFileName, styleName);
546 freetypeData->faceIndices.insert(faceStyle, faceIndex);
551void QFreetypeFace::computeSize(
const QFontDef &fontDef,
int *xsize,
int *ysize,
bool *outline_drawing, QFixed *scalableBitmapScaleFactor)
553 *ysize = qRound(fontDef.pixelSize * 64);
554 *xsize = *ysize * fontDef.stretch / 100;
555 *scalableBitmapScaleFactor = 1;
556 *outline_drawing =
false;
558 if (!(face->face_flags & FT_FACE_FLAG_SCALABLE)) {
560 if (!isScalableBitmap()) {
562
563
564
565 for (
int i = 1; i < face->num_fixed_sizes; i++) {
566 if (qAbs(*ysize - face->available_sizes[i].y_ppem) <
567 qAbs(*ysize - face->available_sizes[best].y_ppem) ||
568 (qAbs(*ysize - face->available_sizes[i].y_ppem) ==
569 qAbs(*ysize - face->available_sizes[best].y_ppem) &&
570 qAbs(*xsize - face->available_sizes[i].x_ppem) <
571 qAbs(*xsize - face->available_sizes[best].x_ppem))) {
577 for (
int i = 1; i < face->num_fixed_sizes; i++) {
578 if (face->available_sizes[i].y_ppem < *ysize) {
579 if (face->available_sizes[i].y_ppem > face->available_sizes[best].y_ppem)
581 }
else if (face->available_sizes[best].y_ppem < *ysize) {
583 }
else if (face->available_sizes[i].y_ppem < face->available_sizes[best].y_ppem) {
591 if (FT_Select_Size(face, best) == 0) {
592 if (isScalableBitmap())
593 *scalableBitmapScaleFactor = QFixed::fromReal((qreal)fontDef.pixelSize / face->available_sizes[best].height);
594 *xsize = face->available_sizes[best].x_ppem;
595 *ysize = face->available_sizes[best].y_ppem;
600#if defined FT_HAS_COLOR
601 if (FT_HAS_COLOR(face))
602 *outline_drawing =
false;
609QFontEngine::Properties QFreetypeFace::properties()
const
611 QFontEngine::Properties p;
612 p.postscriptName = FT_Get_Postscript_Name(face);
613 PS_FontInfoRec font_info;
614 if (FT_Get_PS_Font_Info(face, &font_info) == 0)
615 p.copyright = font_info.notice;
616 if (FT_IS_SCALABLE(face)
617#if defined(FT_HAS_COLOR)
618 && !FT_HAS_COLOR(face)
621 p.ascent = face->ascender;
622 p.descent = -face->descender;
623 p.leading = face->height - face->ascender + face->descender;
624 p.emSquare = face->units_per_EM;
625 p.boundingBox = QRectF(face->bbox.xMin, -face->bbox.yMax,
626 face->bbox.xMax - face->bbox.xMin,
627 face->bbox.yMax - face->bbox.yMin);
629 p.ascent = QFixed::fromFixed(face->size->metrics.ascender);
630 p.descent = QFixed::fromFixed(-face->size->metrics.descender);
631 p.leading = QFixed::fromFixed(face->size->metrics.height - face->size->metrics.ascender + face->size->metrics.descender);
632 p.emSquare = face->size->metrics.y_ppem;
634 p.boundingBox = QRectF(0, -p.ascent.toReal(),
635 face->size->metrics.max_advance/64, (p.ascent + p.descent).toReal() );
638 p.capHeight = p.ascent;
639 p.lineWidth = face->underline_thickness;
644bool QFreetypeFace::getSfntTable(uint tag, uchar *buffer, uint *length)
const
646 return ft_getSfntTable(face, tag, buffer, length);
650
651
652
653
654
655
656
657
658static void scaleOutline(FT_Face face, FT_GlyphSlot g, FT_Fixed x_scale, FT_Fixed y_scale)
660 x_scale = FT_MulDiv(x_scale, 1 << 10, face->units_per_EM);
661 y_scale = FT_MulDiv(y_scale, 1 << 10, face->units_per_EM);
662 FT_Vector *p = g->outline.points;
663 const FT_Vector *e = p + g->outline.n_points;
665 p->x = FT_MulFix(p->x, x_scale);
666 p->y = FT_MulFix(p->y, y_scale);
671#define GLYPH2PATH_DEBUG QT_NO_QDEBUG_MACRO
672void QFreetypeFace::addGlyphToPath(FT_Face face, FT_GlyphSlot g,
const QFixedPoint &point, QPainterPath *path, FT_Fixed x_scale, FT_Fixed y_scale)
674 const qreal factor = 1/64.;
675 scaleOutline(face, g, x_scale, y_scale);
677 QPointF cp = point.toPointF();
681 for (
int j = 0; j < g->outline.n_contours; ++j) {
682 int last_point = g->outline.contours[j];
684 QPointF start = QPointF(g->outline.points[i].x*factor, -g->outline.points[i].y*factor);
685 if (!(g->outline.tags[i] & 1)) {
686 if (!(g->outline.tags[last_point] & 1)) {
688 start = (QPointF(g->outline.points[last_point].x*factor,
689 -g->outline.points[last_point].y*factor) + start) / 2.0;
692 start = QPointF(g->outline.points[last_point].x*factor,
693 -g->outline.points[last_point].y*factor);
704 while (i < last_point) {
706 c[n] = cp + QPointF(g->outline.points[i].x*factor, -g->outline.points[i].y*factor);
707 GLYPH2PATH_DEBUG() <<
" " << i << c[n] <<
"tag =" << (
int)g->outline.tags[i]
708 <<
": on curve =" << (
bool)(g->outline.tags[i] & 1);
710 switch (g->outline.tags[i] & 3) {
715 c[3] = (c[3] + c[2])/2;
722 c[3] = (c[1] + c[2])/2;
723 c[2] = (2*c[1] + c[3])/3;
724 c[1] = (2*c[1] + c[0])/3;
737 c[2] = (2*c[1] + c[3])/3;
738 c[1] = (2*c[1] + c[0])/3;
743 path->cubicTo(c[1], c[2], c[3]);
750 path->closeSubpath();
754 c[2] = (2*c[1] + c[3])/3;
755 c[1] = (2*c[1] + c[0])/3;
758 path->cubicTo(c[1], c[2], c[3]);
764extern void qt_addBitmapToPath(qreal x0, qreal y0,
const uchar *image_data,
int bpl,
int w,
int h, QPainterPath *path);
766void QFreetypeFace::addBitmapToPath(FT_GlyphSlot slot,
const QFixedPoint &point, QPainterPath *path)
768 if (slot->format != FT_GLYPH_FORMAT_BITMAP
769 || slot->bitmap.pixel_mode != FT_PIXEL_MODE_MONO)
772 QPointF cp = point.toPointF();
773 qt_addBitmapToPath(cp.x() +
TRUNC(slot->metrics.horiBearingX), cp.y() -
TRUNC(slot->metrics.horiBearingY),
774 slot->bitmap.buffer, slot->bitmap.pitch, slot->bitmap.width, slot->bitmap.rows, path);
777static inline void convertRGBToARGB(
const uchar *src, uint *dst,
int width,
int height,
int src_pitch,
bool bgr)
779 const int offs = bgr ? -1 : 1;
780 const int w = width * 3;
783 for (
int x = 0; x < w; x += 3) {
784 uchar red = src[x + 1 - offs];
785 uchar green = src[x + 1];
786 uchar blue = src[x + 1 + offs];
787 *dd++ = (0xFFU << 24) | (red << 16) | (green << 8) | blue;
794static inline void convertRGBToARGB_V(
const uchar *src, uint *dst,
int width,
int height,
int src_pitch,
bool bgr)
796 const int offs = bgr ? -src_pitch : src_pitch;
798 for (
int x = 0; x < width; x++) {
799 uchar red = src[x + src_pitch - offs];
800 uchar green = src[x + src_pitch];
801 uchar blue = src[x + src_pitch + offs];
802 *dst++ = (0XFFU << 24) | (red << 16) | (green << 8) | blue;
810 static int type = -1;
812 if (QScreen *screen = QGuiApplication::primaryScreen())
813 type = screen->handle()->subpixelAntialiasingTypeHint();
815 return static_cast<QFontEngine::SubpixelAntialiasingType>(type);
818QFontEngineFT *QFontEngineFT::create(
const QFontDef &fontDef, FaceId faceId,
const QByteArray &fontData)
820 auto engine = std::make_unique<QFontEngineFT>(fontDef);
822 QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono;
823 const bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);
826 QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint();
827 if (subpixelType == QFontEngine::Subpixel_None || (fontDef.styleStrategy & QFont::NoSubpixelAntialias)) {
828 format = QFontEngineFT::Format_A8;
829 engine->subpixelType = QFontEngine::Subpixel_None;
831 format = QFontEngineFT::Format_A32;
832 engine->subpixelType = subpixelType;
836 if (!engine->init(faceId, antialias, format, fontData) || engine->invalid()) {
837 qWarning(
"QFontEngineFT: Failed to create FreeType font engine");
841 engine->setQtDefaultHintStyle(
static_cast<QFont::HintingPreference>(fontDef.hintingPreference));
842 return engine.release();
846 class QFontEngineFTRawData:
public QFontEngineFT
849 QFontEngineFTRawData(
const QFontDef &fontDef) : QFontEngineFT(fontDef)
853 void updateFamilyNameAndStyle()
855 fontDef.families = QStringList(QString::fromLatin1(freetype->face->family_name));
857 if (freetype->face->style_flags & FT_STYLE_FLAG_ITALIC)
858 fontDef.style = QFont::StyleItalic;
860 if (freetype->face->style_flags & FT_STYLE_FLAG_BOLD)
861 fontDef.weight = QFont::Bold;
864 bool initFromData(
const QByteArray &fontData,
const QMap<QFont::Tag,
float> &variableAxisValues)
867 faceId.filename =
"";
869 faceId.uuid = QUuid::createUuid().toByteArray();
870 faceId.variableAxes = variableAxisValues;
872 return init(faceId,
true, Format_None, fontData);
877QFontEngineFT *QFontEngineFT::create(
const QByteArray &fontData,
879 QFont::HintingPreference hintingPreference,
880 const QMap<QFont::Tag,
float> &variableAxisValues)
883 fontDef.pixelSize = pixelSize;
884 fontDef.stretch = QFont::Unstretched;
885 fontDef.hintingPreference = hintingPreference;
886 fontDef.variableAxisValues = variableAxisValues;
888 QFontEngineFTRawData *fe =
new QFontEngineFTRawData(fontDef);
889 if (!fe->initFromData(fontData, variableAxisValues)) {
894 fe->updateFamilyNameAndStyle();
895 fe->setQtDefaultHintStyle(
static_cast<QFont::HintingPreference>(fontDef.hintingPreference));
900QFontEngineFT::QFontEngineFT(
const QFontDef &fd)
901 : QFontEngine(Freetype)
908 cache_cost = 100 * 1024;
909 kerning_pairs_loaded =
false;
915 default_load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
916 default_hint_style = ftInitialDefaultHintStyle;
917 subpixelType = Subpixel_None;
918 lcdFilterType = (
int)((quintptr) FT_LCD_FILTER_DEFAULT);
919 defaultFormat = Format_None;
920 embeddedbitmap =
false;
921 const QByteArray env = qgetenv(
"QT_NO_FT_CACHE");
922 cacheEnabled = env.isEmpty() || env.toInt() == 0;
923 m_subPixelPositionCount = 4;
924 forceAutoHint =
false;
925 stemDarkeningDriver =
false;
928QFontEngineFT::~QFontEngineFT()
931 freetype->release(face_id);
934bool QFontEngineFT::init(FaceId faceId,
bool antialias, GlyphFormat format,
935 const QByteArray &fontData)
937 return init(faceId, antialias, format, QFreetypeFace::getFace(faceId, fontData));
944 FT_MM_Var *var = freetypeFace->mm_var;
945 if (var !=
nullptr && faceId.instanceIndex >= 0 && FT_UInt(faceId.instanceIndex) < var->num_namedstyles) {
946 for (FT_UInt axis = 0; axis < var->num_axis; ++axis) {
947 if (var->axis[axis].tag == QFont::Tag(
"wght").value()) {
948 return var->namedstyle[faceId.instanceIndex].coords[axis] >> 16;
952 if (
const TT_OS2 *os2 =
reinterpret_cast<
const TT_OS2 *>(FT_Get_Sfnt_Table(face, ft_sfnt_os2))) {
953 return os2->usWeightClass;
961 FT_MM_Var *var = freetypeFace->mm_var;
962 if (var !=
nullptr && faceId.instanceIndex >= 0 && FT_UInt(faceId.instanceIndex) < var->num_namedstyles) {
963 for (FT_UInt axis = 0; axis < var->num_axis; ++axis) {
964 if (var->axis[axis].tag == QFont::Tag(
"ital").value()) {
965 return (var->namedstyle[faceId.instanceIndex].coords[axis] >> 16) == 1;
970 return (face->style_flags & FT_STYLE_FLAG_ITALIC);
973bool QFontEngineFT::init(FaceId faceId,
bool antialias, GlyphFormat format,
974 QFreetypeFace *freetypeFace)
976 freetype = freetypeFace;
982 defaultFormat = format;
983 this->antialias = antialias;
986 glyphFormat = QFontEngine::Format_Mono;
988 glyphFormat = defaultFormat;
992 symbol = freetype->symbol_map !=
nullptr;
993 PS_FontInfoRec psrec;
995 if (FT_Get_PS_Font_Info(freetype->face, &psrec) == FT_Err_Ok) {
996 symbol = !fontDef.families.isEmpty() &&
bool(fontDef.families.constFirst().contains(
"symbol"_L1, Qt::CaseInsensitive));
999 freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing, &scalableBitmapScaleFactor);
1001 FT_Face face = lockFace();
1003 if (FT_IS_SCALABLE(face)
1004#if defined(FT_HAS_COLOR)
1005 && !FT_HAS_COLOR(face)
1008 bool isItalic = calculateActualItalic(freetype, face, faceId);
1009 bool fake_oblique = (fontDef.style != QFont::StyleNormal) && !isItalic && !qEnvironmentVariableIsSet(
"QT_NO_SYNTHESIZED_ITALIC");
1012 FT_Set_Transform(face, &matrix,
nullptr);
1013 freetype->matrix = matrix;
1015 if ((fontDef.weight >= QFont::Bold) && !(face->style_flags & FT_STYLE_FLAG_BOLD) && !FT_IS_FIXED_WIDTH(face) && !qEnvironmentVariableIsSet(
"QT_NO_SYNTHESIZED_BOLD")) {
1016 FT_UShort actualWeight = calculateActualWeight(freetype, face, faceId);
1017 if (actualWeight < 700 &&
1018 (fontDef.pixelSize < 64 || qEnvironmentVariableIsSet(
"QT_NO_SYNTHESIZED_BOLD_LIMIT"))) {
1023 line_thickness = QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale));
1024 QFixed center_position = QFixed::fromFixed(-FT_MulFix(face->underline_position, face->size->metrics.y_scale));
1025 underline_position = center_position - line_thickness / 2;
1028 int score = fontDef.weight * fontDef.pixelSize;
1029 line_thickness = score / 7000;
1031 if (line_thickness < 2 && score >= 1050)
1033 underline_position = ((line_thickness * 2) + 3) / 6;
1035 cacheEnabled =
false;
1036#if defined(FT_HAS_COLOR)
1037 if (FT_HAS_COLOR(face))
1038 glyphFormat = defaultFormat = GlyphFormat::Format_ARGB;
1041 if (line_thickness < 1)
1044 metrics = face->size->metrics;
1047
1048
1049
1050
1051
1052
1053 if (FT_IS_SCALABLE(face)) {
1054 for (
int i = 0; i < face->num_fixed_sizes; ++i) {
1055 if (xsize == face->available_sizes[i].x_ppem && ysize == face->available_sizes[i].y_ppem) {
1056 face->face_flags &= ~FT_FACE_FLAG_SCALABLE;
1058 FT_Select_Size(face, i);
1059 if (face->size->metrics.ascender + face->size->metrics.descender > 0) {
1060 FT_Pos leading = metrics.height - metrics.ascender + metrics.descender;
1061 metrics.ascender = face->size->metrics.ascender;
1062 metrics.descender = face->size->metrics.descender;
1063 if (metrics.descender > 0
1064 && QString::fromUtf8(face->family_name) ==
"Courier New"_L1) {
1065 metrics.descender *= -1;
1067 metrics.height = metrics.ascender - metrics.descender + leading;
1069 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
1071 face->face_flags |= FT_FACE_FLAG_SCALABLE;
1076#if defined(FT_FONT_FORMATS_H)
1077 const char *fmt = FT_Get_Font_Format(face);
1078 if (fmt && qstrncmp(fmt,
"CFF", 4) == 0) {
1079 FT_Bool no_stem_darkening =
true;
1080 FT_Error err = FT_Property_Get(qt_getFreetype(),
"cff",
"no-stem-darkening", &no_stem_darkening);
1081 if (err == FT_Err_Ok)
1082 stemDarkeningDriver = !no_stem_darkening;
1084 stemDarkeningDriver =
false;
1088 fontDef.styleName = QString::fromUtf8(face->style_name);
1090 if (!freetype->hbFace) {
1091 faceData.user_data = face;
1092 faceData.get_font_table = ft_getSfntTable;
1093 (
void)harfbuzzFace();
1094 freetype->hbFace = std::move(face_);
1099 face_ = Holder(freetype->hbFace.get(), dont_delete);
1103 fsType = freetype->fsType();
1107void QFontEngineFT::setQtDefaultHintStyle(QFont::HintingPreference hintingPreference)
1109 switch (hintingPreference) {
1110 case QFont::PreferNoHinting:
1111 setDefaultHintStyle(HintNone);
1113 case QFont::PreferFullHinting:
1114 setDefaultHintStyle(HintFull);
1116 case QFont::PreferVerticalHinting:
1117 setDefaultHintStyle(HintLight);
1119 case QFont::PreferDefaultHinting:
1120 setDefaultHintStyle(ftInitialDefaultHintStyle);
1125void QFontEngineFT::setDefaultHintStyle(HintStyle style)
1127 default_hint_style = style;
1130bool QFontEngineFT::expectsGammaCorrectedBlending()
const
1132 return stemDarkeningDriver;
1135int QFontEngineFT::loadFlags(QGlyphSet *set, GlyphFormat format,
int flags,
1136 bool &hsubpixel,
int &vfactor)
const
1138 int load_flags = FT_LOAD_DEFAULT | default_load_flags;
1139 int load_target = default_hint_style == HintLight
1140 ? FT_LOAD_TARGET_LIGHT
1141 : FT_LOAD_TARGET_NORMAL;
1143 if (format == Format_Mono) {
1144 load_target = FT_LOAD_TARGET_MONO;
1145 }
else if (format == Format_A32) {
1146 if (subpixelType == Subpixel_RGB || subpixelType == Subpixel_BGR)
1148 else if (subpixelType == Subpixel_VRGB || subpixelType == Subpixel_VBGR)
1150 }
else if (format == Format_ARGB) {
1152 load_flags |= FT_LOAD_COLOR;
1156 if (set && set->outline_drawing)
1157 load_flags |= FT_LOAD_NO_BITMAP;
1159 if (default_hint_style == HintNone || (flags & DesignMetrics) || (set && set->outline_drawing))
1160 load_flags |= FT_LOAD_NO_HINTING;
1162 load_flags |= load_target;
1165 load_flags |= FT_LOAD_FORCE_AUTOHINT;
1173 return info.width > 0xFF || info.height > 0xFF || info.linearAdvance > 0x7FFF;
1182 FT_Vector_Transform(&vector, matrix);
1187 FT_Vector_Transform(&vector, matrix);
1188 if (l > vector.x) l = vector.x;
1189 if (r < vector.x) r = vector.x;
1190 if (t < vector.y) t = vector.y;
1191 if (b > vector.y) b = vector.y;
1194 FT_Vector_Transform(&vector, matrix);
1195 if (l > vector.x) l = vector.x;
1196 if (r < vector.x) r = vector.x;
1197 if (t < vector.y) t = vector.y;
1198 if (b > vector.y) b = vector.y;
1201 FT_Vector_Transform(&vector, matrix);
1202 if (l > vector.x) l = vector.x;
1203 if (r < vector.x) r = vector.x;
1204 if (t < vector.y) t = vector.y;
1205 if (b > vector.y) b = vector.y;
1212#if defined(QFONTENGINE_FT_SUPPORT_COLRV1)
1213#define FROM_FIXED_16_16(value) (value / 65536.0
)
1215static inline QTransform FTAffineToQTransform(
const FT_Affine23 &matrix)
1217 qreal m11 = FROM_FIXED_16_16(matrix.xx);
1218 qreal m21 = -FROM_FIXED_16_16(matrix.xy);
1219 qreal m12 = -FROM_FIXED_16_16(matrix.yx);
1220 qreal m22 = FROM_FIXED_16_16(matrix.yy);
1221 qreal dx = FROM_FIXED_16_16(matrix.dx);
1222 qreal dy = -FROM_FIXED_16_16(matrix.dy);
1224 return QTransform(m11, m12, m21, m22, dx, dy);
1227bool QFontEngineFT::traverseColr1(FT_OpaquePaint opaquePaint,
1228 QSet<QPair<FT_Byte *, FT_Bool> > *loops,
1229 QColor foregroundColor,
1231 ushort paletteCount,
1232 QColrPaintGraphRenderer *paintGraphRenderer)
const
1234 FT_Face face = freetype->face;
1236 auto key = qMakePair(opaquePaint.p, opaquePaint.insert_root_transform);
1237 if (loops->contains(key)) {
1238 qCWarning(lcColrv1) <<
"Cycle detected in COLRv1 graph";
1242 paintGraphRenderer->save();
1244 auto cleanup = qScopeGuard([&paintGraphRenderer, &key, &loops]() {
1246 paintGraphRenderer->restore();
1249 FT_COLR_Paint paint;
1250 if (!FT_Get_Paint(face, opaquePaint, &paint))
1253 if (paint.format == FT_COLR_PAINTFORMAT_COLR_LAYERS) {
1254 FT_OpaquePaint layerPaint;
1255 layerPaint.p =
nullptr;
1256 while (FT_Get_Paint_Layers(face, &paint.u.colr_layers.layer_iterator, &layerPaint)) {
1257 if (!traverseColr1(layerPaint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1260 }
else if (paint.format == FT_COLR_PAINTFORMAT_TRANSFORM
1261 || paint.format == FT_COLR_PAINTFORMAT_SCALE
1262 || paint.format == FT_COLR_PAINTFORMAT_TRANSLATE
1263 || paint.format == FT_COLR_PAINTFORMAT_ROTATE
1264 || paint.format == FT_COLR_PAINTFORMAT_SKEW) {
1267 FT_OpaquePaint nextPaint;
1268 switch (paint.format) {
1269 case FT_COLR_PAINTFORMAT_TRANSFORM:
1270 xform = FTAffineToQTransform(paint.u.transform.affine);
1271 nextPaint = paint.u.transform.paint;
1273 case FT_COLR_PAINTFORMAT_SCALE:
1275 qreal centerX = FROM_FIXED_16_16(paint.u.scale.center_x);
1276 qreal centerY = -FROM_FIXED_16_16(paint.u.scale.center_y);
1277 qreal scaleX = FROM_FIXED_16_16(paint.u.scale.scale_x);
1278 qreal scaleY = FROM_FIXED_16_16(paint.u.scale.scale_y);
1280 xform.translate(centerX, centerY);
1281 xform.scale(scaleX, scaleY);
1282 xform.translate(-centerX, -centerY);
1284 nextPaint = paint.u.scale.paint;
1287 case FT_COLR_PAINTFORMAT_ROTATE:
1289 qreal centerX = FROM_FIXED_16_16(paint.u.rotate.center_x);
1290 qreal centerY = -FROM_FIXED_16_16(paint.u.rotate.center_y);
1291 qreal angle = -FROM_FIXED_16_16(paint.u.rotate.angle) * 180.0;
1293 xform.translate(centerX, centerY);
1294 xform.rotate(angle);
1295 xform.translate(-centerX, -centerY);
1297 nextPaint = paint.u.rotate.paint;
1301 case FT_COLR_PAINTFORMAT_SKEW:
1303 qreal centerX = FROM_FIXED_16_16(paint.u.skew.center_x);
1304 qreal centerY = -FROM_FIXED_16_16(paint.u.skew.center_y);
1305 qreal angleX = FROM_FIXED_16_16(paint.u.skew.x_skew_angle) * M_PI;
1306 qreal angleY = -FROM_FIXED_16_16(paint.u.skew.y_skew_angle) * M_PI;
1308 xform.translate(centerX, centerY);
1309 xform.shear(qTan(angleX), qTan(angleY));
1310 xform.translate(-centerX, -centerY);
1312 nextPaint = paint.u.rotate.paint;
1315 case FT_COLR_PAINTFORMAT_TRANSLATE:
1317 qreal dx = FROM_FIXED_16_16(paint.u.translate.dx);
1318 qreal dy = -FROM_FIXED_16_16(paint.u.translate.dy);
1320 xform.translate(dx, dy);
1321 nextPaint = paint.u.rotate.paint;
1328 paintGraphRenderer->prependTransform(xform);
1329 if (!traverseColr1(nextPaint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1331 }
else if (paint.format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT
1332 || paint.format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT
1333 || paint.format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT
1334 || paint.format == FT_COLR_PAINTFORMAT_SOLID) {
1335 auto getPaletteColor = [&palette, &paletteCount, &foregroundColor](FT_UInt16 index,
1338 if (index < paletteCount) {
1339 const FT_Color &paletteColor = palette[index];
1340 color = qRgba(paletteColor.red,
1343 paletteColor.alpha);
1344 }
else if (index == 0xffff) {
1345 color = foregroundColor;
1348 if (color.isValid())
1349 color.setAlphaF(color.alphaF() * (alpha / 16384.0));
1354 auto gatherGradientStops = [&](FT_ColorStopIterator it) {
1356 ret.resize(it.num_color_stops);
1358 FT_ColorStop colorStop;
1359 while (FT_Get_Colorline_Stops(face, &colorStop, &it)) {
1360 uint index = it.current_color_stop - 1;
1361 if (qsizetype(index) < ret.size()) {
1362 QGradientStop &gradientStop = ret[index];
1363 gradientStop.first = FROM_FIXED_16_16(colorStop.stop_offset);
1364 gradientStop.second = getPaletteColor(colorStop.color.palette_index,
1365 colorStop.color.alpha);
1372 auto extendToSpread = [](FT_PaintExtend extend) {
1374 case FT_COLR_PAINT_EXTEND_REPEAT:
1375 return QGradient::RepeatSpread;
1376 case FT_COLR_PAINT_EXTEND_REFLECT:
1377 return QGradient::ReflectSpread;
1379 return QGradient::PadSpread;
1383 if (paintGraphRenderer->isRendering()) {
1384 if (paint.format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT) {
1385 const qreal p0x = FROM_FIXED_16_16(paint.u.linear_gradient.p0.x);
1386 const qreal p0y = -FROM_FIXED_16_16(paint.u.linear_gradient.p0.y);
1388 const qreal p1x = FROM_FIXED_16_16(paint.u.linear_gradient.p1.x);
1389 const qreal p1y = -FROM_FIXED_16_16(paint.u.linear_gradient.p1.y);
1391 const qreal p2x = FROM_FIXED_16_16(paint.u.linear_gradient.p2.x);
1392 const qreal p2y = -FROM_FIXED_16_16(paint.u.linear_gradient.p2.y);
1394 QPointF p0(p0x, p0y);
1395 QPointF p1(p1x, p1y);
1396 QPointF p2(p2x, p2y);
1398 const QGradient::Spread spread =
1399 extendToSpread(paint.u.linear_gradient.colorline.extend);
1400 const QGradientStops stops =
1401 gatherGradientStops(paint.u.linear_gradient.colorline.color_stop_iterator);
1402 paintGraphRenderer->setLinearGradient(p0, p1, p2, spread, stops);
1404 }
else if (paint.format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT) {
1405 const qreal c0x = FROM_FIXED_16_16(paint.u.radial_gradient.c0.x);
1406 const qreal c0y = -FROM_FIXED_16_16(paint.u.radial_gradient.c0.y);
1407 const qreal r0 = FROM_FIXED_16_16(paint.u.radial_gradient.r0);
1408 const qreal c1x = FROM_FIXED_16_16(paint.u.radial_gradient.c1.x);
1409 const qreal c1y = -FROM_FIXED_16_16(paint.u.radial_gradient.c1.y);
1410 const qreal r1 = FROM_FIXED_16_16(paint.u.radial_gradient.r1);
1412 const QPointF c0(c0x, c0y);
1413 const QPointF c1(c1x, c1y);
1414 const QGradient::Spread spread =
1415 extendToSpread(paint.u.radial_gradient.colorline.extend);
1416 const QGradientStops stops =
1417 gatherGradientStops(paint.u.radial_gradient.colorline.color_stop_iterator);
1419 paintGraphRenderer->setRadialGradient(c0, r0, c1, r1, spread, stops);
1420 }
else if (paint.format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT) {
1421 const qreal centerX = FROM_FIXED_16_16(paint.u.sweep_gradient.center.x);
1422 const qreal centerY = -FROM_FIXED_16_16(paint.u.sweep_gradient.center.y);
1423 const qreal startAngle = 180.0 * FROM_FIXED_16_16(paint.u.sweep_gradient.start_angle);
1424 const qreal endAngle = 180.0 * FROM_FIXED_16_16(paint.u.sweep_gradient.end_angle);
1426 const QPointF center(centerX, centerY);
1428 const QGradient::Spread spread = extendToSpread(paint.u.radial_gradient.colorline.extend);
1429 const QGradientStops stops = gatherGradientStops(paint.u.sweep_gradient.colorline.color_stop_iterator);
1431 paintGraphRenderer->setConicalGradient(center, startAngle, endAngle, spread, stops);
1433 }
else if (paint.format == FT_COLR_PAINTFORMAT_SOLID) {
1434 QColor color = getPaletteColor(paint.u.solid.color.palette_index,
1435 paint.u.solid.color.alpha);
1436 if (!color.isValid()) {
1437 qCWarning(lcColrv1) <<
"Invalid palette index in COLRv1 graph:"
1438 << paint.u.solid.color.palette_index;
1442 paintGraphRenderer->setSolidColor(color);
1446 paintGraphRenderer->drawCurrentPath();
1447 }
else if (paint.format == FT_COLR_PAINTFORMAT_COMPOSITE) {
1448 if (!paintGraphRenderer->isRendering()) {
1449 if (!traverseColr1(paint.u.composite.backdrop_paint,
1454 paintGraphRenderer)) {
1457 if (!traverseColr1(paint.u.composite.source_paint,
1462 paintGraphRenderer)) {
1466 QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
1467 switch (paint.u.composite.composite_mode) {
1468 case FT_COLR_COMPOSITE_CLEAR:
1469 compositionMode = QPainter::CompositionMode_Clear;
1471 case FT_COLR_COMPOSITE_SRC:
1472 compositionMode = QPainter::CompositionMode_Source;
1474 case FT_COLR_COMPOSITE_DEST:
1475 compositionMode = QPainter::CompositionMode_Destination;
1477 case FT_COLR_COMPOSITE_SRC_OVER:
1478 compositionMode = QPainter::CompositionMode_SourceOver;
1480 case FT_COLR_COMPOSITE_DEST_OVER:
1481 compositionMode = QPainter::CompositionMode_DestinationOver;
1483 case FT_COLR_COMPOSITE_SRC_IN:
1484 compositionMode = QPainter::CompositionMode_SourceIn;
1486 case FT_COLR_COMPOSITE_DEST_IN:
1487 compositionMode = QPainter::CompositionMode_DestinationIn;
1489 case FT_COLR_COMPOSITE_SRC_OUT:
1490 compositionMode = QPainter::CompositionMode_SourceOut;
1492 case FT_COLR_COMPOSITE_DEST_OUT:
1493 compositionMode = QPainter::CompositionMode_DestinationOut;
1495 case FT_COLR_COMPOSITE_SRC_ATOP:
1496 compositionMode = QPainter::CompositionMode_SourceAtop;
1498 case FT_COLR_COMPOSITE_DEST_ATOP:
1499 compositionMode = QPainter::CompositionMode_DestinationAtop;
1501 case FT_COLR_COMPOSITE_XOR:
1502 compositionMode = QPainter::CompositionMode_Xor;
1504 case FT_COLR_COMPOSITE_PLUS:
1505 compositionMode = QPainter::CompositionMode_Plus;
1507 case FT_COLR_COMPOSITE_SCREEN:
1508 compositionMode = QPainter::CompositionMode_Screen;
1510 case FT_COLR_COMPOSITE_OVERLAY:
1511 compositionMode = QPainter::CompositionMode_Overlay;
1513 case FT_COLR_COMPOSITE_DARKEN:
1514 compositionMode = QPainter::CompositionMode_Darken;
1516 case FT_COLR_COMPOSITE_LIGHTEN:
1517 compositionMode = QPainter::CompositionMode_Lighten;
1519 case FT_COLR_COMPOSITE_COLOR_DODGE:
1520 compositionMode = QPainter::CompositionMode_ColorDodge;
1522 case FT_COLR_COMPOSITE_COLOR_BURN:
1523 compositionMode = QPainter::CompositionMode_ColorBurn;
1525 case FT_COLR_COMPOSITE_HARD_LIGHT:
1526 compositionMode = QPainter::CompositionMode_HardLight;
1528 case FT_COLR_COMPOSITE_SOFT_LIGHT:
1529 compositionMode = QPainter::CompositionMode_SoftLight;
1531 case FT_COLR_COMPOSITE_DIFFERENCE:
1532 compositionMode = QPainter::CompositionMode_Difference;
1534 case FT_COLR_COMPOSITE_EXCLUSION:
1535 compositionMode = QPainter::CompositionMode_Exclusion;
1537 case FT_COLR_COMPOSITE_MULTIPLY:
1538 compositionMode = QPainter::CompositionMode_Multiply;
1541 qCWarning(lcColrv1) <<
"Unsupported COLRv1 composition mode" << paint.u.composite.composite_mode;
1545 QColrPaintGraphRenderer compositeRenderer;
1546 compositeRenderer.setBoundingRect(paintGraphRenderer->boundingRect());
1547 compositeRenderer.beginRender(fontDef.pixelSize / face->units_per_EM,
1548 paintGraphRenderer->currentTransform());
1549 if (!traverseColr1(paint.u.composite.backdrop_paint,
1554 &compositeRenderer)) {
1558 compositeRenderer.setCompositionMode(compositionMode);
1559 if (!traverseColr1(paint.u.composite.source_paint,
1564 &compositeRenderer)) {
1567 paintGraphRenderer->drawImage(compositeRenderer.endRender());
1569 }
else if (paint.format == FT_COLR_PAINTFORMAT_GLYPH) {
1570 FT_Error error = FT_Load_Glyph(face,
1571 paint.u.glyph.glyphID,
1572 FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP | FT_LOAD_NO_SVG | FT_LOAD_IGNORE_TRANSFORM | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT | FT_LOAD_BITMAP_METRICS_ONLY);
1574 qCWarning(lcColrv1) <<
"Failed to load glyph"
1575 << paint.u.glyph.glyphID
1576 <<
"in COLRv1 graph. Error: " << error;
1581 QFreetypeFace::addGlyphToPath(face,
1585 face->units_per_EM << 6,
1586 face->units_per_EM << 6);
1588 paintGraphRenderer->appendPath(path);
1590 if (!traverseColr1(paint.u.glyph.paint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1592 }
else if (paint.format == FT_COLR_PAINTFORMAT_COLR_GLYPH) {
1593 FT_OpaquePaint otherOpaquePaint;
1594 otherOpaquePaint.p =
nullptr;
1595 if (!FT_Get_Color_Glyph_Paint(face,
1596 paint.u.colr_glyph.glyphID,
1597 FT_COLOR_NO_ROOT_TRANSFORM,
1598 &otherOpaquePaint)) {
1599 qCWarning(lcColrv1) <<
"Failed to load color glyph"
1600 << paint.u.colr_glyph.glyphID
1601 <<
"in COLRv1 graph.";
1605 if (!traverseColr1(otherOpaquePaint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1612QFontEngineFT::Glyph *QFontEngineFT::loadColrv1Glyph(QGlyphSet *set,
1615 const QColor &foregroundColor,
1616 bool fetchMetricsOnly)
const
1618 FT_Face face = freetype->face;
1621 memset(&info, 0,
sizeof(info));
1625 FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT
1628 | FT_LOAD_BITMAP_METRICS_ONLY);
1629 info.linearAdvance =
int(face->glyph->linearHoriAdvance >> 10);
1630 info.xOff =
short(TRUNC(ROUND(face->glyph->advance.x)));
1632 FT_OpaquePaint opaquePaint;
1633 opaquePaint.p =
nullptr;
1634 if (!FT_Get_Color_Glyph_Paint(face, glyph, FT_COLOR_INCLUDE_ROOT_TRANSFORM, &opaquePaint))
1639 FT_Set_Char_Size(face, face->units_per_EM << 6, face->units_per_EM << 6, 0, 0);
1643 FT_Get_Transform(face, &matrix, &delta);
1644 QTransform originalXform(FROM_FIXED_16_16(matrix.xx), -FROM_FIXED_16_16(matrix.yx),
1645 -FROM_FIXED_16_16(matrix.xy), FROM_FIXED_16_16(matrix.yy),
1646 FROM_FIXED_16_16(delta.x), FROM_FIXED_16_16(delta.y));
1650 FT_Set_Transform(face,
nullptr,
nullptr);
1652 auto cleanup = qScopeGuard([&]() {
1654 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
1655 FT_Set_Transform(face, &matrix, &delta);
1658 qCDebug(lcColrv1).noquote() <<
"================== Start collecting COLRv1 metrics for" << glyph;
1659 QRect designCoordinateBounds;
1663 if (colrv1_bounds_cache_id == glyph) {
1664 designCoordinateBounds = colrv1_bounds_cache;
1669 if (FT_Get_Color_Glyph_ClipBox(face, glyph, &clipBox)) {
1670 FT_Pos left = qMin(clipBox.bottom_left.x, qMin(clipBox.bottom_right.x, qMin(clipBox.top_left.x, clipBox.top_right.x)));
1671 FT_Pos right = qMax(clipBox.bottom_left.x, qMax(clipBox.bottom_right.x, qMax(clipBox.top_left.x, clipBox.top_right.x)));
1673 FT_Pos top = qMin(-clipBox.bottom_left.y, qMin(-clipBox.bottom_right.y, qMin(-clipBox.top_left.y, -clipBox.top_right.y)));
1674 FT_Pos bottom = qMax(-clipBox.bottom_left.y, qMax(-clipBox.bottom_right.y, qMax(-clipBox.top_left.y, -clipBox.top_right.y)));
1676 qreal scale = 1.0 / 64.0;
1677 designCoordinateBounds = QRect(QPoint(qFloor(left * scale), qFloor(top * scale)),
1678 QPoint(qCeil(right * scale), qCeil(bottom * scale)));
1681 QColrPaintGraphRenderer boundingRectCalculator;
1682 boundingRectCalculator.beginCalculateBoundingBox();
1683 QSet<QPair<FT_Byte *, FT_Bool> > loops;
1684 if (traverseColr1(opaquePaint,
1689 &boundingRectCalculator)) {
1690 designCoordinateBounds = boundingRectCalculator.boundingRect().toAlignedRect();
1694 colrv1_bounds_cache_id = glyph;
1695 colrv1_bounds_cache = designCoordinateBounds;
1698 QTransform initialTransform;
1699 initialTransform.scale(fontDef.pixelSize / face->units_per_EM,
1700 fontDef.pixelSize / face->units_per_EM);
1701 QRect bounds = initialTransform.mapRect(designCoordinateBounds);
1702 bounds = originalXform.mapRect(bounds);
1704 info.x = bounds.left();
1705 info.y = -bounds.top();
1706 info.width = bounds.width();
1707 info.height = bounds.height();
1709 qCDebug(lcColrv1) <<
"Bounds of" << glyph <<
"==" << bounds;
1712 QImage destinationImage;
1713 if (!fetchMetricsOnly && !bounds.size().isEmpty()) {
1714 FT_Palette_Data paletteData;
1715 if (FT_Palette_Data_Get(face, &paletteData))
1718 FT_Color *palette =
nullptr;
1719 FT_Error error = FT_Palette_Select(face, 0, &palette);
1721 qWarning(
"selecting palette for COLRv1 failed, err=%x face=%p, glyph=%d",
1727 if (palette ==
nullptr)
1730 ushort paletteCount = paletteData.num_palette_entries;
1732 QColrPaintGraphRenderer paintGraphRenderer;
1733 paintGraphRenderer.setBoundingRect(bounds);
1734 paintGraphRenderer.beginRender(fontDef.pixelSize / face->units_per_EM,
1738 QSet<QPair<FT_Byte *, FT_Bool> > loops;
1739 if (!traverseColr1(opaquePaint,
1744 &paintGraphRenderer)) {
1748 destinationImage = paintGraphRenderer.endRender();
1751 if (fetchMetricsOnly || !destinationImage.isNull()) {
1756 set->setGlyph(glyph, QFixedPoint{}, g);
1759 g->linearAdvance = info.linearAdvance;
1760 g->width = info.width;
1761 g->height = info.height;
1764 g->advance = info.xOff;
1765 g->format = Format_ARGB;
1767 if (!fetchMetricsOnly && !destinationImage.isNull()) {
1768 g->data =
new uchar[info.height * info.width * 4];
1769 memcpy(g->data, destinationImage.constBits(), info.height * info.width * 4);
1779QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
1780 const QFixedPoint &subPixelPosition,
1783 bool fetchMetricsOnly,
1784 bool disableOutlineDrawing)
const
1788 if (format == Format_None)
1789 format = defaultFormat != Format_None ? defaultFormat : Format_Mono;
1790 Q_ASSERT(format != Format_None);
1792 Glyph *g = set ? set->getGlyph(glyph, subPixelPosition) :
nullptr;
1793 if (g && g->format == format && (fetchMetricsOnly || g->data))
1796 if (!g && set && set->isGlyphMissing(glyph))
1800 FT_Face face = freetype->face;
1802 FT_Matrix matrix = freetype->matrix;
1803 bool transform = matrix.xx != 0x10000
1804 || matrix.yy != 0x10000
1807 if (obliquen && transform) {
1812 slant.xx = 0x10000L;
1815 slant.yy = 0x10000L;
1817 FT_Matrix_Multiply(&matrix, &slant);
1822 v.x = format == Format_Mono ? 0 : FT_Pos(subPixelPosition.x.value());
1823 v.y = format == Format_Mono ? 0 : FT_Pos(-subPixelPosition.y.value());
1824 FT_Set_Transform(face, &matrix, &v);
1826 bool hsubpixel =
false;
1828 int load_flags = loadFlags(set, format, 0, hsubpixel, vfactor);
1830 if (transform || obliquen || (format != Format_Mono && !isScalableBitmap()))
1831 load_flags |= FT_LOAD_NO_BITMAP;
1833#if defined(QFONTENGINE_FT_SUPPORT_COLRV1)
1834 if (FT_IS_SCALABLE(freetype->face)
1835 && FT_HAS_COLOR(freetype->face)
1836 && (load_flags & FT_LOAD_COLOR)) {
1838 Glyph *ret = loadColrv1Glyph(set, g, glyph, color, fetchMetricsOnly);
1846 FT_Error err = FT_Load_Glyph(face, glyph, load_flags);
1847 if (err && (load_flags & FT_LOAD_NO_BITMAP)) {
1848 load_flags &= ~FT_LOAD_NO_BITMAP;
1849 err = FT_Load_Glyph(face, glyph, load_flags);
1851 if (err == FT_Err_Too_Few_Arguments) {
1853 load_flags |= FT_LOAD_FORCE_AUTOHINT;
1854 err = FT_Load_Glyph(face, glyph, load_flags);
1855 }
else if (err == FT_Err_Execution_Too_Long) {
1858 qWarning(
"load glyph failed due to broken hinting bytecode in font, switching to auto hinting");
1859 default_load_flags |= FT_LOAD_FORCE_AUTOHINT;
1860 load_flags |= FT_LOAD_FORCE_AUTOHINT;
1861 err = FT_Load_Glyph(face, glyph, load_flags);
1863 if (err != FT_Err_Ok) {
1864 qWarning(
"load glyph failed err=%x face=%p, glyph=%d", err, face, glyph);
1866 set->setGlyphMissing(glyph);
1870 FT_GlyphSlot slot = face->glyph;
1873 FT_GlyphSlot_Embolden(slot);
1874 if (obliquen && !transform) {
1875 FT_GlyphSlot_Oblique(slot);
1886 FT_Matrix_Multiply(&m, &matrix);
1890 info.linearAdvance = slot->linearHoriAdvance >> 10;
1894 if ((set && set->outline_drawing && !disableOutlineDrawing) || fetchMetricsOnly) {
1895 int left = slot->metrics.horiBearingX;
1896 int right = slot->metrics.horiBearingX + slot->metrics.width;
1897 int top = slot->metrics.horiBearingY;
1898 int bottom = slot->metrics.horiBearingY - slot->metrics.height;
1900 if (transform && slot->format != FT_GLYPH_FORMAT_BITMAP)
1901 transformBoundingBox(&left, &top, &right, &bottom, &matrix);
1904 right =
CEIL(right);
1905 bottom =
FLOOR(bottom);
1908 info.x =
TRUNC(left);
1909 info.y =
TRUNC(top);
1910 info.width =
TRUNC(right - left);
1911 info.height =
TRUNC(top - bottom);
1915 if (areMetricsTooLarge(info))
1920 g->linearAdvance = info.linearAdvance;
1921 g->width = info.width;
1922 g->height = info.height;
1925 g->advance = info.xOff;
1929 set->setGlyph(glyph, subPixelPosition, g);
1934 int glyph_buffer_size = 0;
1935 std::unique_ptr<uchar[]> glyph_buffer;
1936 FT_Render_Mode renderMode = (default_hint_style == HintLight) ? FT_RENDER_MODE_LIGHT : FT_RENDER_MODE_NORMAL;
1939 renderMode = FT_RENDER_MODE_MONO;
1942 if (!hsubpixel && vfactor == 1) {
1943 qWarning(
"Format_A32 requested, but subpixel layout is unknown.");
1947 renderMode = hsubpixel ? FT_RENDER_MODE_LCD : FT_RENDER_MODE_LCD_V;
1955 FT_Library_SetLcdFilter(slot->library, (FT_LcdFilter)lcdFilterType);
1957 err = FT_Render_Glyph(slot, renderMode);
1958 if (err != FT_Err_Ok)
1959 qWarning(
"render glyph failed err=%x face=%p, glyph=%d", err, face, glyph);
1961 FT_Library_SetLcdFilter(slot->library, FT_LCD_FILTER_NONE);
1963 info.height = slot->bitmap.rows;
1964 info.width = slot->bitmap.width;
1965 info.x = slot->bitmap_left;
1966 info.y = slot->bitmap_top;
1967 if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD)
1968 info.width = info.width / 3;
1969 if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V)
1970 info.height = info.height / vfactor;
1972 int pitch = (format == Format_Mono ? ((info.width + 31) & ~31) >> 3 :
1973 (format == Format_A8 ? (info.width + 3) & ~3 : info.width * 4));
1975 glyph_buffer_size = info.height * pitch;
1976 glyph_buffer.reset(
new uchar[glyph_buffer_size]);
1978 if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
1979 uchar *src = slot->bitmap.buffer;
1980 uchar *dst = glyph_buffer.get();
1981 int h = slot->bitmap.rows;
1983 if (format == Format_Mono) {
1984 int bytes = ((info.width + 7) & ~7) >> 3;
1986 memcpy (dst, src, bytes);
1988 src += slot->bitmap.pitch;
1990 }
else if (format == Format_A8) {
1992 for (
int x = 0; x <
int{info.width}; x++)
1993 dst[x] = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xff : 0x00);
1995 src += slot->bitmap.pitch;
1999 uint *dd =
reinterpret_cast<uint *>(dst);
2000 for (
int x = 0; x <
int{info.width}; x++)
2001 dd[x] = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xffffffff : 0x00000000);
2003 src += slot->bitmap.pitch;
2006 }
else if (slot->bitmap.pixel_mode == 7 ) {
2007 Q_ASSERT(format == Format_ARGB);
2008 uchar *src = slot->bitmap.buffer;
2009 uchar *dst = glyph_buffer.get();
2010 int h = slot->bitmap.rows;
2012#if Q_BYTE_ORDER == Q_BIG_ENDIAN
2013 const quint32 *srcPixel = (
const quint32 *)src;
2014 quint32 *dstPixel = (quint32 *)dst;
2015 for (
int x = 0; x <
static_cast<
int>(slot->bitmap.width); x++, srcPixel++, dstPixel++) {
2016 const quint32 pixel = *srcPixel;
2017 *dstPixel = qbswap(pixel);
2020 memcpy(dst, src, slot->bitmap.width * 4);
2022 dst += slot->bitmap.pitch;
2023 src += slot->bitmap.pitch;
2025 info.linearAdvance = info.xOff = slot->bitmap.width;
2026 }
else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) {
2027 if (format == Format_A8) {
2028 uchar *src = slot->bitmap.buffer;
2029 uchar *dst = glyph_buffer.get();
2030 int h = slot->bitmap.rows;
2031 int bytes = info.width;
2033 memcpy (dst, src, bytes);
2035 src += slot->bitmap.pitch;
2037 }
else if (format == Format_ARGB) {
2038 uchar *src = slot->bitmap.buffer;
2039 quint32 *dstPixel =
reinterpret_cast<quint32 *>(glyph_buffer.get());
2040 int h = slot->bitmap.rows;
2042 for (
int x = 0; x <
static_cast<
int>(slot->bitmap.width); ++x) {
2043 uchar alpha = src[x];
2044 float alphaF = alpha / 255.0;
2045 dstPixel[x] = qRgba(qRound(alphaF * color.red()),
2046 qRound(alphaF * color.green()),
2047 qRound(alphaF * color.blue()),
2050 src += slot->bitmap.pitch;
2051 dstPixel += info.width;
2054 }
else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
2055 Q_ASSERT(format == Format_A32);
2056 convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB);
2057 }
else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
2058 Q_ASSERT(format == Format_A32);
2059 convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB);
2061 qWarning(
"QFontEngine: Glyph rendered in unknown pixel_mode=%d", slot->bitmap.pixel_mode);
2070 g->linearAdvance = info.linearAdvance;
2071 g->width = info.width;
2072 g->height = info.height;
2075 g->advance = info.xOff;
2078 g->data = glyph_buffer.release();
2081 set->setGlyph(glyph, subPixelPosition, g);
2086QFontEngine::FaceId QFontEngineFT::faceId()
const
2091QFontEngine::Properties QFontEngineFT::properties()
const
2093 Properties p = freetype->properties();
2094 if (p.postscriptName.isEmpty()) {
2095 p.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(fontDef.families.constFirst().toUtf8());
2098 return freetype->properties();
2101QFixed QFontEngineFT::emSquareSize()
const
2103 if (FT_IS_SCALABLE(freetype->face))
2104 return freetype->face->units_per_EM;
2106 return freetype->face->size->metrics.y_ppem;
2109bool QFontEngineFT::getSfntTableData(uint tag, uchar *buffer, uint *length)
const
2111 return ft_getSfntTable(freetype->face, tag, buffer, length);
2114int QFontEngineFT::synthesized()
const
2117 if ((fontDef.style != QFont::StyleNormal) && !(freetype->face->style_flags & FT_STYLE_FLAG_ITALIC))
2118 s = SynthesizedItalic;
2119 if ((fontDef.weight >= QFont::Bold) && !(freetype->face->style_flags & FT_STYLE_FLAG_BOLD))
2120 s |= SynthesizedBold;
2121 if (fontDef.stretch != 100 && FT_IS_SCALABLE(freetype->face))
2122 s |= SynthesizedStretch;
2126void QFontEngineFT::initializeHeightMetrics()
const
2128 m_ascent = QFixed::fromFixed(metrics.ascender);
2129 m_descent = QFixed::fromFixed(-metrics.descender);
2130 m_leading = QFixed::fromFixed(metrics.height - metrics.ascender + metrics.descender);
2132 QFontEngine::initializeHeightMetrics();
2134 if (scalableBitmapScaleFactor != 1) {
2135 m_ascent *= scalableBitmapScaleFactor;
2136 m_descent *= scalableBitmapScaleFactor;
2137 m_leading *= scalableBitmapScaleFactor;
2141QFixed QFontEngineFT::capHeight()
const
2143 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
2144 if (os2 && os2->version >= 2) {
2146 QFixed answer = QFixed::fromFixed(FT_MulFix(os2->sCapHeight, freetype->face->size->metrics.y_scale));
2150 return calculatedCapHeight();
2153QFixed QFontEngineFT::xHeight()
const
2155 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
2156 if (os2 && os2->sxHeight) {
2158 QFixed answer = QFixed(os2->sxHeight * freetype->face->size->metrics.y_ppem) / emSquareSize();
2163 return QFontEngine::xHeight();
2166QFixed QFontEngineFT::averageCharWidth()
const
2168 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
2169 if (os2 && os2->xAvgCharWidth) {
2171 QFixed answer = QFixed(os2->xAvgCharWidth * freetype->face->size->metrics.x_ppem) / emSquareSize();
2176 return QFontEngine::averageCharWidth();
2179qreal QFontEngineFT::maxCharWidth()
const
2181 QFixed max_advance = QFixed::fromFixed(metrics.max_advance);
2182 if (scalableBitmapScaleFactor != 1)
2183 max_advance *= scalableBitmapScaleFactor;
2184 return max_advance.toReal();
2187QFixed QFontEngineFT::lineThickness()
const
2189 return line_thickness;
2192QFixed QFontEngineFT::underlinePosition()
const
2194 return underline_position;
2197void QFontEngineFT::doKerning(QGlyphLayout *g, QFontEngine::ShaperFlags flags)
const
2199 if (!kerning_pairs_loaded) {
2200 kerning_pairs_loaded =
true;
2202 if (freetype->face->size->metrics.x_ppem != 0) {
2203 QFixed scalingFactor = emSquareSize() / QFixed(freetype->face->size->metrics.x_ppem);
2205 const_cast<QFontEngineFT *>(
this)->loadKerningPairs(scalingFactor);
2211 if (shouldUseDesignMetrics(flags))
2212 flags |= DesignMetrics;
2214 flags &= ~DesignMetrics;
2216 QFontEngine::doKerning(g, flags);
2223 m.xx = FT_Fixed(matrix.m11() * 65536);
2224 m.xy = FT_Fixed(-matrix.m21() * 65536);
2225 m.yx = FT_Fixed(-matrix.m12() * 65536);
2226 m.yy = FT_Fixed(matrix.m22() * 65536);
2231QFontEngineFT::QGlyphSet *QFontEngineFT::TransformedGlyphSets::findSet(
const QTransform &matrix,
const QFontDef &fontDef)
2233 FT_Matrix m = QTransformToFTMatrix(matrix);
2236 for (; i < nSets; ++i) {
2237 QGlyphSet *g = sets[i];
2240 if (g->transformationMatrix.xx == m.xx
2241 && g->transformationMatrix.xy == m.xy
2242 && g->transformationMatrix.yx == m.yx
2243 && g->transformationMatrix.yy == m.yy) {
2255 moveToFront(nSets - 1);
2257 sets[0] =
new QGlyphSet;
2258 QGlyphSet *gs = sets[0];
2260 gs->transformationMatrix = m;
2262 Q_ASSERT(gs !=
nullptr);
2267void QFontEngineFT::TransformedGlyphSets::moveToFront(
int i)
2269 QGlyphSet *g = sets[i];
2271 sets[i] = sets[i - 1];
2278QFontEngineFT::QGlyphSet *QFontEngineFT::loadGlyphSet(
const QTransform &matrix)
2280 if (matrix.type() > QTransform::TxShear || !cacheEnabled)
2284 if (!FT_IS_SCALABLE(freetype->face))
2285 return matrix.type() <= QTransform::TxTranslate ? &defaultGlyphSet :
nullptr;
2287 return transformedGlyphSets.findSet(matrix, fontDef);
2290void QFontEngineFT::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
2292 FT_Face face = lockFace(Unscaled);
2293 FT_Set_Transform(face,
nullptr,
nullptr);
2294 FT_Load_Glyph(face, glyph, FT_LOAD_NO_BITMAP);
2296 int left = face->glyph->metrics.horiBearingX;
2297 int right = face->glyph->metrics.horiBearingX + face->glyph->metrics.width;
2298 int top = face->glyph->metrics.horiBearingY;
2299 int bottom = face->glyph->metrics.horiBearingY - face->glyph->metrics.height;
2305 metrics->width = QFixed::fromFixed(right-left);
2306 metrics->height = QFixed::fromFixed(top-bottom);
2307 metrics->x = QFixed::fromFixed(left);
2308 metrics->y = QFixed::fromFixed(-top);
2309 metrics->xoff = QFixed::fromFixed(face->glyph->advance.x);
2311 if (!FT_IS_SCALABLE(freetype->face))
2312 QFreetypeFace::addBitmapToPath(face->glyph, p, path);
2314 QFreetypeFace::addGlyphToPath(face, face->glyph, p, path, face->units_per_EM << 6, face->units_per_EM << 6);
2316 FT_Set_Transform(face, &freetype->matrix,
nullptr);
2320bool QFontEngineFT::supportsTransformation(
const QTransform &transform)
const
2322 return transform.type() <= QTransform::TxRotate;
2325void QFontEngineFT::addOutlineToPath(qreal x, qreal y,
const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
2327 if (!glyphs.numGlyphs)
2330 if (FT_IS_SCALABLE(freetype->face)) {
2331 QFontEngine::addOutlineToPath(x, y, glyphs, path, flags);
2333 QVarLengthArray<QFixedPoint> positions;
2334 QVarLengthArray<glyph_t> positioned_glyphs;
2336 matrix.translate(x, y);
2337 getGlyphPositions(glyphs, matrix, flags, positioned_glyphs, positions);
2339 FT_Face face = lockFace(Unscaled);
2340 for (
int gl = 0; gl < glyphs.numGlyphs; gl++) {
2341 FT_UInt glyph = positioned_glyphs[gl];
2342 FT_Load_Glyph(face, glyph, FT_LOAD_TARGET_MONO);
2343 QFreetypeFace::addBitmapToPath(face->glyph, positions[gl], path);
2349void QFontEngineFT::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions,
int numGlyphs,
2350 QPainterPath *path, QTextItem::RenderFlags)
2352 FT_Face face = lockFace(Unscaled);
2354 for (
int gl = 0; gl < numGlyphs; gl++) {
2355 FT_UInt glyph = glyphs[gl];
2357 FT_Load_Glyph(face, glyph, FT_LOAD_NO_BITMAP);
2359 FT_GlyphSlot g = face->glyph;
2360 if (g->format != FT_GLYPH_FORMAT_OUTLINE)
2363 FT_GlyphSlot_Embolden(g);
2365 FT_GlyphSlot_Oblique(g);
2366 QFreetypeFace::addGlyphToPath(face, g, positions[gl], path, xsize, ysize);
2371glyph_t QFontEngineFT::glyphIndex(uint ucs4)
const
2373 glyph_t glyph = ucs4 < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[ucs4] : 0;
2375 FT_Face face = freetype->face;
2376 glyph = FT_Get_Char_Index(face, ucs4);
2380 if (ucs4 == QChar::Nbsp || ucs4 == QChar::Tabulation) {
2381 glyph = FT_Get_Char_Index(face, QChar::Space);
2382 }
else if (freetype->symbol_map) {
2389 FT_Set_Charmap(face, freetype->symbol_map);
2390 glyph = FT_Get_Char_Index(face, ucs4);
2391 FT_Set_Charmap(face, freetype->unicode_map);
2392 if (!glyph && symbol && ucs4 < 0x100)
2393 glyph = FT_Get_Char_Index(face, ucs4 + 0xf000);
2396 if (ucs4 < QFreetypeFace::cmapCacheSize)
2397 freetype->cmapCache[ucs4] = glyph;
2403QString QFontEngineFT::glyphName(glyph_t index)
const
2406 if (index >= glyph_t(glyphCount()))
2409 FT_Face face = freetype->face;
2410 if (face->face_flags & FT_FACE_FLAG_GLYPH_NAMES) {
2411 char glyphName[128] = {};
2412 if (FT_Get_Glyph_Name(face, index, glyphName,
sizeof(glyphName)) == 0)
2413 result = QString::fromUtf8(glyphName);
2416 return result.isEmpty() ? QFontEngine::glyphName(index) : result;
2419int QFontEngineFT::stringToCMap(
const QChar *str,
int len, QGlyphLayout *glyphs,
int *nglyphs,
2420 QFontEngine::ShaperFlags flags)
const
2422 Q_ASSERT(glyphs->numGlyphs >= *nglyphs);
2423 if (*nglyphs < len) {
2428 int mappedGlyphs = 0;
2430 if (freetype->symbol_map) {
2431 FT_Face face = freetype->face;
2432 QStringIterator it(str, str + len);
2433 while (it.hasNext()) {
2434 uint uc = it.next();
2435 glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
2436 if ( !glyphs->glyphs[glyph_pos] ) {
2443 glyph_t glyph = FT_Get_Char_Index(face, uc);
2446 if (!glyph && (uc == 0xa0 || uc == 0x9)) {
2448 glyph = FT_Get_Char_Index(face, uc);
2451 FT_Set_Charmap(face, freetype->symbol_map);
2452 glyph = FT_Get_Char_Index(face, uc);
2453 FT_Set_Charmap(face, freetype->unicode_map);
2454 if (!glyph && symbol && uc < 0x100)
2455 glyph = FT_Get_Char_Index(face, uc + 0xf000);
2457 glyphs->glyphs[glyph_pos] = glyph;
2458 if (uc < QFreetypeFace::cmapCacheSize)
2459 freetype->cmapCache[uc] = glyph;
2461 if (glyphs->glyphs[glyph_pos] || isIgnorableChar(uc))
2466 FT_Face face = freetype->face;
2467 QStringIterator it(str, str + len);
2468 while (it.hasNext()) {
2469 uint uc = it.next();
2470 glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
2471 if (!glyphs->glyphs[glyph_pos]) {
2474 glyph_t glyph = FT_Get_Char_Index(face, uc);
2475 if (!glyph && (uc == 0xa0 || uc == 0x9)) {
2479 glyphs->glyphs[glyph_pos] = glyph;
2480 if (uc < QFreetypeFace::cmapCacheSize)
2481 freetype->cmapCache[uc] = glyph;
2484 if (glyphs->glyphs[glyph_pos] || isIgnorableChar(uc))
2490 *nglyphs = glyph_pos;
2491 glyphs->numGlyphs = glyph_pos;
2493 if (!(flags & GlyphIndicesOnly))
2494 recalcAdvances(glyphs, flags);
2496 return mappedGlyphs;
2499bool QFontEngineFT::shouldUseDesignMetrics(QFontEngine::ShaperFlags flags)
const
2501 if (!FT_IS_SCALABLE(freetype->face))
2504 return default_hint_style == HintNone || default_hint_style == HintLight || (flags & DesignMetrics);
2507QFixed QFontEngineFT::scaledBitmapMetrics(QFixed m)
const
2509 return m * scalableBitmapScaleFactor;
2512glyph_metrics_t QFontEngineFT::scaledBitmapMetrics(
const glyph_metrics_t &m,
const QTransform &t)
const
2515 trans.setMatrix(t.m11(), t.m12(), t.m13(),
2516 t.m21(), t.m22(), t.m23(),
2518 const qreal scaleFactor = scalableBitmapScaleFactor.toReal();
2519 trans.scale(scaleFactor, scaleFactor);
2521 QRectF rect(m.x.toReal(), m.y.toReal(), m.width.toReal(), m.height.toReal());
2522 QPointF offset(m.xoff.toReal(), m.yoff.toReal());
2524 rect = trans.mapRect(rect);
2525 offset = trans.map(offset);
2527 glyph_metrics_t metrics;
2528 metrics.x = QFixed::fromReal(rect.x());
2529 metrics.y = QFixed::fromReal(rect.y());
2530 metrics.width = QFixed::fromReal(rect.width());
2531 metrics.height = QFixed::fromReal(rect.height());
2532 metrics.xoff = QFixed::fromReal(offset.x());
2533 metrics.yoff = QFixed::fromReal(offset.y());
2537void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags flags)
const
2539 FT_Face face =
nullptr;
2540 bool design = shouldUseDesignMetrics(flags);
2541 for (
int i = 0; i < glyphs->numGlyphs; i++) {
2542 Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyphs->glyphs[i]) :
nullptr;
2544 GlyphFormat acceptableFormat = (defaultFormat != Format_None) ? defaultFormat : Format_Mono;
2545 if (g && g->format == acceptableFormat) {
2546 glyphs->advances[i] = design ? QFixed::fromFixed(g->linearAdvance) : QFixed(g->advance);
2550 g = loadGlyph(cacheEnabled ? &defaultGlyphSet :
nullptr,
2557 glyphs->advances[i] = design ? QFixed::fromFixed(g->linearAdvance) : QFixed(g->advance);
2559 glyphs->advances[i] = design ? QFixed::fromFixed(face->glyph->linearHoriAdvance >> 10)
2560 : QFixed::fromFixed(face->glyph->metrics.horiAdvance).round();
2561 if (!cacheEnabled && g != &emptyGlyph)
2565 if (scalableBitmapScaleFactor != 1)
2566 glyphs->advances[i] *= scalableBitmapScaleFactor;
2572glyph_metrics_t QFontEngineFT::boundingBox(
const QGlyphLayout &glyphs)
2574 FT_Face face =
nullptr;
2576 glyph_metrics_t overall;
2578 if (!isScalableBitmap()) {
2579 overall.y = -ascent();
2580 overall.height = ascent() + descent();
2582 overall.y = QFixed::fromFixed(-metrics.ascender);
2583 overall.height = QFixed::fromFixed(metrics.ascender - metrics.descender);
2588 for (
int i = 0; i < glyphs.numGlyphs; i++) {
2590 if (!glyphs.advances[i] || glyphs.attributes[i].dontPrint)
2592 Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyphs.glyphs[i]) :
nullptr;
2596 g = loadGlyph(cacheEnabled ? &defaultGlyphSet :
nullptr,
2604 QFixed x = overall.xoff + glyphs.offsets[i].x + g->x;
2605 QFixed y = overall.yoff + glyphs.offsets[i].y - g->y;
2606 overall.x = qMin(overall.x, x);
2607 overall.y = qMin(overall.y, y);
2608 xmax = qMax(xmax, x.ceil() + g->width);
2609 ymax = qMax(ymax, y.ceil() + g->height);
2610 if (!cacheEnabled && g != &emptyGlyph)
2613 int left =
FLOOR(face->glyph->metrics.horiBearingX);
2614 int right =
CEIL(face->glyph->metrics.horiBearingX + face->glyph->metrics.width);
2615 int top =
CEIL(face->glyph->metrics.horiBearingY);
2616 int bottom =
FLOOR(face->glyph->metrics.horiBearingY - face->glyph->metrics.height);
2618 QFixed x = overall.xoff + glyphs.offsets[i].x - (-
TRUNC(left));
2619 QFixed y = overall.yoff + glyphs.offsets[i].y -
TRUNC(top);
2620 overall.x = qMin(overall.x, x);
2621 overall.y = qMin(overall.y, y);
2622 xmax = qMax(xmax, x +
TRUNC(right - left));
2623 ymax = qMax(ymax, y +
TRUNC(top - bottom));
2625 overall.xoff += glyphs.effectiveAdvance(i);
2627 overall.height = qMax(overall.height, ymax - overall.y);
2628 overall.width = xmax - overall.x;
2633 if (isScalableBitmap())
2634 overall = scaledBitmapMetrics(overall, QTransform());
2638glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph)
2640 FT_Face face =
nullptr;
2641 glyph_metrics_t overall;
2642 Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyph) :
nullptr;
2645 g = loadGlyph(cacheEnabled ? &defaultGlyphSet :
nullptr,
2655 overall.width = g->width;
2656 overall.height = g->height;
2657 overall.xoff = g->advance;
2658 if (!cacheEnabled && g != &emptyGlyph)
2661 int left =
FLOOR(face->glyph->metrics.horiBearingX);
2662 int right =
CEIL(face->glyph->metrics.horiBearingX + face->glyph->metrics.width);
2663 int top =
CEIL(face->glyph->metrics.horiBearingY);
2664 int bottom =
FLOOR(face->glyph->metrics.horiBearingY - face->glyph->metrics.height);
2666 overall.width =
TRUNC(right-left);
2667 overall.height =
TRUNC(top-bottom);
2668 overall.x =
TRUNC(left);
2669 overall.y = -
TRUNC(top);
2670 overall.xoff =
TRUNC(
ROUND(face->glyph->advance.x));
2675 if (isScalableBitmap())
2676 overall = scaledBitmapMetrics(overall, QTransform());
2680glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph,
const QTransform &matrix)
2682 return alphaMapBoundingBox(glyph, QFixedPoint(), matrix, QFontEngine::Format_None);
2685glyph_metrics_t QFontEngineFT::alphaMapBoundingBox(glyph_t glyph,
2686 const QFixedPoint &subPixelPosition,
2687 const QTransform &matrix,
2688 QFontEngine::GlyphFormat format)
2694 const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face)
2695 && matrix.type() > QTransform::TxTranslate;
2696 if (needsImageTransform && format == QFontEngine::Format_Mono)
2697 format = QFontEngine::Format_A8;
2698 Glyph *g = loadGlyphFor(glyph, subPixelPosition, format, matrix, QColor(),
true,
true);
2700 glyph_metrics_t overall;
2704 overall.width = g->width;
2705 overall.height = g->height;
2706 overall.xoff = g->advance;
2707 if (!cacheEnabled && g != &emptyGlyph)
2710 FT_Face face = lockFace();
2711 int left =
FLOOR(face->glyph->metrics.horiBearingX);
2712 int right =
CEIL(face->glyph->metrics.horiBearingX + face->glyph->metrics.width);
2713 int top =
CEIL(face->glyph->metrics.horiBearingY);
2714 int bottom =
FLOOR(face->glyph->metrics.horiBearingY - face->glyph->metrics.height);
2716 overall.width =
TRUNC(right-left);
2717 overall.height =
TRUNC(top-bottom);
2718 overall.x =
TRUNC(left);
2719 overall.y = -
TRUNC(top);
2720 overall.xoff =
TRUNC(
ROUND(face->glyph->advance.x));
2724 if (isScalableBitmap() || needsImageTransform)
2725 overall = scaledBitmapMetrics(overall, matrix);
2731 if (glyph ==
nullptr || glyph->height == 0 || glyph->width == 0)
2734 QImage::Format format = QImage::Format_Invalid;
2735 int bytesPerLine = -1;
2736 switch (glyphFormat) {
2737 case QFontEngine::Format_Mono:
2738 format = QImage::Format_Mono;
2739 bytesPerLine = ((glyph->width + 31) & ~31) >> 3;
2741 case QFontEngine::Format_A8:
2742 format = QImage::Format_Alpha8;
2743 bytesPerLine = (glyph->width + 3) & ~3;
2745 case QFontEngine::Format_A32:
2746 format = QImage::Format_RGB32;
2747 bytesPerLine = glyph->width * 4;
2753 QImage img(
static_cast<
const uchar *>(glyph->data), glyph->width, glyph->height, bytesPerLine, format);
2754 if (format == QImage::Format_Mono)
2755 img.setColor(1, QColor(Qt::white).rgba());
2759QFontEngine::Glyph *QFontEngineFT::glyphData(glyph_t glyphIndex,
2760 const QFixedPoint &subPixelPosition,
2761 QFontEngine::GlyphFormat neededFormat,
2762 const QTransform &t)
2764 Q_ASSERT(cacheEnabled);
2767 neededFormat = Format_Mono;
2768 else if (neededFormat == Format_None && defaultFormat != Format_None)
2769 neededFormat = defaultFormat;
2770 else if (neededFormat == Format_None)
2771 neededFormat = Format_A8;
2773 Glyph *glyph = loadGlyphFor(glyphIndex, subPixelPosition, neededFormat, t, QColor());
2774 if (!glyph || !glyph->width || !glyph->height)
2782 return qFuzzyCompare(t.m11(), t.m22()) && qFuzzyCompare(t.m12(), -t.m21())
2783 && qFuzzyCompare(t.m11()*t.m22() - t.m12()*t.m21(), qreal(1.0));
2786QFontEngineFT::Glyph *QFontEngineFT::loadGlyphFor(glyph_t g,
2787 const QFixedPoint &subPixelPosition,
2789 const QTransform &t,
2791 bool fetchBoundingBox,
2792 bool disableOutlineDrawing)
2794 QGlyphSet *glyphSet = loadGlyphSet(t);
2795 if (glyphSet !=
nullptr && glyphSet->outline_drawing && !disableOutlineDrawing && !fetchBoundingBox)
2798 Glyph *glyph = glyphSet !=
nullptr ? glyphSet->getGlyph(g, subPixelPosition) :
nullptr;
2799 if (!glyph || glyph->format != format || (!fetchBoundingBox && !glyph->data)) {
2800 QScopedValueRollback<HintStyle> saved_default_hint_style(default_hint_style);
2801 if (t.type() >= QTransform::TxScale && !is2dRotation(t))
2802 default_hint_style = HintNone;
2805 FT_Matrix m =
this->matrix;
2806 FT_Matrix ftMatrix = glyphSet !=
nullptr ? glyphSet->transformationMatrix : QTransformToFTMatrix(t);
2807 FT_Matrix_Multiply(&ftMatrix, &m);
2808 freetype->matrix = m;
2809 glyph = loadGlyph(glyphSet, g, subPixelPosition, color, format,
false, disableOutlineDrawing);
2816QImage QFontEngineFT::alphaMapForGlyph(glyph_t g,
const QFixedPoint &subPixelPosition)
2818 return alphaMapForGlyph(g, subPixelPosition, QTransform());
2821QImage QFontEngineFT::alphaMapForGlyph(glyph_t g,
2822 const QFixedPoint &subPixelPosition,
2823 const QTransform &t)
2825 const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face)
2826 && t.type() > QTransform::TxTranslate;
2827 const GlyphFormat neededFormat = antialias || needsImageTransform ? Format_A8 : Format_Mono;
2829 Glyph *glyph = loadGlyphFor(g, subPixelPosition, neededFormat, t, QColor(),
false,
true);
2831 QImage img = alphaMapFromGlyphData(glyph, neededFormat);
2832 if (needsImageTransform)
2833 img = img.transformed(t, Qt::FastTransformation);
2837 if (!cacheEnabled && glyph != &emptyGlyph)
2843QImage QFontEngineFT::alphaRGBMapForGlyph(glyph_t g,
2844 const QFixedPoint &subPixelPosition,
2845 const QTransform &t)
2847 if (t.type() > QTransform::TxRotate)
2848 return QFontEngine::alphaRGBMapForGlyph(g, subPixelPosition, t);
2850 const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face)
2851 && t.type() > QTransform::TxTranslate;
2854 const GlyphFormat neededFormat = Format_A32;
2856 Glyph *glyph = loadGlyphFor(g, subPixelPosition, neededFormat, t, QColor(),
false,
true);
2858 QImage img = alphaMapFromGlyphData(glyph, neededFormat);
2859 if (needsImageTransform)
2860 img = img.transformed(t, Qt::FastTransformation);
2864 if (!cacheEnabled && glyph != &emptyGlyph)
2870 return QFontEngine::alphaRGBMapForGlyph(g, subPixelPosition, t);
2873QImage QFontEngineFT::bitmapForGlyph(glyph_t g,
2874 const QFixedPoint &subPixelPosition,
2875 const QTransform &t,
2876 const QColor &color)
2878 Glyph *glyph = loadGlyphFor(g, subPixelPosition, defaultFormat, t, color);
2879 if (glyph ==
nullptr)
2883 if (defaultFormat == GlyphFormat::Format_ARGB)
2884 img = QImage(glyph->data, glyph->width, glyph->height, QImage::Format_ARGB32_Premultiplied).copy();
2885 else if (defaultFormat == GlyphFormat::Format_Mono)
2886 img = QImage(glyph->data, glyph->width, glyph->height, QImage::Format_Mono).copy();
2888 if (!img.isNull() && (scalableBitmapScaleFactor != 1 || (!t.isIdentity() && !isSmoothlyScalable))) {
2889 QTransform trans(t);
2890 const qreal scaleFactor = scalableBitmapScaleFactor.toReal();
2891 trans.scale(scaleFactor, scaleFactor);
2892 img = img.transformed(trans, Qt::SmoothTransformation);
2895 if (!cacheEnabled && glyph != &emptyGlyph)
2901void QFontEngineFT::removeGlyphFromCache(glyph_t glyph)
2903 defaultGlyphSet.removeGlyphFromCache(glyph, QFixedPoint());
2906int QFontEngineFT::glyphCount()
const
2909 FT_Face face = lockFace();
2911 count = face->num_glyphs;
2917FT_Face QFontEngineFT::lockFace(Scaling scale)
const
2920 FT_Face face = freetype->face;
2921 if (scale == Unscaled) {
2922 if (FT_Set_Char_Size(face, face->units_per_EM << 6, face->units_per_EM << 6, 0, 0) == 0) {
2923 freetype->xsize = face->units_per_EM << 6;
2924 freetype->ysize = face->units_per_EM << 6;
2926 }
else if (freetype->xsize != xsize || freetype->ysize != ysize) {
2927 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
2928 freetype->xsize = xsize;
2929 freetype->ysize = ysize;
2931 if (freetype->matrix.xx != matrix.xx ||
2932 freetype->matrix.yy != matrix.yy ||
2933 freetype->matrix.xy != matrix.xy ||
2934 freetype->matrix.yx != matrix.yx) {
2935 freetype->matrix = matrix;
2936 FT_Set_Transform(face, &freetype->matrix,
nullptr);
2942void QFontEngineFT::unlockFace()
const
2947FT_Face QFontEngineFT::non_locked_face()
const
2949 return freetype->face;
2953QFontEngineFT::QGlyphSet::QGlyphSet()
2954 : outline_drawing(
false)
2956 transformationMatrix.xx = 0x10000;
2957 transformationMatrix.yy = 0x10000;
2958 transformationMatrix.xy = 0;
2959 transformationMatrix.yx = 0;
2960 memset(fast_glyph_data, 0,
sizeof(fast_glyph_data));
2961 fast_glyph_count = 0;
2964QFontEngineFT::QGlyphSet::~QGlyphSet()
2969void QFontEngineFT::QGlyphSet::clear()
2971 if (fast_glyph_count > 0) {
2972 for (
int i = 0; i < 256; ++i) {
2973 if (fast_glyph_data[i]) {
2974 delete fast_glyph_data[i];
2975 fast_glyph_data[i] =
nullptr;
2978 fast_glyph_count = 0;
2980 qDeleteAll(glyph_data);
2984void QFontEngineFT::QGlyphSet::removeGlyphFromCache(glyph_t index,
2985 const QFixedPoint &subPixelPosition)
2987 if (useFastGlyphData(index, subPixelPosition)) {
2988 if (fast_glyph_data[index]) {
2989 delete fast_glyph_data[index];
2990 fast_glyph_data[index] =
nullptr;
2991 if (fast_glyph_count > 0)
2995 delete glyph_data.take(GlyphAndSubPixelPosition(index, subPixelPosition));
2999void QFontEngineFT::QGlyphSet::setGlyph(glyph_t index,
3000 const QFixedPoint &subPixelPosition,
3003 if (useFastGlyphData(index, subPixelPosition)) {
3004 if (!fast_glyph_data[index])
3006 fast_glyph_data[index] = glyph;
3008 glyph_data.insert(GlyphAndSubPixelPosition(index, subPixelPosition), glyph);
3012int QFontEngineFT::getPointInOutline(glyph_t glyph,
int flags, quint32 point, QFixed *xpos, QFixed *ypos, quint32 *nPoints)
3015 bool hsubpixel =
true;
3017 int load_flags = loadFlags(
nullptr, Format_A8, flags, hsubpixel, vfactor);
3018 int result = freetype->getPointInOutline(glyph, load_flags, point, xpos, ypos, nPoints);
3023bool QFontEngineFT::initFromFontEngine(
const QFontEngineFT *fe)
3025 if (!init(fe->faceId(), fe->antialias, fe->defaultFormat, fe->freetype))
3030 freetype->ref.ref();
3032 default_load_flags = fe->default_load_flags;
3033 default_hint_style = fe->default_hint_style;
3034 antialias = fe->antialias;
3035 transform = fe->transform;
3036 embolden = fe->embolden;
3037 obliquen = fe->obliquen;
3038 subpixelType = fe->subpixelType;
3039 lcdFilterType = fe->lcdFilterType;
3040 embeddedbitmap = fe->embeddedbitmap;
3045QFontEngine *QFontEngineFT::cloneWithSize(qreal pixelSize)
const
3047 QFontDef fontDef(
this->fontDef);
3048 fontDef.pixelSize = pixelSize;
3049 QFontEngineFT *fe =
new QFontEngineFT(fontDef);
3050 if (!fe->initFromFontEngine(
this)) {
3058Qt::HANDLE QFontEngineFT::handle()
const
3060 return non_locked_face();
3063QList<QFontVariableAxis> QFontEngineFT::variableAxes()
const
3065 return freetype->variableAxes();
QHash< QFontEngine::FaceId, QFreetypeFace * > faces
QList< QFreetypeFace * > staleFaces
QHash< FaceStyle, int > faceIndices
static const QFontEngine::HintStyle ftInitialDefaultHintStyle
static QFontEngine::SubpixelAntialiasingType subpixelAntialiasingTypeHint()
static FT_Matrix QTransformToFTMatrix(const QTransform &matrix)
static void transformBoundingBox(int *left, int *top, int *right, int *bottom, FT_Matrix *matrix)
static void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr)
QtFreetypeData * qt_getFreetypeData()
static bool calculateActualItalic(QFreetypeFace *freetypeFace, FT_Face face, QFontEngine::FaceId faceId)
static bool is2dRotation(const QTransform &t)
static QImage alphaMapFromGlyphData(QFontEngineFT::Glyph *glyph, QFontEngine::GlyphFormat glyphFormat)
static QFontEngineFT::Glyph emptyGlyph
QByteArray qt_fontdata_from_index(int)
size_t qHash(const QtFreetypeData::FaceStyle &style, size_t seed)
static bool ft_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length)
void qt_addBitmapToPath(qreal x0, qreal y0, const uchar *image_data, int bpl, int w, int h, QPainterPath *path)
static int computeFaceIndex(const QString &faceFileName, const QString &styleName)
bool operator==(const QtFreetypeData::FaceStyle &style1, const QtFreetypeData::FaceStyle &style2)
FT_Library qt_getFreetype()
static FT_UShort calculateActualWeight(QFreetypeFace *freetypeFace, FT_Face face, QFontEngine::FaceId faceId)
static void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr)
static void scaleOutline(FT_Face face, FT_GlyphSlot g, FT_Fixed x_scale, FT_Fixed y_scale)
static void dont_delete(void *)
static bool areMetricsTooLarge(const QFontEngineFT::GlyphInfo &info)
#define QT_MAX_CACHED_GLYPH_SIZE
FaceStyle(QString faceFileName, QString styleName)