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

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

Issue 1192223002: Optimize Complex Text Shaping and Caching (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Change CachingWordShaperTest as suggested Created 5 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/fonts/FontPlatformData.h ('k') | Source/platform/fonts/WidthCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "platform/fonts/FontPlatformData.h" 22 #include "platform/fonts/FontPlatformData.h"
23 23
24 #include "SkEndian.h" 24 #include "SkEndian.h"
25 #include "SkTypeface.h" 25 #include "SkTypeface.h"
26 #include "hb-ot.h"
27 #include "hb.h"
28 #include "platform/fonts/Character.h"
26 #include "platform/fonts/FontCache.h" 29 #include "platform/fonts/FontCache.h"
27 #include "platform/fonts/shaping/HarfBuzzFace.h" 30 #include "platform/fonts/shaping/HarfBuzzFace.h"
28 #include "wtf/HashMap.h" 31 #include "wtf/HashMap.h"
29 #include "wtf/text/StringHash.h" 32 #include "wtf/text/StringHash.h"
30 #include "wtf/text/WTFString.h" 33 #include "wtf/text/WTFString.h"
31 34
32 #if OS(MACOSX) 35 #if OS(MACOSX)
33 #include "third_party/skia/include/ports/SkTypeface_mac.h" 36 #include "third_party/skia/include/ports/SkTypeface_mac.h"
34 #endif 37 #endif
35 38
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 264 }
262 265
263 HarfBuzzFace* FontPlatformData::harfBuzzFace() const 266 HarfBuzzFace* FontPlatformData::harfBuzzFace() const
264 { 267 {
265 if (!m_harfBuzzFace) 268 if (!m_harfBuzzFace)
266 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this ), uniqueID()); 269 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this ), uniqueID());
267 270
268 return m_harfBuzzFace.get(); 271 return m_harfBuzzFace.get();
269 } 272 }
270 273
274 static inline bool tableHasSpace(hb_face_t* face, hb_set_t* glyphs,
275 hb_tag_t tag, hb_codepoint_t space)
276 {
277 unsigned count = hb_ot_layout_table_get_lookup_count(face, tag);
278 for (unsigned i = 0; i < count; i++) {
279 hb_ot_layout_lookup_collect_glyphs(face, tag, i, glyphs, glyphs, glyphs,
280 0);
281 if (hb_set_has(glyphs, space))
282 return true;
283 }
284 return false;
285 }
286
287 bool FontPlatformData::hasSpaceInLigaturesOrKerning(
288 TypesettingFeatures features) const
289 {
290 const HarfBuzzFace* hbFace = harfBuzzFace();
291 if (!hbFace)
292 return true;
293
294 hb_face_t* face = hbFace->face();
295 ASSERT(face);
296 hb_font_t* font = hbFace->createFont();
297 ASSERT(font);
298
299 hb_codepoint_t space;
300 // If the space glyph isn't present in the font then each space character
301 // will be rendering using a fallback font, which grantees that it cannot
302 // affect the shape of the preceding word.
303 if (!hb_font_get_glyph(font, spaceCharacter, 0, &space))
304 return true;
305
306 if (!hb_ot_layout_has_substitution(face)
307 && !hb_ot_layout_has_positioning(face)) {
308 return true;
309 }
310
311 bool foundSpaceInTable = false;
312 hb_set_t* glyphs = hb_set_create();
313 if (features & Kerning)
314 foundSpaceInTable = tableHasSpace(face, glyphs, HB_OT_TAG_GPOS, space);
315 if (!foundSpaceInTable && (features & Ligatures))
316 foundSpaceInTable = tableHasSpace(face, glyphs, HB_OT_TAG_GSUB, space);
317
318 hb_set_destroy(glyphs);
319 hb_font_destroy(font);
320
321 return foundSpaceInTable;
322 }
323
271 unsigned FontPlatformData::hash() const 324 unsigned FontPlatformData::hash() const
272 { 325 {
273 unsigned h = SkTypeface::UniqueID(typeface()); 326 unsigned h = SkTypeface::UniqueID(typeface());
274 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)); 327 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));
275 328
276 // This memcpy is to avoid a reinterpret_cast that breaks strict-aliasing 329 // This memcpy is to avoid a reinterpret_cast that breaks strict-aliasing
277 // rules. Memcpy is generally optimized enough so that performance doesn't 330 // rules. Memcpy is generally optimized enough so that performance doesn't
278 // matter here. 331 // matter here.
279 uint32_t textSizeBytes; 332 uint32_t textSizeBytes;
280 memcpy(&textSizeBytes, &m_textSize, sizeof(uint32_t)); 333 memcpy(&textSizeBytes, &m_textSize, sizeof(uint32_t));
(...skipping 29 matching lines...) Expand all
310 const size_t tableSize = m_typeface->getTableSize(tag); 363 const size_t tableSize = m_typeface->getTableSize(tag);
311 if (tableSize) { 364 if (tableSize) {
312 Vector<char> tableBuffer(tableSize); 365 Vector<char> tableBuffer(tableSize);
313 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]); 366 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]);
314 buffer = SharedBuffer::adoptVector(tableBuffer); 367 buffer = SharedBuffer::adoptVector(tableBuffer);
315 } 368 }
316 return buffer.release(); 369 return buffer.release();
317 } 370 }
318 371
319 } // namespace blink 372 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/FontPlatformData.h ('k') | Source/platform/fonts/WidthCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698