Changeset 128292 in webkit


Ignore:
Timestamp:
Sep 12, 2012 4:52:24 AM (12 years ago)
Author:
kenneth@webkit.org
Message:

[EFL] Make DumpRenderTree smarter at finding the fonts
http://webkit.org/b/96281

Reviewed by Gyuyoung Kim.

Respect WEBKITOUTPUTDIR and expand the font dir from it.
Use CString consistently.

  • DumpRenderTree/efl/FontManagement.cpp:

(buildPath):
(getCoreFontFiles):
(addFontDirectory):
(addFontFiles):
(getCustomBuildDir):
(getPlatformFontsPath):
(addFontsToEnvironment):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r128280 r128292  
     12012-09-12  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        [EFL] Make DumpRenderTree smarter at finding the fonts
     4        http://webkit.org/b/96281
     5
     6        Reviewed by Gyuyoung Kim.
     7
     8        Respect WEBKITOUTPUTDIR and expand the font dir from it.
     9        Use CString consistently.
     10
     11        * DumpRenderTree/efl/FontManagement.cpp:
     12        (buildPath):
     13        (getCoreFontFiles):
     14        (addFontDirectory):
     15        (addFontFiles):
     16        (getCustomBuildDir):
     17        (getPlatformFontsPath):
     18        (addFontsToEnvironment):
     19
    1202012-09-12  Christophe Dumez  <christophe.dumez@intel.com>
    221
  • trunk/Tools/DumpRenderTree/efl/FontManagement.cpp

    r111598 r128292  
    22 * Copyright (C) 2011 ProFUSION Embedded Systems
    33 * Copyright (C) 2011 Samsung Electronics
     4 * Copyright (C) 2012 Intel Corporation. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3233#include <wtf/Vector.h>
    3334#include <wtf/text/CString.h>
    34 #include <wtf/text/WTFString.h>
     35#include <wtf/text/StringBuilder.h>
    3536
    36 static Vector<String> getFontFiles()
     37static CString buildPath(const char* base, const char* first, ...)
    3738{
    38     Vector<String> fontFilePaths;
     39    va_list ap;
     40    StringBuilder result;
     41    result.append(base);
     42
     43    if (const char* current = first) {
     44        va_start(ap, first);
     45        do {
     46            result.append('/');
     47            result.append(current);
     48        } while ((current = va_arg(ap, const char*)));
     49        va_end(ap);
     50    }
     51
     52    return result.toString().utf8();
     53}
     54
     55static Vector<CString> getCoreFontFiles()
     56{
     57    Vector<CString> fontFilePaths;
    3958
    4059    // Ahem is used by many layout tests.
    41     fontFilePaths.append(String(FONTS_CONF_DIR "/AHEM____.TTF"));
     60    fontFilePaths.append(CString(FONTS_CONF_DIR "/AHEM____.TTF"));
    4261    // A font with no valid Fontconfig encoding to test https://bugs.webkit.org/show_bug.cgi?id=47452
    43     fontFilePaths.append(String(FONTS_CONF_DIR "/FontWithNoValidEncoding.fon"));
     62    fontFilePaths.append(CString(FONTS_CONF_DIR "/FontWithNoValidEncoding.fon"));
    4463
    4564    for (int i = 1; i <= 9; i++) {
    46         char fontPath[PATH_MAX];
    47         snprintf(fontPath, PATH_MAX - 1,
    48                  FONTS_CONF_DIR "/../../fonts/WebKitWeightWatcher%i00.ttf", i);
    49 
    50         fontFilePaths.append(String(fontPath));
     65        char fontPath[EINA_PATH_MAX];
     66        snprintf(fontPath, EINA_PATH_MAX - 1, FONTS_CONF_DIR "/../../fonts/WebKitWeightWatcher%i00.ttf", i);
     67        fontFilePaths.append(CString(fontPath));
    5168    }
    5269
     
    5471}
    5572
    56 static bool addFontDirectory(const CString& fontDirectory, FcConfig* config)
     73static void addFontDirectory(const CString& fontDirectory, FcConfig* config)
    5774{
    58     const char* path = fontDirectory.data();
    59 
    60     if (!ecore_file_is_dir(path)
    61         || !FcConfigAppFontAddDir(config, reinterpret_cast<const FcChar8*>(path))) {
    62         fprintf(stderr, "Could not add font directory %s!\n", path);
    63         return false;
    64     }
    65     return true;
     75    const char* fontPath = fontDirectory.data();
     76    if (!fontPath || !FcConfigAppFontAddDir(config, reinterpret_cast<const FcChar8*>(fontPath)))
     77        fprintf(stderr, "Could not add font directory %s!\n", fontPath);
    6678}
    6779
    68 static void addFontFiles(const Vector<String>& fontFiles, FcConfig* config)
     80static void addFontFiles(const Vector<CString>& fontFiles, FcConfig* config)
    6981{
    70     for (Vector<String>::const_iterator it = fontFiles.begin(); it != fontFiles.end(); ++it) {
    71         const CString currentFile = (*it).utf8();
    72         const char* path = currentFile.data();
     82    Vector<CString>::const_iterator it, end = fontFiles.end();
     83    for (it = fontFiles.begin(); it != end; ++it) {
     84        const char* filePath = (*it).data();
     85        if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(filePath)))
     86            fprintf(stderr, "Could not load font at %s!\n", filePath);
     87    }
     88}
    7389
    74         if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(path)))
    75             fprintf(stderr, "Could not load font at %s!\n", path);
     90static CString getCustomBuildDir()
     91{
     92    if (const char* userChosenBuildDir = getenv("WEBKITOUTPUTDIR")) {
     93        if (ecore_file_is_dir(userChosenBuildDir))
     94            return userChosenBuildDir;
     95        fprintf(stderr, "WEBKITOUTPUTDIR set to '%s', but path doesn't exist.\n", userChosenBuildDir);
    7696    }
     97
     98    return CString();
     99}
     100
     101static CString getPlatformFontsPath()
     102{
     103    CString customBuildDir = getCustomBuildDir();
     104    if (!customBuildDir.isNull()) {
     105        CString fontsPath = buildPath(customBuildDir.data(), "Dependencies", "Root", "webkitgtk-test-fonts", 0);
     106        if (!ecore_file_exists(fontsPath.data()))
     107            fprintf(stderr, "WEBKITOUTPUTDIR set to '%s', but could not local test fonts.\n", customBuildDir.data());
     108        return fontsPath;
     109    }
     110
     111    CString fontsPath = CString(DOWNLOADED_FONTS_DIR);
     112    if (ecore_file_exists(fontsPath.data()))
     113        return fontsPath;
     114
     115    fprintf(stderr, "Could not locate tests fonts, try setting WEBKITOUTPUTDIR.\n");
     116    return CString();
    77117}
    78118
     
    90130    }
    91131
    92     if (!addFontDirectory(DOWNLOADED_FONTS_DIR, config)) {
    93         fprintf(stderr, "None of the font directories could be added. Either install them "
    94                         "or file a bug at http://bugs.webkit.org if they are installed in "
    95                         "another location.\n");
    96         exit(1);
    97     }
    98 
    99     addFontFiles(getFontFiles(), config);
     132    addFontFiles(getCoreFontFiles(), config);
     133    addFontDirectory(getPlatformFontsPath(), config);
    100134
    101135    if (!FcConfigSetCurrent(config)) {
Note: See TracChangeset for help on using the changeset viewer.