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

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

Issue 1179723002: Store glyph bounds in WordMeasurement to avoid slow path width calc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase 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/core/layout/line/WordMeasurement.h ('k') | Source/platform/fonts/Font.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) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org) 3 * (C) 2000 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, 2007, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2008 Holger Hans Peter Freyther 6 * Copyright (C) 2008 Holger Hans Peter Freyther
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 class FloatRect; 54 class FloatRect;
55 class FontData; 55 class FontData;
56 class FontMetrics; 56 class FontMetrics;
57 class FontSelector; 57 class FontSelector;
58 class GlyphBuffer; 58 class GlyphBuffer;
59 class TextRun; 59 class TextRun;
60 struct TextRunPaintInfo; 60 struct TextRunPaintInfo;
61 61
62 struct GlyphData; 62 struct GlyphData;
63 63
64 struct GlyphOverflow {
65 GlyphOverflow()
66 : left(0)
67 , right(0)
68 , top(0)
69 , bottom(0)
70 , computeBounds(false)
71 {
72 }
73
74 bool isZero() const
75 {
76 return !left && !right && !top && !bottom;
77 }
78
79 // If computeBounds, top and bottom are the maximum heights of the glyphs ab ove and below the baseline, respectively.
80 // Otherwise they are the amounts of glyph overflows exceeding the font metr ics' ascent and descent, respectively.
81 // Left and right are the amounts of glyph overflows exceeding the left and right edge of normal layout boundary, respectively.
82 // All fields are in absolute number of pixels rounded up to the nearest int eger.
83 int left;
84 int right;
85 int top;
86 int bottom;
87 bool computeBounds;
88 };
89
90 class PLATFORM_EXPORT Font { 64 class PLATFORM_EXPORT Font {
91 public: 65 public:
92 Font(); 66 Font();
93 Font(const FontDescription&); 67 Font(const FontDescription&);
94 ~Font(); 68 ~Font();
95 69
96 Font(const Font&); 70 Font(const Font&);
97 Font& operator=(const Font&); 71 Font& operator=(const Font&);
98 72
99 bool operator==(const Font& other) const; 73 bool operator==(const Font& other) const;
100 bool operator!=(const Font& other) const { return !(*this == other); } 74 bool operator!=(const Font& other) const { return !(*this == other); }
101 75
102 const FontDescription& fontDescription() const { return m_fontDescription; } 76 const FontDescription& fontDescription() const { return m_fontDescription; }
103 77
104 void update(PassRefPtrWillBeRawPtr<FontSelector>) const; 78 void update(PassRefPtrWillBeRawPtr<FontSelector>) const;
105 79
106 enum CustomFontNotReadyAction { DoNotPaintIfFontNotReady, UseFallbackIfFontN otReady }; 80 enum CustomFontNotReadyAction { DoNotPaintIfFontNotReady, UseFallbackIfFontN otReady };
107 void drawText(SkCanvas*, const TextRunPaintInfo&, const FloatPoint&, float d eviceScaleFactor, const SkPaint&) const; 81 void drawText(SkCanvas*, const TextRunPaintInfo&, const FloatPoint&, float d eviceScaleFactor, const SkPaint&) const;
108 void drawBidiText(SkCanvas*, const TextRunPaintInfo&, const FloatPoint&, Cus tomFontNotReadyAction, float deviceScaleFactor, const SkPaint&) const; 82 void drawBidiText(SkCanvas*, const TextRunPaintInfo&, const FloatPoint&, Cus tomFontNotReadyAction, float deviceScaleFactor, const SkPaint&) const;
109 void drawEmphasisMarks(SkCanvas*, const TextRunPaintInfo&, const AtomicStrin g& mark, const FloatPoint&, float deviceScaleFactor, const SkPaint&) const; 83 void drawEmphasisMarks(SkCanvas*, const TextRunPaintInfo&, const AtomicStrin g& mark, const FloatPoint&, float deviceScaleFactor, const SkPaint&) const;
110 84
111 float width(const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const; 85 // Glyph bounds will be the minimum rect containing all glyph strokes, in co ordinates using
86 // (<text run x position>, <baseline position>) as the origin.
87 float width(const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = nullptr, FloatRect* glyphBounds = nullptr) const;
112 88
113 int offsetForPosition(const TextRun&, float position, bool includePartialGly phs) const; 89 int offsetForPosition(const TextRun&, float position, bool includePartialGly phs) const;
114 FloatRect selectionRectForText(const TextRun&, const FloatPoint&, int h, int from = 0, int to = -1, bool accountForGlyphBounds = false) const; 90 FloatRect selectionRectForText(const TextRun&, const FloatPoint&, int h, int from = 0, int to = -1, bool accountForGlyphBounds = false) const;
115 91
116 // Metrics that we query the FontFallbackList for. 92 // Metrics that we query the FontFallbackList for.
117 const FontMetrics& fontMetrics() const { return primaryFont()->fontMetrics() ; } 93 const FontMetrics& fontMetrics() const { return primaryFont()->fontMetrics() ; }
118 float spaceWidth() const { return primaryFont()->spaceWidth() + fontDescript ion().letterSpacing(); } 94 float spaceWidth() const { return primaryFont()->spaceWidth() + fontDescript ion().letterSpacing(); }
119 float tabWidth(const SimpleFontData&, const TabSize&, float position) const; 95 float tabWidth(const SimpleFontData&, const TabSize&, float position) const;
120 float tabWidth(const TabSize& tabSize, float position) const { return tabWid th(*primaryFont(), tabSize, position); } 96 float tabWidth(const TabSize& tabSize, float position) const { return tabWid th(*primaryFont(), tabSize, position); }
121 97
(...skipping 14 matching lines...) Expand all
136 float buildGlyphBuffer(const TextRunPaintInfo&, GlyphBuffer&, const GlyphDat a* emphasisData = nullptr) const; 112 float buildGlyphBuffer(const TextRunPaintInfo&, GlyphBuffer&, const GlyphDat a* emphasisData = nullptr) const;
137 PassTextBlobPtr buildTextBlob(const GlyphBuffer&) const; 113 PassTextBlobPtr buildTextBlob(const GlyphBuffer&) const;
138 void paintGlyphs(SkCanvas*, const SkPaint&, const SimpleFontData*, const Gly ph glyphs[], unsigned numGlyphs, 114 void paintGlyphs(SkCanvas*, const SkPaint&, const SimpleFontData*, const Gly ph glyphs[], unsigned numGlyphs,
139 const SkPoint pos[], const FloatRect& textRect, float deviceScaleFactor) const; 115 const SkPoint pos[], const FloatRect& textRect, float deviceScaleFactor) const;
140 void paintGlyphsHorizontal(SkCanvas*, const SkPaint&, const SimpleFontData*, const Glyph glyphs[], unsigned numGlyphs, 116 void paintGlyphsHorizontal(SkCanvas*, const SkPaint&, const SimpleFontData*, const Glyph glyphs[], unsigned numGlyphs,
141 const SkScalar xpos[], SkScalar constY, const FloatRect& textRect, float deviceScaleFactor) const; 117 const SkScalar xpos[], SkScalar constY, const FloatRect& textRect, float deviceScaleFactor) const;
142 void drawGlyphs(SkCanvas*, const SkPaint&, const SimpleFontData*, const Glyp hBuffer&, unsigned from, unsigned numGlyphs, 118 void drawGlyphs(SkCanvas*, const SkPaint&, const SimpleFontData*, const Glyp hBuffer&, unsigned from, unsigned numGlyphs,
143 const FloatPoint&, const FloatRect& textRect, float deviceScaleFactor) c onst; 119 const FloatPoint&, const FloatRect& textRect, float deviceScaleFactor) c onst;
144 void drawTextBlob(SkCanvas*, const SkPaint&, const SkTextBlob*, const SkPoin t& origin) const; 120 void drawTextBlob(SkCanvas*, const SkPaint&, const SkTextBlob*, const SkPoin t& origin) const;
145 void drawGlyphBuffer(SkCanvas*, const SkPaint&, const TextRunPaintInfo&, con st GlyphBuffer&, const FloatPoint&, float deviceScaleFactor) const; 121 void drawGlyphBuffer(SkCanvas*, const SkPaint&, const TextRunPaintInfo&, con st GlyphBuffer&, const FloatPoint&, float deviceScaleFactor) const;
146 float floatWidthForSimpleText(const TextRun&, HashSet<const SimpleFontData*> * fallbackFonts = 0, FloatRectOutsets* glyphBounds = 0) const; 122 float floatWidthForSimpleText(const TextRun&, HashSet<const SimpleFontData*> * fallbackFonts = 0, FloatRect* glyphBounds = 0) const;
147 int offsetForPositionForSimpleText(const TextRun&, float position, bool incl udePartialGlyphs) const; 123 int offsetForPositionForSimpleText(const TextRun&, float position, bool incl udePartialGlyphs) const;
148 FloatRect selectionRectForSimpleText(const TextRun&, const FloatPoint&, int h, int from, int to, bool accountForGlyphBounds) const; 124 FloatRect selectionRectForSimpleText(const TextRun&, const FloatPoint&, int h, int from, int to, bool accountForGlyphBounds) const;
149 125
150 bool getEmphasisMarkGlyphData(const AtomicString&, GlyphData&) const; 126 bool getEmphasisMarkGlyphData(const AtomicString&, GlyphData&) const;
151 127
152 float floatWidthForComplexText(const TextRun&, HashSet<const SimpleFontData* >* fallbackFonts, FloatRectOutsets* glyphBounds) const; 128 float floatWidthForComplexText(const TextRun&, HashSet<const SimpleFontData* >* fallbackFonts, FloatRect* glyphBounds) const;
153 int offsetForPositionForComplexText(const TextRun&, float position, bool inc ludePartialGlyphs) const; 129 int offsetForPositionForComplexText(const TextRun&, float position, bool inc ludePartialGlyphs) const;
154 FloatRect selectionRectForComplexText(const TextRun&, const FloatPoint&, int h, int from, int to) const; 130 FloatRect selectionRectForComplexText(const TextRun&, const FloatPoint&, int h, int from, int to) const;
155 131
156 friend struct SimpleShaper; 132 friend struct SimpleShaper;
157 133
158 public: 134 public:
159 FontSelector* fontSelector() const; 135 FontSelector* fontSelector() const;
160 136
161 void willUseFontData(UChar32) const; 137 void willUseFontData(UChar32) const;
162 138
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // to the next tab stop is less than that, advance an additional tab stop. 181 // to the next tab stop is less than that, advance an additional tab stop.
206 if (distanceToTabStop < fontDescription().letterSpacing()) 182 if (distanceToTabStop < fontDescription().letterSpacing())
207 distanceToTabStop += baseTabWidth; 183 distanceToTabStop += baseTabWidth;
208 184
209 return distanceToTabStop; 185 return distanceToTabStop;
210 } 186 }
211 187
212 } // namespace blink 188 } // namespace blink
213 189
214 #endif 190 #endif
OLDNEW
« no previous file with comments | « Source/core/layout/line/WordMeasurement.h ('k') | Source/platform/fonts/Font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698