Changeset 28921 in webkit


Ignore:
Timestamp:
Dec 20, 2007 4:33:46 PM (16 years ago)
Author:
alp@webkit.org
Message:

2007-12-20 Alp Toker <alp@atoker.com>

Rubber-stamped by Maciej.

http://bugs.webkit.org/show_bug.cgi?id=16542
[GTK] Text is missing with old Pango version

Back out commits r28880, r28876, r28865, r28864 which added Pango font
selection support. These changes caused a regression where no text was
displayed with older Pango versions.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r28865 r28921  
     12007-12-20  Alp Toker  <alp@atoker.com>
     2
     3        Rubber-stamped by Maciej.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=16542
     6        [GTK] Text is missing with old Pango version
     7
     8        Back out commits r28880, r28876, r28865, r28864 which added Pango font
     9        selection support. These changes caused a regression where no text was
     10        displayed with older Pango versions.
     11
     12        * WebKit.pri:
     13
    1142007-12-19  Alp Toker  <alp@atoker.com>
    215
  • trunk/WebCore/ChangeLog

    r28918 r28921  
     12007-12-20  Alp Toker  <alp@atoker.com>
     2
     3        Rubber-stamped by Maciej.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=16542
     6        [GTK] Text is missing with old Pango version
     7
     8        Back out commits r28880, r28876, r28865, r28864 which added Pango font
     9        selection support. These changes caused a regression where no text was
     10        displayed with older Pango versions.
     11
     12        * platform/graphics/gtk/FontCacheGtk.cpp:
     13        (WebCore::FontCache::fontExists):
     14        * platform/graphics/gtk/FontDataGtk.cpp:
     15        (WebCore::FontData::platformDestroy):
     16        (WebCore::FontData::containsCharacters):
     17        * platform/graphics/gtk/FontPlatformData.h:
     18        (WebCore::FontPlatformData::FontPlatformData):
     19        (WebCore::FontPlatformData::hash):
     20        * platform/graphics/gtk/FontPlatformDataGtk.cpp:
     21        (WebCore::FontPlatformData::FontPlatformData):
     22        (WebCore::FontPlatformData::init):
     23        (WebCore::FontPlatformData::~FontPlatformData):
     24        (WebCore::FontPlatformData::isFixedPitch):
     25        (WebCore::FontPlatformData::operator==):
     26        * platform/graphics/gtk/GlyphPageTreeNodeGtk.cpp:
     27        (WebCore::GlyphPage::fill):
     28
    1292007-12-20  Timothy Hatcher  <timothy@apple.com>
    230
  • trunk/WebCore/platform/graphics/gtk/FontCacheGtk.cpp

    r28864 r28921  
    6565{
    6666    FontPlatformData platformData(fontDescription, family);
    67     return platformData.m_font != 0;
     67    return platformData.m_pattern != 0;
    6868}
    6969
  • trunk/WebCore/platform/graphics/gtk/FontDataGtk.cpp

    r28864 r28921  
    44 * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
    55 * Copyright (C) 2007 Holger Hans Peter Freyther
    6  * Copyright (C) 2007 Pioneer Research Center USA, Inc.
    76 * All rights reserved.
    87 *
     
    6463void FontData::platformDestroy()
    6564{
    66     if (m_font.m_font && m_font.m_font != reinterpret_cast<PangoFont*>(-1))
    67         g_object_unref(m_font.m_font);
    68     if (m_font.m_context)
    69         g_object_unref(m_font.m_context);
     65    if (m_font.m_pattern && ((FcPattern*)-1 != m_font.m_pattern))
     66        FcPatternDestroy(m_font.m_pattern);
    7067
    7168    if (m_font.m_scaledFont)
     
    8784bool FontData::containsCharacters(const UChar* characters, int length) const
    8885{
    89     bool result = true;
     86    FT_Face face = cairo_ft_scaled_font_lock_face(m_font.m_scaledFont);
    9087
    91     PangoCoverage* requested = pango_coverage_from_bytes((guchar*)characters, length);
    92     PangoCoverage* available = pango_font_get_coverage(m_font.m_font, pango_language_get_default());
    93     pango_coverage_max(requested, available);
     88    if (!face)
     89        return false;
    9490
    9591    for (unsigned i = 0; i < length; i++) {
    96         if (PANGO_COVERAGE_NONE == pango_coverage_get(requested, i)) {
    97             result = false;
    98             break;
     92        if (FcFreeTypeCharIndex(face, characters[i]) == 0) {
     93            cairo_ft_scaled_font_unlock_face(m_font.m_scaledFont);
     94            return false;
    9995        }
    10096    }
    10197
    102     pango_coverage_unref(available);
    103     pango_coverage_unref(requested);
     98    cairo_ft_scaled_font_unlock_face(m_font.m_scaledFont);
    10499
    105     return result;
     100    return true;
    106101}
    107102
  • trunk/WebCore/platform/graphics/gtk/FontPlatformData.h

    r28864 r28921  
    66 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
    77 * Copyright (C) 2007 Holger Hans Peter Freyther
    8  * Copyright (C) 2007 Pioneer Research Center USA, Inc.
    98 * All rights reserved.
    109 *
     
    3231#include "FontDescription.h"
    3332#include <cairo.h>
    34 #include <pango/pangocairo.h>
     33#include <cairo-ft.h>
     34#include <fontconfig/fcfreetype.h>
    3535
    3636namespace WebCore {
     
    4040    class Deleted {};
    4141    FontPlatformData(Deleted)
    42         : m_context(0)
    43         , m_font(reinterpret_cast<PangoFont*>(-1))
     42        : m_pattern(reinterpret_cast<FcPattern*>(-1))
    4443        , m_scaledFont(0)
    4544        { }
    4645
    4746    FontPlatformData()
    48         : m_context(0)
    49         , m_font(0)
     47        : m_pattern(0)
    5048        , m_scaledFont(0)
    5149        { }
     
    6260    unsigned hash() const
    6361    {
    64         uintptr_t hashCodes[1] = {reinterpret_cast<uintptr_t>(m_scaledFont)};
    65         return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
     62        uintptr_t hashCodes[1] = { reinterpret_cast<uintptr_t>(m_scaledFont) };
     63        return StringImpl::computeHash( reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
    6664    }
    6765
    6866    bool operator==(const FontPlatformData&) const;
    6967
    70     static PangoFontMap* m_fontMap;
    71     static GHashTable  * m_hashTable;
    72 
    73     PangoContext* m_context;
    74     PangoFont* m_font;
     68    FcPattern* m_pattern;
    7569    FontDescription m_fontDescription;
    7670    cairo_scaled_font_t* m_scaledFont;
  • trunk/WebCore/platform/graphics/gtk/FontPlatformDataGtk.cpp

    r28880 r28921  
    77 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
    88 * Copyright (C) 2007 Holger Hans Peter Freyther
    9  * Copyright (C) 2007 Pioneer Research Center USA, Inc.
    109 * All rights reserved.
    1110 *
     
    2726 */
    2827
    29 // Use the Pango backend API for compatibility with older Pango versions.
    30 #define PANGO_ENABLE_BACKEND
    31 
    3228#include "config.h"
    3329#include "FontPlatformData.h"
     
    3632#include "PlatformString.h"
    3733#include "FontDescription.h"
     34
     35#include <cairo-ft.h>
    3836#include <cairo.h>
    39 #include <assert.h>
    40 
    41 #include <pango/pango.h>
    42 #include <pango/pangocairo.h>
    43 
    44 // Use cairo-ft if a recent enough Pango version isn't available.
    45 #if !PANGO_VERSION_CHECK(1,18,0)
    46 #include <cairo-ft.h>
    47 #include <pango/pangofc-fontmap.h>
    48 #endif
     37#include <fontconfig/fcfreetype.h>
    4938
    5039namespace WebCore {
    5140
    52 PangoFontMap* FontPlatformData::m_fontMap = 0;
    53 GHashTable* FontPlatformData::m_hashTable = 0;
    54 
    5541FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
    56     : m_context(0)
    57     , m_font(0)
     42    : m_pattern(0)
    5843    , m_fontDescription(fontDescription)
    5944    , m_scaledFont(0)
     
    6146    FontPlatformData::init();
    6247
    63     CString  stored_family = familyName.domString().utf8();
    64     gchar const* families[] = {
    65         stored_family.data(),
    66         NULL
    67     };
     48    CString familyNameString = familyName.domString().utf8();
     49    const char* fcfamily = familyNameString.data();
     50    int fcslant = FC_SLANT_ROMAN;
     51    int fcweight = FC_WEIGHT_NORMAL;
     52    float fcsize = fontDescription.computedSize();
     53    if (fontDescription.italic())
     54        fcslant = FC_SLANT_ITALIC;
     55    if (fontDescription.bold())
     56        fcweight = FC_WEIGHT_BOLD;
    6857
    69     switch (fontDescription.genericFamily()) {
    70     case FontDescription::SerifFamily:
    71         families[1] = "serif";
    72         break;
    73     case FontDescription::SansSerifFamily:
    74         families[1] = "sans";
    75         break;
    76     case FontDescription::MonospaceFamily:
    77         families[1] = "monospace";
    78         break;
    79     case FontDescription::NoFamily:
    80     case FontDescription::StandardFamily:
    81     default:
    82         families[1] = "sans";
    83         break;
     58    int type = fontDescription.genericFamily();
     59
     60    FcPattern* pattern = FcPatternCreate();
     61    cairo_font_face_t* fontFace;
     62    cairo_font_options_t* options;
     63    cairo_matrix_t fontMatrix;
     64
     65    if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily)))
     66        goto freePattern;
     67
     68    switch (type) {
     69        case FontDescription::SerifFamily:
     70            fcfamily = "serif";
     71            break;
     72        case FontDescription::SansSerifFamily:
     73            fcfamily = "sans-serif";
     74            break;
     75        case FontDescription::MonospaceFamily:
     76            fcfamily = "monospace";
     77            break;
     78        case FontDescription::NoFamily:
     79        case FontDescription::StandardFamily:
     80        default:
     81            fcfamily = "sans-serif";
    8482    }
    8583
    86     PangoFontDescription* description = pango_font_description_new();
    87     pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE);
     84    if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily)))
     85        goto freePattern;
     86    if (!FcPatternAddInteger(pattern, FC_SLANT, fcslant))
     87        goto freePattern;
     88    if (!FcPatternAddInteger(pattern, FC_WEIGHT, fcweight))
     89        goto freePattern;
     90    if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fcsize))
     91        goto freePattern;
    8892
    89     if (fontDescription.bold())
    90         pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD);
    91     if (fontDescription.italic())
    92         pango_font_description_set_style(description, PANGO_STYLE_ITALIC);
     93    FcConfigSubstitute(NULL, pattern, FcMatchPattern);
     94    FcDefaultSubstitute(pattern);
    9395
    94     m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap));
     96    FcResult fcresult;
     97    m_pattern = FcFontMatch(NULL, pattern, &fcresult);
     98    // FIXME: should we set some default font?
     99    if (!m_pattern)
     100        goto freePattern;
     101    fontFace = cairo_ft_font_face_create_for_pattern(m_pattern);
     102    cairo_matrix_t ctm;
     103    cairo_matrix_init_scale(&fontMatrix, m_fontDescription.computedSize(), m_fontDescription.computedSize());
     104    cairo_matrix_init_identity(&ctm);
     105    options = cairo_font_options_create();
     106    m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options);
     107    cairo_font_face_destroy(fontFace);
     108    cairo_font_options_destroy(options);
    95109
    96     for (unsigned int i = 0; !m_font && i < G_N_ELEMENTS(families); i++) {
    97         pango_font_description_set_family(description, families[i]);
    98         m_font = pango_font_map_load_font(m_fontMap, m_context, description);
    99     }
    100 
    101     // FIXME: should we set some default font?
    102 #if PANGO_VERSION_CHECK(1,18,0)
    103     if (m_font)
    104         m_scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font)));
    105 #else
    106     // This compatibility code for older versions of Pango is not well-tested.
    107     if (m_font) {
    108         PangoFcFont* fcfont = PANGO_FC_FONT(m_font);
    109         cairo_font_face_t* face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern);
    110         double size;
    111         if (FcPatternGetDouble(fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch)
    112             size = 12.0;
    113         cairo_matrix_t fontMatrix;
    114         cairo_matrix_init_scale(&fontMatrix, size, size);
    115         cairo_font_options_t* fontOptions;
    116         if (pango_cairo_context_get_font_options(m_context))
    117             fontOptions = cairo_font_options_copy(pango_cairo_context_get_font_options(m_context));
    118         else
    119             fontOptions = cairo_font_options_create();
    120         cairo_matrix_t ctm;
    121         cairo_matrix_init_identity(&ctm);
    122         m_scaledFont = cairo_scaled_font_create(face, &fontMatrix, &ctm, fontOptions);
    123         cairo_font_options_destroy(fontOptions);
    124         cairo_font_face_destroy(face);
    125     }
    126 #endif
    127 
    128     pango_font_description_free(description);
     110freePattern:
     111    FcPatternDestroy(pattern);
    129112}
    130113
     
    135118        return true;
    136119    initialized = true;
    137 
    138     if (!m_fontMap)
    139         m_fontMap = pango_cairo_font_map_new();
    140     if (!m_hashTable) {
    141         PangoFontFamily**families = 0;
    142         int n_families = 0;
    143 
    144         m_hashTable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
    145 
    146         pango_font_map_list_families(m_fontMap, &families, &n_families);
    147 
    148         for (int family = 0; family < n_families; family++)
    149                 g_hash_table_insert(m_hashTable,
    150                                     g_strdup(pango_font_family_get_name(families[family])),
    151                                     g_object_ref(families[family]));
    152 
    153         g_free(families);
     120    if (!FcInit()) {
     121        fprintf(stderr, "Can't init font config library\n");
     122        return false;
    154123    }
    155 
    156124    return true;
    157125}
     
    159127FontPlatformData::~FontPlatformData()
    160128{
    161     // Destroy takes place in FontData::platformDestroy().
    162129}
    163130
    164131bool FontPlatformData::isFixedPitch()
    165132{
    166     PangoFontDescription* description = pango_font_describe_with_absolute_size(m_font);
    167     PangoFontFamily* family = reinterpret_cast<PangoFontFamily*>(g_hash_table_lookup(m_hashTable, pango_font_description_get_family(description)));
    168     pango_font_description_free(description);
    169 
    170     return pango_font_family_is_monospace(family);
     133    int spacing;
     134    if (FcPatternGetInteger(m_pattern, FC_SPACING, 0, &spacing) == FcResultMatch)
     135        return spacing == FC_MONO;
     136    return false;
    171137}
    172138
     
    180146bool FontPlatformData::operator==(const FontPlatformData& other) const
    181147{
    182     if (m_font == other.m_font)
     148    if (m_pattern == other.m_pattern)
    183149        return true;
    184     if (m_font == 0 || m_font == reinterpret_cast<PangoFont*>(-1)
    185             || other.m_font == 0 || other.m_font == reinterpret_cast<PangoFont*>(-1))
     150    if (m_pattern == 0 || m_pattern == reinterpret_cast<FcPattern*>(-1)
     151            || other.m_pattern == 0 || other.m_pattern == reinterpret_cast<FcPattern*>(-1))
    186152        return false;
    187 
    188     PangoFontDescription* thisDesc = pango_font_describe(m_font);
    189     PangoFontDescription* otherDesc = pango_font_describe(other.m_font);
    190     bool result = pango_font_description_equal(thisDesc, otherDesc);
    191     pango_font_description_free(otherDesc);
    192     pango_font_description_free(thisDesc);
    193     return result;
     153    return FcPatternEqual(m_pattern, other.m_pattern);
    194154}
    195155
  • trunk/WebCore/platform/graphics/gtk/GlyphPageTreeNodeGtk.cpp

    r28864 r28921  
    33 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
    44 * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
    5  * Copyright (C) 2007 Pioneer Research Center USA, Inc.
    65 *
    76 * Redistribution and use in source and binary forms, with or without
     
    3433
    3534#include "FontData.h"
    36 #include <pango/pango-font.h>
    3735
    3836namespace WebCore {
    39 
    40 static PangoGlyph pango_font_get_glyph(PangoFont* font, PangoContext* context, gunichar wc)
    41 {
    42     PangoGlyph result = 0;
    43     gchar buffer[7];
    44 
    45     gint  length = g_unichar_to_utf8(wc, buffer);
    46     g_return_val_if_fail(length, 0);
    47 
    48     GList* items = pango_itemize(context, buffer, 0, length, NULL, NULL);
    49 
    50     if (g_list_length(items) == 1) {
    51         PangoGlyphString* glyphs = pango_glyph_string_new();
    52 
    53         pango_shape(buffer, length, &((PangoItem*)items->data)->analysis, glyphs);
    54 
    55         if (glyphs->num_glyphs == 1)
    56             result = glyphs->glyphs[0].glyph;
    57         else
    58             g_warning("didn't get 1 glyph but %d", glyphs->num_glyphs);
    59 
    60         pango_glyph_string_free(glyphs);
    61     }
    62 
    63     g_list_foreach(items, (GFunc)pango_item_free, NULL);
    64     g_list_free(items);
    65 
    66     return result;
    67 }
    6837
    6938bool GlyphPage::fill(UChar* buffer, unsigned bufferLength, const FontData* fontData)
     
    7443        return false;
    7544
    76     if (!fontData->m_font.m_font || fontData->m_font.m_font == reinterpret_cast<PangoFont*>(-1))
     45    FT_Face face = cairo_ft_scaled_font_lock_face(fontData->m_font.m_scaledFont);
     46    if (!face)
    7747        return false;
    7848
    7949    bool haveGlyphs = false;
    8050    for (unsigned i = 0; i < GlyphPage::size; i++) {
    81         Glyph glyph = pango_font_get_glyph(fontData->m_font.m_font, fontData->m_font.m_context, buffer[i]);
     51        Glyph glyph = FcFreeTypeCharIndex(face, buffer[i]);
    8252        if (!glyph)
    8353            setGlyphDataForIndex(i, 0, 0);
     
    8858    }
    8959
     60    cairo_ft_scaled_font_unlock_face(fontData->m_font.m_scaledFont);
     61
    9062    return haveGlyphs;
    9163}
  • trunk/WebKit.pri

    r28865 r28921  
    2525
    2626    DEFINES += BUILDING_CAIRO__=1 BUILDING_GTK__=1
     27
     28    # We use FreeType directly with Cairo
     29    PKGCONFIG += cairo-ft
    2730
    2831    directfb: PKGCONFIG += cairo-directfb gtk+-directfb-2.0
Note: See TracChangeset for help on using the changeset viewer.