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

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

Issue 141433026: Font metrics, version 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed windows layout tests Created 6 years, 9 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
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | no next file » | 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 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 #if ENABLE(SVG_FONTS) 171 #if ENABLE(SVG_FONTS)
172 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) 172 if (TextRun::RenderingContext* renderingContext = run.renderingContext())
173 return renderingContext->floatWidthUsingSVGFont(*this, run, charsConsume d, glyphId); 173 return renderingContext->floatWidthUsingSVGFont(*this, run, charsConsume d, glyphId);
174 #endif 174 #endif
175 175
176 charsConsumed = run.length(); 176 charsConsumed = run.length();
177 glyphId = 0; 177 glyphId = 0;
178 return width(run); 178 return width(run);
179 } 179 }
180 180
181 FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point , int h, int from, int to) const 181 FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point , int h, int from, int to, bool accountForGlyphBounds) const
182 { 182 {
183 to = (to == -1 ? run.length() : to); 183 to = (to == -1 ? run.length() : to);
184 184
185 CodePath codePathToUse = codePath(run); 185 CodePath codePathToUse = codePath(run);
186 // FIXME: Use the fast code path once it handles partial runs with kerning a nd ligatures. See http://webkit.org/b/100050 186 // FIXME: Use the fast code path once it handles partial runs with kerning a nd ligatures. See http://webkit.org/b/100050
187 if (codePathToUse != ComplexPath && fontDescription().typesettingFeatures() && (from || to != run.length())) 187 if (codePathToUse != ComplexPath && fontDescription().typesettingFeatures() && (from || to != run.length()))
188 codePathToUse = ComplexPath; 188 codePathToUse = ComplexPath;
189 189
190 if (codePathToUse != ComplexPath) 190 if (codePathToUse != ComplexPath)
191 return selectionRectForSimpleText(run, point, h, from, to); 191 return selectionRectForSimpleText(run, point, h, from, to, accountForGly phBounds);
192 192
193 return selectionRectForComplexText(run, point, h, from, to); 193 return selectionRectForComplexText(run, point, h, from, to);
194 } 194 }
195 195
196 int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyp hs) const 196 int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyp hs) const
197 { 197 {
198 // FIXME: Use the fast code path once it handles partial runs with kerning a nd ligatures. See http://webkit.org/b/100050 198 // FIXME: Use the fast code path once it handles partial runs with kerning a nd ligatures. See http://webkit.org/b/100050
199 if (codePath(run) != ComplexPath && !fontDescription().typesettingFeatures() ) 199 if (codePath(run) != ComplexPath && !fontDescription().typesettingFeatures() )
200 return offsetForPositionForSimpleText(run, x, includePartialGlyphs); 200 return offsetForPositionForSimpleText(run, x, includePartialGlyphs);
201 201
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 if (glyphOverflow) { 748 if (glyphOverflow) {
749 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent())); 749 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
750 glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyp hBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent())) ; 750 glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyp hBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent())) ;
751 glyphOverflow->left = ceilf(it.firstGlyphOverflow()); 751 glyphOverflow->left = ceilf(it.firstGlyphOverflow());
752 glyphOverflow->right = ceilf(it.lastGlyphOverflow()); 752 glyphOverflow->right = ceilf(it.lastGlyphOverflow());
753 } 753 }
754 754
755 return it.m_runWidthSoFar; 755 return it.m_runWidthSoFar;
756 } 756 }
757 757
758 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 758 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
759 { 759 {
760 GlyphBuffer glyphBuffer; 760 GlyphBuffer glyphBuffer;
761 WidthIterator it(this, run); 761 WidthIterator it(this, run, 0, accountForGlyphBounds);
762 it.advance(from, &glyphBuffer); 762 it.advance(from, &glyphBuffer);
763 float beforeWidth = it.m_runWidthSoFar; 763 float beforeWidth = it.m_runWidthSoFar;
764 it.advance(to, &glyphBuffer); 764 it.advance(to, &glyphBuffer);
765 float afterWidth = it.m_runWidthSoFar; 765 float afterWidth = it.m_runWidthSoFar;
766 766
767 // Using roundf() rather than ceilf() for the right edge as a compromise to 767 // Using roundf() rather than ceilf() for the right edge as a compromise to
768 // ensure correct caret positioning. 768 // ensure correct caret positioning.
769 // Use LayoutUnit::epsilon() to ensure that values that cannot be stored as 769 // Use LayoutUnit::epsilon() to ensure that values that cannot be stored as
770 // an integer are floored to n and not n-1 due to floating point imprecision . 770 // an integer are floored to n and not n-1 due to floating point imprecision .
771 if (run.rtl()) { 771 if (run.rtl()) {
772 it.advance(run.length(), &glyphBuffer); 772 it.advance(run.length(), &glyphBuffer);
773 float totalWidth = it.m_runWidthSoFar; 773 float totalWidth = it.m_runWidthSoFar;
774 float pixelAlignedX = floorf(point.x() + totalWidth - afterWidth + Layou tUnit::epsilon()); 774 float pixelAlignedX = floorf(point.x() + totalWidth - afterWidth + Layou tUnit::epsilon());
775 return FloatRect(pixelAlignedX, point.y(), 775 return FloatRect(pixelAlignedX, accountForGlyphBounds ? it.minGlyphBound ingBoxY() : point.y(),
776 roundf(point.x() + totalWidth - beforeWidth) - pixelAlignedX, h); 776 roundf(point.x() + totalWidth - beforeWidth) - pixelAlignedX,
777 accountForGlyphBounds ? it.maxGlyphBoundingBoxY() - it.minGlyphBound ingBoxY() : h);
777 } 778 }
778 779
779 float pixelAlignedX = floorf(point.x() + beforeWidth + LayoutUnit::epsilon() ); 780 float pixelAlignedX = floorf(point.x() + beforeWidth + LayoutUnit::epsilon() );
780 return FloatRect(pixelAlignedX, point.y(), 781 return FloatRect(pixelAlignedX, accountForGlyphBounds ? it.minGlyphBoundingB oxY() : point.y(),
781 roundf(point.x() + afterWidth) - pixelAlignedX, h); 782 roundf(point.x() + afterWidth) - pixelAlignedX,
783 accountForGlyphBounds ? it.maxGlyphBoundingBoxY() - it.minGlyphBoundingB oxY() : h);
782 } 784 }
783 785
784 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const 786 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const
785 { 787 {
786 float delta = x; 788 float delta = x;
787 789
788 WidthIterator it(this, run); 790 WidthIterator it(this, run);
789 GlyphBuffer localGlyphBuffer; 791 GlyphBuffer localGlyphBuffer;
790 unsigned offset; 792 unsigned offset;
791 if (run.rtl()) { 793 if (run.rtl()) {
(...skipping 26 matching lines...) Expand all
818 if (delta <= 0) 820 if (delta <= 0)
819 break; 821 break;
820 } 822 }
821 } 823 }
822 } 824 }
823 825
824 return offset; 826 return offset;
825 } 827 }
826 828
827 } 829 }
OLDNEW
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698