Changeset 28864 in webkit
- Timestamp:
- Dec 19, 2007 10:00:23 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r28861 r28864 1 2007-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 1 30 2007-12-19 Alp Toker <alp@atoker.com> 2 31 -
trunk/WebCore/platform/graphics/gtk/FontCacheGtk.cpp
r28251 r28864 65 65 { 66 66 FontPlatformData platformData(fontDescription, family); 67 return platformData.m_ pattern!= 0;67 return platformData.m_font != 0; 68 68 } 69 69 -
trunk/WebCore/platform/graphics/gtk/FontDataGtk.cpp
r28251 r28864 4 4 * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> 5 5 * Copyright (C) 2007 Holger Hans Peter Freyther 6 * Copyright (C) 2007 Pioneer Research Center USA, Inc. 6 7 * All rights reserved. 7 8 * … … 63 64 void FontData::platformDestroy() 64 65 { 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); 67 70 68 71 if (m_font.m_scaledFont) … … 84 87 bool FontData::containsCharacters(const UChar* characters, int length) const 85 88 { 86 FT_Face face = cairo_ft_scaled_font_lock_face(m_font.m_scaledFont);89 bool result = true; 87 90 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); 90 94 91 95 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; 95 99 } 96 100 } 97 101 98 cairo_ft_scaled_font_unlock_face(m_font.m_scaledFont); 102 pango_coverage_unref(available); 103 pango_coverage_unref(requested); 99 104 100 return true;105 return result; 101 106 } 102 107 -
trunk/WebCore/platform/graphics/gtk/FontPlatformData.h
r28251 r28864 6 6 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 7 7 * Copyright (C) 2007 Holger Hans Peter Freyther 8 * Copyright (C) 2007 Pioneer Research Center USA, Inc. 8 9 * All rights reserved. 9 10 * … … 31 32 #include "FontDescription.h" 32 33 #include <cairo.h> 33 #include <cairo-ft.h> 34 #include <fontconfig/fcfreetype.h> 34 #include <pango/pangocairo.h> 35 35 36 36 namespace WebCore { … … 40 40 class Deleted {}; 41 41 FontPlatformData(Deleted) 42 : m_pattern(reinterpret_cast<FcPattern*>(-1)) 42 : m_context(0) 43 , m_font(reinterpret_cast<PangoFont*>(-1)) 43 44 , m_scaledFont(0) 44 45 { } 45 46 46 47 FontPlatformData() 47 : m_pattern(0) 48 : m_context(0) 49 , m_font(0) 48 50 , m_scaledFont(0) 49 51 { } … … 60 62 unsigned hash() const 61 63 { 62 uintptr_t hashCodes[1] = { reinterpret_cast<uintptr_t>(m_scaledFont)};63 return StringImpl::computeHash( 64 uintptr_t hashCodes[1] = {reinterpret_cast<uintptr_t>(m_scaledFont)}; 65 return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar)); 64 66 } 65 67 66 68 bool operator==(const FontPlatformData&) const; 67 69 68 FcPattern* m_pattern; 70 static PangoFontMap* m_fontMap; 71 static GHashTable * m_hashTable; 72 73 PangoContext* m_context; 74 PangoFont* m_font; 69 75 FontDescription m_fontDescription; 70 76 cairo_scaled_font_t* m_scaledFont; -
trunk/WebCore/platform/graphics/gtk/FontPlatformDataGtk.cpp
r28251 r28864 7 7 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 8 8 * Copyright (C) 2007 Holger Hans Peter Freyther 9 * Copyright (C) 2007 Pioneer Research Center USA, Inc. 9 10 * All rights reserved. 10 11 * … … 32 33 #include "PlatformString.h" 33 34 #include "FontDescription.h" 34 35 #include <cairo-ft.h>36 35 #include <cairo.h> 37 #include < fontconfig/fcfreetype.h>36 #include <assert.h> 38 37 39 38 namespace WebCore { 40 39 40 PangoFontMap* FontPlatformData::m_fontMap = 0; 41 GHashTable* FontPlatformData::m_hashTable = 0; 42 41 43 FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) 42 : m_pattern(0) 44 : m_context(0) 45 , m_font(0) 43 46 , m_fontDescription(fontDescription) 44 47 , m_scaledFont(0) … … 46 49 FontPlatformData::init(); 47 50 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 }; 57 56 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; 82 72 } 83 73 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); 92 76 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); 95 81 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 98 89 // 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)); 109 92 110 freePattern: 111 FcPatternDestroy(pattern); 93 pango_font_description_free(description); 112 94 } 113 95 … … 118 100 return true; 119 101 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); 123 119 } 120 124 121 return true; 125 122 } … … 131 128 bool FontPlatformData::isFixedPitch() 132 129 { 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); 137 135 } 138 136 … … 146 144 bool FontPlatformData::operator==(const FontPlatformData& other) const 147 145 { 148 if (m_ pattern == other.m_pattern)146 if (m_font == other.m_font) 149 147 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)) 152 150 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; 154 158 } 155 159 -
trunk/WebCore/platform/graphics/gtk/GlyphPageTreeNodeGtk.cpp
r28251 r28864 3 3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 4 4 * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> 5 * Copyright (C) 2007 Pioneer Research Center USA, Inc. 5 6 * 6 7 * Redistribution and use in source and binary forms, with or without … … 33 34 34 35 #include "FontData.h" 36 #include <pango/pango-font.h> 35 37 36 38 namespace 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 } 37 68 38 69 bool GlyphPage::fill(UChar* buffer, unsigned bufferLength, const FontData* fontData) … … 43 74 return false; 44 75 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)) 47 77 return false; 48 78 49 79 bool haveGlyphs = false; 50 80 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]); 52 82 if (!glyph) 53 83 setGlyphDataForIndex(i, 0, 0); … … 58 88 } 59 89 60 cairo_ft_scaled_font_unlock_face(fontData->m_font.m_scaledFont);61 62 90 return haveGlyphs; 63 91 }
Note: See TracChangeset
for help on using the changeset viewer.