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

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

Issue 1153173011: Force glyph overflow calculation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More rebaselines Created 5 years, 6 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/Font.h ('k') | Source/platform/fonts/FontTest.cpp » ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. 6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 GlyphBuffer glyphBuffer; 207 GlyphBuffer glyphBuffer;
208 buildGlyphBuffer(runInfo, glyphBuffer, &emphasisGlyphData); 208 buildGlyphBuffer(runInfo, glyphBuffer, &emphasisGlyphData);
209 209
210 if (glyphBuffer.isEmpty()) 210 if (glyphBuffer.isEmpty())
211 return; 211 return;
212 212
213 drawGlyphBuffer(canvas, paint, runInfo, glyphBuffer, point, deviceScaleFacto r); 213 drawGlyphBuffer(canvas, paint, runInfo, glyphBuffer, point, deviceScaleFacto r);
214 } 214 }
215 215
216 static inline void updateGlyphOverflowFromBounds(const IntRectOutsets& glyphBoun ds, 216 static inline void updateGlyphOverflowFromBounds(const FloatRectOutsets& glyphBo unds,
217 const FontMetrics& fontMetrics, GlyphOverflow* glyphOverflow) 217 const FontMetrics& fontMetrics, GlyphOverflow* glyphOverflow)
218 { 218 {
219 glyphOverflow->top = std::max<int>(glyphOverflow->top, 219 glyphOverflow->top = ceilf(glyphOverflow->computeBounds ? glyphBounds.top() : std::max(0.0f, glyphBounds.top() - fontMetrics.floatAscent()));
220 glyphBounds.top() - (glyphOverflow->computeBounds ? 0 : fontMetrics.asce nt())); 220 glyphOverflow->bottom = ceilf(glyphOverflow->computeBounds ? glyphBounds.bot tom() : std::max(0.0f, glyphBounds.bottom() - fontMetrics.floatDescent()));
221 glyphOverflow->bottom = std::max<int>(glyphOverflow->bottom, 221 glyphOverflow->left = ceilf(glyphBounds.left());
222 glyphBounds.bottom() - (glyphOverflow->computeBounds ? 0 : fontMetrics.d escent())); 222 glyphOverflow->right = ceilf(glyphBounds.right());
223 glyphOverflow->left = glyphBounds.left();
224 glyphOverflow->right = glyphBounds.right();
225 } 223 }
226 224
227 float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFo nts, GlyphOverflow* glyphOverflow) const 225 float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFo nts, GlyphOverflow* glyphOverflow) const
228 { 226 {
229 FontCachePurgePreventer purgePreventer; 227 FontCachePurgePreventer purgePreventer;
230 228
231 CodePath codePathToUse = codePath(TextRunPaintInfo(run)); 229 CodePath codePathToUse = codePath(TextRunPaintInfo(run));
232 230
233 float result; 231 float result;
234 IntRectOutsets glyphBounds; 232 FloatRectOutsets glyphBounds;
235 if (codePathToUse == ComplexPath) { 233 if (codePathToUse == ComplexPath)
236 result = floatWidthForComplexText(run, fallbackFonts, &glyphBounds); 234 result = floatWidthForComplexText(run, fallbackFonts, &glyphBounds);
237 } else { 235 else
238 // The simple path can optimize the case where glyph overflow is not obs ervable.
239 if (codePathToUse != SimpleWithGlyphOverflowPath && (glyphOverflow && !g lyphOverflow->computeBounds))
240 glyphOverflow = 0;
241 result = floatWidthForSimpleText(run, fallbackFonts, glyphOverflow ? &gl yphBounds : 0); 236 result = floatWidthForSimpleText(run, fallbackFonts, glyphOverflow ? &gl yphBounds : 0);
242 }
243 237
244 if (glyphOverflow) 238 if (glyphOverflow)
245 updateGlyphOverflowFromBounds(glyphBounds, fontMetrics(), glyphOverflow) ; 239 updateGlyphOverflowFromBounds(glyphBounds, fontMetrics(), glyphOverflow) ;
246 return result; 240 return result;
247 } 241 }
248 242
249 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer) const 243 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer) const
250 { 244 {
251 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); 245 ASSERT(RuntimeEnabledFeatures::textBlobEnabled());
252 246
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 canvas->restoreToCount(canvasStackLevel); 681 canvas->restoreToCount(canvasStackLevel);
688 } 682 }
689 683
690 void Font::drawTextBlob(SkCanvas* canvas, const SkPaint& paint, const SkTextBlob * blob, const SkPoint& origin) const 684 void Font::drawTextBlob(SkCanvas* canvas, const SkPaint& paint, const SkTextBlob * blob, const SkPoint& origin) const
691 { 685 {
692 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); 686 ASSERT(RuntimeEnabledFeatures::textBlobEnabled());
693 687
694 canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); 688 canvas->drawTextBlob(blob, origin.x(), origin.y(), paint);
695 } 689 }
696 690
697 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* fallbackFonts, IntRectOutsets* glyphBounds) const 691 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* fallbackFonts, FloatRectOutsets* glyphBounds) const
698 { 692 {
699 bool hasWordSpacingOrLetterSpacing = fontDescription().wordSpacing() 693 bool hasWordSpacingOrLetterSpacing = fontDescription().wordSpacing()
700 || fontDescription().letterSpacing(); 694 || fontDescription().letterSpacing();
701 // Word spacing and letter spacing can change the width of a word. 695 // Word spacing and letter spacing can change the width of a word.
702 // If a tab occurs inside a word, the width of the word varies based on its 696 // If a tab occurs inside a word, the width of the word varies based on its
703 // position on the line. 697 // position on the line.
704 bool isCacheable = !hasWordSpacingOrLetterSpacing && !run.allowTabs(); 698 bool isCacheable = !hasWordSpacingOrLetterSpacing && !run.allowTabs();
705 699
706 WidthCacheEntry* cacheEntry = isCacheable 700 WidthCacheEntry* cacheEntry = isCacheable
707 ? m_fontFallbackList->widthCache().add(run, WidthCacheEntry()) 701 ? m_fontFallbackList->widthCache().add(run, WidthCacheEntry())
708 : 0; 702 : 0;
709 if (cacheEntry && cacheEntry->isValid()) { 703 if (cacheEntry && cacheEntry->isValid()) {
710 ASSERT(glyphBounds); 704 ASSERT(glyphBounds);
711 *glyphBounds = cacheEntry->glyphBounds; 705 *glyphBounds = cacheEntry->glyphBounds;
712 return cacheEntry->width; 706 return cacheEntry->width;
713 } 707 }
714 708
715 FloatRect bounds; 709 FloatRect bounds;
716 HarfBuzzShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &boun ds : 0); 710 HarfBuzzShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &boun ds : 0);
717 if (!shaper.shape()) 711 if (!shaper.shape())
718 return 0; 712 return 0;
719 713
720 glyphBounds->setTop(ceilf(-bounds.y())); 714 glyphBounds->setTop(-bounds.y());
721 glyphBounds->setBottom(ceilf(bounds.maxY())); 715 glyphBounds->setBottom(bounds.maxY());
722 glyphBounds->setLeft(std::max<int>(0, ceilf(-bounds.x()))); 716 glyphBounds->setLeft(std::max(0.0f, -bounds.x()));
723 glyphBounds->setRight(std::max<int>(0, ceilf(bounds.maxX() - shaper.totalWid th()))); 717 glyphBounds->setRight(std::max(0.0f, bounds.maxX() - shaper.totalWidth()));
724 718
725 float result = shaper.totalWidth(); 719 float result = shaper.totalWidth();
726 if (cacheEntry && (!fallbackFonts || fallbackFonts->isEmpty())) { 720 if (cacheEntry && (!fallbackFonts || fallbackFonts->isEmpty())) {
727 cacheEntry->glyphBounds = *glyphBounds; 721 cacheEntry->glyphBounds = *glyphBounds;
728 cacheEntry->width = result; 722 cacheEntry->width = result;
729 } 723 }
730 724
731 return result; 725 return result;
732 } 726 }
733 727
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (nextFontData != fontData) { 773 if (nextFontData != fontData) {
780 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, point, runInfo.bounds, deviceScaleFactor); 774 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, point, runInfo.bounds, deviceScaleFactor);
781 lastFrom = nextGlyph; 775 lastFrom = nextGlyph;
782 fontData = nextFontData; 776 fontData = nextFontData;
783 } 777 }
784 } 778 }
785 779
786 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastF rom, point, runInfo.bounds, deviceScaleFactor); 780 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastF rom, point, runInfo.bounds, deviceScaleFactor);
787 } 781 }
788 782
789 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, IntRectOutsets* glyphBounds) const 783 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, FloatRectOutsets* glyphBounds) const
790 { 784 {
791 FloatRect bounds; 785 FloatRect bounds;
792 SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &bounds : 0); 786 SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &bounds : 0);
793 shaper.advance(run.length()); 787 shaper.advance(run.length());
794 float runWidth = shaper.runWidthSoFar(); 788 float runWidth = shaper.runWidthSoFar();
795 789
796 if (glyphBounds) { 790 if (glyphBounds) {
797 glyphBounds->setTop(ceilf(-bounds.y())); 791 glyphBounds->setTop(-bounds.y());
798 glyphBounds->setBottom(ceilf(bounds.maxY())); 792 glyphBounds->setBottom(bounds.maxY());
799 glyphBounds->setLeft(std::max<int>(0, ceilf(-bounds.x()))); 793 glyphBounds->setLeft(std::max(0.0f, -bounds.x()));
800 glyphBounds->setRight(std::max<int>(0, ceilf(bounds.maxX() - runWidth))) ; 794 glyphBounds->setRight(std::max(0.0f, bounds.maxX() - runWidth));
801 } 795 }
802 return runWidth; 796 return runWidth;
803 } 797 }
804 798
805 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const 799 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
806 { 800 {
807 FloatRect bounds; 801 FloatRect bounds;
808 SimpleShaper shaper(this, run, nullptr, nullptr, accountForGlyphBounds ? &bo unds : nullptr); 802 SimpleShaper shaper(this, run, nullptr, nullptr, accountForGlyphBounds ? &bo unds : nullptr);
809 shaper.advance(from); 803 shaper.advance(from);
810 float fromX = shaper.runWidthSoFar(); 804 float fromX = shaper.runWidthSoFar();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 { 866 {
873 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); 867 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts();
874 } 868 }
875 869
876 bool Font::isFallbackValid() const 870 bool Font::isFallbackValid() const
877 { 871 {
878 return !m_fontFallbackList || m_fontFallbackList->isValid(); 872 return !m_fontFallbackList || m_fontFallbackList->isValid();
879 } 873 }
880 874
881 } // namespace blink 875 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | Source/platform/fonts/FontTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698