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

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

Issue 1479003002: Remove Simple Text Path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 1 month 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 15 matching lines...) Expand all
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "platform/fonts/SimpleFontData.h" 30 #include "platform/fonts/SimpleFontData.h"
31 31
32 #include "SkPath.h" 32 #include "SkPath.h"
33 #include "SkTypeface.h" 33 #include "SkTypeface.h"
34 #include "SkTypes.h" 34 #include "SkTypes.h"
35 #include "platform/fonts/FontDescription.h" 35 #include "platform/fonts/FontDescription.h"
36 #include "platform/fonts/GlyphPage.h"
37 #include "platform/fonts/VDMXParser.h" 36 #include "platform/fonts/VDMXParser.h"
38 #include "platform/fonts/skia/SkiaTextMetrics.h" 37 #include "platform/fonts/skia/SkiaTextMetrics.h"
39 #include "platform/geometry/FloatRect.h" 38 #include "platform/geometry/FloatRect.h"
40 #include "wtf/MathExtras.h" 39 #include "wtf/MathExtras.h"
41 #include "wtf/PtrUtil.h" 40 #include "wtf/PtrUtil.h"
42 #include "wtf/allocator/Partitions.h" 41 #include "wtf/allocator/Partitions.h"
43 #include "wtf/text/CharacterNames.h" 42 #include "wtf/text/CharacterNames.h"
44 #include "wtf/text/Unicode.h" 43 #include "wtf/text/Unicode.h"
45 #include <memory> 44 #include <memory>
46 #include <unicode/unorm.h> 45 #include <unicode/unorm.h>
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 m_spaceGlyph = glyphForCharacter(' '); 279 m_spaceGlyph = glyphForCharacter(' ');
281 float width = widthForGlyph(m_spaceGlyph); 280 float width = widthForGlyph(m_spaceGlyph);
282 m_spaceWidth = width; 281 m_spaceWidth = width;
283 m_zeroGlyph = glyphForCharacter('0'); 282 m_zeroGlyph = glyphForCharacter('0');
284 m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph)); 283 m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph));
285 284
286 m_missingGlyphData.fontData = this; 285 m_missingGlyphData.fontData = this;
287 m_missingGlyphData.glyph = 0; 286 m_missingGlyphData.glyph = 0;
288 } 287 }
289 288
290 SimpleFontData::~SimpleFontData() {
291 if (isCustomFont())
292 GlyphPageTreeNode::pruneTreeCustomFontData(this);
293 else
294 GlyphPageTreeNode::pruneTreeFontData(this);
295 }
296
297 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const { 289 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const {
298 return this; 290 return this;
299 } 291 }
300 292
301 Glyph SimpleFontData::glyphForCharacter(UChar32 codepoint) const { 293 Glyph SimpleFontData::glyphForCharacter(UChar32 codepoint) const {
302 uint16_t glyph; 294 uint16_t glyph;
303 SkTypeface* typeface = platformData().typeface(); 295 SkTypeface* typeface = platformData().typeface();
304 RELEASE_ASSERT(typeface); 296 RELEASE_ASSERT(typeface);
305 typeface->charsToGlyphs(&codepoint, SkTypeface::kUTF32_Encoding, &glyph, 1); 297 typeface->charsToGlyphs(&codepoint, SkTypeface::kUTF32_Encoding, &glyph, 1);
306 return glyph; 298 return glyph;
307 } 299 }
308 300
309 bool SimpleFontData::isSegmented() const { 301 bool SimpleFontData::isSegmented() const {
310 return false; 302 return false;
311 } 303 }
312 304
313 PassRefPtr<SimpleFontData> SimpleFontData::verticalRightOrientationFontData() 305 PassRefPtr<SimpleFontData> SimpleFontData::verticalRightOrientationFontData()
314 const { 306 const {
315 if (!m_derivedFontData) 307 if (!m_derivedFontData)
316 m_derivedFontData = DerivedFontData::create(isCustomFont()); 308 m_derivedFontData = DerivedFontData::create();
317 if (!m_derivedFontData->verticalRightOrientation) { 309 if (!m_derivedFontData->verticalRightOrientation) {
318 FontPlatformData verticalRightPlatformData(m_platformData); 310 FontPlatformData verticalRightPlatformData(m_platformData);
319 verticalRightPlatformData.setOrientation(FontOrientation::Horizontal); 311 verticalRightPlatformData.setOrientation(FontOrientation::Horizontal);
320 m_derivedFontData->verticalRightOrientation = 312 m_derivedFontData->verticalRightOrientation =
321 create(verticalRightPlatformData, 313 create(verticalRightPlatformData,
322 isCustomFont() ? CustomFontData::create() : nullptr, true); 314 isCustomFont() ? CustomFontData::create() : nullptr, true);
323 } 315 }
324 return m_derivedFontData->verticalRightOrientation; 316 return m_derivedFontData->verticalRightOrientation;
325 } 317 }
326 318
327 PassRefPtr<SimpleFontData> SimpleFontData::uprightOrientationFontData() const { 319 PassRefPtr<SimpleFontData> SimpleFontData::uprightOrientationFontData() const {
328 if (!m_derivedFontData) 320 if (!m_derivedFontData)
329 m_derivedFontData = DerivedFontData::create(isCustomFont()); 321 m_derivedFontData = DerivedFontData::create();
330 if (!m_derivedFontData->uprightOrientation) 322 if (!m_derivedFontData->uprightOrientation)
331 m_derivedFontData->uprightOrientation = 323 m_derivedFontData->uprightOrientation =
332 create(m_platformData, 324 create(m_platformData,
333 isCustomFont() ? CustomFontData::create() : nullptr, true); 325 isCustomFont() ? CustomFontData::create() : nullptr, true);
334 return m_derivedFontData->uprightOrientation; 326 return m_derivedFontData->uprightOrientation;
335 } 327 }
336 328
337 PassRefPtr<SimpleFontData> SimpleFontData::smallCapsFontData( 329 PassRefPtr<SimpleFontData> SimpleFontData::smallCapsFontData(
338 const FontDescription& fontDescription) const { 330 const FontDescription& fontDescription) const {
339 if (!m_derivedFontData) 331 if (!m_derivedFontData)
340 m_derivedFontData = DerivedFontData::create(isCustomFont()); 332 m_derivedFontData = DerivedFontData::create();
341 if (!m_derivedFontData->smallCaps) 333 if (!m_derivedFontData->smallCaps)
342 m_derivedFontData->smallCaps = 334 m_derivedFontData->smallCaps =
343 createScaledFontData(fontDescription, smallCapsFontSizeMultiplier); 335 createScaledFontData(fontDescription, smallCapsFontSizeMultiplier);
344 336
345 return m_derivedFontData->smallCaps; 337 return m_derivedFontData->smallCaps;
346 } 338 }
347 339
348 PassRefPtr<SimpleFontData> SimpleFontData::emphasisMarkFontData( 340 PassRefPtr<SimpleFontData> SimpleFontData::emphasisMarkFontData(
349 const FontDescription& fontDescription) const { 341 const FontDescription& fontDescription) const {
350 if (!m_derivedFontData) 342 if (!m_derivedFontData)
351 m_derivedFontData = DerivedFontData::create(isCustomFont()); 343 m_derivedFontData = DerivedFontData::create();
352 if (!m_derivedFontData->emphasisMark) 344 if (!m_derivedFontData->emphasisMark)
353 m_derivedFontData->emphasisMark = 345 m_derivedFontData->emphasisMark =
354 createScaledFontData(fontDescription, emphasisMarkFontSizeMultiplier); 346 createScaledFontData(fontDescription, emphasisMarkFontSizeMultiplier);
355 347
356 return m_derivedFontData->emphasisMark; 348 return m_derivedFontData->emphasisMark;
357 } 349 }
358 350
359 bool SimpleFontData::isTextOrientationFallbackOf( 351 bool SimpleFontData::isTextOrientationFallbackOf(
360 const SimpleFontData* fontData) const { 352 const SimpleFontData* fontData) const {
361 if (!isTextOrientationFallback() || !fontData->m_derivedFontData) 353 if (!isTextOrientationFallback() || !fontData->m_derivedFontData)
362 return false; 354 return false;
363 return fontData->m_derivedFontData->uprightOrientation == this || 355 return fontData->m_derivedFontData->uprightOrientation == this ||
364 fontData->m_derivedFontData->verticalRightOrientation == this; 356 fontData->m_derivedFontData->verticalRightOrientation == this;
365 } 357 }
366 358
367 std::unique_ptr<SimpleFontData::DerivedFontData> 359 std::unique_ptr<SimpleFontData::DerivedFontData>
368 SimpleFontData::DerivedFontData::create(bool forCustomFont) { 360 SimpleFontData::DerivedFontData::create() {
369 return wrapUnique(new DerivedFontData(forCustomFont)); 361 return wrapUnique(new DerivedFontData());
370 }
371
372 SimpleFontData::DerivedFontData::~DerivedFontData() {
373 if (!forCustomFont)
374 return;
375
376 if (smallCaps)
377 GlyphPageTreeNode::pruneTreeCustomFontData(smallCaps.get());
378 if (emphasisMark)
379 GlyphPageTreeNode::pruneTreeCustomFontData(emphasisMark.get());
380 if (verticalRightOrientation)
381 GlyphPageTreeNode::pruneTreeCustomFontData(verticalRightOrientation.get());
382 if (uprightOrientation)
383 GlyphPageTreeNode::pruneTreeCustomFontData(uprightOrientation.get());
384 } 362 }
385 363
386 PassRefPtr<SimpleFontData> SimpleFontData::createScaledFontData( 364 PassRefPtr<SimpleFontData> SimpleFontData::createScaledFontData(
387 const FontDescription& fontDescription, 365 const FontDescription& fontDescription,
388 float scaleFactor) const { 366 float scaleFactor) const {
389 const float scaledSize = 367 const float scaledSize =
390 lroundf(fontDescription.computedSize() * scaleFactor); 368 lroundf(fontDescription.computedSize() * scaleFactor);
391 return SimpleFontData::create( 369 return SimpleFontData::create(
392 FontPlatformData(m_platformData, scaledSize), 370 FontPlatformData(m_platformData, scaledSize),
393 isCustomFont() ? CustomFontData::create() : nullptr); 371 isCustomFont() ? CustomFontData::create() : nullptr);
(...skipping 12 matching lines...) Expand all
406 384
407 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { 385 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const {
408 if (!m_platformData.size()) 386 if (!m_platformData.size())
409 return 0; 387 return 0;
410 388
411 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); 389 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
412 390
413 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); 391 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph);
414 } 392 }
415 393
416 bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill,
417 unsigned offset,
418 unsigned length,
419 UChar* buffer,
420 unsigned bufferLength) const {
421 if (U16_IS_LEAD(buffer[bufferLength - 1])) {
422 DLOG(ERROR) << "Last UTF-16 code unit is high-surrogate.";
423 return false;
424 }
425
426 SkTypeface* typeface = platformData().typeface();
427 if (!typeface) {
428 DLOG(ERROR) << "fillGlyphPage called on an empty Skia typeface.";
429 return false;
430 }
431
432 SkAutoSTMalloc<GlyphPage::size, uint16_t> glyphStorage(length);
433 uint16_t* glyphs = glyphStorage.get();
434 typeface->charsToGlyphs(buffer, SkTypeface::kUTF16_Encoding, glyphs, length);
435
436 bool haveGlyphs = false;
437 for (unsigned i = 0; i < length; i++) {
438 if (glyphs[i]) {
439 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this);
440 haveGlyphs = true;
441 }
442 }
443
444 return haveGlyphs;
445 }
446
447 } // namespace blink 394 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698