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
57using namespace Qt::StringLiterals;
59#define FLOOR(x) ((x) & -64
)
60#define CEIL(x) (((x)+63
) & -64
)
61#define TRUNC(x) ((x) >> 6
)
62#define ROUND(x) (((x)+32
) & -64
)
64static bool ft_getSfntTable(
void *user_data, uint tag, uchar *buffer, uint *length)
66 FT_Face face = (FT_Face)user_data;
69 if (FT_IS_SFNT(face)) {
70 FT_ULong len = *length;
71 result = FT_Load_Sfnt_Table(face, tag, 0, buffer, &len) == FT_Err_Ok;
73 Q_ASSERT(!result ||
int(*length) > 0);
83 QFontEngineFT::HintFull;
85 QFontEngineFT::HintNone;
116 for (
auto iter = faces.cbegin(); iter != faces.cend(); ++iter) {
117 iter.value()->cleanup();
118 if (!iter.value()->ref.deref())
123 for (
auto iter = staleFaces.cbegin(); iter != staleFaces.cend(); ++iter) {
125 if (!(*iter)->ref.deref())
130 FT_Done_FreeType(library);
136 return style1.faceFileName == style2.faceFileName && style1.styleName == style2.styleName;
141 return qHashMulti(seed, style.faceFileName, style.styleName);
151 if (!freetypeData->library) {
152 FT_Init_FreeType(&freetypeData->library);
153#if defined(FT_FONT_FORMATS_H)
155 FT_Bool no_darkening =
false;
156 FT_Property_Set(freetypeData->library,
"cff",
"no-stem-darkening", &no_darkening);
165 Q_ASSERT(freetypeData->library);
166 return freetypeData->library;
169int QFreetypeFace::fsType()
const
172 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);
174 fsType = os2->fsType;
178int QFreetypeFace::getPointInOutline(glyph_t glyph,
int flags, quint32 point, QFixed *xpos, QFixed *ypos, quint32 *nPoints)
180 if (
int error = FT_Load_Glyph(face, glyph, flags))
183 if (face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)
184 return Err_Invalid_SubTable;
186 *nPoints = face->glyph->outline.n_points;
190 if (point > *nPoints)
191 return Err_Invalid_SubTable;
193 *xpos = QFixed::fromFixed(face->glyph->outline.points[point].x);
194 *ypos = QFixed::fromFixed(face->glyph->outline.points[point].y);
199bool QFreetypeFace::isScalableBitmap()
const
202 return !FT_IS_SCALABLE(face) && FT_HAS_COLOR(face);
211
212
213
214
215
216
217QFreetypeFace *QFreetypeFace::getFace(
const QFontEngine::FaceId &face_id,
218 const QByteArray &fontData)
220 if (face_id.filename.isEmpty() && fontData.isEmpty())
223 QtFreetypeData *freetypeData = qt_getFreetypeData();
226 freetypeData->staleFaces.removeIf([](QFreetypeFace *face) {
227 if (face->ref.loadRelaxed() == 1) {
235 QFreetypeFace *freetype =
nullptr;
236 auto it = freetypeData->faces.find(face_id);
237 if (it != freetypeData->faces.end()) {
240 Q_ASSERT(freetype->ref.loadRelaxed() > 0);
241 if (freetype->ref.loadRelaxed() == 1) {
248 freetypeData->faces.erase(it);
257 const auto deleter = [](QFreetypeFace *f) {
delete f; };
258 std::unique_ptr<QFreetypeFace,
decltype(deleter)> newFreetype(
new QFreetypeFace, deleter);
261 if (!face_id.filename.isEmpty()) {
262 QString fileName = QFile::decodeName(face_id.filename);
263 if (
const char *prefix =
":qmemoryfonts/"; face_id.filename.startsWith(prefix)) {
265 QByteArray idx = face_id.filename;
266 idx.remove(0, strlen(prefix));
268 newFreetype->fontData = qt_fontdata_from_index(idx.toInt(&ok));
270 newFreetype->fontData = QByteArray();
271 }
else if (!QFileInfo(fileName).isNativePath()) {
272 QFile file(fileName);
273 if (!file.open(QIODevice::ReadOnly)) {
276 newFreetype->fontData = file.readAll();
279 newFreetype->fontData = fontData;
282 FT_Int major, minor, patch;
283 FT_Library_Version(qt_getFreetype(), &major, &minor, &patch);
284 const bool goodVersion = major > 2 || (major == 2 && minor > 13) || (major == 2 && minor == 13 && patch > 2);
286 if (!newFreetype->fontData.isEmpty()) {
287 if (FT_New_Memory_Face(freetypeData->library,
288 (
const FT_Byte *)newFreetype->fontData.constData(),
289 newFreetype->fontData.size(),
299 if (FT_Reference_Face(face))
301 }
else if (!FT_HAS_MULTIPLE_MASTERS(face)
302 || FT_New_Memory_Face(freetypeData->library,
303 (
const FT_Byte *)newFreetype->fontData.constData(),
304 newFreetype->fontData.size(),
306 &tmpFace) != FT_Err_Ok) {
310 if (FT_New_Face(freetypeData->library, face_id.filename, face_id.index, &face))
317 if (FT_Reference_Face(face))
319 }
else if (!FT_HAS_MULTIPLE_MASTERS(face)
320 || FT_New_Face(freetypeData->library, face_id.filename, face_id.index, &tmpFace) != FT_Err_Ok) {
325#if (FREETYPE_MAJOR*10000
+ FREETYPE_MINOR*100
+ FREETYPE_PATCH) >= 20900
326 if (face_id.instanceIndex >= 0) {
328 <<
"Selecting named instance" << (face_id.instanceIndex)
329 <<
"in" << face_id.filename;
330 FT_Set_Named_Instance(face, face_id.instanceIndex + 1);
338 if (tmpFace !=
nullptr) {
340 if (FT_Get_MM_Var(tmpFace, &var) == FT_Err_Ok) {
341 for (FT_UInt i = 0; i < var->num_axis; ++i) {
342 FT_Var_Axis *axis = var->axis + i;
344 QFontVariableAxis fontVariableAxis;
345 if (
const auto tag = QFont::Tag::fromValue(axis->tag)) {
346 fontVariableAxis.setTag(*tag);
348 qWarning() <<
"QFreetypeFace::getFace: Invalid variable axis tag encountered"
352 fontVariableAxis.setMinimumValue(axis->minimum / 65536.0);
353 fontVariableAxis.setMaximumValue(axis->maximum / 65536.0);
354 fontVariableAxis.setDefaultValue(axis->def / 65536.0);
355 fontVariableAxis.setName(QString::fromUtf8(axis->name));
357 newFreetype->variableAxisList.append(fontVariableAxis);
360 if (!face_id.variableAxes.isEmpty()) {
361 QVarLengthArray<FT_Fixed, 16> coords(var->num_axis);
362 FT_Get_Var_Design_Coordinates(face, var->num_axis, coords.data());
363 for (qsizetype i = 0; i < newFreetype->variableAxisList.size(); ++i) {
364 const QFontVariableAxis &axis = newFreetype->variableAxisList.at(i);
365 if (axis.tag().isValid()) {
366 const auto it = face_id.variableAxes.constFind(axis.tag());
367 if (it != face_id.variableAxes.constEnd())
368 coords[i] = FT_Fixed(*it * 65536);
371 FT_Set_Var_Design_Coordinates(face, var->num_axis, coords.data());
374 FT_Done_MM_Var(qt_getFreetype(), var);
377 FT_Done_Face(tmpFace);
380 newFreetype->face = face;
381 newFreetype->mm_var =
nullptr;
382 if (FT_IS_NAMED_INSTANCE(newFreetype->face)) {
384 ftresult = FT_Get_MM_Var(face, &newFreetype->mm_var);
385 if (ftresult != FT_Err_Ok)
386 newFreetype->mm_var =
nullptr;
389 newFreetype->ref.storeRelaxed(1);
390 newFreetype->xsize = 0;
391 newFreetype->ysize = 0;
392 newFreetype->matrix.xx = 0x10000;
393 newFreetype->matrix.yy = 0x10000;
394 newFreetype->matrix.xy = 0;
395 newFreetype->matrix.yx = 0;
396 newFreetype->unicode_map =
nullptr;
397 newFreetype->symbol_map =
nullptr;
399 memset(newFreetype->cmapCache, 0,
sizeof(newFreetype->cmapCache));
401 for (
int i = 0; i < newFreetype->face->num_charmaps; ++i) {
402 FT_CharMap cm = newFreetype->face->charmaps[i];
403 switch(cm->encoding) {
404 case FT_ENCODING_UNICODE:
405 newFreetype->unicode_map = cm;
407 case FT_ENCODING_APPLE_ROMAN:
408 case FT_ENCODING_ADOBE_LATIN_1:
409 if (!newFreetype->unicode_map || newFreetype->unicode_map->encoding != FT_ENCODING_UNICODE)
410 newFreetype->unicode_map = cm;
412 case FT_ENCODING_ADOBE_CUSTOM:
413 case FT_ENCODING_MS_SYMBOL:
414 if (!newFreetype->symbol_map)
415 newFreetype->symbol_map = cm;
422 if (!FT_IS_SCALABLE(newFreetype->face) && newFreetype->face->num_fixed_sizes == 1)
423 FT_Set_Char_Size(face, newFreetype->face->available_sizes[0].x_ppem, newFreetype->face->available_sizes[0].y_ppem, 0, 0);
425 FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map);
428 freetypeData->faces.insert(face_id, newFreetype.get());
430 newFreetype.release()->release(face_id);
434 freetype = newFreetype.release();
440void QFreetypeFace::cleanup()
444 FT_Done_MM_Var(qt_getFreetype(), mm_var);
450void QFreetypeFace::release(
const QFontEngine::FaceId &face_id)
453 bool deleteThis = !ref.deref();
459 if (face && ref.loadRelaxed() == 1) {
460 QtFreetypeData *freetypeData = qt_getFreetypeData();
462 freetypeData->staleFaces.removeIf([&deleteThis,
this](QFreetypeFace *face){
463 if (face->ref.loadRelaxed() == 1) {
474 for (
auto it = freetypeData->faces.constBegin();
475 it != freetypeData->faces.constEnd();
476 it = freetypeData->faces.erase(it)) {
477 if (it.value()->ref.loadRelaxed() == 1) {
478 it.value()->cleanup();
479 if (it.value() ==
this)
484 freetypeData->staleFaces.append(it.value());
488 if (freetypeData->faces.isEmpty() && freetypeData->staleFaces.isEmpty()) {
489 FT_Done_FreeType(freetypeData->library);
490 freetypeData->library =
nullptr;
500 FT_Library library = qt_getFreetype();
508 FT_Error error = FT_New_Face(library, faceFileName.toUtf8().constData(), faceIndex, &face);
509 if (error != FT_Err_Ok) {
510 qDebug() <<
"FT_New_Face failed for face index" << faceIndex <<
':' << Qt::hex << error;
514 const bool found = QLatin1StringView(face->style_name) == styleName;
515 numFaces = face->num_faces;
521 }
while (++faceIndex < numFaces);
527int QFreetypeFace::getFaceIndexByStyleName(
const QString &faceFileName,
const QString &styleName)
529 QtFreetypeData *freetypeData = qt_getFreetypeData();
532 QtFreetypeData::FaceStyle faceStyle(faceFileName, styleName);
533 int faceIndex = freetypeData->faceIndices.value(faceStyle, -1);
538 faceIndex = computeFaceIndex(faceFileName, styleName);
540 freetypeData->faceIndices.insert(faceStyle, faceIndex);
545void QFreetypeFace::computeSize(
const QFontDef &fontDef,
int *xsize,
int *ysize,
bool *outline_drawing, QFixed *scalableBitmapScaleFactor)
547 *ysize = qRound(fontDef.pixelSize * 64);
548 *xsize = *ysize * fontDef.stretch / 100;
549 *scalableBitmapScaleFactor = 1;
550 *outline_drawing =
false;
552 if (!(face->face_flags & FT_FACE_FLAG_SCALABLE)) {
554 if (!isScalableBitmap()) {
556
557
558
559 for (
int i = 1; i < face->num_fixed_sizes; i++) {
560 if (qAbs(*ysize - face->available_sizes[i].y_ppem) <
561 qAbs(*ysize - face->available_sizes[best].y_ppem) ||
562 (qAbs(*ysize - face->available_sizes[i].y_ppem) ==
563 qAbs(*ysize - face->available_sizes[best].y_ppem) &&
564 qAbs(*xsize - face->available_sizes[i].x_ppem) <
565 qAbs(*xsize - face->available_sizes[best].x_ppem))) {
571 for (
int i = 1; i < face->num_fixed_sizes; i++) {
572 if (face->available_sizes[i].y_ppem < *ysize) {
573 if (face->available_sizes[i].y_ppem > face->available_sizes[best].y_ppem)
575 }
else if (face->available_sizes[best].y_ppem < *ysize) {
577 }
else if (face->available_sizes[i].y_ppem < face->available_sizes[best].y_ppem) {
585 if (FT_Select_Size(face, best) == 0) {
586 if (isScalableBitmap())
587 *scalableBitmapScaleFactor = QFixed::fromReal((qreal)fontDef.pixelSize / face->available_sizes[best].height);
588 *xsize = face->available_sizes[best].x_ppem;
589 *ysize = face->available_sizes[best].y_ppem;
594#if defined FT_HAS_COLOR
595 if (FT_HAS_COLOR(face)) {
596 *outline_drawing =
false;
600 int maxCachedGlyphSize = QFontEngine::maxCachedGlyphSize();
601 *outline_drawing = (*xsize > (maxCachedGlyphSize << 6) || *ysize > (maxCachedGlyphSize << 6));
606QFontEngine::Properties QFreetypeFace::properties()
const
608 QFontEngine::Properties p;
609 p.postscriptName = FT_Get_Postscript_Name(face);
610 PS_FontInfoRec font_info;
611 if (FT_Get_PS_Font_Info(face, &font_info) == 0)
612 p.copyright = font_info.notice;
613 if (FT_IS_SCALABLE(face)
614#if defined(FT_HAS_COLOR)
615 && !FT_HAS_COLOR(face)
618 p.ascent = face->ascender;
619 p.descent = -face->descender;
620 p.leading = face->height - face->ascender + face->descender;
621 p.emSquare = face->units_per_EM;
622 p.boundingBox = QRectF(face->bbox.xMin, -face->bbox.yMax,
623 face->bbox.xMax - face->bbox.xMin,
624 face->bbox.yMax - face->bbox.yMin);
626 p.ascent = QFixed::fromFixed(face->size->metrics.ascender);
627 p.descent = QFixed::fromFixed(-face->size->metrics.descender);
628 p.leading = QFixed::fromFixed(face->size->metrics.height - face->size->metrics.ascender + face->size->metrics.descender);
629 p.emSquare = face->size->metrics.y_ppem;
631 p.boundingBox = QRectF(0, -p.ascent.toReal(),
632 face->size->metrics.max_advance/64, (p.ascent + p.descent).toReal() );
635 p.capHeight = p.ascent;
636 p.lineWidth = face->underline_thickness;
641bool QFreetypeFace::getSfntTable(uint tag, uchar *buffer, uint *length)
const
643 return ft_getSfntTable(face, tag, buffer, length);
647
648
649
650
651
652
653
654
655static void scaleOutline(FT_Face face, FT_GlyphSlot g, FT_Fixed x_scale, FT_Fixed y_scale)
657 x_scale = FT_MulDiv(x_scale, 1 << 10, face->units_per_EM);
658 y_scale = FT_MulDiv(y_scale, 1 << 10, face->units_per_EM);
659 FT_Vector *p = g->outline.points;
660 const FT_Vector *e = p + g->outline.n_points;
662 p->x = FT_MulFix(p->x, x_scale);
663 p->y = FT_MulFix(p->y, y_scale);
668#define GLYPH2PATH_DEBUG QT_NO_QDEBUG_MACRO
669void QFreetypeFace::addGlyphToPath(FT_Face face, FT_GlyphSlot g,
const QFixedPoint &point, QPainterPath *path, FT_Fixed x_scale, FT_Fixed y_scale)
671 const qreal factor = 1/64.;
672 scaleOutline(face, g, x_scale, y_scale);
674 QPointF cp = point.toPointF();
678 for (
int j = 0; j < g->outline.n_contours; ++j) {
679 int last_point = g->outline.contours[j];
681 QPointF start = QPointF(g->outline.points[i].x*factor, -g->outline.points[i].y*factor);
682 if (!(g->outline.tags[i] & 1)) {
683 if (!(g->outline.tags[last_point] & 1)) {
685 start = (QPointF(g->outline.points[last_point].x*factor,
686 -g->outline.points[last_point].y*factor) + start) / 2.0;
689 start = QPointF(g->outline.points[last_point].x*factor,
690 -g->outline.points[last_point].y*factor);
701 while (i < last_point) {
703 c[n] = cp + QPointF(g->outline.points[i].x*factor, -g->outline.points[i].y*factor);
704 GLYPH2PATH_DEBUG() <<
" " << i << c[n] <<
"tag =" << (
int)g->outline.tags[i]
705 <<
": on curve =" << (
bool)(g->outline.tags[i] & 1);
707 switch (g->outline.tags[i] & 3) {
712 c[3] = (c[3] + c[2])/2;
719 c[3] = (c[1] + c[2])/2;
720 c[2] = (2*c[1] + c[3])/3;
721 c[1] = (2*c[1] + c[0])/3;
734 c[2] = (2*c[1] + c[3])/3;
735 c[1] = (2*c[1] + c[0])/3;
740 path->cubicTo(c[1], c[2], c[3]);
747 path->closeSubpath();
751 c[2] = (2*c[1] + c[3])/3;
752 c[1] = (2*c[1] + c[0])/3;
755 path->cubicTo(c[1], c[2], c[3]);
761extern void qt_addBitmapToPath(qreal x0, qreal y0,
const uchar *image_data,
int bpl,
int w,
int h, QPainterPath *path);
763void QFreetypeFace::addBitmapToPath(FT_GlyphSlot slot,
const QFixedPoint &point, QPainterPath *path)
765 if (slot->format != FT_GLYPH_FORMAT_BITMAP
766 || slot->bitmap.pixel_mode != FT_PIXEL_MODE_MONO)
769 QPointF cp = point.toPointF();
770 qt_addBitmapToPath(cp.x() +
TRUNC(slot->metrics.horiBearingX), cp.y() -
TRUNC(slot->metrics.horiBearingY),
771 slot->bitmap.buffer, slot->bitmap.pitch, slot->bitmap.width, slot->bitmap.rows, path);
774static inline void convertRGBToARGB(
const uchar *src, uint *dst,
int width,
int height,
int src_pitch,
bool bgr)
776 const int offs = bgr ? -1 : 1;
777 const int w = width * 3;
780 for (
int x = 0; x < w; x += 3) {
781 uchar red = src[x + 1 - offs];
782 uchar green = src[x + 1];
783 uchar blue = src[x + 1 + offs];
784 *dd++ = (0xFFU << 24) | (red << 16) | (green << 8) | blue;
791static inline void convertRGBToARGB_V(
const uchar *src, uint *dst,
int width,
int height,
int src_pitch,
bool bgr)
793 const int offs = bgr ? -src_pitch : src_pitch;
795 for (
int x = 0; x < width; x++) {
796 uchar red = src[x + src_pitch - offs];
797 uchar green = src[x + src_pitch];
798 uchar blue = src[x + src_pitch + offs];
799 *dst++ = (0XFFU << 24) | (red << 16) | (green << 8) | blue;
807 static int type = -1;
809 if (QScreen *screen = QGuiApplication::primaryScreen())
810 type = screen->handle()->subpixelAntialiasingTypeHint();
812 return static_cast<QFontEngine::SubpixelAntialiasingType>(type);
815QFontEngineFT *QFontEngineFT::create(
const QFontDef &fontDef, FaceId faceId,
const QByteArray &fontData)
817 auto engine = std::make_unique<QFontEngineFT>(fontDef);
819 QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono;
820 const bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);
823 QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint();
824 if (subpixelType == QFontEngine::Subpixel_None || (fontDef.styleStrategy & QFont::NoSubpixelAntialias)) {
825 format = QFontEngineFT::Format_A8;
826 engine->subpixelType = QFontEngine::Subpixel_None;
828 format = QFontEngineFT::Format_A32;
829 engine->subpixelType = subpixelType;
833 if (!engine->init(faceId, antialias, format, fontData) || engine->invalid()) {
834 qWarning(
"QFontEngineFT: Failed to create FreeType font engine");
838 engine->setQtDefaultHintStyle(
static_cast<QFont::HintingPreference>(fontDef.hintingPreference));
839 return engine.release();
844 FT_MM_Var *var = freetypeFace->mm_var;
845 if (var !=
nullptr && faceId.instanceIndex >= 0 && FT_UInt(faceId.instanceIndex) < var->num_namedstyles) {
846 for (FT_UInt axis = 0; axis < var->num_axis; ++axis) {
847 if (var->axis[axis].tag == QFont::Tag(
"wght").value()) {
848 return var->namedstyle[faceId.instanceIndex].coords[axis] >> 16;
852 if (
const TT_OS2 *os2 =
reinterpret_cast<
const TT_OS2 *>(FT_Get_Sfnt_Table(face, ft_sfnt_os2))) {
853 return os2->usWeightClass;
860 class QFontEngineFTRawData:
public QFontEngineFT
863 QFontEngineFTRawData(
const QFontDef &fontDef) : QFontEngineFT(fontDef)
867 void updateFamilyNameAndStyle()
869 fontDef.families = QStringList(QString::fromLatin1(freetype->face->family_name));
871 if (freetype->face->style_flags & FT_STYLE_FLAG_ITALIC)
872 fontDef.style = QFont::StyleItalic;
874 if (freetype->face->style_flags & FT_STYLE_FLAG_BOLD)
875 fontDef.weight = QFont::Bold;
877 fontDef.weight = calculateActualWeight(freetype, freetype->face, faceId());
881 const QMap<QFont::Tag,
float> &variableAxisValues,
885 faceId.filename =
"";
887 faceId.uuid = QUuid::createUuid().toByteArray();
888 faceId.variableAxes = variableAxisValues;
889 faceId.instanceIndex = instanceIndex;
891 return init(faceId,
true, Format_None, fontData);
896QFontEngineFT *QFontEngineFT::create(
const QByteArray &fontData,
898 QFont::HintingPreference hintingPreference,
899 const QMap<QFont::Tag,
float> &variableAxisValues,
903 fontDef.pixelSize = pixelSize;
904 fontDef.stretch = QFont::Unstretched;
905 fontDef.hintingPreference = hintingPreference;
906 fontDef.variableAxisValues = variableAxisValues;
908 QFontEngineFTRawData *fe =
new QFontEngineFTRawData(fontDef);
909 if (!fe->initFromData(fontData, variableAxisValues, instanceIndex)) {
914 fe->updateFamilyNameAndStyle();
915 fe->setQtDefaultHintStyle(
static_cast<QFont::HintingPreference>(fontDef.hintingPreference));
920QFontEngineFT::QFontEngineFT(
const QFontDef &fd)
921 : QFontEngine(Freetype)
928 cache_cost = 100 * 1024;
929 kerning_pairs_loaded =
false;
935 default_load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
936 default_hint_style = ftInitialDefaultHintStyle;
937 subpixelType = Subpixel_None;
938 lcdFilterType = (
int)((quintptr) FT_LCD_FILTER_DEFAULT);
939 defaultFormat = Format_None;
940 embeddedbitmap =
false;
941 const QByteArray env = qgetenv(
"QT_NO_FT_CACHE");
942 cacheEnabled = env.isEmpty() || env.toInt() == 0;
943 m_subPixelPositionCount = 4;
944 forceAutoHint =
false;
945 stemDarkeningDriver =
false;
948QFontEngineFT::~QFontEngineFT()
951 freetype->release(face_id);
954bool QFontEngineFT::init(FaceId faceId,
bool antialias, GlyphFormat format,
955 const QByteArray &fontData)
957 return init(faceId, antialias, format, QFreetypeFace::getFace(faceId, fontData));
964 FT_MM_Var *var = freetypeFace->mm_var;
965 if (var !=
nullptr && faceId.instanceIndex >= 0 && FT_UInt(faceId.instanceIndex) < var->num_namedstyles) {
966 for (FT_UInt axis = 0; axis < var->num_axis; ++axis) {
967 if (var->axis[axis].tag == QFont::Tag(
"ital").value()) {
968 return (var->namedstyle[faceId.instanceIndex].coords[axis] >> 16) == 1;
973 return (face->style_flags & FT_STYLE_FLAG_ITALIC);
976bool QFontEngineFT::init(FaceId faceId,
bool antialias, GlyphFormat format,
977 QFreetypeFace *freetypeFace)
979 freetype = freetypeFace;
985 defaultFormat = format;
986 this->antialias = antialias;
989 glyphFormat = QFontEngine::Format_Mono;
991 glyphFormat = defaultFormat;
995 symbol = freetype->symbol_map !=
nullptr;
996 PS_FontInfoRec psrec;
998 if (FT_Get_PS_Font_Info(freetype->face, &psrec) == FT_Err_Ok) {
999 symbol = !fontDef.families.isEmpty() &&
bool(fontDef.families.constFirst().contains(
"symbol"_L1, Qt::CaseInsensitive));
1002 freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing, &scalableBitmapScaleFactor);
1004 FT_Face face = lockFace();
1006 if (FT_IS_SCALABLE(face)
1007#if defined(FT_HAS_COLOR)
1008 && !FT_HAS_COLOR(face)
1011 bool isItalic = calculateActualItalic(freetype, face, faceId);
1012 bool fake_oblique = (fontDef.style != QFont::StyleNormal) && !isItalic && !qEnvironmentVariableIsSet(
"QT_NO_SYNTHESIZED_ITALIC");
1015 FT_Set_Transform(face, &matrix,
nullptr);
1016 freetype->matrix = matrix;
1018 if ((fontDef.weight >= QFont::Bold) && !(face->style_flags & FT_STYLE_FLAG_BOLD) && !FT_IS_FIXED_WIDTH(face) && !qEnvironmentVariableIsSet(
"QT_NO_SYNTHESIZED_BOLD")) {
1019 FT_UShort actualWeight = calculateActualWeight(freetype, face, faceId);
1020 if (actualWeight < 700 &&
1021 (fontDef.pixelSize < 64 || qEnvironmentVariableIsSet(
"QT_NO_SYNTHESIZED_BOLD_LIMIT"))) {
1026 line_thickness = QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale));
1027 QFixed center_position = QFixed::fromFixed(-FT_MulFix(face->underline_position, face->size->metrics.y_scale));
1028 underline_position = center_position - line_thickness / 2;
1031 int score = fontDef.weight * fontDef.pixelSize;
1032 line_thickness = score / 7000;
1034 if (line_thickness < 2 && score >= 1050)
1036 underline_position = ((line_thickness * 2) + 3) / 6;
1038 cacheEnabled =
false;
1039#if defined(FT_HAS_COLOR)
1040 if (FT_HAS_COLOR(face))
1041 glyphFormat = defaultFormat = GlyphFormat::Format_ARGB;
1044 if (line_thickness < 1)
1047 metrics = face->size->metrics;
1050
1051
1052
1053
1054
1055
1056 if (FT_IS_SCALABLE(face)) {
1057 for (
int i = 0; i < face->num_fixed_sizes; ++i) {
1058 if (xsize == face->available_sizes[i].x_ppem && ysize == face->available_sizes[i].y_ppem) {
1059 face->face_flags &= ~FT_FACE_FLAG_SCALABLE;
1061 FT_Select_Size(face, i);
1062 if (face->size->metrics.ascender + face->size->metrics.descender > 0) {
1063 FT_Pos leading = metrics.height - metrics.ascender + metrics.descender;
1064 metrics.ascender = face->size->metrics.ascender;
1065 metrics.descender = face->size->metrics.descender;
1066 if (metrics.descender > 0
1067 && QString::fromUtf8(face->family_name) ==
"Courier New"_L1) {
1068 metrics.descender *= -1;
1070 metrics.height = metrics.ascender - metrics.descender + leading;
1072 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
1074 face->face_flags |= FT_FACE_FLAG_SCALABLE;
1079#if defined(FT_FONT_FORMATS_H)
1080 const char *fmt = FT_Get_Font_Format(face);
1081 if (fmt && qstrncmp(fmt,
"CFF", 4) == 0) {
1082 FT_Bool no_stem_darkening =
true;
1083 FT_Error err = FT_Property_Get(qt_getFreetype(),
"cff",
"no-stem-darkening", &no_stem_darkening);
1084 if (err == FT_Err_Ok)
1085 stemDarkeningDriver = !no_stem_darkening;
1087 stemDarkeningDriver =
false;
1091 fontDef.styleName = QString::fromUtf8(face->style_name);
1093 if (!freetype->hbFace) {
1094 faceData.user_data = face;
1095 faceData.get_font_table = ft_getSfntTable;
1096 (
void)harfbuzzFace();
1097 freetype->hbFace = std::move(face_);
1102 face_ = Holder(freetype->hbFace.get(), dont_delete);
1106 fsType = freetype->fsType();
1110void QFontEngineFT::setQtDefaultHintStyle(QFont::HintingPreference hintingPreference)
1112 switch (hintingPreference) {
1113 case QFont::PreferNoHinting:
1114 setDefaultHintStyle(HintNone);
1116 case QFont::PreferFullHinting:
1117 setDefaultHintStyle(HintFull);
1119 case QFont::PreferVerticalHinting:
1120 setDefaultHintStyle(HintLight);
1122 case QFont::PreferDefaultHinting:
1123 setDefaultHintStyle(ftInitialDefaultHintStyle);
1128void QFontEngineFT::setDefaultHintStyle(HintStyle style)
1130 default_hint_style = style;
1133bool QFontEngineFT::expectsGammaCorrectedBlending(QFontEngine::GlyphFormat format)
const
1136 return stemDarkeningDriver;
1139int QFontEngineFT::loadFlags(QGlyphSet *set, GlyphFormat format,
int flags,
1140 bool &hsubpixel,
int &vfactor)
const
1142 int load_flags = FT_LOAD_DEFAULT | default_load_flags;
1143 int load_target = default_hint_style == HintLight
1144 ? FT_LOAD_TARGET_LIGHT
1145 : FT_LOAD_TARGET_NORMAL;
1147 if (format == Format_Mono) {
1148 load_target = FT_LOAD_TARGET_MONO;
1149 }
else if (format == Format_A32) {
1150 if (subpixelType == Subpixel_RGB || subpixelType == Subpixel_BGR)
1152 else if (subpixelType == Subpixel_VRGB || subpixelType == Subpixel_VBGR)
1154 }
else if (format == Format_ARGB) {
1156 load_flags |= FT_LOAD_COLOR;
1160 if (set && set->outline_drawing)
1161 load_flags |= FT_LOAD_NO_BITMAP;
1163 if (default_hint_style == HintNone || (flags & DesignMetrics) || (set && set->outline_drawing))
1164 load_flags |= FT_LOAD_NO_HINTING;
1166 load_flags |= load_target;
1169 load_flags |= FT_LOAD_FORCE_AUTOHINT;
1177 return info.width > 0xFF || info.height > 0xFF || info.linearAdvance > 0x7FFF;
1186 FT_Vector_Transform(&vector, matrix);
1191 FT_Vector_Transform(&vector, matrix);
1192 if (l > vector.x) l = vector.x;
1193 if (r < vector.x) r = vector.x;
1194 if (t < vector.y) t = vector.y;
1195 if (b > vector.y) b = vector.y;
1198 FT_Vector_Transform(&vector, matrix);
1199 if (l > vector.x) l = vector.x;
1200 if (r < vector.x) r = vector.x;
1201 if (t < vector.y) t = vector.y;
1202 if (b > vector.y) b = vector.y;
1205 FT_Vector_Transform(&vector, matrix);
1206 if (l > vector.x) l = vector.x;
1207 if (r < vector.x) r = vector.x;
1208 if (t < vector.y) t = vector.y;
1209 if (b > vector.y) b = vector.y;
1216#if defined(QFONTENGINE_FT_SUPPORT_COLRV1)
1217#define FROM_FIXED_16_16(value) (value / 65536.0
)
1219static inline QTransform FTAffineToQTransform(
const FT_Affine23 &matrix)
1221 qreal m11 = FROM_FIXED_16_16(matrix.xx);
1222 qreal m21 = -FROM_FIXED_16_16(matrix.xy);
1223 qreal m12 = -FROM_FIXED_16_16(matrix.yx);
1224 qreal m22 = FROM_FIXED_16_16(matrix.yy);
1225 qreal dx = FROM_FIXED_16_16(matrix.dx);
1226 qreal dy = -FROM_FIXED_16_16(matrix.dy);
1228 return QTransform(m11, m12, m21, m22, dx, dy);
1231bool QFontEngineFT::traverseColr1(FT_OpaquePaint opaquePaint,
1232 QSet<std::pair<FT_Byte *, FT_Bool> > *loops,
1233 QColor foregroundColor,
1235 ushort paletteCount,
1236 QColrPaintGraphRenderer *paintGraphRenderer)
const
1238 FT_Face face = freetype->face;
1240 auto key = std::pair{opaquePaint.p, opaquePaint.insert_root_transform};
1241 if (loops->contains(key)) {
1242 qCWarning(lcColrv1) <<
"Cycle detected in COLRv1 graph";
1246 paintGraphRenderer->save();
1248 auto cleanup = qScopeGuard([&paintGraphRenderer, &key, &loops]() {
1250 paintGraphRenderer->restore();
1253 FT_COLR_Paint paint;
1254 if (!FT_Get_Paint(face, opaquePaint, &paint))
1257 if (paint.format == FT_COLR_PAINTFORMAT_COLR_LAYERS) {
1258 FT_OpaquePaint layerPaint;
1259 layerPaint.p =
nullptr;
1260 while (FT_Get_Paint_Layers(face, &paint.u.colr_layers.layer_iterator, &layerPaint)) {
1261 if (!traverseColr1(layerPaint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1264 }
else if (paint.format == FT_COLR_PAINTFORMAT_TRANSFORM
1265 || paint.format == FT_COLR_PAINTFORMAT_SCALE
1266 || paint.format == FT_COLR_PAINTFORMAT_TRANSLATE
1267 || paint.format == FT_COLR_PAINTFORMAT_ROTATE
1268 || paint.format == FT_COLR_PAINTFORMAT_SKEW) {
1271 FT_OpaquePaint nextPaint;
1272 switch (paint.format) {
1273 case FT_COLR_PAINTFORMAT_TRANSFORM:
1274 xform = FTAffineToQTransform(paint.u.transform.affine);
1275 nextPaint = paint.u.transform.paint;
1277 case FT_COLR_PAINTFORMAT_SCALE:
1279 qreal centerX = FROM_FIXED_16_16(paint.u.scale.center_x);
1280 qreal centerY = -FROM_FIXED_16_16(paint.u.scale.center_y);
1281 qreal scaleX = FROM_FIXED_16_16(paint.u.scale.scale_x);
1282 qreal scaleY = FROM_FIXED_16_16(paint.u.scale.scale_y);
1284 xform.translate(centerX, centerY);
1285 xform.scale(scaleX, scaleY);
1286 xform.translate(-centerX, -centerY);
1288 nextPaint = paint.u.scale.paint;
1291 case FT_COLR_PAINTFORMAT_ROTATE:
1293 qreal centerX = FROM_FIXED_16_16(paint.u.rotate.center_x);
1294 qreal centerY = -FROM_FIXED_16_16(paint.u.rotate.center_y);
1295 qreal angle = -FROM_FIXED_16_16(paint.u.rotate.angle) * 180.0;
1297 xform.translate(centerX, centerY);
1298 xform.rotate(angle);
1299 xform.translate(-centerX, -centerY);
1301 nextPaint = paint.u.rotate.paint;
1305 case FT_COLR_PAINTFORMAT_SKEW:
1307 qreal centerX = FROM_FIXED_16_16(paint.u.skew.center_x);
1308 qreal centerY = -FROM_FIXED_16_16(paint.u.skew.center_y);
1309 qreal angleX = FROM_FIXED_16_16(paint.u.skew.x_skew_angle) * M_PI;
1310 qreal angleY = -FROM_FIXED_16_16(paint.u.skew.y_skew_angle) * M_PI;
1312 xform.translate(centerX, centerY);
1313 xform.shear(qTan(angleX), qTan(angleY));
1314 xform.translate(-centerX, -centerY);
1316 nextPaint = paint.u.rotate.paint;
1319 case FT_COLR_PAINTFORMAT_TRANSLATE:
1321 qreal dx = FROM_FIXED_16_16(paint.u.translate.dx);
1322 qreal dy = -FROM_FIXED_16_16(paint.u.translate.dy);
1324 xform.translate(dx, dy);
1325 nextPaint = paint.u.rotate.paint;
1332 paintGraphRenderer->prependTransform(xform);
1333 if (!traverseColr1(nextPaint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1335 }
else if (paint.format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT
1336 || paint.format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT
1337 || paint.format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT
1338 || paint.format == FT_COLR_PAINTFORMAT_SOLID) {
1339 auto getPaletteColor = [&palette, &paletteCount, &foregroundColor](FT_UInt16 index,
1342 if (index < paletteCount) {
1343 const FT_Color &paletteColor = palette[index];
1344 color = qRgba(paletteColor.red,
1347 paletteColor.alpha);
1348 }
else if (index == 0xffff) {
1349 color = foregroundColor;
1352 if (color.isValid())
1353 color.setAlphaF(color.alphaF() * (alpha / 16384.0));
1358 auto gatherGradientStops = [&](FT_ColorStopIterator it) {
1360 ret.resize(it.num_color_stops);
1362 FT_ColorStop colorStop;
1363 while (FT_Get_Colorline_Stops(face, &colorStop, &it)) {
1364 uint index = it.current_color_stop - 1;
1365 if (qsizetype(index) < ret.size()) {
1366 QGradientStop &gradientStop = ret[index];
1367 gradientStop.first = FROM_FIXED_16_16(colorStop.stop_offset);
1368 gradientStop.second = getPaletteColor(colorStop.color.palette_index,
1369 colorStop.color.alpha);
1376 auto extendToSpread = [](FT_PaintExtend extend) {
1378 case FT_COLR_PAINT_EXTEND_REPEAT:
1379 return QGradient::RepeatSpread;
1380 case FT_COLR_PAINT_EXTEND_REFLECT:
1381 return QGradient::ReflectSpread;
1383 return QGradient::PadSpread;
1387 if (paintGraphRenderer->isRendering()) {
1388 if (paint.format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT) {
1389 const qreal p0x = FROM_FIXED_16_16(paint.u.linear_gradient.p0.x);
1390 const qreal p0y = -FROM_FIXED_16_16(paint.u.linear_gradient.p0.y);
1392 const qreal p1x = FROM_FIXED_16_16(paint.u.linear_gradient.p1.x);
1393 const qreal p1y = -FROM_FIXED_16_16(paint.u.linear_gradient.p1.y);
1395 const qreal p2x = FROM_FIXED_16_16(paint.u.linear_gradient.p2.x);
1396 const qreal p2y = -FROM_FIXED_16_16(paint.u.linear_gradient.p2.y);
1398 QPointF p0(p0x, p0y);
1399 QPointF p1(p1x, p1y);
1400 QPointF p2(p2x, p2y);
1402 const QGradient::Spread spread =
1403 extendToSpread(paint.u.linear_gradient.colorline.extend);
1404 const QGradientStops stops =
1405 gatherGradientStops(paint.u.linear_gradient.colorline.color_stop_iterator);
1406 paintGraphRenderer->setLinearGradient(p0, p1, p2, spread, stops);
1408 }
else if (paint.format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT) {
1409 const qreal c0x = FROM_FIXED_16_16(paint.u.radial_gradient.c0.x);
1410 const qreal c0y = -FROM_FIXED_16_16(paint.u.radial_gradient.c0.y);
1411 const qreal r0 = FROM_FIXED_16_16(paint.u.radial_gradient.r0);
1412 const qreal c1x = FROM_FIXED_16_16(paint.u.radial_gradient.c1.x);
1413 const qreal c1y = -FROM_FIXED_16_16(paint.u.radial_gradient.c1.y);
1414 const qreal r1 = FROM_FIXED_16_16(paint.u.radial_gradient.r1);
1416 const QPointF c0(c0x, c0y);
1417 const QPointF c1(c1x, c1y);
1418 const QGradient::Spread spread =
1419 extendToSpread(paint.u.radial_gradient.colorline.extend);
1420 const QGradientStops stops =
1421 gatherGradientStops(paint.u.radial_gradient.colorline.color_stop_iterator);
1423 paintGraphRenderer->setRadialGradient(c0, r0, c1, r1, spread, stops);
1424 }
else if (paint.format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT) {
1425 const qreal centerX = FROM_FIXED_16_16(paint.u.sweep_gradient.center.x);
1426 const qreal centerY = -FROM_FIXED_16_16(paint.u.sweep_gradient.center.y);
1427 const qreal startAngle = 180.0 * FROM_FIXED_16_16(paint.u.sweep_gradient.start_angle);
1428 const qreal endAngle = 180.0 * FROM_FIXED_16_16(paint.u.sweep_gradient.end_angle);
1430 const QPointF center(centerX, centerY);
1432 const QGradient::Spread spread = extendToSpread(paint.u.radial_gradient.colorline.extend);
1433 const QGradientStops stops = gatherGradientStops(paint.u.sweep_gradient.colorline.color_stop_iterator);
1435 paintGraphRenderer->setConicalGradient(center, startAngle, endAngle, spread, stops);
1437 }
else if (paint.format == FT_COLR_PAINTFORMAT_SOLID) {
1438 QColor color = getPaletteColor(paint.u.solid.color.palette_index,
1439 paint.u.solid.color.alpha);
1440 if (!color.isValid()) {
1441 qCWarning(lcColrv1) <<
"Invalid palette index in COLRv1 graph:"
1442 << paint.u.solid.color.palette_index;
1446 paintGraphRenderer->setSolidColor(color);
1450 paintGraphRenderer->drawCurrentPath();
1451 }
else if (paint.format == FT_COLR_PAINTFORMAT_COMPOSITE) {
1452 if (!paintGraphRenderer->isRendering()) {
1453 if (!traverseColr1(paint.u.composite.backdrop_paint,
1458 paintGraphRenderer)) {
1461 if (!traverseColr1(paint.u.composite.source_paint,
1466 paintGraphRenderer)) {
1470 QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
1471 switch (paint.u.composite.composite_mode) {
1472 case FT_COLR_COMPOSITE_CLEAR:
1473 compositionMode = QPainter::CompositionMode_Clear;
1475 case FT_COLR_COMPOSITE_SRC:
1476 compositionMode = QPainter::CompositionMode_Source;
1478 case FT_COLR_COMPOSITE_DEST:
1479 compositionMode = QPainter::CompositionMode_Destination;
1481 case FT_COLR_COMPOSITE_SRC_OVER:
1482 compositionMode = QPainter::CompositionMode_SourceOver;
1484 case FT_COLR_COMPOSITE_DEST_OVER:
1485 compositionMode = QPainter::CompositionMode_DestinationOver;
1487 case FT_COLR_COMPOSITE_SRC_IN:
1488 compositionMode = QPainter::CompositionMode_SourceIn;
1490 case FT_COLR_COMPOSITE_DEST_IN:
1491 compositionMode = QPainter::CompositionMode_DestinationIn;
1493 case FT_COLR_COMPOSITE_SRC_OUT:
1494 compositionMode = QPainter::CompositionMode_SourceOut;
1496 case FT_COLR_COMPOSITE_DEST_OUT:
1497 compositionMode = QPainter::CompositionMode_DestinationOut;
1499 case FT_COLR_COMPOSITE_SRC_ATOP:
1500 compositionMode = QPainter::CompositionMode_SourceAtop;
1502 case FT_COLR_COMPOSITE_DEST_ATOP:
1503 compositionMode = QPainter::CompositionMode_DestinationAtop;
1505 case FT_COLR_COMPOSITE_XOR:
1506 compositionMode = QPainter::CompositionMode_Xor;
1508 case FT_COLR_COMPOSITE_PLUS:
1509 compositionMode = QPainter::CompositionMode_Plus;
1511 case FT_COLR_COMPOSITE_SCREEN:
1512 compositionMode = QPainter::CompositionMode_Screen;
1514 case FT_COLR_COMPOSITE_OVERLAY:
1515 compositionMode = QPainter::CompositionMode_Overlay;
1517 case FT_COLR_COMPOSITE_DARKEN:
1518 compositionMode = QPainter::CompositionMode_Darken;
1520 case FT_COLR_COMPOSITE_LIGHTEN:
1521 compositionMode = QPainter::CompositionMode_Lighten;
1523 case FT_COLR_COMPOSITE_COLOR_DODGE:
1524 compositionMode = QPainter::CompositionMode_ColorDodge;
1526 case FT_COLR_COMPOSITE_COLOR_BURN:
1527 compositionMode = QPainter::CompositionMode_ColorBurn;
1529 case FT_COLR_COMPOSITE_HARD_LIGHT:
1530 compositionMode = QPainter::CompositionMode_HardLight;
1532 case FT_COLR_COMPOSITE_SOFT_LIGHT:
1533 compositionMode = QPainter::CompositionMode_SoftLight;
1535 case FT_COLR_COMPOSITE_DIFFERENCE:
1536 compositionMode = QPainter::CompositionMode_Difference;
1538 case FT_COLR_COMPOSITE_EXCLUSION:
1539 compositionMode = QPainter::CompositionMode_Exclusion;
1541 case FT_COLR_COMPOSITE_MULTIPLY:
1542 compositionMode = QPainter::CompositionMode_Multiply;
1545 qCWarning(lcColrv1) <<
"Unsupported COLRv1 composition mode" << paint.u.composite.composite_mode;
1549 QColrPaintGraphRenderer compositeRenderer;
1550 compositeRenderer.setBoundingRect(paintGraphRenderer->boundingRect());
1551 compositeRenderer.beginRender(fontDef.pixelSize / face->units_per_EM,
1552 paintGraphRenderer->currentTransform());
1553 if (!traverseColr1(paint.u.composite.backdrop_paint,
1558 &compositeRenderer)) {
1562 compositeRenderer.setCompositionMode(compositionMode);
1563 if (!traverseColr1(paint.u.composite.source_paint,
1568 &compositeRenderer)) {
1571 paintGraphRenderer->drawImage(compositeRenderer.endRender());
1573 }
else if (paint.format == FT_COLR_PAINTFORMAT_GLYPH) {
1574 FT_Error error = FT_Load_Glyph(face,
1575 paint.u.glyph.glyphID,
1576 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);
1578 qCWarning(lcColrv1) <<
"Failed to load glyph"
1579 << paint.u.glyph.glyphID
1580 <<
"in COLRv1 graph. Error: " << error;
1585 QFreetypeFace::addGlyphToPath(face,
1589 face->units_per_EM << 6,
1590 face->units_per_EM << 6);
1592 paintGraphRenderer->appendPath(path);
1594 if (!traverseColr1(paint.u.glyph.paint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1596 }
else if (paint.format == FT_COLR_PAINTFORMAT_COLR_GLYPH) {
1597 FT_OpaquePaint otherOpaquePaint;
1598 otherOpaquePaint.p =
nullptr;
1599 if (!FT_Get_Color_Glyph_Paint(face,
1600 paint.u.colr_glyph.glyphID,
1601 FT_COLOR_NO_ROOT_TRANSFORM,
1602 &otherOpaquePaint)) {
1603 qCWarning(lcColrv1) <<
"Failed to load color glyph"
1604 << paint.u.colr_glyph.glyphID
1605 <<
"in COLRv1 graph.";
1609 if (!traverseColr1(otherOpaquePaint, loops, foregroundColor, palette, paletteCount, paintGraphRenderer))
1616QFontEngineFT::Glyph *QFontEngineFT::loadColrv1Glyph(QGlyphSet *set,
1619 const QColor &foregroundColor,
1620 bool fetchMetricsOnly)
const
1622 FT_Face face = freetype->face;
1625 memset(&info, 0,
sizeof(info));
1629 FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT
1632 | FT_LOAD_BITMAP_METRICS_ONLY);
1633 info.linearAdvance =
int(face->glyph->linearHoriAdvance >> 10);
1634 info.xOff =
short(TRUNC(ROUND(face->glyph->advance.x)));
1636 FT_OpaquePaint opaquePaint;
1637 opaquePaint.p =
nullptr;
1638 if (!FT_Get_Color_Glyph_Paint(face, glyph, FT_COLOR_INCLUDE_ROOT_TRANSFORM, &opaquePaint))
1643 FT_Set_Char_Size(face, face->units_per_EM << 6, face->units_per_EM << 6, 0, 0);
1647 FT_Get_Transform(face, &matrix, &delta);
1648 QTransform originalXform(FROM_FIXED_16_16(matrix.xx), -FROM_FIXED_16_16(matrix.yx),
1649 -FROM_FIXED_16_16(matrix.xy), FROM_FIXED_16_16(matrix.yy),
1650 FROM_FIXED_16_16(delta.x), FROM_FIXED_16_16(delta.y));
1654 FT_Set_Transform(face,
nullptr,
nullptr);
1656 auto cleanup = qScopeGuard([&]() {
1658 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
1659 FT_Set_Transform(face, &matrix, &delta);
1662 qCDebug(lcColrv1).noquote() <<
"================== Start collecting COLRv1 metrics for" << glyph;
1663 QRect designCoordinateBounds;
1667 if (colrv1_bounds_cache_id == glyph) {
1668 designCoordinateBounds = colrv1_bounds_cache;
1673 if (FT_Get_Color_Glyph_ClipBox(face, glyph, &clipBox)) {
1674 FT_Pos left = qMin(clipBox.bottom_left.x, qMin(clipBox.bottom_right.x, qMin(clipBox.top_left.x, clipBox.top_right.x)));
1675 FT_Pos right = qMax(clipBox.bottom_left.x, qMax(clipBox.bottom_right.x, qMax(clipBox.top_left.x, clipBox.top_right.x)));
1677 FT_Pos top = qMin(-clipBox.bottom_left.y, qMin(-clipBox.bottom_right.y, qMin(-clipBox.top_left.y, -clipBox.top_right.y)));
1678 FT_Pos bottom = qMax(-clipBox.bottom_left.y, qMax(-clipBox.bottom_right.y, qMax(-clipBox.top_left.y, -clipBox.top_right.y)));
1680 qreal scale = 1.0 / 64.0;
1681 designCoordinateBounds = QRect(QPoint(qFloor(left * scale), qFloor(top * scale)),
1682 QPoint(qCeil(right * scale), qCeil(bottom * scale)));
1685 QColrPaintGraphRenderer boundingRectCalculator;
1686 boundingRectCalculator.beginCalculateBoundingBox();
1687 QSet<std::pair<FT_Byte *, FT_Bool> > loops;
1688 if (traverseColr1(opaquePaint,
1693 &boundingRectCalculator)) {
1694 designCoordinateBounds = boundingRectCalculator.boundingRect().toAlignedRect();
1698 colrv1_bounds_cache_id = glyph;
1699 colrv1_bounds_cache = designCoordinateBounds;
1702 QTransform initialTransform;
1703 initialTransform.scale(fontDef.pixelSize / face->units_per_EM,
1704 fontDef.pixelSize / face->units_per_EM);
1705 QRect bounds = initialTransform.mapRect(designCoordinateBounds);
1706 bounds = originalXform.mapRect(bounds);
1708 info.x = bounds.left();
1709 info.y = -bounds.top();
1710 info.width = bounds.width();
1711 info.height = bounds.height();
1713 qCDebug(lcColrv1) <<
"Bounds of" << glyph <<
"==" << bounds;
1716 QImage destinationImage;
1717 if (!fetchMetricsOnly && !bounds.size().isEmpty()) {
1718 FT_Palette_Data paletteData;
1719 if (FT_Palette_Data_Get(face, &paletteData))
1722 FT_Color *palette =
nullptr;
1723 FT_Error error = FT_Palette_Select(face, 0, &palette);
1725 qWarning(
"selecting palette for COLRv1 failed, err=%x face=%p, glyph=%d",
1731 if (palette ==
nullptr)
1734 ushort paletteCount = paletteData.num_palette_entries;
1736 QColrPaintGraphRenderer paintGraphRenderer;
1737 paintGraphRenderer.setBoundingRect(bounds);
1738 paintGraphRenderer.beginRender(fontDef.pixelSize / face->units_per_EM,
1742 QSet<std::pair<FT_Byte *, FT_Bool> > loops;
1743 if (!traverseColr1(opaquePaint,
1748 &paintGraphRenderer)) {
1752 destinationImage = paintGraphRenderer.endRender();
1755 if (fetchMetricsOnly || !destinationImage.isNull()) {
1760 set->setGlyph(glyph, QFixedPoint{}, g);
1763 g->linearAdvance = info.linearAdvance;
1764 g->width = info.width;
1765 g->height = info.height;
1768 g->advance = info.xOff;
1769 g->format = Format_ARGB;
1771 if (!fetchMetricsOnly && !destinationImage.isNull()) {
1772 g->data =
new uchar[info.height * info.width * 4];
1773 memcpy(g->data, destinationImage.constBits(), info.height * info.width * 4);
1783QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
1784 const QFixedPoint &subPixelPosition,
1787 bool fetchMetricsOnly,
1788 bool disableOutlineDrawing)
const
1792 if (format == Format_None)
1793 format = defaultFormat != Format_None ? defaultFormat : Format_Mono;
1794 Q_ASSERT(format != Format_None);
1796 Glyph *g = set ? set->getGlyph(glyph, subPixelPosition) :
nullptr;
1797 if (g && g->format == format && (fetchMetricsOnly || g->data))
1800 if (!g && set && set->isGlyphMissing(glyph))
1804 FT_Face face = freetype->face;
1806 FT_Matrix matrix = freetype->matrix;
1807 bool transform = matrix.xx != 0x10000
1808 || matrix.yy != 0x10000
1811 if (obliquen && transform) {
1816 slant.xx = 0x10000L;
1819 slant.yy = 0x10000L;
1821 FT_Matrix_Multiply(&matrix, &slant);
1826 v.x = format == Format_Mono ? 0 : FT_Pos(subPixelPosition.x.value());
1827 v.y = format == Format_Mono ? 0 : FT_Pos(-subPixelPosition.y.value());
1828 FT_Set_Transform(face, &matrix, &v);
1830 bool hsubpixel =
false;
1832 int load_flags = loadFlags(set, format, 0, hsubpixel, vfactor);
1834 if (transform || obliquen || (format != Format_Mono && !isScalableBitmap()))
1835 load_flags |= FT_LOAD_NO_BITMAP;
1837#if (FREETYPE_MAJOR*10000
+ FREETYPE_MINOR*100
+ FREETYPE_PATCH) >= 20701
1839 if (fetchMetricsOnly)
1840 load_flags |= FT_LOAD_BITMAP_METRICS_ONLY;
1843#if defined(QFONTENGINE_FT_SUPPORT_COLRV1)
1844 if (FT_IS_SCALABLE(freetype->face)
1845 && FT_HAS_COLOR(freetype->face)
1846 && (load_flags & FT_LOAD_COLOR)) {
1848 Glyph *ret = loadColrv1Glyph(set, g, glyph, color, fetchMetricsOnly);
1856 FT_Error err = FT_Load_Glyph(face, glyph, load_flags);
1857 if (err && (load_flags & FT_LOAD_NO_BITMAP)) {
1858 load_flags &= ~FT_LOAD_NO_BITMAP;
1859 err = FT_Load_Glyph(face, glyph, load_flags);
1861 if (err == FT_Err_Too_Few_Arguments) {
1863 load_flags |= FT_LOAD_FORCE_AUTOHINT;
1864 err = FT_Load_Glyph(face, glyph, load_flags);
1865 }
else if (err == FT_Err_Execution_Too_Long) {
1868 qWarning(
"load glyph failed due to broken hinting bytecode in font, switching to auto hinting");
1869 default_load_flags |= FT_LOAD_FORCE_AUTOHINT;
1870 load_flags |= FT_LOAD_FORCE_AUTOHINT;
1871 err = FT_Load_Glyph(face, glyph, load_flags);
1873 if (err != FT_Err_Ok) {
1874 qWarning(
"load glyph failed err=%x face=%p, glyph=%d", err, face, glyph);
1876 set->setGlyphMissing(glyph);
1880 FT_GlyphSlot slot = face->glyph;
1883 FT_GlyphSlot_Embolden(slot);
1884 if (obliquen && !transform) {
1885 FT_GlyphSlot_Oblique(slot);
1896 FT_Matrix_Multiply(&m, &matrix);
1900 info.linearAdvance = slot->linearHoriAdvance >> 10;
1904 if ((set && set->outline_drawing && !disableOutlineDrawing) || fetchMetricsOnly) {
1905 int left = slot->metrics.horiBearingX;
1906 int right = slot->metrics.horiBearingX + slot->metrics.width;
1907 int top = slot->metrics.horiBearingY;
1908 int bottom = slot->metrics.horiBearingY - slot->metrics.height;
1910 if (transform && slot->format != FT_GLYPH_FORMAT_BITMAP)
1911 transformBoundingBox(&left, &top, &right, &bottom, &matrix);
1914 right =
CEIL(right);
1915 bottom =
FLOOR(bottom);
1918 info.x =
TRUNC(left);
1919 info.y =
TRUNC(top);
1920 info.width =
TRUNC(right - left);
1921 info.height =
TRUNC(top - bottom);
1925 if (areMetricsTooLarge(info))
1930 g->linearAdvance = info.linearAdvance;
1931 g->width = info.width;
1932 g->height = info.height;
1935 g->advance = info.xOff;
1939 set->setGlyph(glyph, subPixelPosition, g);
1944 if (slot->format == FT_GLYPH_FORMAT_OUTLINE) {
1945 const QTransform xform(matrix.xx / 65536.0, matrix.xy / 65536.0,
1946 matrix.yx / 65536.0, matrix.yy / 65536.0, 0, 0);
1948 FT_Outline_Get_CBox(&slot->outline, &cbox);
1949 const qreal glyphWidth = qreal((cbox.xMax - cbox.xMin) >> 6);
1950 const qreal glyphHeight = qreal((cbox.yMax - cbox.yMin) >> 6);
1951 if (glyphBoundingBoxExceedsLimit(glyphWidth, glyphHeight, effectivePixelSizeSquared(xform))) {
1953 set->setGlyphMissing(glyph);
1958 int glyph_buffer_size = 0;
1959 std::unique_ptr<uchar[]> glyph_buffer;
1960 FT_Render_Mode renderMode = (default_hint_style == HintLight) ? FT_RENDER_MODE_LIGHT : FT_RENDER_MODE_NORMAL;
1963 renderMode = FT_RENDER_MODE_MONO;
1966 if (!hsubpixel && vfactor == 1) {
1967 qWarning(
"Format_A32 requested, but subpixel layout is unknown.");
1971 renderMode = hsubpixel ? FT_RENDER_MODE_LCD : FT_RENDER_MODE_LCD_V;
1979 FT_Library_SetLcdFilter(slot->library, (FT_LcdFilter)lcdFilterType);
1981 err = FT_Render_Glyph(slot, renderMode);
1982 FT_Library_SetLcdFilter(slot->library, FT_LCD_FILTER_NONE);
1984 if (err != FT_Err_Ok) {
1985 qWarning(
"render glyph failed err=%x face=%p, glyph=%d", err, face, glyph);
1989 info.height = slot->bitmap.rows;
1990 info.width = slot->bitmap.width;
1991 info.x = slot->bitmap_left;
1992 info.y = slot->bitmap_top;
1993 if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD)
1994 info.width = info.width / 3;
1995 if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V)
1996 info.height = info.height / vfactor;
1998 int pitch = (format == Format_Mono ? ((info.width + 31) & ~31) >> 3 :
1999 (format == Format_A8 ? (info.width + 3) & ~3 : info.width * 4));
2001 glyph_buffer_size = info.height * pitch;
2002 glyph_buffer.reset(
new uchar[glyph_buffer_size]);
2004 if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
2005 uchar *src = slot->bitmap.buffer;
2006 uchar *dst = glyph_buffer.get();
2007 int h = slot->bitmap.rows;
2009 if (format == Format_Mono) {
2010 int bytes = ((info.width + 7) & ~7) >> 3;
2012 memcpy (dst, src, bytes);
2014 src += slot->bitmap.pitch;
2016 }
else if (format == Format_A8) {
2018 for (
int x = 0; x <
int{info.width}; x++)
2019 dst[x] = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xff : 0x00);
2021 src += slot->bitmap.pitch;
2025 uint *dd =
reinterpret_cast<uint *>(dst);
2026 for (
int x = 0; x <
int{info.width}; x++)
2027 dd[x] = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xffffffff : 0x00000000);
2029 src += slot->bitmap.pitch;
2032 }
else if (slot->bitmap.pixel_mode == 7 ) {
2033 Q_ASSERT(format == Format_ARGB);
2034 uchar *src = slot->bitmap.buffer;
2035 uchar *dst = glyph_buffer.get();
2036 int h = slot->bitmap.rows;
2038#if Q_BYTE_ORDER == Q_BIG_ENDIAN
2039 const quint32 *srcPixel = (
const quint32 *)src;
2040 quint32 *dstPixel = (quint32 *)dst;
2041 for (
int x = 0; x <
static_cast<
int>(slot->bitmap.width); x++, srcPixel++, dstPixel++) {
2042 const quint32 pixel = *srcPixel;
2043 *dstPixel = qbswap(pixel);
2046 memcpy(dst, src, slot->bitmap.width * 4);
2048 dst += slot->bitmap.pitch;
2049 src += slot->bitmap.pitch;
2051 info.linearAdvance = info.xOff = slot->bitmap.width;
2052 }
else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) {
2053 if (format == Format_A8) {
2054 uchar *src = slot->bitmap.buffer;
2055 uchar *dst = glyph_buffer.get();
2056 int h = slot->bitmap.rows;
2057 int bytes = info.width;
2059 memcpy (dst, src, bytes);
2061 src += slot->bitmap.pitch;
2063 }
else if (format == Format_ARGB) {
2064 uchar *src = slot->bitmap.buffer;
2065 quint32 *dstPixel =
reinterpret_cast<quint32 *>(glyph_buffer.get());
2066 int h = slot->bitmap.rows;
2068 for (
int x = 0; x <
static_cast<
int>(slot->bitmap.width); ++x) {
2069 uchar alpha = src[x];
2070 float alphaF = alpha / 255.0;
2071 dstPixel[x] = qRgba(qRound(alphaF * color.red()),
2072 qRound(alphaF * color.green()),
2073 qRound(alphaF * color.blue()),
2076 src += slot->bitmap.pitch;
2077 dstPixel += info.width;
2080 }
else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
2081 Q_ASSERT(format == Format_A32);
2082 convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB);
2083 }
else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
2084 Q_ASSERT(format == Format_A32);
2085 convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB);
2087 qWarning(
"QFontEngine: Glyph rendered in unknown pixel_mode=%d", slot->bitmap.pixel_mode);
2096 g->linearAdvance = info.linearAdvance;
2097 g->width = info.width;
2098 g->height = info.height;
2101 g->advance = info.xOff;
2104 g->data = glyph_buffer.release();
2107 set->setGlyph(glyph, subPixelPosition, g);
2112QFontEngine::FaceId QFontEngineFT::faceId()
const
2117QFontEngine::Properties QFontEngineFT::properties()
const
2119 Properties p = freetype->properties();
2120 if (p.postscriptName.isEmpty()) {
2121 p.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(fontDef.family().toUtf8());
2124 return freetype->properties();
2127QFixed QFontEngineFT::emSquareSize()
const
2129 if (FT_IS_SCALABLE(freetype->face))
2130 return freetype->face->units_per_EM;
2132 return freetype->face->size->metrics.y_ppem;
2135bool QFontEngineFT::getSfntTableData(uint tag, uchar *buffer, uint *length)
const
2137 return ft_getSfntTable(freetype->face, tag, buffer, length);
2140int QFontEngineFT::synthesized()
const
2143 if ((fontDef.style != QFont::StyleNormal) && !(freetype->face->style_flags & FT_STYLE_FLAG_ITALIC))
2144 s = SynthesizedItalic;
2145 if ((fontDef.weight >= QFont::Bold) && !(freetype->face->style_flags & FT_STYLE_FLAG_BOLD))
2146 s |= SynthesizedBold;
2147 if (fontDef.stretch != 100 && FT_IS_SCALABLE(freetype->face))
2148 s |= SynthesizedStretch;
2152void QFontEngineFT::initializeHeightMetrics()
const
2154 m_ascent = QFixed::fromFixed(metrics.ascender);
2155 m_descent = QFixed::fromFixed(-metrics.descender);
2156 m_leading = QFixed::fromFixed(metrics.height - metrics.ascender + metrics.descender);
2158 QFontEngine::initializeHeightMetrics();
2160 if (scalableBitmapScaleFactor != 1) {
2161 m_ascent *= scalableBitmapScaleFactor;
2162 m_descent *= scalableBitmapScaleFactor;
2163 m_leading *= scalableBitmapScaleFactor;
2167QFixed QFontEngineFT::capHeight()
const
2169 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
2170 if (os2 && os2->version >= 2) {
2172 QFixed answer = QFixed::fromFixed(FT_MulFix(os2->sCapHeight, freetype->face->size->metrics.y_scale));
2176 return calculatedCapHeight();
2179QFixed QFontEngineFT::xHeight()
const
2181 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
2182 if (os2 && os2->sxHeight) {
2184 QFixed answer = QFixed(os2->sxHeight * freetype->face->size->metrics.y_ppem) / emSquareSize();
2189 return QFontEngine::xHeight();
2192QFixed QFontEngineFT::averageCharWidth()
const
2194 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(freetype->face, ft_sfnt_os2);
2195 if (os2 && os2->xAvgCharWidth) {
2197 QFixed answer = QFixed(os2->xAvgCharWidth * freetype->face->size->metrics.x_ppem) / emSquareSize();
2202 return QFontEngine::averageCharWidth();
2205qreal QFontEngineFT::maxCharWidth()
const
2207 QFixed max_advance = QFixed::fromFixed(metrics.max_advance);
2208 if (scalableBitmapScaleFactor != 1)
2209 max_advance *= scalableBitmapScaleFactor;
2210 return max_advance.toReal();
2213QFixed QFontEngineFT::lineThickness()
const
2215 return line_thickness;
2218QFixed QFontEngineFT::underlinePosition()
const
2220 return underline_position;
2223void QFontEngineFT::doKerning(QGlyphLayout *g, QFontEngine::ShaperFlags flags)
const
2225 if (!kerning_pairs_loaded) {
2226 kerning_pairs_loaded =
true;
2228 if (freetype->face->size->metrics.x_ppem != 0) {
2229 QFixed scalingFactor = emSquareSize() / QFixed(freetype->face->size->metrics.x_ppem);
2231 const_cast<QFontEngineFT *>(
this)->loadKerningPairs(scalingFactor);
2237 if (shouldUseDesignMetrics(flags))
2238 flags |= DesignMetrics;
2240 flags &= ~DesignMetrics;
2242 QFontEngine::doKerning(g, flags);
2249 m.xx = FT_Fixed(matrix.m11() * 65536);
2250 m.xy = FT_Fixed(-matrix.m21() * 65536);
2251 m.yx = FT_Fixed(-matrix.m12() * 65536);
2252 m.yy = FT_Fixed(matrix.m22() * 65536);
2257QFontEngineFT::QGlyphSet *QFontEngineFT::TransformedGlyphSets::findSet(
const QTransform &matrix,
const QFontDef &fontDef)
2259 FT_Matrix m = QTransformToFTMatrix(matrix);
2262 for (; i < nSets; ++i) {
2263 QGlyphSet *g = sets[i];
2266 if (g->transformationMatrix.xx == m.xx
2267 && g->transformationMatrix.xy == m.xy
2268 && g->transformationMatrix.yx == m.yx
2269 && g->transformationMatrix.yy == m.yy) {
2281 moveToFront(nSets - 1);
2283 sets[0] =
new QGlyphSet;
2284 QGlyphSet *gs = sets[0];
2285 Q_ASSERT(gs !=
nullptr);
2288 gs->transformationMatrix = m;
2289 const int maxCachedSize = maxCachedGlyphSize();
2290 gs->outline_drawing = fontDef.pixelSize * fontDef.pixelSize * qAbs(matrix.determinant()) > maxCachedSize * maxCachedSize;
2295void QFontEngineFT::TransformedGlyphSets::moveToFront(
int i)
2297 QGlyphSet *g = sets[i];
2299 sets[i] = sets[i - 1];
2306QFontEngineFT::QGlyphSet *QFontEngineFT::loadGlyphSet(
const QTransform &matrix)
2308 if (matrix.type() > QTransform::TxShear || !cacheEnabled)
2312 if (!FT_IS_SCALABLE(freetype->face))
2313 return matrix.type() <= QTransform::TxTranslate ? &defaultGlyphSet :
nullptr;
2315 return transformedGlyphSets.findSet(matrix, fontDef);
2318void QFontEngineFT::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
2320 FT_Face face = lockFace(Unscaled);
2321 FT_Set_Transform(face,
nullptr,
nullptr);
2322 FT_Load_Glyph(face, glyph, FT_LOAD_NO_BITMAP);
2324 int left = face->glyph->metrics.horiBearingX;
2325 int right = face->glyph->metrics.horiBearingX + face->glyph->metrics.width;
2326 int top = face->glyph->metrics.horiBearingY;
2327 int bottom = face->glyph->metrics.horiBearingY - face->glyph->metrics.height;
2333 metrics->width = QFixed::fromFixed(right-left);
2334 metrics->height = QFixed::fromFixed(top-bottom);
2335 metrics->x = QFixed::fromFixed(left);
2336 metrics->y = QFixed::fromFixed(-top);
2337 metrics->xoff = QFixed::fromFixed(face->glyph->advance.x);
2339 if (!FT_IS_SCALABLE(freetype->face))
2340 QFreetypeFace::addBitmapToPath(face->glyph, p, path);
2342 QFreetypeFace::addGlyphToPath(face, face->glyph, p, path, face->units_per_EM << 6, face->units_per_EM << 6);
2344 FT_Set_Transform(face, &freetype->matrix,
nullptr);
2348bool QFontEngineFT::supportsTransformation(
const QTransform &transform)
const
2350 return transform.type() <= QTransform::TxRotate;
2353void QFontEngineFT::addOutlineToPath(qreal x, qreal y,
const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
2355 if (!glyphs.numGlyphs)
2358 if (FT_IS_SCALABLE(freetype->face)) {
2359 QFontEngine::addOutlineToPath(x, y, glyphs, path, flags);
2361 QVarLengthArray<QFixedPoint> positions;
2362 QVarLengthArray<glyph_t> positioned_glyphs;
2364 matrix.translate(x, y);
2365 getGlyphPositions(glyphs, matrix, flags, positioned_glyphs, positions);
2367 FT_Face face = lockFace(Unscaled);
2368 for (
int gl = 0; gl < glyphs.numGlyphs; gl++) {
2369 FT_UInt glyph = positioned_glyphs[gl];
2370 FT_Load_Glyph(face, glyph, FT_LOAD_TARGET_MONO);
2371 QFreetypeFace::addBitmapToPath(face->glyph, positions[gl], path);
2377void QFontEngineFT::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions,
int numGlyphs,
2378 QPainterPath *path, QTextItem::RenderFlags)
2380 FT_Face face = lockFace(Unscaled);
2382 for (
int gl = 0; gl < numGlyphs; gl++) {
2383 FT_UInt glyph = glyphs[gl];
2385 FT_Load_Glyph(face, glyph, FT_LOAD_NO_BITMAP);
2387 FT_GlyphSlot g = face->glyph;
2388 if (g->format != FT_GLYPH_FORMAT_OUTLINE)
2391 FT_GlyphSlot_Embolden(g);
2393 FT_GlyphSlot_Oblique(g);
2394 QFreetypeFace::addGlyphToPath(face, g, positions[gl], path, xsize, ysize);
2399glyph_t QFontEngineFT::glyphIndex(uint ucs4)
const
2401 glyph_t glyph = ucs4 < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[ucs4] : 0;
2403 FT_Face face = freetype->face;
2404 glyph = FT_Get_Char_Index(face, ucs4);
2408 if (ucs4 == QChar::Nbsp || ucs4 == QChar::Tabulation) {
2409 glyph = FT_Get_Char_Index(face, QChar::Space);
2410 }
else if (freetype->symbol_map) {
2417 FT_Set_Charmap(face, freetype->symbol_map);
2418 glyph = FT_Get_Char_Index(face, ucs4);
2419 FT_Set_Charmap(face, freetype->unicode_map);
2420 if (!glyph && symbol && ucs4 < 0x100)
2421 glyph = FT_Get_Char_Index(face, ucs4 + 0xf000);
2424 if (ucs4 < QFreetypeFace::cmapCacheSize)
2425 freetype->cmapCache[ucs4] = glyph;
2431QString QFontEngineFT::glyphName(glyph_t index)
const
2434 if (index >= glyph_t(glyphCount()))
2437 FT_Face face = freetype->face;
2438 if (face->face_flags & FT_FACE_FLAG_GLYPH_NAMES) {
2439 char glyphName[128] = {};
2440 if (FT_Get_Glyph_Name(face, index, glyphName,
sizeof(glyphName)) == 0)
2441 result = QString::fromUtf8(glyphName);
2444 return result.isEmpty() ? QFontEngine::glyphName(index) : result;
2447int QFontEngineFT::stringToCMap(
const QChar *str,
int len, QGlyphLayout *glyphs,
int *nglyphs,
2448 QFontEngine::ShaperFlags flags)
const
2450 Q_ASSERT(glyphs->numGlyphs >= *nglyphs);
2451 if (*nglyphs < len) {
2456 int mappedGlyphs = 0;
2458 if (freetype->symbol_map) {
2459 FT_Face face = freetype->face;
2460 QStringIterator it(str, str + len);
2461 while (it.hasNext()) {
2462 uint uc = it.next();
2463 glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
2464 if ( !glyphs->glyphs[glyph_pos] ) {
2471 glyph_t glyph = FT_Get_Char_Index(face, uc);
2474 if (!glyph && (uc == 0xa0 || uc == 0x9)) {
2476 glyph = FT_Get_Char_Index(face, uc);
2479 FT_Set_Charmap(face, freetype->symbol_map);
2480 glyph = FT_Get_Char_Index(face, uc);
2481 FT_Set_Charmap(face, freetype->unicode_map);
2482 if (!glyph && symbol && uc < 0x100)
2483 glyph = FT_Get_Char_Index(face, uc + 0xf000);
2485 glyphs->glyphs[glyph_pos] = glyph;
2486 if (uc < QFreetypeFace::cmapCacheSize)
2487 freetype->cmapCache[uc] = glyph;
2489 if (glyphs->glyphs[glyph_pos] || isIgnorableChar(uc))
2494 FT_Face face = freetype->face;
2495 QStringIterator it(str, str + len);
2496 while (it.hasNext()) {
2497 uint uc = it.next();
2498 glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
2499 if (!glyphs->glyphs[glyph_pos]) {
2502 glyph_t glyph = FT_Get_Char_Index(face, uc);
2503 if (!glyph && (uc == 0xa0 || uc == 0x9)) {
2507 glyphs->glyphs[glyph_pos] = glyph;
2508 if (uc < QFreetypeFace::cmapCacheSize)
2509 freetype->cmapCache[uc] = glyph;
2512 if (glyphs->glyphs[glyph_pos] || isIgnorableChar(uc))
2518 *nglyphs = glyph_pos;
2519 glyphs->numGlyphs = glyph_pos;
2521 if (!(flags & GlyphIndicesOnly))
2522 recalcAdvances(glyphs, flags);
2524 return mappedGlyphs;
2527bool QFontEngineFT::shouldUseDesignMetrics(QFontEngine::ShaperFlags flags)
const
2529 if (!FT_IS_SCALABLE(freetype->face))
2532 return default_hint_style == HintNone || default_hint_style == HintLight || (flags & DesignMetrics);
2535QFixed QFontEngineFT::scaledBitmapMetrics(QFixed m)
const
2537 return m * scalableBitmapScaleFactor;
2540glyph_metrics_t QFontEngineFT::scaledBitmapMetrics(
const glyph_metrics_t &m,
const QTransform &t)
const
2543 trans.setMatrix(t.m11(), t.m12(), t.m13(),
2544 t.m21(), t.m22(), t.m23(),
2546 const qreal scaleFactor = scalableBitmapScaleFactor.toReal();
2547 trans.scale(scaleFactor, scaleFactor);
2549 QRectF rect(m.x.toReal(), m.y.toReal(), m.width.toReal(), m.height.toReal());
2550 QPointF offset(m.xoff.toReal(), m.yoff.toReal());
2552 rect = trans.mapRect(rect);
2553 offset = trans.map(offset);
2555 glyph_metrics_t metrics;
2556 metrics.x = QFixed::fromReal(rect.x());
2557 metrics.y = QFixed::fromReal(rect.y());
2558 metrics.width = QFixed::fromReal(rect.width());
2559 metrics.height = QFixed::fromReal(rect.height());
2560 metrics.xoff = QFixed::fromReal(offset.x());
2561 metrics.yoff = QFixed::fromReal(offset.y());
2565void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags flags)
const
2567 FT_Face face =
nullptr;
2568 bool design = shouldUseDesignMetrics(flags);
2569 for (
int i = 0; i < glyphs->numGlyphs; i++) {
2570 Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyphs->glyphs[i]) :
nullptr;
2572 GlyphFormat acceptableFormat = (defaultFormat != Format_None) ? defaultFormat : Format_Mono;
2573 if (g && g->format == acceptableFormat) {
2574 glyphs->advances[i] = design ? QFixed::fromFixed(g->linearAdvance) : QFixed(g->advance);
2578 g = loadGlyph(cacheEnabled ? &defaultGlyphSet :
nullptr,
2585 glyphs->advances[i] = design ? QFixed::fromFixed(g->linearAdvance) : QFixed(g->advance);
2587 glyphs->advances[i] = design ? QFixed::fromFixed(face->glyph->linearHoriAdvance >> 10)
2588 : QFixed::fromFixed(face->glyph->metrics.horiAdvance).round();
2589 if (!cacheEnabled && g != &emptyGlyph)
2593 if (scalableBitmapScaleFactor != 1)
2594 glyphs->advances[i] *= scalableBitmapScaleFactor;
2600glyph_metrics_t QFontEngineFT::boundingBox(
const QGlyphLayout &glyphs)
2602 FT_Face face =
nullptr;
2604 glyph_metrics_t overall;
2606 if (!isScalableBitmap()) {
2607 overall.y = -ascent();
2608 overall.height = ascent() + descent();
2610 overall.y = QFixed::fromFixed(-metrics.ascender);
2611 overall.height = QFixed::fromFixed(metrics.ascender - metrics.descender);
2616 for (
int i = 0; i < glyphs.numGlyphs; i++) {
2618 if (!glyphs.advances[i] || glyphs.attributes[i].dontPrint)
2620 Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyphs.glyphs[i]) :
nullptr;
2624 g = loadGlyph(cacheEnabled ? &defaultGlyphSet :
nullptr,
2632 QFixed x = overall.xoff + glyphs.offsets[i].x + g->x;
2633 QFixed y = overall.yoff + glyphs.offsets[i].y - g->y;
2634 overall.x = qMin(overall.x, x);
2635 overall.y = qMin(overall.y, y);
2636 xmax = qMax(xmax, x.ceil() + g->width);
2637 ymax = qMax(ymax, y.ceil() + g->height);
2638 if (!cacheEnabled && g != &emptyGlyph)
2641 int left =
FLOOR(face->glyph->metrics.horiBearingX);
2642 int right =
CEIL(face->glyph->metrics.horiBearingX + face->glyph->metrics.width);
2643 int top =
CEIL(face->glyph->metrics.horiBearingY);
2644 int bottom =
FLOOR(face->glyph->metrics.horiBearingY - face->glyph->metrics.height);
2646 QFixed x = overall.xoff + glyphs.offsets[i].x - (-
TRUNC(left));
2647 QFixed y = overall.yoff + glyphs.offsets[i].y -
TRUNC(top);
2648 overall.x = qMin(overall.x, x);
2649 overall.y = qMin(overall.y, y);
2650 xmax = qMax(xmax, x +
TRUNC(right - left));
2651 ymax = qMax(ymax, y +
TRUNC(top - bottom));
2653 overall.xoff += glyphs.effectiveAdvance(i);
2655 overall.height = qMax(overall.height, ymax - overall.y);
2656 overall.width = xmax - overall.x;
2661 if (isScalableBitmap())
2662 overall = scaledBitmapMetrics(overall, QTransform());
2666glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph)
2668 FT_Face face =
nullptr;
2669 glyph_metrics_t overall;
2670 Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyph) :
nullptr;
2673 g = loadGlyph(cacheEnabled ? &defaultGlyphSet :
nullptr,
2683 overall.width = g->width;
2684 overall.height = g->height;
2685 overall.xoff = g->advance;
2686 if (!cacheEnabled && g != &emptyGlyph)
2689 int left =
FLOOR(face->glyph->metrics.horiBearingX);
2690 int right =
CEIL(face->glyph->metrics.horiBearingX + face->glyph->metrics.width);
2691 int top =
CEIL(face->glyph->metrics.horiBearingY);
2692 int bottom =
FLOOR(face->glyph->metrics.horiBearingY - face->glyph->metrics.height);
2694 overall.width =
TRUNC(right-left);
2695 overall.height =
TRUNC(top-bottom);
2696 overall.x =
TRUNC(left);
2697 overall.y = -
TRUNC(top);
2698 overall.xoff =
TRUNC(
ROUND(face->glyph->advance.x));
2703 if (isScalableBitmap())
2704 overall = scaledBitmapMetrics(overall, QTransform());
2708glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph,
const QTransform &matrix)
2710 return alphaMapBoundingBox(glyph, QFixedPoint(), matrix, QFontEngine::Format_None);
2713glyph_metrics_t QFontEngineFT::alphaMapBoundingBox(glyph_t glyph,
2714 const QFixedPoint &subPixelPosition,
2715 const QTransform &matrix,
2716 QFontEngine::GlyphFormat format)
2722 const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face)
2723 && matrix.type() > QTransform::TxTranslate;
2724 if (needsImageTransform && format == QFontEngine::Format_Mono)
2725 format = QFontEngine::Format_A8;
2726 Glyph *g = loadGlyphFor(glyph, subPixelPosition, format, matrix, QColor(),
true,
true);
2728 glyph_metrics_t overall;
2732 overall.width = g->width;
2733 overall.height = g->height;
2734 overall.xoff = g->advance;
2735 if (!cacheEnabled && g != &emptyGlyph)
2738 FT_Face face = lockFace();
2739 int left =
FLOOR(face->glyph->metrics.horiBearingX);
2740 int right =
CEIL(face->glyph->metrics.horiBearingX + face->glyph->metrics.width);
2741 int top =
CEIL(face->glyph->metrics.horiBearingY);
2742 int bottom =
FLOOR(face->glyph->metrics.horiBearingY - face->glyph->metrics.height);
2744 overall.width =
TRUNC(right-left);
2745 overall.height =
TRUNC(top-bottom);
2746 overall.x =
TRUNC(left);
2747 overall.y = -
TRUNC(top);
2748 overall.xoff =
TRUNC(
ROUND(face->glyph->advance.x));
2752 if (isScalableBitmap() || needsImageTransform)
2753 overall = scaledBitmapMetrics(overall, matrix);
2759 if (glyph ==
nullptr || glyph->height == 0 || glyph->width == 0)
2762 QImage::Format format = QImage::Format_Invalid;
2763 int bytesPerLine = -1;
2764 switch (glyphFormat) {
2765 case QFontEngine::Format_Mono:
2766 format = QImage::Format_Mono;
2767 bytesPerLine = ((glyph->width + 31) & ~31) >> 3;
2769 case QFontEngine::Format_A8:
2770 format = QImage::Format_Alpha8;
2771 bytesPerLine = (glyph->width + 3) & ~3;
2773 case QFontEngine::Format_A32:
2774 format = QImage::Format_RGB32;
2775 bytesPerLine = glyph->width * 4;
2781 QImage img(
static_cast<
const uchar *>(glyph->data), glyph->width, glyph->height, bytesPerLine, format);
2782 if (format == QImage::Format_Mono)
2783 img.setColor(1, QColor(Qt::white).rgba());
2787QFontEngine::Glyph *QFontEngineFT::glyphData(glyph_t glyphIndex,
2788 const QFixedPoint &subPixelPosition,
2789 QFontEngine::GlyphFormat neededFormat,
2790 const QTransform &t)
2792 Q_ASSERT(cacheEnabled);
2795 neededFormat = Format_Mono;
2796 else if (neededFormat == Format_None && defaultFormat != Format_None)
2797 neededFormat = defaultFormat;
2798 else if (neededFormat == Format_None)
2799 neededFormat = Format_A8;
2801 Glyph *glyph = loadGlyphFor(glyphIndex, subPixelPosition, neededFormat, t, QColor());
2802 if (!glyph || !glyph->width || !glyph->height)
2810 return qFuzzyCompare(t.m11(), t.m22()) && qFuzzyCompare(t.m12(), -t.m21())
2811 && qFuzzyCompare(t.m11()*t.m22() - t.m12()*t.m21(), qreal(1.0));
2814QFontEngineFT::Glyph *QFontEngineFT::loadGlyphFor(glyph_t g,
2815 const QFixedPoint &subPixelPosition,
2817 const QTransform &t,
2819 bool fetchBoundingBox,
2820 bool disableOutlineDrawing)
2822 QGlyphSet *glyphSet = loadGlyphSet(t);
2823 if (glyphSet !=
nullptr && glyphSet->outline_drawing && !disableOutlineDrawing && !fetchBoundingBox)
2826 Glyph *glyph = glyphSet !=
nullptr ? glyphSet->getGlyph(g, subPixelPosition) :
nullptr;
2827 if (!glyph || glyph->format != format || (!fetchBoundingBox && !glyph->data)) {
2828 QScopedValueRollback<HintStyle> saved_default_hint_style(default_hint_style);
2829 if (t.type() >= QTransform::TxScale && !is2dRotation(t))
2830 default_hint_style = HintNone;
2833 FT_Matrix m =
this->matrix;
2834 FT_Matrix ftMatrix = glyphSet !=
nullptr ? glyphSet->transformationMatrix : QTransformToFTMatrix(t);
2835 FT_Matrix_Multiply(&ftMatrix, &m);
2836 freetype->matrix = m;
2837 glyph = loadGlyph(glyphSet, g, subPixelPosition, color, format,
false, disableOutlineDrawing);
2844QImage QFontEngineFT::alphaMapForGlyph(glyph_t g,
const QFixedPoint &subPixelPosition)
2846 return alphaMapForGlyph(g, subPixelPosition, QTransform());
2849QImage QFontEngineFT::alphaMapForGlyph(glyph_t g,
2850 const QFixedPoint &subPixelPosition,
2851 const QTransform &t)
2853 const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face)
2854 && t.type() > QTransform::TxTranslate;
2855 const GlyphFormat neededFormat = antialias || needsImageTransform ? Format_A8 : Format_Mono;
2857 Glyph *glyph = loadGlyphFor(g, subPixelPosition, neededFormat, t, QColor(),
false,
true);
2859 QImage img = alphaMapFromGlyphData(glyph, neededFormat);
2860 if (needsImageTransform)
2861 img = img.transformed(t, Qt::FastTransformation);
2865 if (!cacheEnabled && glyph != &emptyGlyph)
2871QImage QFontEngineFT::alphaRGBMapForGlyph(glyph_t g,
2872 const QFixedPoint &subPixelPosition,
2873 const QTransform &t)
2875 if (t.type() > QTransform::TxRotate)
2876 return QFontEngine::alphaRGBMapForGlyph(g, subPixelPosition, t);
2878 const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face)
2879 && t.type() > QTransform::TxTranslate;
2882 const GlyphFormat neededFormat = Format_A32;
2884 Glyph *glyph = loadGlyphFor(g, subPixelPosition, neededFormat, t, QColor(),
false,
true);
2886 QImage img = alphaMapFromGlyphData(glyph, neededFormat);
2887 if (needsImageTransform)
2888 img = img.transformed(t, Qt::FastTransformation);
2892 if (!cacheEnabled && glyph != &emptyGlyph)
2898 return QFontEngine::alphaRGBMapForGlyph(g, subPixelPosition, t);
2901QImage QFontEngineFT::bitmapForGlyph(glyph_t g,
2902 const QFixedPoint &subPixelPosition,
2903 const QTransform &t,
2904 const QColor &color)
2906 Glyph *glyph = loadGlyphFor(g, subPixelPosition, defaultFormat, t, color);
2907 if (glyph ==
nullptr)
2911 if (defaultFormat == GlyphFormat::Format_ARGB)
2912 img = QImage(glyph->data, glyph->width, glyph->height, QImage::Format_ARGB32_Premultiplied).copy();
2913 else if (defaultFormat == GlyphFormat::Format_Mono)
2914 img = QImage(glyph->data, glyph->width, glyph->height, QImage::Format_Mono).copy();
2916 if (!img.isNull() && (scalableBitmapScaleFactor != 1 || (!t.isIdentity() && !isSmoothlyScalable))) {
2917 QTransform trans(t);
2918 const qreal scaleFactor = scalableBitmapScaleFactor.toReal();
2919 trans.scale(scaleFactor, scaleFactor);
2920 img = img.transformed(trans, Qt::SmoothTransformation);
2923 if (!cacheEnabled && glyph != &emptyGlyph)
2929void QFontEngineFT::removeGlyphFromCache(glyph_t glyph)
2931 defaultGlyphSet.removeGlyphFromCache(glyph, QFixedPoint());
2934int QFontEngineFT::glyphCount()
const
2937 FT_Face face = lockFace();
2939 count = face->num_glyphs;
2945FT_Face QFontEngineFT::lockFace(Scaling scale)
const
2948 FT_Face face = freetype->face;
2949 if (scale == Unscaled) {
2950 if (FT_Set_Char_Size(face, face->units_per_EM << 6, face->units_per_EM << 6, 0, 0) == 0) {
2951 freetype->xsize = face->units_per_EM << 6;
2952 freetype->ysize = face->units_per_EM << 6;
2954 }
else if (freetype->xsize != xsize || freetype->ysize != ysize) {
2955 FT_Set_Char_Size(face, xsize, ysize, 0, 0);
2956 freetype->xsize = xsize;
2957 freetype->ysize = ysize;
2959 if (freetype->matrix.xx != matrix.xx ||
2960 freetype->matrix.yy != matrix.yy ||
2961 freetype->matrix.xy != matrix.xy ||
2962 freetype->matrix.yx != matrix.yx) {
2963 freetype->matrix = matrix;
2964 FT_Set_Transform(face, &freetype->matrix,
nullptr);
2970void QFontEngineFT::unlockFace()
const
2975FT_Face QFontEngineFT::non_locked_face()
const
2977 return freetype->face;
2981QFontEngineFT::QGlyphSet::QGlyphSet()
2982 : outline_drawing(
false)
2984 transformationMatrix.xx = 0x10000;
2985 transformationMatrix.yy = 0x10000;
2986 transformationMatrix.xy = 0;
2987 transformationMatrix.yx = 0;
2988 memset(fast_glyph_data, 0,
sizeof(fast_glyph_data));
2989 fast_glyph_count = 0;
2992QFontEngineFT::QGlyphSet::~QGlyphSet()
2997void QFontEngineFT::QGlyphSet::clear()
2999 if (fast_glyph_count > 0) {
3000 for (
int i = 0; i < 256; ++i) {
3001 if (fast_glyph_data[i]) {
3002 delete fast_glyph_data[i];
3003 fast_glyph_data[i] =
nullptr;
3006 fast_glyph_count = 0;
3008 qDeleteAll(glyph_data);
3012void QFontEngineFT::QGlyphSet::removeGlyphFromCache(glyph_t index,
3013 const QFixedPoint &subPixelPosition)
3015 if (useFastGlyphData(index, subPixelPosition)) {
3016 if (fast_glyph_data[index]) {
3017 delete fast_glyph_data[index];
3018 fast_glyph_data[index] =
nullptr;
3019 if (fast_glyph_count > 0)
3023 delete glyph_data.take(GlyphAndSubPixelPosition(index, subPixelPosition));
3027void QFontEngineFT::QGlyphSet::setGlyph(glyph_t index,
3028 const QFixedPoint &subPixelPosition,
3031 if (useFastGlyphData(index, subPixelPosition)) {
3032 if (!fast_glyph_data[index])
3034 fast_glyph_data[index] = glyph;
3036 glyph_data.insert(GlyphAndSubPixelPosition(index, subPixelPosition), glyph);
3040int QFontEngineFT::getPointInOutline(glyph_t glyph,
int flags, quint32 point, QFixed *xpos, QFixed *ypos, quint32 *nPoints)
3043 bool hsubpixel =
true;
3045 int load_flags = loadFlags(
nullptr, Format_A8, flags, hsubpixel, vfactor);
3046 int result = freetype->getPointInOutline(glyph, load_flags, point, xpos, ypos, nPoints);
3051bool QFontEngineFT::initFromFontEngine(
const QFontEngineFT *fe)
3053 if (!init(fe->faceId(), fe->antialias, fe->defaultFormat, fe->freetype))
3058 freetype->ref.ref();
3060 default_load_flags = fe->default_load_flags;
3061 default_hint_style = fe->default_hint_style;
3062 antialias = fe->antialias;
3063 transform = fe->transform;
3064 embolden = fe->embolden;
3065 obliquen = fe->obliquen;
3066 subpixelType = fe->subpixelType;
3067 lcdFilterType = fe->lcdFilterType;
3068 embeddedbitmap = fe->embeddedbitmap;
3073QFontEngine *QFontEngineFT::cloneWithSize(qreal pixelSize)
const
3075 QFontDef fontDef(
this->fontDef);
3076 fontDef.pixelSize = pixelSize;
3077 QFontEngineFT *fe =
new QFontEngineFT(fontDef);
3078 if (!fe->initFromFontEngine(
this)) {
3086Qt::HANDLE QFontEngineFT::handle()
const
3088 return non_locked_face();
3091QList<QFontVariableAxis> QFontEngineFT::variableAxes()
const
3093 return freetype->variableAxes();
QHash< QFontEngine::FaceId, QFreetypeFace * > faces
QList< QFreetypeFace * > staleFaces
QHash< FaceStyle, int > faceIndices
Combined button and popup list for selecting options.
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)
FaceStyle(QString faceFileName, QString styleName)