VALUE shoes_load_font(const char *filename) { FcConfig *fc = FcConfigGetCurrent(); FcFontSet *fonts = FcFontSetCreate(); if (!FcFileScan(fonts, NULL, NULL, NULL, (const FcChar8 *)filename, FcTrue)) return Qnil; VALUE ary = rb_ary_new(); shoes_make_font_list(fonts, ary); FcFontSetDestroy(fonts); if (!FcConfigAppFontAddFile(fc, (const FcChar8 *)filename)) return Qnil; // refresh the FONTS list shoes_update_fonts(shoes_font_list()); return ary; }
/** \brief Try to register the CBM font with the OS * * This tries to use fontconfig on Unix, and uses GDI on windows. * * \return bool as int */ int archdep_register_cbmfont(void) { FcConfig *fc_config; char *datadir; char *path; if (!FcInit()) { return 0; } fc_config = FcConfigGetCurrent(); datadir = archdep_get_vice_datadir(); path = archdep_join_paths(datadir, "..", "fonts", "CBM.ttf", NULL); lib_free(datadir); if (!FcConfigAppFontAddFile(fc_config, (FcChar8 *)path)) { lib_free(path); return 0; } lib_free(path); return 1; }
static void setupFontconfig() { // We wish to make the layout tests reproducable with respect to fonts. Skia // uses fontconfig to resolve font family names from WebKit into actual font // files found on the current system. This means that fonts vary based on the // system and also on the fontconfig configuration. // // To avoid this we initialise fontconfig here and install a configuration // which only knows about a few, select, fonts. // We have fontconfig parse a config file from our resources file. This // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any // font directories. FcInit(); char drtPath[PATH_MAX + 1]; int drtPathSize = readlink("/proc/self/exe", drtPath, PATH_MAX); if (drtPathSize < 0 || drtPathSize > PATH_MAX) { fputs("Unable to resolve /proc/self/exe.", stderr); exit(1); } drtPath[drtPathSize] = 0; std::string drtDirPath(drtPath); size_t lastPathPos = drtDirPath.rfind("/"); ASSERT(lastPathPos != std::string::npos); drtDirPath.erase(lastPathPos + 1); FcConfig* fontcfg = FcConfigCreate(); std::string fontconfigPath = drtDirPath + "fonts.conf"; if (!FcConfigParseAndLoad(fontcfg, reinterpret_cast<const FcChar8*>(fontconfigPath.c_str()), true)) { fputs("Failed to parse fontconfig config file\n", stderr); exit(1); } // This is the list of fonts that fontconfig will know about. It // will try its best to match based only on the fonts here in. The // paths are where these fonts are found on our Ubuntu boxes. static const char *const fonts[] = { "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf", "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf", "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf", "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf", "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf", "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf", "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf", "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf", "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf", "/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf", "/usr/share/fonts/truetype/thai/Garuda.ttf", // The DejaVuSans font is used by the css2.1 tests. "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf", "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf", "/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf", }; for (size_t i = 0; i < arraysize(fonts); ++i) { if (access(fonts[i], R_OK)) { fprintf(stderr, "You are missing %s. Try re-running build/install-build-deps.sh. Also see " "http://code.google.com/p/chromium/wiki/LayoutTestsLinux", fonts[i]); exit(1); } if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) fonts[i])) { fprintf(stderr, "Failed to load font %s\n", fonts[i]); exit(1); } } // We special case these fonts because they're only needed in a // few layout tests. static const char* const optionalFonts[] = { "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf", }; for (size_t i = 0; i < arraysize(optionalFonts); ++i) { const char* font = optionalFonts[i]; // This font changed paths across Ubuntu releases, so try checking in both locations. if (!strcmp(font, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf") && access(font, R_OK) < 0) font = "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf"; if (access(font, R_OK) < 0) { fprintf(stderr, "You are missing %s. Without this, some layout tests may fail. " "See http://code.google.com/p/chromium/wiki/LayoutTestsLinux " "for more.\n", font); } else if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) font)) { fprintf(stderr, "Failed to load font %s\n", font); exit(1); } } // Also load the layout-test-specific "Ahem" font. std::string ahemPath = drtDirPath + "AHEM____.TTF"; if (!FcConfigAppFontAddFile(fontcfg, reinterpret_cast<const FcChar8*>(ahemPath.c_str()))) { fprintf(stderr, "Failed to load font %s\n", ahemPath.c_str()); exit(1); } if (!FcConfigSetCurrent(fontcfg)) { fputs("Failed to set the default font configuration\n", stderr); exit(1); } }
void initializeFontConfigSetting() { if (g_getenv("WEBKIT_SKIP_WEBKITTESTRUNNER_FONTCONFIG_INITIALIZATION")) return; FcInit(); // If a test resulted a font being added or removed via the @font-face rule, then // we want to reset the FontConfig configuration to prevent it from affecting other tests. static int numFonts = 0; FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication); if (appFontSet && numFonts && appFontSet->nfont == numFonts) return; // Load our configuration file, which sets up proper aliases for family // names like sans, serif and monospace. FcConfig* config = FcConfigCreate(); GUniquePtr<gchar> fontConfigFilename(g_build_filename(FONTS_CONF_DIR, "fonts.conf", nullptr)); if (!g_file_test(fontConfigFilename.get(), G_FILE_TEST_IS_REGULAR)) g_error("Cannot find fonts.conf at %s\n", fontConfigFilename.get()); if (!FcConfigParseAndLoad(config, reinterpret_cast<FcChar8*>(fontConfigFilename.get()), true)) g_error("Couldn't load font configuration file from: %s", fontConfigFilename.get()); CString fontsPath = getFontsPath(); if (fontsPath.isNull()) g_error("Could not locate test fonts at %s. Is WEBKIT_TOP_LEVEL set?", fontsPath.data()); GUniquePtr<GDir> fontsDirectory(g_dir_open(fontsPath.data(), 0, nullptr)); while (const char* directoryEntry = g_dir_read_name(fontsDirectory.get())) { if (!g_str_has_suffix(directoryEntry, ".ttf") && !g_str_has_suffix(directoryEntry, ".otf")) continue; GUniquePtr<gchar> fontPath(g_build_filename(fontsPath.data(), directoryEntry, nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(fontPath.get()))) g_error("Could not load font at %s!", fontPath.get()); } // Ahem is used by many layout tests. GUniquePtr<gchar> ahemFontFilename(g_build_filename(FONTS_CONF_DIR, "AHEM____.TTF", nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(ahemFontFilename.get()))) g_error("Could not load font at %s!", ahemFontFilename.get()); static const char* fontFilenames[] = { "WebKitWeightWatcher100.ttf", "WebKitWeightWatcher200.ttf", "WebKitWeightWatcher300.ttf", "WebKitWeightWatcher400.ttf", "WebKitWeightWatcher500.ttf", "WebKitWeightWatcher600.ttf", "WebKitWeightWatcher700.ttf", "WebKitWeightWatcher800.ttf", "WebKitWeightWatcher900.ttf", 0 }; for (size_t i = 0; fontFilenames[i]; ++i) { GUniquePtr<gchar> fontFilename(g_build_filename(FONTS_CONF_DIR, "..", "..", "fonts", fontFilenames[i], nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontFilename.get()))) g_error("Could not load font at %s!", fontFilename.get()); } // A font with no valid Fontconfig encoding to test https://bugs.webkit.org/show_bug.cgi?id=47452 GUniquePtr<gchar> fontWithNoValidEncodingFilename(g_build_filename(FONTS_CONF_DIR, "FontWithNoValidEncoding.fon", nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontWithNoValidEncodingFilename.get()))) g_error("Could not load font at %s!", fontWithNoValidEncodingFilename.get()); if (!FcConfigSetCurrent(config)) g_error("Could not set the current font configuration!"); numFonts = FcConfigGetFonts(config, FcSetApplication)->nfont; }
int main(int argc, char** argv) { cairo_t *cr; cairo_status_t status; cairo_surface_t *surface; //FT_Bitmap bmp = {0}; int stride = 0; int width = 640; int height = 480; bool ok = FcConfigAppFontAddFile(NULL, (FcChar8*)"fonts/ComicSansAfrica.ttf"); if (!ok) { printf("Failed to load ComicSansAfrica.ttf\n"); } FcChar8 *configName = FcConfigFilename(NULL); printf("%s", (const char*)configName); printf("\n"); FcConfig* config = FcConfigCreate(); FcConfigParseAndLoad(config, configName, true); FcConfigSetCurrent(config); /* FT buffer */ //FT_Bitmap_New(&bmp); //bmp.rows = height; //bmp.width = width; //bmp.buffer = (unsigned char*)malloc(bmp.rows * bmp.width * 4); // if (NULL == bmp.buffer) // { // printf("+ error: cannot allocate the buffer for the output bitmap.\n"); // exit(EXIT_FAILURE); // } //bmp.pitch = ((width+3) & -4) * 4; //bmp.pixel_mode = FT_PIXEL_MODE_BGRA; //printf("%d\n", bmp.pitch); //stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); //printf("%d\n", stride); //surface = cairo_image_surface_create_for_data(bmp.buffer, CAIRO_FORMAT_ARGB32, width, height, stride); surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); if (CAIRO_STATUS_SUCCESS != cairo_surface_status(surface)) { printf("+ error: couldn't create the surface.\n"); exit(EXIT_FAILURE); } cr = cairo_create(surface); if (CAIRO_STATUS_NO_MEMORY == cairo_status(cr)) { printf("+ error: out of memory, cannot create cairo_t*\n"); exit(EXIT_FAILURE); } cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_paint(cr); rendertext(cr); status = cairo_surface_write_to_png(surface, "out.png"); cairo_surface_destroy(surface); cairo_destroy(cr); return 0; }
void inititializeFontConfigSetting() { FcInit(); // If a test resulted a font being added or removed via the @font-face rule, then // we want to reset the FontConfig configuration to prevent it from affecting other tests. static int numFonts = 0; FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication); if (appFontSet && numFonts && appFontSet->nfont == numFonts) return; // Load our configuration file, which sets up proper aliases for family // names like sans, serif and monospace. FcConfig* config = FcConfigCreate(); GOwnPtr<gchar> fontConfigFilename(g_build_filename(FONTS_CONF_DIR, "fonts.conf", NULL)); if (!g_file_test(fontConfigFilename.get(), G_FILE_TEST_IS_REGULAR)) g_error("Cannot find fonts.conf at %s\n", fontConfigFilename.get()); if (!FcConfigParseAndLoad(config, reinterpret_cast<FcChar8*>(fontConfigFilename.get()), true)) g_error("Couldn't load font configuration file from: %s", fontConfigFilename.get()); static const char *const fontDirectories[] = { "/usr/share/fonts/truetype/liberation", "/usr/share/fonts/truetype/ttf-liberation", "/usr/share/fonts/liberation", "/usr/share/fonts/truetype/ttf-dejavu", "/usr/share/fonts/dejavu", "/usr/share/fonts/opentype/stix", "/usr/share/fonts/stix" }; static const char *const fontPaths[] = { "LiberationMono-BoldItalic.ttf", "LiberationMono-Bold.ttf", "LiberationMono-Italic.ttf", "LiberationMono-Regular.ttf", "LiberationSans-BoldItalic.ttf", "LiberationSans-Bold.ttf", "LiberationSans-Italic.ttf", "LiberationSans-Regular.ttf", "LiberationSerif-BoldItalic.ttf", "LiberationSerif-Bold.ttf", "LiberationSerif-Italic.ttf", "LiberationSerif-Regular.ttf", "DejaVuSans.ttf", "DejaVuSerif.ttf", // MathML tests require the STIX fonts. "STIXGeneral.otf", "STIXGeneralBolIta.otf", "STIXGeneralBol.otf", "STIXGeneralItalic.otf" }; // TODO: Some tests use Lucida. We should load these as well, once it becomes // clear how to install these fonts easily on Fedora. for (size_t font = 0; font < G_N_ELEMENTS(fontPaths); font++) { bool found = false; for (size_t path = 0; path < G_N_ELEMENTS(fontDirectories); path++) { GOwnPtr<gchar> fullPath(g_build_filename(fontDirectories[path], fontPaths[font], NULL)); if (g_file_test(fullPath.get(), G_FILE_TEST_EXISTS)) { found = true; if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(fullPath.get()))) g_error("Could not load font at %s!", fullPath.get()); else break; } } if (!found) { GOwnPtr<gchar> directoriesDescription; for (size_t path = 0; path < G_N_ELEMENTS(fontDirectories); path++) directoriesDescription.set(g_strjoin(":", directoriesDescription.release(), fontDirectories[path], NULL)); g_error("Could not find font %s in %s. Either install this font or file a bug " "at http://bugs.webkit.org if it is installed in another location.", fontPaths[font], directoriesDescription.get()); } } // Ahem is used by many layout tests. GOwnPtr<gchar> ahemFontFilename(g_build_filename(FONTS_CONF_DIR, "AHEM____.TTF", NULL)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(ahemFontFilename.get()))) g_error("Could not load font at %s!", ahemFontFilename.get()); static const char* fontFilenames[] = { "WebKitWeightWatcher100.ttf", "WebKitWeightWatcher200.ttf", "WebKitWeightWatcher300.ttf", "WebKitWeightWatcher400.ttf", "WebKitWeightWatcher500.ttf", "WebKitWeightWatcher600.ttf", "WebKitWeightWatcher700.ttf", "WebKitWeightWatcher800.ttf", "WebKitWeightWatcher900.ttf", 0 }; for (size_t i = 0; fontFilenames[i]; ++i) { GOwnPtr<gchar> fontFilename(g_build_filename(FONTS_CONF_DIR, "..", "..", "fonts", fontFilenames[i], NULL)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontFilename.get()))) g_error("Could not load font at %s!", fontFilename.get()); } // A font with no valid Fontconfig encoding to test https://bugs.webkit.org/show_bug.cgi?id=47452 GOwnPtr<gchar> fontWithNoValidEncodingFilename(g_build_filename(FONTS_CONF_DIR, "FontWithNoValidEncoding.fon", NULL)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontWithNoValidEncodingFilename.get()))) g_error("Could not load font at %s!", fontWithNoValidEncodingFilename.get()); if (!FcConfigSetCurrent(config)) g_error("Could not set the current font configuration!"); numFonts = FcConfigGetFonts(config, FcSetApplication)->nfont; }