Changeset 28864 in webkit


Ignore:
Timestamp:
Dec 19, 2007 10:00:23 AM (16 years ago)
Author:
alp@webkit.org
Message:

2007-12-19 Sven Herzberg <sven@imendio.com>

Reviewed by Alp Toker.

Replace the fontconfig/freetype based font management with a pango
based one. Fixes:
http://bugs.webkit.org/show_bug.cgi?id=15229

  • platform/gtk/FontDataGtk.cpp (FontData::platformDestroy()): updated the platform specific destroy code (FontData::containsCharacters()): implemented font coverage with pango
  • platform/gtk/FontPlatformData.h: replaced fontconfig specific members with pango-specific ones
  • platform/gtk/FontPlatformDataGtk.cpp: added static members for the FontPlatformData class (FontPlatformData::FontPlatformData()): implemented the font-matching with a PangoFontDescription instead of an FcPattern; initialize the scaled font by using the API for PangoCairoFont (FontPlatformData::init()): initialize the PangoFontMap and set up a hash table to translate the font family name into a font family (FontPlatformData::isFixedPitch()): implemented by querying the PangoFontFamily (FontPlatformData::operator==): compare the FontPlatformData by comparing the font pointers or the described fonts
  • platform/gtk/GlyphPageTreeNodeGtk.cpp (pango_font_get_glyph()): added a function to query a glyph from a PangoFont (GlyphPage::fill()): implemented the fill function with Pango instead of fontconfig/freetype
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28861 r28864  
     12007-12-19  Sven Herzberg  <sven@imendio.com>
     2
     3        Reviewed by Alp Toker.
     4
     5        Replace the fontconfig/freetype based font management with a pango
     6        based one. Fixes:
     7        http://bugs.webkit.org/show_bug.cgi?id=15229
     8
     9        * platform/gtk/FontDataGtk.cpp (FontData::platformDestroy()): updated
     10        the platform specific destroy code
     11        (FontData::containsCharacters()): implemented font coverage with pango
     12        * platform/gtk/FontPlatformData.h: replaced fontconfig specific
     13        members with pango-specific ones
     14        * platform/gtk/FontPlatformDataGtk.cpp: added static members for the
     15        FontPlatformData class
     16        (FontPlatformData::FontPlatformData()): implemented the font-matching
     17        with a PangoFontDescription instead of an FcPattern; initialize the
     18        scaled font by using the API for PangoCairoFont
     19        (FontPlatformData::init()): initialize the PangoFontMap and set up a
     20        hash table to translate the font family name into a font family
     21        (FontPlatformData::isFixedPitch()): implemented by querying the
     22        PangoFontFamily
     23        (FontPlatformData::operator==): compare the FontPlatformData by
     24        comparing the font pointers or the described fonts
     25        * platform/gtk/GlyphPageTreeNodeGtk.cpp (pango_font_get_glyph()):
     26        added a function to query a glyph from a PangoFont
     27        (GlyphPage::fill()): implemented the fill function with Pango instead
     28        of fontconfig/freetype
     29
    1302007-12-19  Alp Toker  <alp@atoker.com>
    231
  • trunk/WebCore/platform/graphics/gtk/FontCacheGtk.cpp

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

    r28251 r28864  
    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.
    67 * All rights reserved.
    78 *
     
    6364void FontData::platformDestroy()
    6465{
    65     if (m_font.m_pattern && ((FcPattern*)-1 != m_font.m_pattern))
    66         FcPatternDestroy(m_font.m_pattern);
     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);
    6770
    6871    if (m_font.m_scaledFont)
     
    8487bool FontData::containsCharacters(const UChar* characters, int length) const
    8588{
    86     FT_Face face = cairo_ft_scaled_font_lock_face(m_font.m_scaledFont);
     89    bool result = true;
    8790
    88     if (!face)
    89         return false;
     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);
    9094
    9195    for (unsigned i = 0; i < length; i++) {
    92         if (FcFreeTypeCharIndex(face, characters[i]) == 0) {
    93             cairo_ft_scaled_font_unlock_face(m_font.m_scaledFont);
    94             return false;
     96        if (PANGO_COVERAGE_NONE == pango_coverage_get(requested, i)) {
     97            result = false;
     98            break;
    9599        }
    96100    }
    97101
    98     cairo_ft_scaled_font_unlock_face(m_font.m_scaledFont);
     102    pango_coverage_unref(available);
     103    pango_coverage_unref(requested);
    99104
    100     return true;
     105    return result;
    101106}
    102107
  • trunk/WebCore/platform/graphics/gtk/FontPlatformData.h

    r28251 r28864  
    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.
    89 * All rights reserved.
    910 *
     
    3132#include "FontDescription.h"
    3233#include <cairo.h>
    33 #include <cairo-ft.h>
    34 #include <fontconfig/fcfreetype.h>
     34#include <pango/pangocairo.h>
    3535
    3636namespace WebCore {
     
    4040    class Deleted {};
    4141    FontPlatformData(Deleted)
    42         : m_pattern(reinterpret_cast<FcPattern*>(-1))
     42        : m_context(0)
     43        , m_font(reinterpret_cast<PangoFont*>(-1))
    4344        , m_scaledFont(0)
    4445        { }
    4546
    4647    FontPlatformData()
    47         : m_pattern(0)
     48        : m_context(0)
     49        , m_font(0)
    4850        , m_scaledFont(0)
    4951        { }
     
    6062    unsigned hash() const
    6163    {
    62         uintptr_t hashCodes[1] = { reinterpret_cast<uintptr_t>(m_scaledFont) };
    63         return StringImpl::computeHash( reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
     64        uintptr_t hashCodes[1] = {reinterpret_cast<uintptr_t>(m_scaledFont)};
     65        return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
    6466    }
    6567
    6668    bool operator==(const FontPlatformData&) const;
    6769
    68     FcPattern* m_pattern;
     70    static PangoFontMap* m_fontMap;
     71    static GHashTable  * m_hashTable;
     72
     73    PangoContext* m_context;
     74    PangoFont* m_font;
    6975    FontDescription m_fontDescription;
    7076    cairo_scaled_font_t* m_scaledFont;
  • trunk/WebCore/platform/graphics/gtk/FontPlatformDataGtk.cpp

    r28251 r28864  
    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.
    910 * All rights reserved.
    1011 *
     
    3233#include "PlatformString.h"
    3334#include "FontDescription.h"
    34 
    35 #include <cairo-ft.h>
    3635#include <cairo.h>
    37 #include <fontconfig/fcfreetype.h>
     36#include <assert.h>
    3837
    3938namespace WebCore {
    4039
     40PangoFontMap* FontPlatformData::m_fontMap = 0;
     41GHashTable* FontPlatformData::m_hashTable = 0;
     42
    4143FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
    42     : m_pattern(0)
     44    : m_context(0)
     45    , m_font(0)
    4346    , m_fontDescription(fontDescription)
    4447    , m_scaledFont(0)
     
    4649    FontPlatformData::init();
    4750
    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;
     51    CString  stored_family = familyName.domString().utf8();
     52    gchar const* families[] = {
     53        stored_family.data(),
     54        NULL
     55    };
    5756
    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";
     57    switch (fontDescription.genericFamily()) {
     58    case FontDescription::SerifFamily:
     59        families[1] = "serif";
     60        break;
     61    case FontDescription::SansSerifFamily:
     62        families[1] = "sans";
     63        break;
     64    case FontDescription::MonospaceFamily:
     65        families[1] = "monospace";
     66        break;
     67    case FontDescription::NoFamily:
     68    case FontDescription::StandardFamily:
     69    default:
     70        families[1] = "sans";
     71        break;
    8272    }
    8373
    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;
     74    PangoFontDescription* description = pango_font_description_new();
     75    pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE);
    9276
    93     FcConfigSubstitute(NULL, pattern, FcMatchPattern);
    94     FcDefaultSubstitute(pattern);
     77    if (fontDescription.bold())
     78        pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD);
     79    if (fontDescription.italic())
     80        pango_font_description_set_style(description, PANGO_STYLE_ITALIC);
    9581
    96     FcResult fcresult;
    97     m_pattern = FcFontMatch(NULL, pattern, &fcresult);
     82    m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap));
     83
     84    for (unsigned int i = 0; !m_font && i < G_N_ELEMENTS(families); i++) {
     85        pango_font_description_set_family(description, families[i]);
     86        m_font = pango_font_map_load_font(m_fontMap, m_context, description);
     87    }
     88
    9889    // 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);
     90    if (m_font)
     91        m_scaledFont = pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font));
    10992
    110 freePattern:
    111     FcPatternDestroy(pattern);
     93    pango_font_description_free(description);
    11294}
    11395
     
    118100        return true;
    119101    initialized = true;
    120     if (!FcInit()) {
    121         fprintf(stderr, "Can't init font config library\n");
    122         return false;
     102
     103    if (!m_fontMap)
     104        m_fontMap = pango_cairo_font_map_new();
     105    if (!m_hashTable) {
     106        PangoFontFamily**families = 0;
     107        int n_families = 0;
     108
     109        m_hashTable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
     110
     111        pango_font_map_list_families(m_fontMap, &families, &n_families);
     112
     113        for (int family = 0; family < n_families; family++)
     114                g_hash_table_insert(m_hashTable,
     115                                    g_strdup(pango_font_family_get_name(families[family])),
     116                                    g_object_ref(families[family]));
     117
     118        g_free(families);
    123119    }
     120
    124121    return true;
    125122}
     
    131128bool FontPlatformData::isFixedPitch()
    132129{
    133     int spacing;
    134     if (FcPatternGetInteger(m_pattern, FC_SPACING, 0, &spacing) == FcResultMatch)
    135         return spacing == FC_MONO;
    136     return false;
     130    PangoFontDescription* description = pango_font_describe_with_absolute_size(m_font);
     131    PangoFontFamily* family = reinterpret_cast<PangoFontFamily*>(g_hash_table_lookup(m_hashTable, pango_font_description_get_family(description)));
     132    pango_font_description_free(description);
     133
     134    return pango_font_family_is_monospace(family);
    137135}
    138136
     
    146144bool FontPlatformData::operator==(const FontPlatformData& other) const
    147145{
    148     if (m_pattern == other.m_pattern)
     146    if (m_font == other.m_font)
    149147        return true;
    150     if (m_pattern == 0 || m_pattern == reinterpret_cast<FcPattern*>(-1)
    151             || other.m_pattern == 0 || other.m_pattern == reinterpret_cast<FcPattern*>(-1))
     148    if (m_font == 0 || m_font == reinterpret_cast<PangoFont*>(-1)
     149            || other.m_font == 0 || other.m_font == reinterpret_cast<PangoFont*>(-1))
    152150        return false;
    153     return FcPatternEqual(m_pattern, other.m_pattern);
     151
     152    PangoFontDescription* thisDesc = pango_font_describe(m_font);
     153    PangoFontDescription* otherDesc = pango_font_describe(other.m_font);
     154    bool result = pango_font_description_equal(thisDesc, otherDesc);
     155    pango_font_description_free(otherDesc);
     156    pango_font_description_free(thisDesc);
     157    return result;
    154158}
    155159
  • trunk/WebCore/platform/graphics/gtk/GlyphPageTreeNodeGtk.cpp

    r28251 r28864  
    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.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    3334
    3435#include "FontData.h"
     36#include <pango/pango-font.h>
    3537
    3638namespace WebCore {
     39
     40static 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}
    3768
    3869bool GlyphPage::fill(UChar* buffer, unsigned bufferLength, const FontData* fontData)
     
    4374        return false;
    4475
    45     FT_Face face = cairo_ft_scaled_font_lock_face(fontData->m_font.m_scaledFont);
    46     if (!face)
     76    if (!fontData->m_font.m_font || fontData->m_font.m_font == reinterpret_cast<PangoFont*>(-1))
    4777        return false;
    4878
    4979    bool haveGlyphs = false;
    5080    for (unsigned i = 0; i < GlyphPage::size; i++) {
    51         Glyph glyph = FcFreeTypeCharIndex(face, buffer[i]);
     81        Glyph glyph = pango_font_get_glyph(fontData->m_font.m_font, fontData->m_font.m_context, buffer[i]);
    5282        if (!glyph)
    5383            setGlyphDataForIndex(i, 0, 0);
     
    5888    }
    5989
    60     cairo_ft_scaled_font_unlock_face(fontData->m_font.m_scaledFont);
    61 
    6290    return haveGlyphs;
    6391}
Note: See TracChangeset for help on using the changeset viewer.