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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/SimpleFontData.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) 2005, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 Alexey Proskuryakov 3 * Copyright (C) 2006 Alexey Proskuryakov
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace blink { 47 namespace blink {
48 48
49 const float smallCapsFontSizeMultiplier = 0.7f; 49 const float smallCapsFontSizeMultiplier = 0.7f;
50 const float emphasisMarkFontSizeMultiplier = 0.5f; 50 const float emphasisMarkFontSizeMultiplier = 0.5f;
51 51
52 #if OS(LINUX) || OS(ANDROID) 52 #if OS(LINUX) || OS(ANDROID)
53 // This is the largest VDMX table which we'll try to load and parse. 53 // This is the largest VDMX table which we'll try to load and parse.
54 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB 54 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB
55 #endif 55 #endif
56 56
57 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, PassRefPtr< CustomFontData> customData, bool isTextOrientationFallback) 57 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, float fontS ize, PassRefPtr<CustomFontData> customData, bool isTextOrientationFallback)
58 : m_maxCharWidth(-1) 58 : m_maxCharWidth(-1)
59 , m_avgCharWidth(-1) 59 , m_avgCharWidth(-1)
60 , m_platformData(platformData) 60 , m_platformData(platformData)
61 , m_fontSize(fontSize)
61 , m_isTextOrientationFallback(isTextOrientationFallback) 62 , m_isTextOrientationFallback(isTextOrientationFallback)
62 , m_verticalData(nullptr) 63 , m_verticalData(nullptr)
63 , m_hasVerticalGlyphs(false) 64 , m_hasVerticalGlyphs(false)
64 , m_customFontData(customData) 65 , m_customFontData(customData)
65 { 66 {
66 platformInit(); 67 platformInit();
67 platformGlyphInit(); 68 platformGlyphInit();
68 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) { 69 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) {
69 m_verticalData = platformData.verticalData(); 70 m_verticalData = platformData.verticalData();
70 m_hasVerticalGlyphs = m_verticalData.get() && m_verticalData->hasVertica lMetrics(); 71 m_hasVerticalGlyphs = m_verticalData.get() && m_verticalData->hasVertica lMetrics();
71 } 72 }
72 } 73 }
73 74
74 SimpleFontData::SimpleFontData(PassRefPtr<CustomFontData> customData, float font Size, bool syntheticBold, bool syntheticItalic) 75 SimpleFontData::SimpleFontData(PassRefPtr<CustomFontData> customData, float font Size, bool syntheticBold, bool syntheticItalic)
75 : m_platformData(FontPlatformData(fontSize, syntheticBold, syntheticItalic)) 76 : m_platformData(FontPlatformData(syntheticBold, syntheticItalic))
77 , m_fontSize(fontSize)
76 , m_isTextOrientationFallback(false) 78 , m_isTextOrientationFallback(false)
77 , m_verticalData(nullptr) 79 , m_verticalData(nullptr)
78 , m_hasVerticalGlyphs(false) 80 , m_hasVerticalGlyphs(false)
79 , m_customFontData(customData) 81 , m_customFontData(customData)
80 { 82 {
81 if (m_customFontData) 83 if (m_customFontData)
82 m_customFontData->initializeFontData(this, fontSize); 84 m_customFontData->initializeFontData(this, fontSize);
83 } 85 }
84 86
85 void SimpleFontData::platformInit() 87 void SimpleFontData::platformInit()
86 { 88 {
87 if (!m_platformData.size()) { 89 if (!m_fontSize) {
88 m_fontMetrics.reset(); 90 m_fontMetrics.reset();
89 m_avgCharWidth = 0; 91 m_avgCharWidth = 0;
90 m_maxCharWidth = 0; 92 m_maxCharWidth = 0;
91 return; 93 return;
92 } 94 }
93 95
94 SkPaint paint; 96 SkPaint paint;
95 SkPaint::FontMetrics metrics; 97 SkPaint::FontMetrics metrics;
96 98
97 m_platformData.setupPaint(&paint); 99 m_platformData.setupPaint(&paint);
100 m_style.apply(&paint);
101 paint.setTextSize(SkFloatToScalar(m_fontSize));
98 paint.getFontMetrics(&metrics); 102 paint.getFontMetrics(&metrics);
99 SkTypeface* face = paint.getTypeface(); 103 SkTypeface* face = paint.getTypeface();
100 ASSERT(face); 104 ASSERT(face);
101 105
102 int vdmxAscent = 0, vdmxDescent = 0; 106 int vdmxAscent = 0, vdmxDescent = 0;
103 bool isVDMXValid = false; 107 bool isVDMXValid = false;
104 108
105 #if OS(LINUX) || OS(ANDROID) 109 #if OS(LINUX) || OS(ANDROID)
106 // Manually digging up VDMX metrics is only applicable when bytecode hinting using FreeType. 110 // Manually digging up VDMX metrics is only applicable when bytecode hinting using FreeType.
107 // With DirectWrite or CoreText, no bytecode hinting is ever done. 111 // With DirectWrite or CoreText, no bytecode hinting is ever done.
108 // This code should be pushed into FreeType (hinted font metrics). 112 // This code should be pushed into FreeType (hinted font metrics).
109 static const uint32_t vdmxTag = SkSetFourByteTag('V', 'D', 'M', 'X'); 113 static const uint32_t vdmxTag = SkSetFourByteTag('V', 'D', 'M', 'X');
110 int pixelSize = m_platformData.size() + 0.5; 114 int pixelSize = m_fontSize + 0.5;
111 if (!paint.isAutohinted() 115 if (!paint.isAutohinted()
112 && (paint.getHinting() == SkPaint::kFull_Hinting 116 && (paint.getHinting() == SkPaint::kFull_Hinting
113 || paint.getHinting() == SkPaint::kNormal_Hinting)) 117 || paint.getHinting() == SkPaint::kNormal_Hinting))
114 { 118 {
115 size_t vdmxSize = face->getTableSize(vdmxTag); 119 size_t vdmxSize = face->getTableSize(vdmxTag);
116 if (vdmxSize && vdmxSize < maxVDMXTableSize) { 120 if (vdmxSize && vdmxSize < maxVDMXTableSize) {
117 uint8_t* vdmxTable = (uint8_t*)WTF::Partitions::fastMalloc(vdmxSize, WTF_HEAP_PROFILER_TYPE_NAME(SimpleFontData)); 121 uint8_t* vdmxTable = (uint8_t*)WTF::Partitions::fastMalloc(vdmxSize, WTF_HEAP_PROFILER_TYPE_NAME(SimpleFontData));
118 if (vdmxTable 122 if (vdmxTable
119 && face->getTableData(vdmxTag, 0, vdmxSize, vdmxTable) == vdmxSi ze 123 && face->getTableData(vdmxTag, 0, vdmxSize, vdmxTable) == vdmxSi ze
120 && parseVDMX(&vdmxAscent, &vdmxDescent, vdmxTable, vdmxSize, pix elSize)) 124 && parseVDMX(&vdmxAscent, &vdmxDescent, vdmxTable, vdmxSize, pix elSize))
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return false; 300 return false;
297 } 301 }
298 302
299 PassRefPtr<SimpleFontData> SimpleFontData::verticalRightOrientationFontData() co nst 303 PassRefPtr<SimpleFontData> SimpleFontData::verticalRightOrientationFontData() co nst
300 { 304 {
301 if (!m_derivedFontData) 305 if (!m_derivedFontData)
302 m_derivedFontData = DerivedFontData::create(isCustomFont()); 306 m_derivedFontData = DerivedFontData::create(isCustomFont());
303 if (!m_derivedFontData->verticalRightOrientation) { 307 if (!m_derivedFontData->verticalRightOrientation) {
304 FontPlatformData verticalRightPlatformData(m_platformData); 308 FontPlatformData verticalRightPlatformData(m_platformData);
305 verticalRightPlatformData.setOrientation(FontOrientation::Horizontal); 309 verticalRightPlatformData.setOrientation(FontOrientation::Horizontal);
306 m_derivedFontData->verticalRightOrientation = create(verticalRightPlatfo rmData, isCustomFont() ? CustomFontData::create(): nullptr, true); 310 m_derivedFontData->verticalRightOrientation = create(verticalRightPlatfo rmData, m_fontSize, isCustomFont() ? CustomFontData::create(): nullptr, true);
307 } 311 }
308 return m_derivedFontData->verticalRightOrientation; 312 return m_derivedFontData->verticalRightOrientation;
309 } 313 }
310 314
311 PassRefPtr<SimpleFontData> SimpleFontData::uprightOrientationFontData() const 315 PassRefPtr<SimpleFontData> SimpleFontData::uprightOrientationFontData() const
312 { 316 {
313 if (!m_derivedFontData) 317 if (!m_derivedFontData)
314 m_derivedFontData = DerivedFontData::create(isCustomFont()); 318 m_derivedFontData = DerivedFontData::create(isCustomFont());
315 if (!m_derivedFontData->uprightOrientation) 319 if (!m_derivedFontData->uprightOrientation)
316 m_derivedFontData->uprightOrientation = create(m_platformData, isCustomF ont() ? CustomFontData::create(): nullptr, true); 320 m_derivedFontData->uprightOrientation = create(m_platformData, m_fontSiz e, isCustomFont() ? CustomFontData::create(): nullptr, true);
317 return m_derivedFontData->uprightOrientation; 321 return m_derivedFontData->uprightOrientation;
318 } 322 }
319 323
320 PassRefPtr<SimpleFontData> SimpleFontData::smallCapsFontData(const FontDescripti on& fontDescription) const 324 PassRefPtr<SimpleFontData> SimpleFontData::smallCapsFontData(const FontDescripti on& fontDescription) const
321 { 325 {
322 if (!m_derivedFontData) 326 if (!m_derivedFontData)
323 m_derivedFontData = DerivedFontData::create(isCustomFont()); 327 m_derivedFontData = DerivedFontData::create(isCustomFont());
324 if (!m_derivedFontData->smallCaps) 328 if (!m_derivedFontData->smallCaps)
325 m_derivedFontData->smallCaps = createScaledFontData(fontDescription, sma llCapsFontSizeMultiplier); 329 m_derivedFontData->smallCaps = createScaledFontData(fontDescription, sma llCapsFontSizeMultiplier);
326 330
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 370 }
367 371
368 PassRefPtr<SimpleFontData> SimpleFontData::createScaledFontData(const FontDescri ption& fontDescription, float scaleFactor) const 372 PassRefPtr<SimpleFontData> SimpleFontData::createScaledFontData(const FontDescri ption& fontDescription, float scaleFactor) const
369 { 373 {
370 return platformCreateScaledFontData(fontDescription, scaleFactor); 374 return platformCreateScaledFontData(fontDescription, scaleFactor);
371 } 375 }
372 376
373 PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo ntDescription& fontDescription, float scaleFactor) const 377 PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo ntDescription& fontDescription, float scaleFactor) const
374 { 378 {
375 const float scaledSize = lroundf(fontDescription.computedSize() * scaleFacto r); 379 const float scaledSize = lroundf(fontDescription.computedSize() * scaleFacto r);
376 return SimpleFontData::create(FontPlatformData(m_platformData, scaledSize), isCustomFont() ? CustomFontData::create() : nullptr); 380 return SimpleFontData::create(m_platformData, scaledSize, isCustomFont() ? C ustomFontData::create() : nullptr);
377 } 381 }
378 382
379 static inline void getSkiaBoundsForGlyph(SkPaint& paint, Glyph glyph, SkRect& bo unds) 383 static inline void getSkiaBoundsForGlyph(SkPaint& paint, Glyph glyph, SkRect& bo unds)
380 { 384 {
381 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 385 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
382 386
383 SkPath path; 387 SkPath path;
384 paint.getTextPath(&glyph, sizeof(glyph), 0, 0, &path); 388 paint.getTextPath(&glyph, sizeof(glyph), 0, 0, &path);
385 bounds = path.getBounds(); 389 bounds = path.getBounds();
386 390
387 if (!paint.isSubpixelText()) { 391 if (!paint.isSubpixelText()) {
388 SkIRect ir; 392 SkIRect ir;
389 bounds.round(&ir); 393 bounds.round(&ir);
390 bounds.set(ir); 394 bounds.set(ir);
391 } 395 }
392 } 396 }
393 397
394 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const 398 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph glyph) const
395 { 399 {
396 if (!m_platformData.size()) 400 if (!m_fontSize)
397 return FloatRect(); 401 return FloatRect();
398 402
399 SkASSERT(sizeof(glyph) == 2); // compile-time assert 403 SkASSERT(sizeof(glyph) == 2); // compile-time assert
400 404
401 SkPaint paint; 405 SkPaint paint;
406 m_style.apply(&paint);
407 paint.setTextSize(SkFloatToScalar(m_fontSize));
402 m_platformData.setupPaint(&paint); 408 m_platformData.setupPaint(&paint);
403 409
404 SkRect bounds; 410 SkRect bounds;
405 getSkiaBoundsForGlyph(paint, glyph, bounds); 411 getSkiaBoundsForGlyph(paint, glyph, bounds);
406 return FloatRect(bounds); 412 return FloatRect(bounds);
407 } 413 }
408 414
409 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const 415 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
410 { 416 {
411 if (!m_platformData.size()) 417 if (!m_fontSize)
412 return 0; 418 return 0;
413 419
414 SkASSERT(sizeof(glyph) == 2); // compile-time assert 420 SkASSERT(sizeof(glyph) == 2); // compile-time assert
415 421
416 SkPaint paint; 422 SkPaint paint;
417 423 m_style.apply(&paint);
424 paint.setTextSize(SkFloatToScalar(m_fontSize));
418 m_platformData.setupPaint(&paint); 425 m_platformData.setupPaint(&paint);
419 426
420 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 427 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
421 SkScalar width = paint.measureText(&glyph, 2); 428 SkScalar width = paint.measureText(&glyph, 2);
422 if (!paint.isSubpixelText()) 429 if (!paint.isSubpixelText())
423 width = SkScalarRoundToInt(width); 430 width = SkScalarRoundToInt(width);
424 return SkScalarToFloat(width); 431 return SkScalarToFloat(width);
425 } 432 }
426 433
427 bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill, unsigned offset, unsig ned length, UChar* buffer, unsigned bufferLength) const 434 bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill, unsigned offset, unsig ned length, UChar* buffer, unsigned bufferLength) const
(...skipping 18 matching lines...) Expand all
446 if (glyphs[i]) { 453 if (glyphs[i]) {
447 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this); 454 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this);
448 haveGlyphs = true; 455 haveGlyphs = true;
449 } 456 }
450 } 457 }
451 458
452 return haveGlyphs; 459 return haveGlyphs;
453 } 460 }
454 461
455 } // namespace blink 462 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698