Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontPlatformData.cpp

Issue 1931393002: Introduce typeface cache in blink::FontCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip: others Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Brent Fulgham 2 * Copyright (C) 2011 Brent Fulgham
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 26 matching lines...) Expand all
37 37
38 using namespace std; 38 using namespace std;
39 39
40 namespace blink { 40 namespace blink {
41 41
42 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) 42 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
43 : m_typeface(nullptr) 43 : m_typeface(nullptr)
44 #if !OS(WIN) 44 #if !OS(WIN)
45 , m_family(CString()) 45 , m_family(CString())
46 #endif 46 #endif
47 , m_textSize(0)
48 , m_syntheticBold(false) 47 , m_syntheticBold(false)
49 , m_syntheticItalic(false) 48 , m_syntheticItalic(false)
50 , m_orientation(FontOrientation::Horizontal) 49 , m_orientation(FontOrientation::Horizontal)
51 #if !OS(MACOSX) 50 #if !OS(MACOSX)
52 , m_style(FontRenderStyle()) 51 , m_style(FontRenderStyle())
53 #endif 52 #endif
54 , m_isHashTableDeletedValue(true) 53 , m_isHashTableDeletedValue(true)
55 #if OS(WIN) 54 #if OS(WIN)
56 , m_paintTextFlags(0) 55 , m_paintTextFlags(0)
57 , m_minSizeForAntiAlias(0) 56 , m_minSizeForAntiAlias(0)
58 , m_minSizeForSubpixel(0) 57 , m_minSizeForSubpixel(0)
59 #endif 58 #endif
60 { 59 {
61 } 60 }
62 61
63 FontPlatformData::FontPlatformData() 62 FontPlatformData::FontPlatformData()
64 : m_typeface(nullptr) 63 : m_typeface(nullptr)
65 #if !OS(WIN) 64 #if !OS(WIN)
66 , m_family(CString()) 65 , m_family(CString())
67 #endif 66 #endif
68 , m_textSize(0)
69 , m_syntheticBold(false) 67 , m_syntheticBold(false)
70 , m_syntheticItalic(false) 68 , m_syntheticItalic(false)
71 , m_orientation(FontOrientation::Horizontal) 69 , m_orientation(FontOrientation::Horizontal)
72 #if !OS(MACOSX) 70 #if !OS(MACOSX)
73 , m_style(FontRenderStyle()) 71 , m_style(FontRenderStyle())
74 #endif 72 #endif
75 , m_isHashTableDeletedValue(false) 73 , m_isHashTableDeletedValue(false)
76 #if OS(WIN) 74 #if OS(WIN)
77 , m_paintTextFlags(0) 75 , m_paintTextFlags(0)
78 , m_minSizeForAntiAlias(0) 76 , m_minSizeForAntiAlias(0)
79 , m_minSizeForSubpixel(0) 77 , m_minSizeForSubpixel(0)
80 #endif 78 #endif
81 { 79 {
82 } 80 }
83 81
84 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti cItalic, FontOrientation orientation) 82 FontPlatformData::FontPlatformData(bool syntheticBold, bool syntheticItalic, Fon tOrientation orientation)
85 : m_typeface(nullptr) 83 : m_typeface(nullptr)
86 #if !OS(WIN) 84 #if !OS(WIN)
87 , m_family(CString()) 85 , m_family(CString())
88 #endif 86 #endif
89 , m_textSize(size)
90 , m_syntheticBold(syntheticBold) 87 , m_syntheticBold(syntheticBold)
91 , m_syntheticItalic(syntheticItalic) 88 , m_syntheticItalic(syntheticItalic)
92 , m_orientation(orientation) 89 , m_orientation(orientation)
93 #if !OS(MACOSX) 90 #if !OS(MACOSX)
94 , m_style(FontRenderStyle()) 91 , m_style(FontRenderStyle())
95 #endif 92 #endif
96 , m_isHashTableDeletedValue(false) 93 , m_isHashTableDeletedValue(false)
97 #if OS(WIN) 94 #if OS(WIN)
98 , m_paintTextFlags(0) 95 , m_paintTextFlags(0)
99 , m_minSizeForAntiAlias(0) 96 , m_minSizeForAntiAlias(0)
100 , m_minSizeForSubpixel(0) 97 , m_minSizeForSubpixel(0)
101 #endif 98 #endif
102 { 99 {
103 } 100 }
104 101
105 FontPlatformData::FontPlatformData(const FontPlatformData& source) 102 FontPlatformData::FontPlatformData(const FontPlatformData& source)
106 : m_typeface(source.m_typeface) 103 : m_typeface(source.m_typeface)
107 #if !OS(WIN) 104 #if !OS(WIN)
108 , m_family(source.m_family) 105 , m_family(source.m_family)
109 #endif 106 #endif
110 , m_textSize(source.m_textSize)
111 , m_syntheticBold(source.m_syntheticBold) 107 , m_syntheticBold(source.m_syntheticBold)
112 , m_syntheticItalic(source.m_syntheticItalic) 108 , m_syntheticItalic(source.m_syntheticItalic)
113 , m_orientation(source.m_orientation) 109 , m_orientation(source.m_orientation)
114 #if !OS(MACOSX) 110 #if !OS(MACOSX)
115 , m_style(source.m_style) 111 , m_style(source.m_style)
116 #endif 112 #endif
117 , m_harfBuzzFace(nullptr) 113 , m_harfBuzzFace(nullptr)
118 , m_isHashTableDeletedValue(false) 114 , m_isHashTableDeletedValue(false)
119 #if OS(WIN) 115 #if OS(WIN)
120 , m_paintTextFlags(source.m_paintTextFlags) 116 , m_paintTextFlags(source.m_paintTextFlags)
121 , m_minSizeForAntiAlias(source.m_minSizeForAntiAlias) 117 , m_minSizeForAntiAlias(source.m_minSizeForAntiAlias)
122 , m_minSizeForSubpixel(source.m_minSizeForSubpixel) 118 , m_minSizeForSubpixel(source.m_minSizeForSubpixel)
123 #endif 119 #endif
124 { 120 {
125 } 121 }
126 122
127 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
128 : m_typeface(src.m_typeface)
129 #if !OS(WIN)
130 , m_family(src.m_family)
131 #endif
132 , m_textSize(textSize)
133 , m_syntheticBold(src.m_syntheticBold)
134 , m_syntheticItalic(src.m_syntheticItalic)
135 , m_orientation(src.m_orientation)
136 #if !OS(MACOSX)
137 , m_style(src.m_style)
138 #endif
139 , m_harfBuzzFace(nullptr)
140 , m_isHashTableDeletedValue(false)
141 #if OS(WIN)
142 , m_paintTextFlags(src.m_paintTextFlags)
143 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
144 , m_minSizeForSubpixel(src.m_minSizeForSubpixel)
145 #endif
146 {
147 #if !OS(MACOSX)
148 querySystemForRenderStyle();
149 #endif
150 }
151
152 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, 123 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf,
153 const char* family, float textSize, bool syntheticBold, 124 const char* family, bool syntheticBold,
154 bool syntheticItalic, FontOrientation orientation) 125 bool syntheticItalic, FontOrientation orientation)
155 : m_typeface(tf) 126 : m_typeface(tf)
156 #if !OS(WIN) 127 #if !OS(WIN)
157 , m_family(family) 128 , m_family(family)
158 #endif 129 #endif
159 , m_textSize(textSize)
160 , m_syntheticBold(syntheticBold) 130 , m_syntheticBold(syntheticBold)
161 , m_syntheticItalic(syntheticItalic) 131 , m_syntheticItalic(syntheticItalic)
162 , m_orientation(orientation) 132 , m_orientation(orientation)
163 , m_isHashTableDeletedValue(false) 133 , m_isHashTableDeletedValue(false)
164 #if OS(WIN) 134 #if OS(WIN)
165 , m_paintTextFlags(0) 135 , m_paintTextFlags(0)
166 , m_minSizeForAntiAlias(0) 136 , m_minSizeForAntiAlias(0)
167 , m_minSizeForSubpixel(0) 137 , m_minSizeForSubpixel(0)
168 #endif 138 #endif
169 { 139 {
170 #if !OS(MACOSX)
171 querySystemForRenderStyle();
172 #endif
173 } 140 }
174 141
175 FontPlatformData::~FontPlatformData() 142 FontPlatformData::~FontPlatformData()
176 { 143 {
177 } 144 }
178 145
179 #if OS(MACOSX) 146 #if OS(MACOSX)
180 CTFontRef FontPlatformData::ctFont() const 147 CTFontRef FontPlatformData::ctFont() const
181 { 148 {
182 return SkTypeface_GetCTFontRef(m_typeface.get()); 149 return SkTypeface_GetCTFontRef(m_typeface.get());
183 }; 150 };
184 151
185 CGFontRef FontPlatformData::cgFont() const 152 CGFontRef FontPlatformData::cgFont() const
186 { 153 {
187 return CTFontCopyGraphicsFont(ctFont(), 0); 154 return CTFontCopyGraphicsFont(ctFont(), 0);
188 } 155 }
189 #endif 156 #endif
190 157
191 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe r) 158 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe r)
192 { 159 {
193 // Check for self-assignment. 160 // Check for self-assignment.
194 if (this == &other) 161 if (this == &other)
195 return *this; 162 return *this;
196 163
197 m_typeface = other.m_typeface; 164 m_typeface = other.m_typeface;
198 #if !OS(WIN) 165 #if !OS(WIN)
199 m_family = other.m_family; 166 m_family = other.m_family;
200 #endif 167 #endif
201 m_textSize = other.m_textSize;
202 m_syntheticBold = other.m_syntheticBold; 168 m_syntheticBold = other.m_syntheticBold;
203 m_syntheticItalic = other.m_syntheticItalic; 169 m_syntheticItalic = other.m_syntheticItalic;
204 m_harfBuzzFace = nullptr; 170 m_harfBuzzFace = nullptr;
205 m_orientation = other.m_orientation; 171 m_orientation = other.m_orientation;
206 #if !OS(MACOSX) 172 #if !OS(MACOSX)
207 m_style = other.m_style; 173 m_style = other.m_style;
208 #endif 174 #endif
209 175
210 #if OS(WIN) 176 #if OS(WIN)
211 m_paintTextFlags = 0; 177 m_paintTextFlags = 0;
212 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias; 178 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias;
213 m_minSizeForSubpixel = other.m_minSizeForSubpixel; 179 m_minSizeForSubpixel = other.m_minSizeForSubpixel;
214 #endif 180 #endif
215 181
216 return *this; 182 return *this;
217 } 183 }
218 184
219 bool FontPlatformData::operator==(const FontPlatformData& a) const 185 bool FontPlatformData::operator==(const FontPlatformData& a) const
220 { 186 {
221 // If either of the typeface pointers are null then we test for pointer 187 // If either of the typeface pointers are null then we test for pointer
222 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers. 188 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers.
223 bool typefacesEqual = false; 189 bool typefacesEqual = false;
224 if (!typeface() || !a.typeface()) 190 if (!typeface() || !a.typeface())
225 typefacesEqual = typeface() == a.typeface(); 191 typefacesEqual = typeface() == a.typeface();
226 else 192 else
227 typefacesEqual = SkTypeface::Equal(typeface(), a.typeface()); 193 typefacesEqual = SkTypeface::Equal(typeface(), a.typeface());
228 194
229 return typefacesEqual 195 return typefacesEqual
230 && m_textSize == a.m_textSize
231 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue 196 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue
232 && m_syntheticBold == a.m_syntheticBold 197 && m_syntheticBold == a.m_syntheticBold
233 && m_syntheticItalic == a.m_syntheticItalic 198 && m_syntheticItalic == a.m_syntheticItalic
234 #if !OS(MACOSX) 199 #if !OS(MACOSX)
235 && m_style == a.m_style 200 && m_style == a.m_style
236 #endif 201 #endif
237 && m_orientation == a.m_orientation; 202 && m_orientation == a.m_orientation;
238 } 203 }
239 204
240 SkFontID FontPlatformData::uniqueID() const 205 SkFontID FontPlatformData::uniqueID() const
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 for (unsigned i = 0; i < count; i++) { 237 for (unsigned i = 0; i < count; i++) {
273 hb_ot_layout_lookup_collect_glyphs(face, tag, i, glyphs, glyphs, glyphs, 238 hb_ot_layout_lookup_collect_glyphs(face, tag, i, glyphs, glyphs, glyphs,
274 0); 239 0);
275 if (hb_set_has(glyphs, space)) 240 if (hb_set_has(glyphs, space))
276 return true; 241 return true;
277 } 242 }
278 return false; 243 return false;
279 } 244 }
280 245
281 bool FontPlatformData::hasSpaceInLigaturesOrKerning( 246 bool FontPlatformData::hasSpaceInLigaturesOrKerning(
247 float fontSize,
248 const FontRenderStyle& style,
282 TypesettingFeatures features) const 249 TypesettingFeatures features) const
283 { 250 {
284 const HarfBuzzFace* hbFace = harfBuzzFace(); 251 const HarfBuzzFace* hbFace = harfBuzzFace();
285 if (!hbFace) 252 if (!hbFace)
286 return false; 253 return false;
287 254
288 hb_face_t* face = hbFace->face(); 255 hb_face_t* face = hbFace->face();
289 ASSERT(face); 256 ASSERT(face);
290 OwnPtr<hb_font_t> font = adoptPtr(hbFace->createFont()); 257 OwnPtr<hb_font_t> font = adoptPtr(hbFace->createFont(fontSize, style));
291 ASSERT(font); 258 ASSERT(font);
292 259
293 hb_codepoint_t space; 260 hb_codepoint_t space;
294 // If the space glyph isn't present in the font then each space character 261 // If the space glyph isn't present in the font then each space character
295 // will be rendering using a fallback font, which grantees that it cannot 262 // will be rendering using a fallback font, which grantees that it cannot
296 // affect the shape of the preceding word. 263 // affect the shape of the preceding word.
297 if (!hb_font_get_glyph(font.get(), spaceCharacter, 0, &space)) 264 if (!hb_font_get_glyph(font.get(), spaceCharacter, 0, &space))
298 return false; 265 return false;
299 266
300 if (!hb_ot_layout_has_substitution(face) 267 if (!hb_ot_layout_has_substitution(face)
(...skipping 10 matching lines...) Expand all
311 278
312 hb_set_destroy(glyphs); 279 hb_set_destroy(glyphs);
313 280
314 return foundSpaceInTable; 281 return foundSpaceInTable;
315 } 282 }
316 283
317 unsigned FontPlatformData::hash() const 284 unsigned FontPlatformData::hash() const
318 { 285 {
319 unsigned h = SkTypeface::UniqueID(typeface()); 286 unsigned h = SkTypeface::UniqueID(typeface());
320 h ^= 0x01010101 * ((static_cast<int>(m_isHashTableDeletedValue) << 3) | (sta tic_cast<int>(m_orientation) << 2) | (static_cast<int>(m_syntheticBold) << 1) | static_cast<int>(m_syntheticItalic)); 287 h ^= 0x01010101 * ((static_cast<int>(m_isHashTableDeletedValue) << 3) | (sta tic_cast<int>(m_orientation) << 2) | (static_cast<int>(m_syntheticBold) << 1) | static_cast<int>(m_syntheticItalic));
321
322 // This memcpy is to avoid a reinterpret_cast that breaks strict-aliasing
323 // rules. Memcpy is generally optimized enough so that performance doesn't
324 // matter here.
325 uint32_t textSizeBytes;
326 memcpy(&textSizeBytes, &m_textSize, sizeof(uint32_t));
327 h ^= textSizeBytes;
328
329 return h; 288 return h;
330 } 289 }
331 290
332 #if !OS(MACOSX) 291 #if !OS(MACOSX)
333 bool FontPlatformData::fontContainsCharacter(UChar32 character) 292 bool FontPlatformData::fontContainsCharacter(UChar32 character)
334 { 293 {
335 SkPaint paint; 294 SkPaint paint;
336 setupPaint(&paint); 295 setupPaint(&paint);
337 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); 296 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
338 297
(...skipping 16 matching lines...) Expand all
355 const size_t tableSize = m_typeface->getTableSize(tag); 314 const size_t tableSize = m_typeface->getTableSize(tag);
356 if (tableSize) { 315 if (tableSize) {
357 Vector<char> tableBuffer(tableSize); 316 Vector<char> tableBuffer(tableSize);
358 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]); 317 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]);
359 buffer = SharedBuffer::adoptVector(tableBuffer); 318 buffer = SharedBuffer::adoptVector(tableBuffer);
360 } 319 }
361 return buffer.release(); 320 return buffer.release();
362 } 321 }
363 322
364 } // namespace blink 323 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698