void TkpGetFontFamilies( Tcl_Interp *interp, /* Interp to hold result. */ Tk_Window tkwin) /* For display to query. */ { Tcl_Obj *resultPtr; XftFontSet *list; int i; resultPtr = Tcl_NewListObj(0, NULL); list = XftListFonts(Tk_Display(tkwin), Tk_ScreenNumber(tkwin), (char*)0, /* pattern elements */ XFT_FAMILY, (char*)0); /* fields */ for (i = 0; i < list->nfont; i++) { char *family, **familyPtr = &family; if (XftPatternGetString(list->fonts[i], XFT_FAMILY, 0, familyPtr) == XftResultMatch) { Tcl_Obj *strPtr = Tcl_NewStringObj(family, -1); Tcl_ListObjAppendElement(NULL, resultPtr, strPtr); } } XftFontSetDestroy(list); Tcl_SetObjResult(interp, resultPtr); }
void JXFontManager::GetFontNames ( JPtrArray<JString>* fontNames ) const { if (itsAllFontNames != NULL) { fontNames->CopyObjects(*itsAllFontNames, fontNames->GetCleanUpAction(), kJFalse); } else { fontNames->CleanOut(); fontNames->SetCompareFunction(JCompareStringsCaseInsensitive); fontNames->SetSortOrder(JOrderedSetT::kSortAscending); #ifdef _J_USE_XFT FcBool scalable = 1; XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_SCALABLE, XftTypeBool, scalable, 0, XFT_FAMILY, 0); for (int i=0; i<fs->nfont; i++) { char* raw_name; if (XftPatternGetString(fs->fonts[i], XFT_FAMILY, 0, &raw_name) == XftResultMatch) { JString name(raw_name); JBoolean isDuplicate; const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { fontNames->InsertAtIndex(index, name); } } } XftFontSetDestroy(fs); #else int nameCount; char** nameList = XListFonts(*itsDisplay, "-*-*-*-*-*-*-*-*-75-75-*-*-*-*", INT_MAX, &nameCount); if (nameList == NULL) { return; } JString name, charSet; for (int i=0; i<nameCount; i++) { const std::string s(nameList[i], strlen(nameList[i])); std::istringstream input(s); input.ignore(); // initial dash JIgnoreUntil(input, '-'); // foundry name name = JReadUntil(input, '-'); // font name JIgnoreUntil(input, "-75-75-"); // ignore specs JIgnoreUntil(input, '-'); JIgnoreUntil(input, '-'); JReadAll(input, &charSet); // char set if (name.IsEmpty() || name == "nil") { continue; } ConvertToPSFontName(&name); // Until JPSPrinter can embed fonts in a Postscript file, we are limited // to only the standard Postscript fonts. if (name == JXGetCourierFontName() || name == JXGetHelveticaFontName() || name == JXGetSymbolFontName() || name == JXGetTimesFontName()) { // if (name != JXGetSymbolFontName()) // { // name = CombineNameAndCharacterSet(name, charSet); // } JBoolean isDuplicate; const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { fontNames->InsertAtIndex(index, name); } } } XFreeFontNames(nameList); #endif // save names for next time JXFontManager* me = const_cast<JXFontManager*>(this); me->itsAllFontNames = new JPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll, kJTrue); assert( me->itsAllFontNames != NULL ); } }
JFontStyle JXFontManager::GetFontStyles ( const JCharacter* name, const JSize size ) const { JFontStyle style(kJFalse, kJFalse, 0, kJTrue); #ifdef _J_USE_XFT double raw_size = size; XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_FAMILY, XftTypeString, name, XFT_SIZE, XftTypeDouble, raw_size, 0, XFT_SLANT, XFT_WEIGHT, 0); if (fs->nfont == 0) { return style; } for (int i=0; i<fs->nfont; i++) { int raw_slant; if (XftPatternGetInteger(fs->fonts[i], XFT_SLANT, 0, &raw_slant) == XftResultMatch) { if (raw_slant == XFT_SLANT_ITALIC) style.italic = kJTrue; } int raw_weight; if (XftPatternGetInteger(fs->fonts[i], XFT_WEIGHT, 0, &raw_weight) == XftResultMatch) { if (raw_weight == XFT_WEIGHT_BOLD) style.bold = kJTrue; } } XftFontSetDestroy(fs); #else JString xFontName, charSet; if (!ConvertToXFontName(name, &xFontName, &charSet)) { charSet = "*-*"; } const JString regexStr = "-*-" + xFontName + "-*-*-*-*-*-" + JString(10*size, 0, JString::kForceNoExponent) + "-75-75-*-*-" + charSet; int nameCount; char** nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount); if (nameList == NULL) { return style; } JString weight, slant; for (int i=0; i<nameCount; i++) { const std::string s(nameList[i], strlen(nameList[i])); std::istringstream input(s); input.ignore(); // initial dash JIgnoreUntil(input, '-'); // foundry name JIgnoreUntil(input, '-'); // font name weight = JReadUntil(input, '-'); // medium/bold slant = JReadUntil(input, '-'); // roman/oblique/italic if (weight == "bold") { style.bold = kJTrue; } if (slant == "o" || slant == "i") { style.italic = kJTrue; } } XFreeFontNames(nameList); #endif return style; }
JBoolean JXFontManager::GetFontSizes ( const JCharacter* name, JSize* minSize, JSize* maxSize, JArray<JSize>* sizeList ) const { *minSize = *maxSize = 0; sizeList->RemoveAll(); sizeList->SetCompareFunction(JCompareSizes); sizeList->SetSortOrder(JOrderedSetT::kSortAscending); #ifdef _J_USE_XFT XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_FAMILY, XftTypeString, name, 0, XFT_SIZE, 0); if (fs->nfont == 0) { *minSize = 8; *maxSize = 24; XftFontSetDestroy(fs); return kJTrue; } for (int i=0; i<fs->nfont; i++) { double raw_size; if (XftPatternGetDouble(fs->fonts[i], XFT_SIZE, 0, &raw_size) == XftResultMatch) { JSize fontSize = static_cast<JSize>(raw_size); if (sizeList->IsEmpty()) { *minSize = *maxSize = fontSize; } JBoolean isDuplicate; const JIndex index = sizeList->GetInsertionSortIndex(fontSize, &isDuplicate); if (!isDuplicate) { sizeList->InsertElementAtIndex(index, fontSize); if (fontSize < *minSize) { *minSize = fontSize; } else if (fontSize > *maxSize) { *maxSize = fontSize; } } } } // Look for scalable if ((*minSize == 0) && (*maxSize == 0)) { *minSize = 8; *maxSize = 24; XftFontSetDestroy(fs); return kJTrue; } XftFontSetDestroy(fs); #else JString xFontName, charSet; if (!ConvertToXFontName(name, &xFontName, &charSet)) { charSet = "*-*"; } // check for rescalable font JString regexStr = "-*-" + xFontName + "-*-*-*-*-*-0-75-75-*-*-" + charSet; int nameCount; char** nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount); if (nameList != NULL) { *minSize = 8; *maxSize = 24; XFreeFontNames(nameList); return kJTrue; } // get list of available sizes regexStr = "-*-" + xFontName + "-*-*-*-*-*-*-75-75-*-*-" + charSet; nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount); if (nameList == NULL) { return kJFalse; } JSize fontSize; for (int i=0; i<nameCount; i++) { const std::string s(nameList[i], strlen(nameList[i])); std::istringstream input(s); input.ignore(); // initial dash JIgnoreUntil(input, '-'); // foundry name JIgnoreUntil(input, '-'); // font name JIgnoreUntil(input, '-'); // medium/bold JIgnoreUntil(input, '-'); // roman/oblique/italic JIgnoreUntil(input, '-'); // character spacing input.ignore(); // extra dash JIgnoreUntil(input, '-'); // pixel height input >> fontSize; // 10*(point size) if (fontSize < 10) { continue; // we already checked for rescalable version } fontSize /= 10; if (sizeList->IsEmpty()) { *minSize = *maxSize = fontSize; } JBoolean isDuplicate; const JIndex index = sizeList->GetInsertionSortIndex(fontSize, &isDuplicate); if (!isDuplicate) { sizeList->InsertElementAtIndex(index, fontSize); if (fontSize < *minSize) { *minSize = fontSize; } else if (fontSize > *maxSize) { *maxSize = fontSize; } } } XFreeFontNames(nameList); #endif return JNegate( sizeList->IsEmpty() ); }
void JXFontManager::GetMonospaceFontNames ( JPtrArray<JString>* fontNames ) const { if (itsMonoFontNames != NULL) { fontNames->CopyObjects(*itsMonoFontNames, fontNames->GetCleanUpAction(), kJFalse); } else { (JXGetApplication())->DisplayBusyCursor(); fontNames->CleanOut(); fontNames->SetCompareFunction(JCompareStringsCaseInsensitive); fontNames->SetSortOrder(JOrderedSetT::kSortAscending); #ifdef _J_USE_XFT FcBool scalable = 1; XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_SPACING, XftTypeInteger, XFT_MONO, XFT_SCALABLE, XftTypeBool, scalable, 0, XFT_FAMILY, 0); for (int i=0; i<fs->nfont; i++) { char* raw_name; if (XftPatternGetString(fs->fonts[i], XFT_FAMILY, 0, &raw_name) == XftResultMatch) { JString name(raw_name); JBoolean isDuplicate; const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { fontNames->InsertAtIndex(index, name); } } } XftFontSetDestroy(fs); #else JPtrArray<JString> allFontNames(JPtrArrayT::kDeleteAll); allFontNames.SetCompareFunction(JCompareStringsCaseInsensitive); allFontNames.SetSortOrder(JOrderedSetT::kSortAscending); for (int j=0; j<kMonospaceFontPatternCount; j++) { int nameCount; char** nameList = XListFonts(*itsDisplay, kMonospaceFontPattern[j], INT_MAX, &nameCount); if (nameList == NULL) { return; } JString name, charSet; for (int i=0; i<nameCount; i++) { const std::string s(nameList[i], strlen(nameList[i])); std::istringstream input(s); input.ignore(); // initial dash JIgnoreUntil(input, '-'); // foundry name name = JReadUntil(input, '-'); // font name JIgnoreUntil(input, "-iso"); // ignore specs JReadAll(input, &charSet); // char set if (name.IsEmpty() || name == "nil") { continue; } ConvertToPSFontName(&name); #if ! QUERY_FOR_MONOSPACE if (name == "Clean" || name == "Courier" || name == "Fixed" || name == "Terminal" || name == "Lucidatypewriter" || name == "Profontwindows") { #endif // charSet.Prepend("iso"); // name = CombineNameAndCharacterSet(name, charSet); JBoolean isDuplicate; const JIndex index = allFontNames.GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { allFontNames.InsertAtIndex(index, name); // cout << nameList[i] << endl; XFontStruct* xfont = XLoadQueryFont(*itsDisplay, nameList[i]); if (xfont != NULL) { if (IsMonospace(*xfont)) { JString* n = new JString(name); assert( n != NULL ); const JBoolean ok = fontNames->InsertSorted(n, kJFalse); assert( ok ); } XFreeFont(*itsDisplay, xfont); } } #if ! QUERY_FOR_MONOSPACE } #endif } XFreeFontNames(nameList); } #endif // save names for next time JXFontManager* me = const_cast<JXFontManager*>(this); me->itsMonoFontNames = new JPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll, kJTrue); assert( me->itsMonoFontNames != NULL ); } }
void JXFontManager::GetMonospaceFontNames ( JPtrArray<JString>* fontNames ) const { if (itsMonoFontNames != NULL) { fontNames->CopyObjects(*itsMonoFontNames, fontNames->GetCleanUpAction(), kJFalse); } else { (JXGetApplication())->DisplayBusyCursor(); fontNames->CleanOut(); fontNames->SetCompareFunction(JCompareStringsCaseInsensitive); fontNames->SetSortOrder(JOrderedSetT::kSortAscending); JPtrArray<JString> allFontNames(JPtrArrayT::kDeleteAll); allFontNames.SetCompareFunction(JCompareStringsCaseInsensitive); allFontNames.SetSortOrder(JOrderedSetT::kSortAscending); JString name; #if ENABLE_TRUE_TYPE FcFontSet* set = XftListFonts(*itsDisplay, itsDisplay->GetScreen(), FC_SPACING, FcTypeInteger, FC_MONO, NULL, FC_FAMILY, NULL); for (int i=0; i < set->nfont; i++) { FcChar8* s = FcNameUnparse(set->fonts[i]); name.Set((JCharacter*) s); // cout << "tt mono: " << name << endl; #if ONLY_STD_MONOSPACE if (!name.BeginsWith("Courier") && !name.BeginsWith("Consolas") && !name.Contains(" Mono") && name != "LucidaTypewriter") { FcStrFree(s); continue; } #endif if (IsUseless(name)) { FcStrFree(s); continue; } JBoolean isDuplicate; const JIndex index = allFontNames.GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { allFontNames.InsertAtIndex(index, name); JString* n = new JString(name); assert( n != NULL ); const JBoolean ok = fontNames->InsertSorted(n, kJFalse); assert( ok ); } FcStrFree(s); } FcFontSetDestroy(set); #else for (int j=0; j<kMonospaceFontPatternCount; j++) { int nameCount; char** nameList = XListFonts(*itsDisplay, kMonospaceFontPattern[j], INT_MAX, &nameCount); if (nameList == NULL) { return; } for (int i=0; i<nameCount; i++) { const std::string s(nameList[i], strlen(nameList[i])); std::istringstream input(s); input.ignore(); // initial dash JIgnoreUntil(input, '-'); // foundry name name = JReadUntil(input, '-'); // font name if (name.IsEmpty() || name == "nil") { continue; } ConvertToPSFontName(&name); // cout << "std mono: " << name << endl; #if ONLY_STD_MONOSPACE if (name != "Clean" && name != "Fixed" && name != "Terminal" && name != "Courier" && name != "Lucidatypewriter" && name != "Profontwindows") { continue; } #endif if (IsUseless(name)) { continue; } JBoolean isDuplicate; const JIndex index = allFontNames.GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { allFontNames.InsertAtIndex(index, name); XFontStruct* xfont = XLoadQueryFont(*itsDisplay, nameList[i]); if (xfont != NULL) { if (xfont->min_bounds.width == xfont->max_bounds.width) { JString* n = new JString(name); assert( n != NULL ); const JBoolean ok = fontNames->InsertSorted(n, kJFalse); assert( ok ); } XFreeFont(*itsDisplay, xfont); } } } XFreeFontNames(nameList); } #endif // save names for next time itsMonoFontNames = new JDCCPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll); assert( itsMonoFontNames != NULL ); } }
void JXFontManager::GetFontNames ( JPtrArray<JString>* fontNames ) const { if (itsAllFontNames != NULL) { fontNames->CopyObjects(*itsAllFontNames, fontNames->GetCleanUpAction(), kJFalse); } else { fontNames->CleanOut(); fontNames->SetCompareFunction(JCompareStringsCaseInsensitive); fontNames->SetSortOrder(JOrderedSetT::kSortAscending); JString name; #if ENABLE_TRUE_TYPE FcFontSet* set = XftListFonts(*itsDisplay, itsDisplay->GetScreen(), NULL, FC_FAMILY, NULL); for (int i=0; i < set->nfont; i++) { FcChar8* s = FcNameUnparse(set->fonts[i]); name.Set((JCharacter*) s); // cout << "tt font: " << name << endl; if (!IsPostscript(name) || IsUseless(name)) { FcStrFree(s); continue; } JBoolean isDuplicate; const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { fontNames->InsertAtIndex(index, name); } FcStrFree(s); } FcFontSetDestroy(set); #endif int nameCount; char** nameList = XListFonts(*itsDisplay, "-*-*-medium-r-normal-*-*-*-75-75-*-*-*-*", INT_MAX, &nameCount); if (nameList == NULL) { return; } for (int i=0; i<nameCount; i++) { const std::string s(nameList[i], strlen(nameList[i])); std::istringstream input(s); input.ignore(); // initial dash JIgnoreUntil(input, '-'); // foundry name name = JReadUntil(input, '-'); // font name if (name.IsEmpty() || name == "nil") { continue; } ConvertToPSFontName(&name); // cout << "std font: " << name << endl; if (!IsPostscript(name) || IsUseless(name)) { continue; } JBoolean isDuplicate; const JIndex index = fontNames->GetInsertionSortIndex(&name, &isDuplicate); if (!isDuplicate) { fontNames->InsertAtIndex(index, name); } } XFreeFontNames(nameList); // save names for next time itsAllFontNames = new JDCCPtrArray<JString>(*fontNames, JPtrArrayT::kDeleteAll); assert( itsAllFontNames != NULL ); } }
static void nr_type_xft_init (void) { XftFontSet *fs; const char *debugenv; int debug, ret; int i, pos, fpos; debugenv = getenv ("INKSCAPE_DEBUG_XFT"); debug = (debugenv && *debugenv && (*debugenv != '0')); ret = XftInit (NULL); if (debug) { fprintf (stderr, "XftInit result %d\n", ret); fprintf (stderr, "Reading Xft font database...\n"); } /* Get family list */ fs = XftListFonts (GDK_DISPLAY (), 0, XFT_SCALABLE, XftTypeBool, 1, XFT_OUTLINE, XftTypeBool, 1, 0, XFT_FAMILY, 0); NRXftFamilies.length = fs->nfont; NRXftFamilies.names = nr_new (gchar *, NRXftFamilies.length); NRXftFamilies.destructor = NULL; XftFontSetDestroy (fs); if (debug) { fprintf (stderr, "Read %lu families\n", NRXftFamilies.length); } /* Get typeface list */ NRXftPatterns = XftListFonts (GDK_DISPLAY (), 0, XFT_SCALABLE, XftTypeBool, 1, XFT_OUTLINE, XftTypeBool, 1, 0, XFT_FAMILY, XFT_WEIGHT, XFT_SLANT, XFT_FILE, XFT_INDEX, 0); NRXftTypefaces.length = NRXftPatterns->nfont; NRXftTypefaces.names = nr_new (gchar *, NRXftTypefaces.length); NRXftTypefaces.destructor = NULL; NRXftNamedict = g_hash_table_new (g_str_hash, g_str_equal); NRXftFamilydict = g_hash_table_new (g_str_hash, g_str_equal); if (debug) { fprintf (stderr, "Read %lu fonts\n", NRXftTypefaces.length); } pos = 0; fpos = 0; for (i = 0; i < NRXftPatterns->nfont; i++) { char *name, *file; XftPatternGetString (NRXftPatterns->fonts[i], XFT_FAMILY, 0, &name); if (debug) { fprintf (stderr, "Typeface %s\n", name); } XftPatternGetString (NRXftPatterns->fonts[i], XFT_FILE, 0, &file); if (file) { int len; if (debug) { fprintf (stderr, "Got filename %s\n", file); } len = strlen (file); /* fixme: This is silly and evil */ /* But Freetype just does not load pfa reliably (Lauris) */ /* Changed to exclude pfa, better for OSX */ if ((len > 4) && /* (!strcmp (file + len - 4, ".ttf") || !strcmp (file + len - 4, ".TTF") || !strcmp (file + len - 4, ".ttc") || !strcmp (file + len - 4, ".TTC") || !strcmp (file + len - 4, ".otf") || !strcmp (file + len - 4, ".OTF") || !strcmp (file + len - 4, ".pfb") || !strcmp (file + len - 4, ".PFB"))) { */ strcmp (file + len - 4, ".pfa") && strcmp (file + len - 4, ".PFA")) { char *fn, *wn, *sn, *name; int weight; int slant; if (debug) { fprintf (stderr, "Seems valid\n"); } XftPatternGetString (NRXftPatterns->fonts[i], XFT_FAMILY, 0, &fn); XftPatternGetInteger (NRXftPatterns->fonts[i], XFT_WEIGHT, 0, &weight); XftPatternGetInteger (NRXftPatterns->fonts[i], XFT_SLANT, 0, &slant); switch (weight) { case XFT_WEIGHT_LIGHT: wn = "Light"; break; case XFT_WEIGHT_MEDIUM: wn = "Book"; break; case XFT_WEIGHT_DEMIBOLD: wn = "Demibold"; break; case XFT_WEIGHT_BOLD: wn = "Bold"; break; case XFT_WEIGHT_BLACK: wn = "Black"; break; default: wn = "Normal"; break; } switch (slant) { case XFT_SLANT_ROMAN: sn = "Roman"; break; case XFT_SLANT_ITALIC: sn = "Italic"; break; case XFT_SLANT_OBLIQUE: sn = "Oblique"; break; default: sn = "Normal"; break; } name = g_strdup_printf ("%s %s %s", fn, wn, sn); if (!g_hash_table_lookup (NRXftNamedict, name)) { if (!g_hash_table_lookup (NRXftFamilydict, fn)) { NRXftFamilies.names[fpos] = g_strdup (fn); g_hash_table_insert (NRXftFamilydict, NRXftFamilies.names[fpos++], (void *) TRUE); } NRXftTypefaces.names[pos++] = name; g_hash_table_insert (NRXftNamedict, name, NRXftPatterns->fonts[i]); } else { g_free (name); } } } } NRXftTypefaces.length = pos; NRXftFamilies.length = fpos; nrxfti = TRUE; }