Changeset 100601 in webkit


Ignore:
Timestamp:
Nov 17, 2011 4:16:57 AM (12 years ago)
Author:
bashi@chromium.org
Message:

[chromium] don't call fontconfig twice in complex text path
https://bugs.webkit.org/show_bug.cgi?id=38701

Source/WebCore:

Adds a new API for getting font family. For now, FontCacheLinux calls the new API, but don't use additional properties for compatibility. The old API will be removed when Chromium is ready to use new API.

Reviewed by Tony Chang.

No new tests. No behavior changes for now.

  • platform/chromium/PlatformSupport.h: Added FontFamily struct and changed the declaration of getFontFamilyForCharacters().
  • platform/graphics/chromium/FontCacheLinux.cpp:

(WebCore::FontCache::getFontDataForCharacters): Uses new PlatformSupport::getFontFamilyForCharacters().

  • platform/graphics/chromium/FontPlatformDataLinux.h:

(WebCore::FontPlatformData::setFakeBold): Added.
(WebCore::FontPlatformData::setFakeItalic): Added.

Source/WebKit/chromium:

Reviewed by Tony Chang.

Add new API for getFamilyForChars() so that keeping correct font mapping of the given characters.

  • public/linux/WebFontFamily.h: Added.
  • public/linux/WebFontInfo.h: Add a new API.
  • public/linux/WebSandboxSupport.h:

(WebKit::WebSandboxSupport::getFontFamilyForCharacters): Ditto.

  • src/PlatformSupport.cpp:

(WebCore::PlatformSupport::getFontFamilyForCharacters): Ditto.

  • src/linux/WebFontInfo.cpp:

(WebKit::WebFontInfo::familyForChars): Modified to get weight and italic properties of the font. Old API uses new API internally.

