Py::Object FT2Font::get_ps_font_info(const Py::Tuple & args) { _VERBOSE("FT2Font::get_ps_font_info"); args.verify_length(0); PS_FontInfoRec fontinfo; FT_Error error = FT_Get_PS_Font_Info(face, &fontinfo); if (error) { Py::RuntimeError("Could not get PS font info"); return Py::Object(); } Py::Tuple info(9); info[0] = Py::String(fontinfo.version); info[1] = Py::String(fontinfo.notice); info[2] = Py::String(fontinfo.full_name); info[3] = Py::String(fontinfo.family_name); info[4] = Py::String(fontinfo.weight); info[5] = Py::Long(fontinfo.italic_angle); info[6] = Py::Int(fontinfo.is_fixed_pitch); info[7] = Py::Int(fontinfo.underline_position); info[8] = Py::Int(fontinfo.underline_thickness); return info; }
void XeTeXFontInst_FT2::initialize(LEErrorCode &status) { if (face == 0) { status = LE_FONT_FILE_NOT_FOUND_ERROR; return; } XeTeXFontInst::initialize(status); if (LE_FAILURE(status)) { /* font can ONLY be used via FreeType APIs, not direct table access */ fFreeTypeOnly = true; status = LE_NO_ERROR; /* fill in fields that XeTeXFontInst::initialize failed to get for us */ fUnitsPerEM = face->units_per_EM; fAscent = yUnitsToPoints(face->ascender); fDescent = yUnitsToPoints(face->descender); // fLeading = ; fItalicAngle = 0; PS_FontInfoRec font_info; if (FT_Get_PS_Font_Info(face, &font_info) == 0) { // will return error if it wasn't a PS font fItalicAngle = font_info.italic_angle; } } return; }
FreeTypeType1Wrapper::FreeTypeType1Wrapper(FT_Face inFace,const std::string& inFontFilePath,const std::string& inPFMFilePath) { if(FT_Get_PS_Font_Info(inFace,&mPSFontInfo) != 0) { TRACE_LOG("Unexpected failure in FreeTypeType1Wrapper::FreeTypeType1Wrapper. could not retrieve PS font info"); mPSavailable = false; // this is obviousy an exception } else mPSavailable = true; if(FT_Get_PS_Font_Private(inFace,&mPrivateInfo) != 0) { TRACE_LOG("Unexpected failure in FreeTypeType1Wrapper::FreeTypeType1Wrapper. could not retrieve PS private font info"); mPSPrivateAvailable = false; // this is obviousy an exception } else mPSPrivateAvailable = true; T1_EncodingType encodingType; FT_Get_PS_Font_Value(inFace, PS_DICT_ENCODING_TYPE, 0, (void*)&encodingType, sizeof(encodingType)); mIsCustomEncoding = encodingType == T1_ENCODING_TYPE_ARRAY; mPFMFileInfoRelevant = (inPFMFilePath.size() != 0 && mPFMReader.Read(inPFMFilePath) != PDFHummus::eFailure); // parse type 1 input file (my own parsing), to get extra info about encoding if(inFontFilePath.size() != 0) { InputFile type1File; type1File.OpenFile(inFontFilePath); mType1File.ReadType1File(type1File.GetInputStream()); type1File.CloseFile(); } mFace = inFace; }
FT_Error get_file_info(FontManagerFontInfo *fileinfo, const gchar * filepath, gint index) { FT_Face face; FT_Library library; FT_Error error; PS_FontInfoRec ps_info; BDF_PropertyRec prop; gsize filesize = 0; gchar * font = NULL; if (G_UNLIKELY(!g_file_get_contents(filepath, &font, &filesize, NULL))) { g_warning("Failed to load file : %s", filepath); return FT_Err_Cannot_Open_Resource; } error = FT_Init_FreeType(&library); if (G_UNLIKELY(error)) return error; error = FT_New_Memory_Face(library, (const FT_Byte *) font, (FT_Long) filesize, index, &face); if (G_UNLIKELY(error)) { g_warning("Failed to create FT_Face for file : %s", filepath); return error; } font_manager_font_info_set_owner(fileinfo, get_file_owner(filepath)); font_manager_font_info_set_filetype(fileinfo, FT_Get_X11_Font_Format(face)); gchar * _size = g_format_size(filesize); font_manager_font_info_set_filesize(fileinfo, _size); g_free0(_size); gchar * _md5 = g_compute_checksum_for_data(G_CHECKSUM_MD5, (const guchar *) font, filesize); font_manager_font_info_set_checksum(fileinfo, _md5); g_free0(_md5); font_manager_font_info_set_psname(fileinfo, FT_Get_Postscript_Name(face)); TT_OS2 * os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (G_LIKELY(os2 && os2->version >= 0x0001 && os2->version != 0xffff)) { gchar * _vendor = get_vendor_from_vendor_id((gchar *) os2->achVendID); font_manager_font_info_set_vendor(fileinfo, _vendor); g_free0(_vendor); gchar * panose = g_strdup_printf("%i:%i:%i:%i:%i:%i:%i:%i:%i:%i", os2->panose[0], os2->panose[1], os2->panose[2], os2->panose[3], os2->panose[4], os2->panose[5], os2->panose[6], os2->panose[7], os2->panose[8], os2->panose[9]); font_manager_font_info_set_panose(fileinfo, panose); g_free0(panose); } if (G_LIKELY(FT_IS_SFNT(face))) get_sfnt_info(fileinfo, face); if (FT_Get_PS_Font_Info(face, &ps_info) == 0) get_ps_info(fileinfo, ps_info, face); gint lic_type = get_license_type(font_manager_font_info_get_license_data(fileinfo), font_manager_font_info_get_copyright(fileinfo), font_manager_font_info_get_license_url(fileinfo)); gchar * _name = get_license_name(lic_type); font_manager_font_info_set_license_type(fileinfo, _name); g_free0(_name); if (!font_manager_font_info_get_license_url(fileinfo)) { gchar * _url = get_license_url(lic_type); if (_url) font_manager_font_info_set_license_url(fileinfo, _url); g_free0(_url); } if (!font_manager_font_info_get_version(fileinfo)) { TT_Header * head = (TT_Header *) FT_Get_Sfnt_Table (face, ft_sfnt_head); if (head) if (head->Font_Revision) { gchar * rev = g_strdup_printf("%f", (float) head->Font_Revision); font_manager_font_info_set_version(fileinfo, rev); g_free0(rev); } } if (!font_manager_font_info_get_vendor(fileinfo)) { int result = FT_Get_BDF_Property(face, "FOUNDRY", &prop); if(result == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) font_manager_font_info_set_vendor(fileinfo, prop.u.atom); else font_manager_font_info_set_vendor(fileinfo, "Unknown Vendor"); } FT_Done_Face(face); error = FT_Done_FreeType(library); g_free0(font); return error; }
bool CFontEngine::openFontFt(const QString &file) { enum ETtfWeight { TTF_WEIGHT_UNKNOWN = 0, TTF_WEIGHT_THIN = 100 + 50, TTF_WEIGHT_EXTRALIGHT = 200 + 50, TTF_WEIGHT_LIGHT = 300 + 50, TTF_WEIGHT_NORMAL = 400 + 50, TTF_WEIGHT_MEDIUM = 500 + 50, TTF_WEIGHT_SEMIBOLD = 600 + 50, TTF_WEIGHT_BOLD = 700 + 50, TTF_WEIGHT_EXTRABOLD = 800 + 50, TTF_WEIGHT_BLACK = 900 + 50 }; bool status = FT_New_Face(itsFt.library, QFile::encodeName(file), 0, &itsFt.face) ? false : true; if(status) itsFt.open = true; PS_FontInfoRec t1info; if(0 == FT_Get_PS_Font_Info(itsFt.face, &t1info)) { itsFamily = t1info.family_name; itsType = TYPE_1; } else { itsFamily = getName(itsFt.face, TT_NAME_ID_FONT_FAMILY); itsType = TRUE_TYPE; } if(itsFamily.isEmpty()) itsFamily = FT_Get_Postscript_Name(itsFt.face); if(itsFamily.isEmpty()) status = false; // Hmm... couldn't find any of the names! if(status) { removeSymbols(itsFamily); itsPsName = (FT_Get_Postscript_Name(itsFt.face)); if(TYPE_1 == itsType) { itsWeight = strToWeight(t1info.weight); itsItalic = t1info.italic_angle <= -4 || t1info.italic_angle >= 4 ? ITALIC_ITALIC : ITALIC_NONE; } else // TrueType... { TT_Postscript *post = NULL; TT_OS2 *os2 = NULL; TT_Header *head = NULL; bool gotItalic = false; if(NULL == (os2 = (TT_OS2 *)FT_Get_Sfnt_Table(itsFt.face, ft_sfnt_os2)) || 0xFFFF == os2->version) itsWeight = WEIGHT_UNKNOWN; else { FT_UShort weight = (os2->usWeightClass > 0 && os2->usWeightClass < 100) ? os2->usWeightClass * 100 : os2->usWeightClass; if(weight < TTF_WEIGHT_THIN) itsWeight = WEIGHT_THIN; else if(weight < TTF_WEIGHT_EXTRALIGHT) itsWeight = WEIGHT_EXTRA_LIGHT; else if(weight < TTF_WEIGHT_LIGHT) itsWeight = WEIGHT_LIGHT; else if(/*weight<TTF_WEIGHT_NORMAL || */ weight < TTF_WEIGHT_MEDIUM) itsWeight = WEIGHT_MEDIUM; else if(weight < TTF_WEIGHT_SEMIBOLD) itsWeight = WEIGHT_SEMI_BOLD; else if(weight < TTF_WEIGHT_BOLD) itsWeight = WEIGHT_BOLD; else if(weight < TTF_WEIGHT_EXTRABOLD) itsWeight = WEIGHT_EXTRA_BOLD; else if(weight < TTF_WEIGHT_BLACK) itsWeight = WEIGHT_BLACK; else if(os2->fsSelection & (1 << 5)) itsWeight = WEIGHT_BOLD; else itsWeight = WEIGHT_UNKNOWN; itsItalic = os2->fsSelection & (1 << 0) ? ITALIC_ITALIC : ITALIC_NONE; gotItalic = true; } if(WEIGHT_UNKNOWN == itsWeight) itsWeight = NULL != (head = (TT_Header *)FT_Get_Sfnt_Table(itsFt.face, ft_sfnt_head)) && head->Mac_Style & 1 ? WEIGHT_BOLD : WEIGHT_MEDIUM; if(!gotItalic && (head != NULL || NULL != (head = (TT_Header *)FT_Get_Sfnt_Table(itsFt.face, ft_sfnt_head)))) { gotItalic = true; itsItalic = head->Mac_Style & 2 ? ITALIC_ITALIC : ITALIC_NONE; } if(!gotItalic && NULL != (post = (TT_Postscript *)FT_Get_Sfnt_Table(itsFt.face, ft_sfnt_post))) { struct TFixed { TFixed(unsigned long v) : upper(v >> 16), lower(v & 0xFFFF) { } short upper, lower; float value() { return upper + (lower / 65536.0); } }; gotItalic = true; itsItalic = 0.0f == ((TFixed)post->italicAngle).value() ? ITALIC_NONE : ITALIC_ITALIC; } } }
static bool check_postscript_ft(void *data) { FontDataFT *fd = (FontDataFT *)data; PS_FontInfoRec postscript_info; return !FT_Get_PS_Font_Info(fd->face, &postscript_info); }
static void add_face_info(GtkWidget *table, gint *row_p, const gchar *uri, FT_Face face) { gchar *s; GFile *file; GFileInfo *info; PS_FontInfoRec ps_info; add_row(table, row_p, _("Name:"), face->family_name, FALSE, FALSE); if (face->style_name) add_row(table, row_p, _("Style:"), face->style_name, FALSE, FALSE); file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (info) { s = g_content_type_get_description (g_file_info_get_content_type (info)); add_row (table, row_p, _("Type:"), s, FALSE, FALSE); g_free (s); s = g_format_size (g_file_info_get_size (info)); add_row (table, row_p, _("Size:"), s, FALSE, FALSE); g_free (s); g_object_unref (info); } if (FT_IS_SFNT(face)) { gint i, len; gchar *version = NULL, *copyright = NULL, *description = NULL; len = FT_Get_Sfnt_Name_Count(face); for (i = 0; i < len; i++) { FT_SfntName sname; if (FT_Get_Sfnt_Name(face, i, &sname) != 0) continue; /* only handle the unicode names for US langid */ if (!(sname.platform_id == TT_PLATFORM_MICROSOFT && sname.encoding_id == TT_MS_ID_UNICODE_CS && sname.language_id == TT_MS_LANGID_ENGLISH_UNITED_STATES)) continue; switch (sname.name_id) { case TT_NAME_ID_COPYRIGHT: g_free(copyright); copyright = g_convert((gchar *)sname.string, sname.string_len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); break; case TT_NAME_ID_VERSION_STRING: g_free(version); version = g_convert((gchar *)sname.string, sname.string_len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); break; case TT_NAME_ID_DESCRIPTION: g_free(description); description = g_convert((gchar *)sname.string, sname.string_len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); break; default: break; } } if (version) { add_row(table, row_p, _("Version:"), version, FALSE, FALSE); g_free(version); } if (copyright) { add_row(table, row_p, _("Copyright:"), copyright, TRUE, TRUE); g_free(copyright); } if (description) { add_row(table, row_p, _("Description:"), description, TRUE, TRUE); g_free(description); } } else if (FT_Get_PS_Font_Info(face, &ps_info) == 0) { if (ps_info.version && g_utf8_validate(ps_info.version, -1, NULL)) add_row(table, row_p, _("Version:"), ps_info.version, FALSE, FALSE); if (ps_info.notice && g_utf8_validate(ps_info.notice, -1, NULL)) add_row(table, row_p, _("Copyright:"), ps_info.notice, TRUE, FALSE); } }
// // _checkLicenses(); // void FontFace::_checkLicenses(void){ // // Assign the default: // _licenseData = UnknownLicense::pData; std::string licenseString; /////////////////////////////////////// // // Handle both (1) TrueType/OpenType // and (2) Type1 fonts // /////////////////////////////////////// if(FT_IS_SFNT(_face)){ /////////////////////////////// // // TrueType / OpenType CASE: // /////////////////////////////// FT_UInt count=FT_Get_Sfnt_Name_Count(_face); FT_SfntName fontName; // // Check both the COPYRIGHT (TTF) and LICENSE (OPENTYPE) fields: // for(unsigned j=0;j<count;j++){ FT_Get_Sfnt_Name(_face,j,&fontName); if(fontName.name_id==NID_LICENSE || fontName.name_id==NID_COPYRIGHT){ licenseString = _getStringFromTrueTypeFont(fontName); if(fontName.name_id==NID_COPYRIGHT){ _storeCopyrightSummary(licenseString); } if(_checkAllKnownLicenses(licenseString)){ return; } } if(fontName.name_id==NID_URL_LICENSE){ _licenseURL = _getStringFromTrueTypeFont(fontName); } } // // Get here if not a known license string: // }else if(FT_IS_SCALABLE(_face)){ /////////////////////////////// // // Could be Type 1, Type 42, // CID, or PFR CASES: // /////////////////////////////// PS_FontInfoRec fi; FT_Get_PS_Font_Info(_face,&fi); if(fi.notice){ licenseString = fi.notice; _checkAllKnownLicenses(licenseString); _storeCopyrightSummary(licenseString); } } }
ListPtr makeXLFD(char *filename, FT_Face face, int isBitmap) { ListPtr xlfd = NULL; const char *foundry, *family, *weight, *slant, *sWidth, *adstyle, *spacing, *full_name, *tmp; TT_Header *head; TT_HoriHeader *hhea; TT_OS2 *os2; TT_Postscript *post; PS_FontInfoRec *t1info, t1info_rec; int rc; foundry = NULL; family = NULL; weight = NULL; slant = NULL; sWidth = NULL; adstyle = NULL; spacing = NULL; full_name = NULL; head = FT_Get_Sfnt_Table(face, ft_sfnt_head); hhea = FT_Get_Sfnt_Table(face, ft_sfnt_hhea); os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2); post = FT_Get_Sfnt_Table(face, ft_sfnt_post); rc = FT_Get_PS_Font_Info(face, &t1info_rec); if(rc == 0) t1info = &t1info_rec; else t1info = NULL; if(!family) family = getName(face, TT_NAME_ID_FONT_FAMILY); if(!family) family = getName(face, TT_NAME_ID_FULL_NAME); if(!family) family = getName(face, TT_NAME_ID_PS_NAME); if(!full_name) full_name = getName(face, TT_NAME_ID_FULL_NAME); if(!full_name) full_name = getName(face, TT_NAME_ID_PS_NAME); if(os2 && os2->version != 0xFFFF) { if(!weight) weight = os2Weight(os2->usWeightClass); if(!sWidth) sWidth = os2Width(os2->usWidthClass); if(!foundry) foundry = vendor_foundry(os2->achVendID); if(!slant) slant = os2->fsSelection & 1 ? "i" : "r"; } if(post) { if(!spacing) { if(post->isFixedPitch) { if(hhea->min_Left_Side_Bearing >= 0 && hhea->xMax_Extent <= hhea->advance_Width_Max) { spacing = "c"; } else { spacing = "m"; } } else { spacing = "p"; } } } if(t1info) { if(!family && t1info->family_name) family = strdup(t1info->family_name); if(!family && t1info->full_name) family = strdup(t1info->full_name); /* Hershey fonts miss /FamilyName */ if(!family && face->family_name) family = strdup(face->family_name); if(!full_name && t1info->full_name) full_name = strdup(t1info->full_name); if(!foundry) foundry = notice_foundry(t1info->notice); if(!weight) weight = t1Weight(t1info->weight); if(!spacing) spacing = t1info->is_fixed_pitch ? "m" : "p"; if(!slant) { /* Bitstream fonts have positive italic angle. */ slant = t1info->italic_angle <= -4 || t1info->italic_angle >= 4 ? "i" : "r"; } } if(!full_name) { fprintf(stderr, "Couldn't determine full name for %s\n", filename); full_name = strdup(filename); } if(head) { if(!slant) slant = head->Mac_Style & 2 ? "i" : "r"; if(!weight) weight = head->Mac_Style & 1 ? "bold" : "medium"; } if(!slant) { fprintf(stderr, "Couldn't determine slant for %s\n", filename); slant = "r"; } if(!weight) { fprintf(stderr, "Couldn't determine weight for %s\n", filename); weight = "medium"; } if(!foundry) { char *notice; notice = getName(face, TT_NAME_ID_TRADEMARK); if(notice) { foundry = notice_foundry(notice); free(notice); } if(!foundry) { notice = getName(face, TT_NAME_ID_MANUFACTURER); if(notice) { foundry = notice_foundry(notice); free(notice); } } } if(strcmp(slant, "i") == 0) { if(strstr(full_name, "Oblique")) slant = "o"; if(strstr(full_name, "Slanted")) slant = "o"; } if(!sWidth) sWidth = nameWidth(full_name); if(!foundry) foundry = "misc"; if(!family) { fprintf(stderr, "Couldn't get family name for %s\n", filename); family = strdup(filename); } if(!weight) weight = "medium"; if(!slant) slant = "r"; if(!sWidth) sWidth = "normal"; if(!adstyle) adstyle = ""; if(!spacing) spacing = "p"; foundry = safe(foundry); tmp = family; family = safe(family); free((void *)tmp); if(!isBitmap) { xlfd = listConsF(xlfd, "-%s-%s-%s-%s-%s-%s-0-0-0-0-%s-0", foundry, family, weight, slant, sWidth, adstyle, spacing); } else { int i, w, h, xres, yres; for(i = 0; i < face->num_fixed_sizes; i++) { w = face->available_sizes[i].width; h = face->available_sizes[i].height; xres = 75; yres = (double)h / w * xres; xlfd = listConsF(xlfd, "-%s-%s-%s-%s-%s-%s-%d-%d-%d-%d-%s-%d", foundry, family, weight, slant, sWidth, adstyle, h, (int)(h / (double)yres * 72.27 * 10 + 0.5), xres, yres, spacing, 60); } } free((void *)family); free((void *)foundry); free((void *)full_name); return xlfd; }