void addFontsToEnvironment() { FcInit(); // Load our configuration file, which sets up proper aliases for family // names like sans, serif and monospace. FcConfig* config = FcConfigCreate(); const char* fontConfigFilename = FONTS_CONF_DIR "/fonts.conf"; if (!FcConfigParseAndLoad(config, reinterpret_cast<const FcChar8*>(fontConfigFilename), true)) { fprintf(stderr, "Couldn't load font configuration file from: %s\n", fontConfigFilename); exit(1); } if (!addFontDirectory(DOWNLOADED_FONTS_DIR, config)) { fprintf(stderr, "None of the font directories could be added. Either install them " "or file a bug at http://bugs.webkit.org if they are installed in " "another location.\n"); exit(1); } addFontFiles(getFontFiles(), config); if (!FcConfigSetCurrent(config)) { fprintf(stderr, "Could not set the current font configuration!\n"); exit(1); } }
static void gimp_fonts_load_func (FcConfig *config) { if (! FcConfigBuildFonts (config)) FcConfigDestroy (config); else FcConfigSetCurrent (config); }
/* * Reread the configuration and available font lists */ FcBool FcInitReinitialize (void) { FcConfig *config; config = FcInitLoadConfigAndFonts (); if (!config) return FcFalse; return FcConfigSetCurrent (config); }
void gimp_fonts_reset (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); if (gimp->no_fonts) return; /* We clear the default config here, so any subsequent fontconfig use will * reinit the library with defaults. (Maybe we should call FcFini here too?) */ FcConfigSetCurrent (NULL); }
void gimp_fonts_load (Gimp *gimp) { FcConfig *config; gchar *fonts_conf; gchar *path; g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts)); gimp_set_busy (gimp); if (gimp->be_verbose) g_print ("Loading fonts\n"); gimp_container_freeze (GIMP_CONTAINER (gimp->fonts)); gimp_container_clear (GIMP_CONTAINER (gimp->fonts)); config = FcInitLoadConfig (); if (! config) goto cleanup; fonts_conf = gimp_personal_rc_file (CONF_FNAME); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; fonts_conf = g_build_filename (gimp_sysconf_directory (), CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; path = gimp_config_path_expand (gimp->config->font_path, TRUE, NULL); gimp_fonts_add_directories (config, path); g_free (path); if (! FcConfigBuildFonts (config)) { FcConfigDestroy (config); goto cleanup; } FcConfigSetCurrent (config); gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts)); cleanup: gimp_container_thaw (GIMP_CONTAINER (gimp->fonts)); gimp_unset_busy (gimp); }
void gimp_fonts_load (Gimp *gimp) { FcConfig *config; GFile *fonts_conf; GList *path; g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts)); gimp_set_busy (gimp); if (gimp->be_verbose) g_print ("Loading fonts\n"); gimp_container_freeze (GIMP_CONTAINER (gimp->fonts)); gimp_container_clear (GIMP_CONTAINER (gimp->fonts)); config = FcInitLoadConfig (); if (! config) goto cleanup; fonts_conf = gimp_directory_file (CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; fonts_conf = gimp_sysconf_directory_file (CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; path = gimp_config_path_expand_to_files (gimp->config->font_path, FALSE); gimp_fonts_add_directories (config, path); g_list_free_full (path, (GDestroyNotify) g_object_unref); if (! FcConfigBuildFonts (config)) { FcConfigDestroy (config); goto cleanup; } FcConfigSetCurrent (config); gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts)); cleanup: gimp_container_thaw (GIMP_CONTAINER (gimp->fonts)); gimp_unset_busy (gimp); }
/* * Initialize the default library configuration */ FcBool FcInit (void) { FcConfig *config; if (_fcConfig) return FcTrue; config = FcInitLoadConfigAndFonts (); if (!config) return FcTrue; FcConfigSetCurrent (config); if (FcDebug() & FC_DBG_MEMORY) FcMemReport (); return FcTrue; }
void QtTestSupport::initializeTestFonts() { QFontDatabase::removeAllApplicationFonts(); #if HAVE(FONTCONFIG) static int numFonts = -1; FcInit(); // Some test cases may add or remove application fonts (via @font-face). // Make sure to re-initialize the font set if necessary. FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication); if (appFontSet && numFonts >= 0 && appFontSet->nfont == numFonts) return; QByteArray fontDir = getenv("WEBKIT_TESTFONTS"); if (fontDir.isEmpty() || !QDir(QString::fromLatin1(fontDir)).exists()) { qFatal("\n\n" "----------------------------------------------------------------------\n" "WEBKIT_TESTFONTS environment variable is not set correctly.\n" "This variable has to point to the directory containing the fonts\n" "you can clone from git://gitorious.org/qtwebkit/testfonts.git\n" "----------------------------------------------------------------------\n" ); } QByteArray configFile = fontDir + "/fonts.conf"; FcConfig* config = FcConfigCreate(); if (!FcConfigParseAndLoad(config, reinterpret_cast<const FcChar8*>(configFile.constData()), FcTrue)) qFatal("Couldn't load font configuration file"); if (!FcConfigAppFontAddDir(config, reinterpret_cast<const FcChar8*>(fontDir.data()))) qFatal("Couldn't add font dir!"); FcConfigSetCurrent(config); appFontSet = FcConfigGetFonts(config, FcSetApplication); numFonts = appFontSet->nfont; WebCore::fontCache()->invalidate(); #endif }
void activateFonts() { #if defined(Q_WS_X11) static int numFonts = -1; // Some test cases may add or remove application fonts (via @font-face). // Make sure to re-initialize the font set if necessary. FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication); if (appFontSet && numFonts >= 0 && appFontSet->nfont == numFonts) return; QByteArray fontDir = getenv("WEBKIT_TESTFONTS"); if (fontDir.isEmpty() || !QDir(fontDir).exists()) { fprintf(stderr, "\n\n" "----------------------------------------------------------------------\n" "WEBKIT_TESTFONTS environment variable is not set correctly.\n" "This variable has to point to the directory containing the fonts\n" "you can clone from git://gitorious.org/qtwebkit/testfonts.git\n" "----------------------------------------------------------------------\n" ); exit(1); } char currentPath[PATH_MAX+1]; if (!getcwd(currentPath, PATH_MAX)) qFatal("Couldn't get current working directory"); QByteArray configFile = currentPath; FcConfig* config = FcConfigCreate(); configFile += "/WebKitTools/DumpRenderTree/qt/fonts.conf"; if (!FcConfigParseAndLoad (config, (FcChar8*) configFile.data(), true)) qFatal("Couldn't load font configuration file"); if (!FcConfigAppFontAddDir (config, (FcChar8*) fontDir.data())) qFatal("Couldn't add font dir!"); FcConfigSetCurrent(config); appFontSet = FcConfigGetFonts(config, FcSetApplication); numFonts = appFontSet->nfont; #endif }
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; }
int main (int argc, char **argv) { int i; int ret = 0; FcFontSet *fs; FcStrSet *dirs; FcStrSet *args = NULL; FcStrList *arglist; FcCache *cache; FcConfig *config; FcChar8 *arg; int verbose = 0; int recurse = 0; FcBool first = FcTrue; #if HAVE_GETOPT_LONG || HAVE_GETOPT int c; #if HAVE_GETOPT_LONG while ((c = getopt_long (argc, argv, "Vvrh", longopts, NULL)) != -1) #else while ((c = getopt (argc, argv, "Vvrh")) != -1) #endif { switch (c) { case 'V': fprintf (stderr, "fontconfig version %d.%d.%d\n", FC_MAJOR, FC_MINOR, FC_REVISION); exit (0); case 'v': verbose++; break; case 'r': recurse++; break; case 'h': usage (argv[0], 0); default: usage (argv[0], 1); } } i = optind; #else i = 1; #endif config = FcInitLoadConfig (); if (!config) { fprintf (stderr, "%s: Can't init font config library\n", argv[0]); return 1; } FcConfigSetCurrent (config); args = FcStrSetCreate (); if (!args) { fprintf (stderr, "%s: malloc failure\n", argv[0]); return 1; } if (i < argc) { for (; i < argc; i++) { if (!FcStrSetAddFilename (args, (const FcChar8 *) argv[i])) { fprintf (stderr, "%s: malloc failure\n", argv[0]); return 1; } } arglist = FcStrListCreate (args); if (!arglist) { fprintf (stderr, "%s: malloc failure\n", argv[0]); return 1; } } else { recurse++; arglist = FcConfigGetFontDirs (config); while ((arg = FcStrListNext (arglist))) if (!FcStrSetAdd (args, arg)) { fprintf (stderr, "%s: malloc failure\n", argv[0]); return 1; } FcStrListDone (arglist); } arglist = FcStrListCreate (args); if (!arglist) { fprintf (stderr, "%s: malloc failure\n", argv[0]); return 1; } while ((arg = FcStrListNext (arglist))) { int j; FcChar8 *cache_file = NULL; struct stat file_stat; if (FcFileIsDir (arg)) cache = FcDirCacheLoad (arg, config, &cache_file); else cache = FcDirCacheLoadFile (arg, &file_stat); if (!cache) { perror ((char *) arg); ret++; continue; } dirs = FcStrSetCreate (); fs = FcCacheCopySet (cache); for (j = 0; j < FcCacheNumSubdir (cache); j++) { FcStrSetAdd (dirs, FcCacheSubdir (cache, j)); if (recurse) FcStrSetAdd (args, FcCacheSubdir (cache, j)); } if (verbose) { if (!first) printf ("\n"); printf ("Directory: %s\nCache: %s\n--------\n", FcCacheDir(cache), cache_file ? cache_file : arg); first = FcFalse; } cache_print_set (fs, dirs, FcCacheDir (cache), verbose); FcStrSetDestroy (dirs); FcFontSetDestroy (fs); FcDirCacheUnload (cache); if (cache_file) FcStrFree (cache_file); } FcFini (); return 0; }
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); } }
int main (int argc, char **argv) { FcStrSet *dirs; FcStrList *list; FcBool verbose = FcFalse; FcBool force = FcFalse; FcBool really_force = FcFalse; FcBool systemOnly = FcFalse; FcConfig *config; int i; int changed; int ret; #if HAVE_GETOPT_LONG || HAVE_GETOPT int c; #if HAVE_GETOPT_LONG while ((c = getopt_long (argc, argv, "frsVvh", longopts, NULL)) != -1) #else while ((c = getopt (argc, argv, "frsVvh")) != -1) #endif { switch (c) { case 'r': really_force = FcTrue; /* fall through */ case 'f': force = FcTrue; break; case 's': systemOnly = FcTrue; break; case 'V': fprintf (stderr, "fontconfig version %d.%d.%d\n", FC_MAJOR, FC_MINOR, FC_REVISION); exit (0); case 'v': verbose = FcTrue; break; case 'h': usage (argv[0], 0); default: usage (argv[0], 1); } } i = optind; #else i = 1; #endif if (systemOnly) FcConfigEnableHome (FcFalse); config = FcInitLoadConfig (); if (!config) { fprintf (stderr, "%s: Can't init font config library\n", argv[0]); return 1; } FcConfigSetCurrent (config); if (argv[i]) { dirs = FcStrSetCreate (); if (!dirs) { fprintf (stderr, "%s: Can't create list of directories\n", argv[0]); return 1; } while (argv[i]) { if (!FcStrSetAddFilename (dirs, (FcChar8 *) argv[i])) { fprintf (stderr, "%s: Can't add directory\n", argv[0]); return 1; } i++; } list = FcStrListCreate (dirs); FcStrSetDestroy (dirs); } else list = FcConfigGetConfigDirs (config); if ((processed_dirs = FcStrSetCreate()) == NULL) { fprintf(stderr, "Cannot malloc\n"); return 1; } changed = 0; ret = scanDirs (list, config, force, really_force, verbose, &changed); /* * Try to create CACHEDIR.TAG anyway. * This expects the fontconfig cache directory already exists. * If it doesn't, it won't be simply created. */ FcCacheCreateTagFile (config); FcStrSetDestroy (processed_dirs); cleanCacheDirectories (config, verbose); /* * Now we need to sleep a second (or two, to be extra sure), to make * sure that timestamps for changes after this run of fc-cache are later * then any timestamps we wrote. We don't use gettimeofday() because * sleep(3) can't be interrupted by a signal here -- this isn't in the * library, and there aren't any signals flying around here. */ FcConfigDestroy (config); FcFini (); if (changed) sleep (2); if (verbose) printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded"); return ret; }
int main(int argc, char* argv[]) { #ifdef Q_WS_X11 FcInit(); FcConfig *config = FcConfigCreate(); QByteArray fontDir = getenv("WEBKIT_TESTFONTS"); if (fontDir.isEmpty() || !QDir(fontDir).exists()) { fprintf(stderr, "\n\n" "--------------------------------------------------------------------\n" "WEBKIT_TESTFONTS environment variable is not set correctly.\n" "This variable has to point to the directory containing the fonts\n" "you can checkout from svn://labs.trolltech.com/svn/webkit/testfonts\n" "--------------------------------------------------------------------\n" ); exit(1); } char currentPath[PATH_MAX+1]; getcwd(currentPath, PATH_MAX); QByteArray configFile = currentPath; configFile += "/WebKitTools/DumpRenderTree/qt/fonts.conf"; if (!FcConfigParseAndLoad (config, (FcChar8*) configFile.data(), true)) qFatal("Couldn't load font configuration file"); if (!FcConfigAppFontAddDir (config, (FcChar8*) fontDir.data())) qFatal("Couldn't add font dir!"); FcConfigSetCurrent(config); #endif QApplication app(argc, argv); #ifdef Q_WS_X11 QX11Info::setAppDpiY(0, 96); QX11Info::setAppDpiX(0, 96); #endif QFont f("Sans Serif"); f.setPointSize(9); f.setWeight(QFont::Normal); f.setStyle(QFont::StyleNormal); app.setFont(f); app.setStyle(QLatin1String("Plastique")); signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ signal(SIGFPE, crashHandler); /* 8: floating point exception */ signal(SIGBUS, crashHandler); /* 10: bus error */ signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ QStringList args = app.arguments(); if (args.count() < 2) { qDebug() << "Usage: DumpRenderTree [-v] filename"; exit(0); } // supress debug output from Qt if not started with -v if (!args.contains(QLatin1String("-v"))) qInstallMsgHandler(messageHandler); WebCore::DumpRenderTree dumper; if (args.last() == QLatin1String("-")) { dumper.open(); } else { if (!args.last().startsWith("/") && !args.last().startsWith("file:") && !args.last().startsWith("http:") && !args.last().startsWith("https:")) { QString path = QDir::currentPath(); if (!path.endsWith('/')) path.append('/'); args.last().prepend(path); } dumper.open(QUrl(args.last())); } return app.exec(); #ifdef Q_WS_X11 FcConfigSetCurrent(0); #endif }
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[]) { #ifdef Q_WS_X11 FcInit(); WebCore::DumpRenderTree::initializeFonts(); #if QT_VERSION >= 0x040500 QApplication::setGraphicsSystem("raster"); #endif #endif QApplication app(argc, argv); #ifdef Q_WS_X11 QX11Info::setAppDpiY(0, 96); QX11Info::setAppDpiX(0, 96); #endif QFont f("Sans Serif"); f.setPointSize(9); f.setWeight(QFont::Normal); f.setStyle(QFont::StyleNormal); app.setFont(f); app.setStyle(QLatin1String("Plastique")); signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ signal(SIGFPE, crashHandler); /* 8: floating point exception */ signal(SIGBUS, crashHandler); /* 10: bus error */ signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ QStringList args = app.arguments(); if (args.count() < 2) { qDebug() << "Usage: DumpRenderTree [-v] filename"; exit(0); } // supress debug output from Qt if not started with -v if (!args.contains(QLatin1String("-v"))) qInstallMsgHandler(messageHandler); WebCore::DumpRenderTree dumper; if (args.contains("--pixel-tests")) dumper.setDumpPixels(true); QString dbDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QDir::separator() + "qtwebkitdrt"; QWebSettings::setOfflineStoragePath(dbDir); QWebDatabase::removeAllDatabases(); if (args.last() == QLatin1String("-")) { dumper.open(); } else { if (!args.last().startsWith("/") && !args.last().startsWith("file:") && !args.last().startsWith("http:") && !args.last().startsWith("https:")) { QString path = QDir::currentPath(); if (!path.endsWith('/')) path.append('/'); args.last().prepend(path); } dumper.open(QUrl(args.last())); } return app.exec(); #ifdef Q_WS_X11 FcConfigSetCurrent(0); #endif }
int main(int argc, char* argv[]) { #ifdef Q_OS_WIN _setmode(1, _O_BINARY); _setmode(2, _O_BINARY); #endif #ifdef Q_WS_X11 FcInit(); WebCore::DumpRenderTree::initializeFonts(); #endif QApplication::setGraphicsSystem("raster"); QApplication::setStyle(new QWindowsStyle); QFont f("Sans Serif"); f.setPointSize(9); f.setWeight(QFont::Normal); f.setStyle(QFont::StyleNormal); QApplication::setFont(f); QApplication app(argc, argv); #ifdef Q_WS_X11 QX11Info::setAppDpiY(0, 96); QX11Info::setAppDpiX(0, 96); #endif #if HAVE(SIGNAL_H) signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ signal(SIGFPE, crashHandler); /* 8: floating point exception */ signal(SIGBUS, crashHandler); /* 10: bus error */ signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ #endif QStringList args = app.arguments(); if (args.count() < 2) { qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename [filename2..n]"; qDebug() << "Or folder containing test files: DumpRenderTree [-v|--pixel-tests] dirpath"; exit(0); } // Suppress debug output from Qt if not started with -v if (!args.contains(QLatin1String("-v"))) qInstallMsgHandler(messageHandler); WebCore::DumpRenderTree dumper; if (args.contains(QLatin1String("--pixel-tests"))) dumper.setDumpPixels(true); QWebDatabase::removeAllDatabases(); if (args.contains(QLatin1String("-"))) { QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection); QTimer::singleShot(0, &dumper, SLOT(readLine())); } else dumper.processArgsLine(args); return app.exec(); #ifdef Q_WS_X11 FcConfigSetCurrent(0); #endif }
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; }