Location:
trunk/Source
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r100597 r100601  
     12011-11-17  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        [chromium] don't call fontconfig twice in complex text path
     4        https://bugs.webkit.org/show_bug.cgi?id=38701
     5
     6        Adds a new API for getting font family. For now, FontCacheLinux calls the new API, but don't use additional properties for compatibility. The old API will be removed when Chromium is ready to use new API.
     7
     8        Reviewed by Tony Chang.
     9
     10        No new tests. No behavior changes for now.
     11
     12        * platform/chromium/PlatformSupport.h: Added FontFamily struct and changed the declaration of getFontFamilyForCharacters().
     13        * platform/graphics/chromium/FontCacheLinux.cpp:
     14        (WebCore::FontCache::getFontDataForCharacters): Uses new PlatformSupport::getFontFamilyForCharacters().
     15        * platform/graphics/chromium/FontPlatformDataLinux.h:
     16        (WebCore::FontPlatformData::setFakeBold): Added.
     17        (WebCore::FontPlatformData::setFakeItalic): Added.
     18
    1192011-11-17  Mario Sanchez Prada  <msanchez@igalia.com>
    220
  • trunk/Source/WebCore/platform/chromium/PlatformSupport.h

    r100495 r100601  
    153153#elif OS(UNIX)
    154154    static void getRenderStyleForStrike(const char* family, int sizeAndStyle, FontRenderStyle* result);
    155     static String getFontFamilyForCharacters(const UChar*, size_t numCharacters, const char* preferredLocale);
     155    struct FontFamily {
     156        String name;
     157        bool isBold;
     158        bool isItalic;
     159    };
     160    static void getFontFamilyForCharacters(const UChar*, size_t numCharacters, const char* preferredLocale, FontFamily*);
    156161#endif
    157162
  • trunk/Source/WebCore/platform/graphics/chromium/FontCacheLinux.cpp

    r100070 r100601  
    6060{
    6161    icu::Locale locale = icu::Locale::getDefault();
    62     String family = PlatformSupport::getFontFamilyForCharacters(characters, length, locale.getLanguage());
    63     if (family.isEmpty())
     62    PlatformSupport::FontFamily family;
     63    PlatformSupport::getFontFamilyForCharacters(characters, length, locale.getLanguage(), &family);
     64    if (family.name.isEmpty())
    6465        return 0;
    6566
    66     AtomicString atomicFamily(family);
     67    AtomicString atomicFamily(family.name);
     68    // FIXME: Remove this #if after API transition complete.
     69#if 0
     70    // Changes weight and/or italic of given FontDescription depends on
     71    // the result of fontconfig so that keeping the correct font mapping
     72    // of the given characters. See http://crbug.com/32109 for details.
     73    bool shouldSetFakeBold = false;
     74    bool shouldSetFakeItalic = false;
     75    FontDescription description(font.fontDescription());
     76    if (family.isBold && description.weight() < FontWeightBold)
     77        description.setWeight(FontWeightBold);
     78    if (!family.isBold && description.weight() >= FontWeightBold) {
     79        shouldSetFakeBold = true;
     80        description.setWeight(FontWeightNormal);
     81    }
     82    if (family.isItalic && description.italic() == FontItalicOff)
     83        description.setItalic(FontItalicOn);
     84    if (!family.isItalic && description.italic() == FontItalicOn) {
     85        shouldSetFakeItalic = true;
     86        description.setItalic(FontItalicOff);
     87    }
     88
     89    FontPlatformData platformData = FontPlatformData(*getCachedFontPlatformData(description, atomicFamily, DoNotRetain));
     90    platformData.setFakeBold(shouldSetFakeBold);
     91    platformData.setFakeItalic(shouldSetFakeItalic);
     92    return getCachedFontData(&platformData, DoNotRetain);
     93#else
    6794    return getCachedFontData(getCachedFontPlatformData(font.fontDescription(), atomicFamily, DoNotRetain), DoNotRetain);
     95#endif
    6896}
    6997
  • trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataLinux.h

    r95901 r100601  
    119119    FontOrientation orientation() const { return m_orientation; }
    120120    void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
    121    
     121    void setFakeBold(bool fakeBold) { m_fakeBold = fakeBold; }
     122    void setFakeItalic(bool fakeItalic) { m_fakeItalic = fakeItalic; }
    122123    bool operator==(const FontPlatformData&) const;
    123124    FontPlatformData& operator=(const FontPlatformData&);
  • trunk/Source/WebKit/chromium/ChangeLog

    r100582 r100601  
     12011-11-17  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        [chromium] don't call fontconfig twice in complex text path
     4        https://bugs.webkit.org/show_bug.cgi?id=38701
     5
     6        Reviewed by Tony Chang.
     7
     8        Add new API for getFamilyForChars() so that keeping correct font mapping of the given characters.
     9
     10        * public/linux/WebFontFamily.h: Added.
     11        * public/linux/WebFontInfo.h: Add a new API.
     12        * public/linux/WebSandboxSupport.h:
     13        (WebKit::WebSandboxSupport::getFontFamilyForCharacters): Ditto.
     14        * src/PlatformSupport.cpp:
     15        (WebCore::PlatformSupport::getFontFamilyForCharacters): Ditto.
     16        * src/linux/WebFontInfo.cpp:
     17        (WebKit::WebFontInfo::familyForChars): Modified to get weight and italic properties of the font. Old API uses new API internally.
     18
    1192011-11-17  Adam Barth  <abarth@webkit.org>
    220
  • trunk/Source/WebKit/chromium/public/linux/WebFontFamily.h

    r100600 r100601  
    11/*
    2  * Copyright (C) 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2011 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef WebSandboxSupport_h
    32 #define WebSandboxSupport_h
     31#ifndef WebFontFamily_h
     32#define WebFontFamily_h
    3333
     34#include "../WebCString.h"
    3435#include "../WebCommon.h"
    35 #include "../WebString.h"
    3636
    3737namespace WebKit {
    3838
    39 struct WebFontRenderStyle;
    40 
    41 // Put methods here that are required due to sandbox restrictions.
    42 class WebSandboxSupport {
    43 public:
    44     // Fonts ---------------------------------------------------------------
    45 
    46     // Get a font family which contains glyphs for the given Unicode
    47     // code-points.
    48     //   characters: a UTF-16 encoded string
    49     //   numCharacters: the number of 16-bit words in |characters|
    50     //   preferredLocale: preferred locale identifier for the |characters|
    51     //                    (e.g. "en", "ja", "zh-CN")
    52     //
    53     // Returns a string with the font family on an empty string if the
    54     // request cannot be satisfied.
    55     virtual WebString getFontFamilyForCharacters(const WebUChar* characters, size_t numCharacters, const char* preferredLocale)  = 0;
    56     virtual void getRenderStyleForStrike(const char* family, int sizeAndStyle, WebFontRenderStyle* style) = 0;
     39struct WebFontFamily {
     40    WebCString name;
     41    bool isBold;
     42    bool isItalic;
    5743};
    5844
    5945} // namespace WebKit
    6046
    61 #endif
     47#endif // WebFontFamily_h
  • trunk/Source/WebKit/chromium/public/linux/WebFontInfo.h

    r96233 r100601  
    3333
    3434#include "../WebCString.h"
     35#include "../linux/WebFontFamily.h"
    3536#include "../linux/WebFontRenderStyle.h"
    3637
     
    5152    // Returns: the font family or an empty string if the request could not be
    5253    // satisfied.
     54    // FIXME: Depreciated API. Remove later.
    5355    WEBKIT_EXPORT static WebCString familyForChars(const WebUChar* characters, size_t numCharacters, const char* preferredLocale);
     56    // Returns: the font family instance. The instance has an empty font name if the request could not be satisfied.
     57    WEBKIT_EXPORT static void familyForChars(const WebUChar* characters, size_t numCharacters, const char* preferredLocale, WebFontFamily*);
    5458
    5559    // Fill out the given WebFontRenderStyle with the user's preferences for
  • trunk/Source/WebKit/chromium/public/linux/WebSandboxSupport.h

    r95901 r100601  
    3434#include "../WebCommon.h"
    3535#include "../WebString.h"
     36#include "WebFontFamily.h"
    3637
    3738namespace WebKit {
     
    5354    // Returns a string with the font family on an empty string if the
    5455    // request cannot be satisfied.
    55     virtual WebString getFontFamilyForCharacters(const WebUChar* characters, size_t numCharacters, const char* preferredLocale)  = 0;
     56    // FIXME: Depreciated API. Remove later.
     57    virtual WebString getFontFamilyForCharacters(const WebUChar* characters, size_t numCharacters, const char* preferredLocale) { return WebString(); }
     58    // Returns a WebFontFamily instance with the font name. The instance has empty font name if the request cannot be satisfied.
     59    // FIXME: Make this to be a pure virtual function after transition.
     60    virtual void getFontFamilyForCharacters(const WebUChar* characters, size_t numCharacters, const char* preferredLocale, WebFontFamily* family)
     61    {
     62        family->name = getFontFamilyForCharacters(characters, numCharacters, preferredLocale).utf8();
     63    }
     64
    5665    virtual void getRenderStyleForStrike(const char* family, int sizeAndStyle, WebFontRenderStyle* style) = 0;
    5766};
  • trunk/Source/WebKit/chromium/src/PlatformSupport.cpp

    r100495 r100601  
    438438}
    439439#elif OS(UNIX)
    440 String PlatformSupport::getFontFamilyForCharacters(const UChar* characters, size_t numCharacters, const char* preferredLocale)
     440void PlatformSupport::getFontFamilyForCharacters(const UChar* characters, size_t numCharacters, const char* preferredLocale, FontFamily* family)
    441441{
    442442#if OS(ANDROID)
    443443    // FIXME: We do not use fontconfig on Android, so use simple logic for now.
    444444    // https://bugs.webkit.org/show_bug.cgi?id=67587
    445     return WebString("Arial");
     445    family->name = "Arial";
     446    family->isBold = false;
     447    family->isItalic = false;
    446448#else
     449    WebFontFamily webFamily;
    447450    if (webKitPlatformSupport()->sandboxSupport())
    448         return webKitPlatformSupport()->sandboxSupport()->getFontFamilyForCharacters(characters, numCharacters, preferredLocale);
    449 
    450     WebCString family = WebFontInfo::familyForChars(characters, numCharacters, preferredLocale);
    451     if (family.data())
    452         return WebString::fromUTF8(family.data());
    453 
    454     return WebString();
     451        webKitPlatformSupport()->sandboxSupport()->getFontFamilyForCharacters(characters, numCharacters, preferredLocale, &webFamily);
     452    else
     453        WebFontInfo::familyForChars(characters, numCharacters, preferredLocale, &webFamily);
     454    family->name = String::fromUTF8(webFamily.name.data(), webFamily.name.length());
     455    family->isBold = webFamily.isBold;
     456    family->isItalic = webFamily.isItalic;
    455457#endif
    456458}
  • trunk/Source/WebKit/chromium/src/linux/WebFontInfo.cpp

    r96660 r100601  
    3232#include "WebFontInfo.h"
    3333
     34#include "WebFontFamily.h"
    3435#include "WebFontRenderStyle.h"
    3536
     
    4041namespace WebKit {
    4142
     43// FIXME: Depreciated API. Remove later.
    4244WebCString WebFontInfo::familyForChars(const WebUChar* characters, size_t numCharacters, const char* preferredLocale)
     45{
     46    WebFontFamily family;
     47    familyForChars(characters, numCharacters, preferredLocale, &family);
     48    return family.name;
     49}
     50
     51void WebFontInfo::familyForChars(const WebUChar* characters, size_t numCharacters, const char* preferredLocale, WebFontFamily* family)
    4352{
    4453    FcCharSet* cset = FcCharSetCreate();
     
    7988    FcCharSetDestroy(cset);
    8089
    81     if (!fontSet)
    82         return WebCString();
    83 
     90    if (!fontSet) {
     91        family->name = WebCString();
     92        family->isBold = false;
     93        family->isItalic = false;
     94        return;
     95    }
    8496    // Older versions of fontconfig have a bug where they cannot select
    8597    // only scalable fonts so we have to manually filter the results.
     
    100112            continue;
    101113
    102         FcChar8* family;
    103         WebCString result;
    104         if (FcPatternGetString(current, FC_FAMILY, 0, &family) == FcResultMatch) {
    105             const char* charFamily = reinterpret_cast<char*>(family);
    106             result = WebCString(charFamily, strlen(charFamily));
     114        FcChar8* familyName;
     115        if (FcPatternGetString(current, FC_FAMILY, 0, &familyName) == FcResultMatch) {
     116            const char* charFamily = reinterpret_cast<char*>(familyName);
     117            family->name = WebCString(charFamily, strlen(charFamily));
    107118        }
     119        int weight;
     120        if (FcPatternGetInteger(current, FC_WEIGHT, 0, &weight) == FcResultMatch)
     121            family->isBold = weight >= FC_WEIGHT_BOLD;
     122        else
     123            family->isBold = false;
     124        int slant;
     125        if (FcPatternGetInteger(current, FC_SLANT, 0, &slant) == FcResultMatch)
     126            family->isItalic = slant != FC_SLANT_ROMAN;
     127        else
     128            family->isItalic = false;
    108129        FcFontSetDestroy(fontSet);
    109         return result;
     130        return;
    110131    }
    111132
    112133    FcFontSetDestroy(fontSet);
    113     return WebCString();
    114134}
    115135
Note: See TracChangeset for help on using the changeset viewer.