/* * Class: com_sun_javafx_font_MacFontFinder * Method: getFontData * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_com_sun_javafx_font_MacFontFinder_getFontData (JNIEnv *env, jclass obj) { /* No caching as this method is only invoked once */ jclass jStringClass = (*env)->FindClass(env, "java/lang/String"); if (jStringClass == NULL) return NULL; CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(NULL); CFArrayRef fonts = CTFontCollectionCreateMatchingFontDescriptors(collection); CFRelease(collection); CFIndex count = CFArrayGetCount(fonts); jobjectArray result = (*env)->NewObjectArray(env, (count + 2) * 3, jStringClass, NULL); if (result == NULL) { /* out of memory */ CFRelease(fonts); return NULL; } CFIndex i = 0, j = 0; while (i < count) { CTFontDescriptorRef fd = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i++); j = addCTFontDescriptor(fd, env, result, j); } CFRelease(fonts); /* Sometimes a font name starting with dot (internal font, e.g. ".Helvetica NeueUI") * is returned as a system UI font, but such font is not available in the collection * of available fonts. Thus, it is safer to always add the system font manually * to the list so JavaFX can find it. If the UI font is added twice it gets * handled in Java. */ CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 0, NULL); CTFontDescriptorRef fd = CTFontCopyFontDescriptor(font); j = addCTFontDescriptor(fd, env, result, j); CFRelease(fd); CFRelease(font); /* Also add the EmphasizedSystemFont as it might make the bold version * for the system font available to JavaFX. */ font = CTFontCreateUIFontForLanguage(kCTFontEmphasizedSystemFontType, 0, NULL); fd = CTFontCopyFontDescriptor(font); j = addCTFontDescriptor(fd, env, result, j); CFRelease(fd); CFRelease(font); return result; }
static void match_fonts(ASS_Library *lib, ASS_FontProvider *provider, char *name) { const size_t attributes_n = 3; CTFontDescriptorRef ctdescrs[attributes_n]; CFMutableDictionaryRef cfattrs[attributes_n]; CFStringRef attributes[attributes_n] = { kCTFontFamilyNameAttribute, kCTFontDisplayNameAttribute, kCTFontNameAttribute, }; CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8); for (int i = 0; i < attributes_n; i++) { cfattrs[i] = CFDictionaryCreateMutable(NULL, 0, 0, 0); CFDictionaryAddValue(cfattrs[i], attributes[i], cfname); ctdescrs[i] = CTFontDescriptorCreateWithAttributes(cfattrs[i]); } CFArrayRef descriptors = CFArrayCreate(NULL, (const void **)&ctdescrs, attributes_n, NULL); CTFontCollectionRef ctcoll = CTFontCollectionCreateWithFontDescriptors(descriptors, 0); CFArrayRef fontsd = CTFontCollectionCreateMatchingFontDescriptors(ctcoll); process_descriptors(provider, fontsd); SAFE_CFRelease(fontsd); SAFE_CFRelease(ctcoll); for (int i = 0; i < attributes_n; i++) { SAFE_CFRelease(cfattrs[i]); SAFE_CFRelease(ctdescrs[i]); } SAFE_CFRelease(descriptors); SAFE_CFRelease(cfname); }
bool coretext_get_font_names(MCListRef &r_names) { CTFontCollectionRef t_fonts; t_fonts = CTFontCollectionCreateFromAvailableFonts(NULL); CFArrayRef t_descriptors; t_descriptors = CTFontCollectionCreateMatchingFontDescriptors(t_fonts); MCAutoListRef t_names; MCListCreateMutable('\n', &t_names); char t_cstring_font_name[256]; bool t_success; t_success = true; for(CFIndex i = 0; t_success && i < CFArrayGetCount(t_descriptors); i++) { CTFontDescriptorRef t_font; t_font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(t_descriptors, i); CFStringRef t_font_name; t_font_name = (CFStringRef)CTFontDescriptorCopyAttribute(t_font, kCTFontDisplayNameAttribute); if (t_font_name != NULL && CFStringGetCString(t_font_name, t_cstring_font_name, 256, kCFStringEncodingMacRoman) && t_cstring_font_name[0] != '%' && t_cstring_font_name[0] != '.') t_success = MCListAppendCString(*t_names, t_cstring_font_name); if (t_font_name != NULL) CFRelease(t_font_name); } if (t_descriptors != NULL) CFRelease(t_descriptors); if (t_fonts != NULL) CFRelease(t_fonts); if (t_success) t_success = MCListCopy(*t_names, r_names); return t_success; }
void loadfonts(void) { int i, n; CTFontCollectionRef allc; CFArrayRef array; CFStringRef s; CTFontDescriptorRef f; allc = CTFontCollectionCreateFromAvailableFonts(0); array = CTFontCollectionCreateMatchingFontDescriptors(allc); n = CFArrayGetCount(array); xfont = emalloc9p(n*sizeof xfont[0]); for(i=0; i<n; i++) { f = (void*)CFArrayGetValueAtIndex(array, i); if(f == nil) continue; s = CTFontDescriptorCopyAttribute(f, kCTFontNameAttribute); xfont[nxfont].name = mac2c(s); CFRelease(s); nxfont++; } }
static void initializeDb() { QFontDatabasePrivate *db = privateDb(); if(!db || db->count) return; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { QCFType<CTFontCollectionRef> collection = CTFontCollectionCreateFromAvailableFonts(0); if(!collection) return; QCFType<CFArrayRef> fonts = CTFontCollectionCreateMatchingFontDescriptors(collection); if(!fonts) return; QString foundry_name = "CoreText"; const int numFonts = CFArrayGetCount(fonts); for(int i = 0; i < numFonts; ++i) { CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i); QCFString family_name = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute); QtFontFamily *family = db->family(family_name, true); for(int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) family->writingSystems[ws] = QtFontFamily::Supported; QtFontFoundry *foundry = family->foundry(foundry_name, true); QtFontStyle::Key styleKey; if(QCFType<CFDictionaryRef> styles = (CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute)) { if(CFNumberRef weight = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontWeightTrait)) { Q_ASSERT(CFNumberIsFloatType(weight)); double d; if(CFNumberGetValue(weight, kCFNumberDoubleType, &d)) { //qDebug() << "BOLD" << (QString)family_name << d; styleKey.weight = (d > 0.0) ? QFont::Bold : QFont::Normal; } } if(CFNumberRef italic = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontSlantTrait)) { Q_ASSERT(CFNumberIsFloatType(italic)); double d; if(CFNumberGetValue(italic, kCFNumberDoubleType, &d)) { //qDebug() << "ITALIC" << (QString)family_name << d; if (d > 0.0) styleKey.style = QFont::StyleItalic; } } } QtFontStyle *style = foundry->style(styleKey, true); style->smoothScalable = true; if(QCFType<CFNumberRef> size = (CFNumberRef)CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute)) { //qDebug() << "WHEE"; int pixel_size=0; if(CFNumberIsFloatType(size)) { double d; CFNumberGetValue(size, kCFNumberDoubleType, &d); pixel_size = d; } else { CFNumberGetValue(size, kCFNumberIntType, &pixel_size); } //qDebug() << "SIZE" << (QString)family_name << pixel_size; if(pixel_size) style->pixelSize(pixel_size, true); } else { //qDebug() << "WTF?"; } } } else #endif { FMFontIterator it; if (!FMCreateFontIterator(0, 0, kFMUseGlobalScopeOption, &it)) { while (true) { FMFont fmFont; if (FMGetNextFont(&it, &fmFont) != noErr) break; FMFontFamily fmFamily; FMFontStyle fmStyle; QString familyName; QtFontStyle::Key styleKey; ATSFontRef atsFont = FMGetATSFontRefFromFont(fmFont); if (!FMGetFontFamilyInstanceFromFont(fmFont, &fmFamily, &fmStyle)) { { //sanity check the font, and see if we can use it at all! --Sam ATSUFontID fontID; if(ATSUFONDtoFontID(fmFamily, 0, &fontID) != noErr) continue; } if (fmStyle & ::italic) styleKey.style = QFont::StyleItalic; if (fmStyle & ::bold) styleKey.weight = QFont::Bold; ATSFontFamilyRef familyRef = FMGetATSFontFamilyRefFromFontFamily(fmFamily); QCFString cfFamilyName;; ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &cfFamilyName); familyName = cfFamilyName; } else { QCFString cfFontName; ATSFontGetName(atsFont, kATSOptionFlagsDefault, &cfFontName); familyName = cfFontName; quint16 macStyle = 0; { uchar data[4]; ByteCount len = 4; if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 44, 4, &data, &len) == noErr) macStyle = qFromBigEndian<quint16>(data); } if (macStyle & 1) styleKey.weight = QFont::Bold; if (macStyle & 2) styleKey.style = QFont::StyleItalic; } QtFontFamily *family = db->family(familyName, true); QtFontFoundry *foundry = family->foundry(QString(), true); QtFontStyle *style = foundry->style(styleKey, true); style->pixelSize(0, true); style->smoothScalable = true; initWritingSystems(family, atsFont); } FMDisposeFontIterator(&it); } } }
void XMacFontMgr::BuildFontList() { fFontFamilies.SetCount(0); //fFontNames.SetCount(0); fFontNames.clear(); /* FMFontFamilyIterator iterator; OSErr error = ::FMCreateFontFamilyIterator(NULL, NULL, kFMDefaultOptions, &iterator); if (error == noErr) { FMFontFamily family; assert(sizeof(FMFontFamily) == sizeof(sWORD)); while (::FMGetNextFontFamily(&iterator, &family) == noErr) { Str255 spFontName; if (testAssert(::FMGetFontFamilyName(family, spFontName) == noErr)) { VStr255 name; CFStringRef cfname; ATSFontFamilyRef ffref = ::ATSFontFamilyFindFromQuickDrawName(spFontName); ::ATSFontFamilyGetName(ffref, kATSOptionFlagsDefault, &cfname); //name.MAC_FromMacPString(spFontName); name.MAC_FromCFString(cfname); if(name[0] != '.' && name[0] != '%') { fFontNames.AppendString(name); fFontFamilies.AppendWord((sWORD) family); } //CFRelease(cfname); } } ::FMDisposeFontFamilyIterator(&iterator); }*/ CTFontCollectionRef FontCollection = ::CTFontCollectionCreateFromAvailableFonts(0);//kCTFontCollectionRemoveDuplicatesOption if(FontCollection) { CFArrayRef fonts = CTFontCollectionCreateMatchingFontDescriptors(FontCollection); if(fonts) { const int numFonts = CFArrayGetCount(fonts); for(int i = 0; i < numFonts; ++i) { VString vname; CTFontDescriptorRef vfont = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i); CFStringRef family_name = (CFStringRef)CTFontDescriptorCopyAttribute(vfont, kCTFontFamilyNameAttribute); if(family_name!=NULL) { vname.MAC_FromCFString(family_name); if( std::find(fFontNames.begin(), fFontNames.end(), vname) == fFontNames.end()) fFontNames.push_back(vname); } //CFRelease(family_name); } } } //fFontNames.SynchronizedSort(false, &fFontFamilies); //fFontNames.Sort(0, fFontNames.GetCount()-1); std::sort(fFontNames.begin(),fFontNames.end()); }
static void pango_core_text_family_list_faces (PangoFontFamily *family, PangoFontFace ***faces, int *n_faces) { PangoCoreTextFamily *ctfamily = PANGO_CORE_TEXT_FAMILY (family); if (ctfamily->n_faces < 0) { GList *l; GList *faces = NULL; GList *synthetic_faces = NULL; GHashTable *italic_faces; const char *real_family = get_real_family (ctfamily->family_name); CTFontCollectionRef collection; CFArrayRef ctfaces; CFArrayRef font_descriptors; CFDictionaryRef attributes; CFIndex i, count; CFTypeRef keys[] = { (CFTypeRef) kCTFontFamilyNameAttribute }; CFStringRef values[] = { CFStringCreateWithCString (kCFAllocatorDefault, real_family, kCFStringEncodingUTF8) }; CTFontDescriptorRef descriptors[1]; attributes = CFDictionaryCreate (kCFAllocatorDefault, (const void **)keys, (const void **)values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); descriptors[0] = CTFontDescriptorCreateWithAttributes (attributes); font_descriptors = CFArrayCreate (kCFAllocatorDefault, (const void **)descriptors, 1, &kCFTypeArrayCallBacks); collection = CTFontCollectionCreateWithFontDescriptors (font_descriptors, NULL); ctfaces = CTFontCollectionCreateMatchingFontDescriptors (collection); italic_faces = g_hash_table_new (g_direct_hash, g_direct_equal); count = CFArrayGetCount (ctfaces); for (i = 0; i < count; i++) { PangoCoreTextFace *face; CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i); face = pango_core_text_face_from_ct_font_descriptor (desc); face->family = ctfamily; faces = g_list_prepend (faces, face); if (face->traits & kCTFontItalicTrait || pango_core_text_face_is_oblique (face)) g_hash_table_insert (italic_faces, GINT_TO_POINTER ((gint)face->weight), face); } CFRelease (font_descriptors); CFRelease (attributes); CFRelease (ctfaces); /* For all fonts for which a non-synthetic italic variant does * not exist on the system, we create synthesized versions here. */ for (l = faces; l; l = l->next) { PangoCoreTextFace *face = l->data; if (!g_hash_table_lookup (italic_faces, GINT_TO_POINTER ((gint)face->weight))) { PangoCoreTextFace *italic_face; italic_face = g_object_new (PANGO_TYPE_CORE_TEXT_FACE, NULL); italic_face->family = ctfamily; italic_face->postscript_name = g_strdup (face->postscript_name); italic_face->weight = face->weight; italic_face->traits = face->traits | kCTFontItalicTrait; italic_face->synthetic_italic = TRUE; italic_face->coverage = pango_coverage_ref (face->coverage); /* Try to create a sensible face name. */ if (strcasecmp (face->style_name, "regular") == 0) italic_face->style_name = g_strdup ("Oblique"); else italic_face->style_name = g_strdup_printf ("%s Oblique", face->style_name); synthetic_faces = g_list_prepend (synthetic_faces, italic_face); } } faces = g_list_concat (faces, synthetic_faces); ctfamily->n_faces = g_list_length (faces); ctfamily->faces = g_new (PangoFontFace *, ctfamily->n_faces); for (l = faces, i = 0; l; l = l->next, i++) ctfamily->faces[i] = l->data; g_list_free (faces); g_hash_table_destroy (italic_faces); }