qfontengine_ft.rar

  • PUDN用户
    了解作者
  • Unix_Linux
    开发工具
  • 14KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2013-09-04 11:24
    上传日期
Freetype 2.1.7 and earlier used width/height for matching sizes in the BDF and PCF loaders for Linux.
qfontengine_ft.rar
  • qfontengine_ft.cpp
    63.1KB
  • qfontengine_ft_p.h
    52B
内容介绍
#include "qdir.h" #include "qmetatype.h" #include "qtextstream.h" #include "qvariant.h" #include "qfontengine_ft_p.h" #ifndef QT_NO_FREETYPE #include "qfile.h" #include "qabstractfileengine.h" #include "qthreadstorage.h" #include <qmath.h> #include <private/qpdf_p.h> #include <private/qharfbuzz_p.h> #include "qfontengine_ft_p.h" #include <ft2build.h> #include FT_FREETYPE_H #include FT_OUTLINE_H #include FT_SYNTHESIS_H #include FT_TRUETYPE_TABLES_H #include FT_TYPE1_TABLES_H #include FT_GLYPH_H #if defined(FT_LCD_FILTER_H) #include FT_LCD_FILTER_H #endif #if defined(FT_CONFIG_OPTIONS_H) #include FT_CONFIG_OPTIONS_H #endif #if defined(FT_LCD_FILTER_H) && defined(FT_CONFIG_OPTION_SUBPIXEL_RENDERING) #define QT_USE_FREETYPE_LCDFILTER #endif #ifdef QT_LINUXBASE #include FT_ERRORS_H #endif QT_BEGIN_NAMESPACE /* * Freetype 2.1.7 and earlier used width/height * for matching sizes in the BDF and PCF loaders. * This has been fixed for 2.1.8. */ #if (FREETYPE_MAJOR*10000+FREETYPE_MINOR*100+FREETYPE_PATCH) >= 20105 #define X_SIZE(face,i) ((face)->available_sizes[i].x_ppem) #define Y_SIZE(face,i) ((face)->available_sizes[i].y_ppem) #else #define X_SIZE(face,i) ((face)->available_sizes[i].width << 6) #define Y_SIZE(face,i) ((face)->available_sizes[i].height << 6) #endif /* FreeType 2.1.10 starts to provide FT_GlyphSlot_Embolden */ #if (FREETYPE_MAJOR*10000+FREETYPE_MINOR*100+FREETYPE_PATCH) >= 20110 #define Q_FT_GLYPHSLOT_EMBOLDEN(slot) FT_GlyphSlot_Embolden(slot) #else #define Q_FT_GLYPHSLOT_EMBOLDEN(slot) #endif #define FLOOR(x) ((x) & -64) #define CEIL(x) (((x)+63) & -64) #define TRUNC(x) ((x) >> 6) #define ROUND(x) (((x)+32) & -64) static HB_Error hb_getSFntTable(void *font, HB_Tag tableTag, HB_Byte *buffer, HB_UInt *length) { #if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) > 20103 FT_Face face = (FT_Face)font; FT_ULong ftlen = *length; FT_Error error = 0; if ( !FT_IS_SFNT(face) ) return HB_Err_Invalid_Argument; error = FT_Load_Sfnt_Table(face, tableTag, 0, buffer, &ftlen); *length = ftlen; return (HB_Error)error; #else return HB_Err_Invalid_Argument; #endif } // -------------------------- Freetype support ------------------------------ class QtFreetypeData { public: QtFreetypeData() : library(0) { } FT_Library library; QHash<QFontEngine::FaceId, QFreetypeFace *> faces; }; #ifdef QT_NO_THREAD Q_GLOBAL_STATIC(QtFreetypeData, theFreetypeData) QtFreetypeData *qt_getFreetypeData() { return theFreetypeData(); } #else Q_GLOBAL_STATIC(QThreadStorage<QtFreetypeData *>, theFreetypeData) QtFreetypeData *qt_getFreetypeData() { QtFreetypeData *&freetypeData = theFreetypeData()->localData(); if (!freetypeData) freetypeData = new QtFreetypeData; return freetypeData; } #endif FT_Library qt_getFreetype() { QtFreetypeData *freetypeData = qt_getFreetypeData(); if (!freetypeData->library) FT_Init_FreeType(&freetypeData->library); return freetypeData->library; } int QFreetypeFace::fsType() const { int fsType = 0; TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (os2) fsType = os2->fsType; return fsType; } HB_Error QFreetypeFace::getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints) { int load_flags = (flags & HB_ShaperFlag_UseDesignMetrics) ? FT_LOAD_NO_HINTING : FT_LOAD_DEFAULT; if (HB_Error error = (HB_Error)FT_Load_Glyph(face, glyph, load_flags)) return error; if (face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) return HB_Err_Invalid_SubTable; *nPoints = face->glyph->outline.n_points; if (!(*nPoints)) return HB_Err_Ok; if (point > *nPoints) return HB_Err_Invalid_SubTable; *xpos = face->glyph->outline.points[point].x; *ypos = face->glyph->outline.points[point].y; return HB_Err_Ok; } /* * One font file can contain more than one font (bold/italic for example) * find the right one and return it. * * Returns the freetype face or 0 in case of an empty file or any other problems * (like not being able to open the file) */ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id) { if (face_id.filename.isEmpty()) return 0; QtFreetypeData *freetypeData = qt_getFreetypeData(); if (!freetypeData->library) FT_Init_FreeType(&freetypeData->library); QFreetypeFace *freetype = freetypeData->faces.value(face_id, 0); if (freetype) { freetype->ref.ref(); } else { QScopedPointer<QFreetypeFace> newFreetype(new QFreetypeFace); FT_Face face; QFile file(QString::fromUtf8(face_id.filename)); if (face_id.filename.startsWith(":qmemoryfonts/")) { // from qfontdatabase.cpp extern QByteArray qt_fontdata_from_index(int); QByteArray idx = face_id.filename; idx.remove(0, 14); // remove ':qmemoryfonts/' bool ok = false; newFreetype->fontData = qt_fontdata_from_index(idx.toInt(&ok)); if (!ok) newFreetype->fontData = QByteArray(); } else if (!(file.fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)) { if (!file.open(QIODevice::ReadOnly)) { return 0; } newFreetype->fontData = file.readAll(); } if (!newFreetype->fontData.isEmpty()) { if (FT_New_Memory_Face(freetypeData->library, (const FT_Byte *)newFreetype->fontData.constData(), newFreetype->fontData.size(), face_id.index, &face)) { return 0; } } else if (FT_New_Face(freetypeData->library, face_id.filename, face_id.index, &face)) { return 0; } newFreetype->face = face; newFreetype->hbFace = qHBNewFace(face, hb_getSFntTable); Q_CHECK_PTR(newFreetype->hbFace); newFreetype->ref = 1; newFreetype->xsize = 0; newFreetype->ysize = 0; newFreetype->matrix.xx = 0x10000; newFreetype->matrix.yy = 0x10000; newFreetype->matrix.xy = 0; newFreetype->matrix.yx = 0; newFreetype->unicode_map = 0; newFreetype->symbol_map = 0; #ifndef QT_NO_FONTCONFIG newFreetype->charset = 0; #endif memset(newFreetype->cmapCache, 0, sizeof(newFreetype->cmapCache)); for (int i = 0; i < newFreetype->face->num_charmaps; ++i) { FT_CharMap cm = newFreetype->face->charmaps[i]; switch(cm->encoding) { case FT_ENCODING_UNICODE: newFreetype->unicode_map = cm; break; case FT_ENCODING_APPLE_ROMAN: case FT_ENCODING_ADOBE_LATIN_1: if (!newFreetype->unicode_map || newFreetype->unicode_map->encoding != FT_ENCODING_UNICODE) newFreetype->unicode_map = cm; break; case FT_ENCODING_ADOBE_CUSTOM: case FT_ENCODING_MS_SYMBOL: if (!newFreetype->symbol_map) newFreetype->symbol_map = cm; break; default: break; } } if (!FT_IS_SCALABLE(newFreetype->face) && newFreetype->face->num_fixed_sizes == 1) FT_Set_Char_Size (face, X_SIZE(newFreetype->face, 0), Y_SIZE(newFreetype->face, 0), 0, 0); # if 0 FcChar8 *name; FcPatternGetString(pattern, FC_FAMILY, 0, &name); qDebug("%s: using maps: default: %x unicode: %x, symbol: %x", name, newFreetype->face->charmap ? newFreetype->face->charmap->encoding : 0, newFreetype->unicode_map ? newFreetype->unicode_map->encoding : 0, newFreetype->symbol_map ? newFreetype->symbol_map->encoding : 0); for (int i = 0; i < 256; i += 8) qDebug(" %x: %d %d %d %d %d %d %d %d", i,
评论
    相关推荐