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

Side by Side Diff: Source/core/platform/graphics/harfbuzz/FontHarfBuzz.cpp

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase with TOT Created 7 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. 2 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return false; 54 return false;
55 } 55 }
56 56
57 bool Font::canExpandAroundIdeographsInComplexText() 57 bool Font::canExpandAroundIdeographsInComplexText()
58 { 58 {
59 return false; 59 return false;
60 } 60 }
61 61
62 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, 62 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
63 const GlyphBuffer& glyphBuffer, int from, int numGlyphs, 63 const GlyphBuffer& glyphBuffer, int from, int numGlyphs,
64 const FloatPoint& point) const { 64 const FloatPoint& point, const FloatRect& textRect) const {
65 SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t)); // compile-time asse rt 65 SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t)); // compile-time asse rt
66 66
67 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); 67 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
68 SkScalar x = SkFloatToScalar(point.x()); 68 SkScalar x = SkFloatToScalar(point.x());
69 SkScalar y = SkFloatToScalar(point.y()); 69 SkScalar y = SkFloatToScalar(point.y());
70 70
71 // FIXME: text rendering speed: 71 // FIXME: text rendering speed:
72 // Android has code in their WebCore fork to special case when the 72 // Android has code in their WebCore fork to special case when the
73 // GlyphBuffer has no advances other than the defaults. In that case the 73 // GlyphBuffer has no advances other than the defaults. In that case the
74 // text drawing can proceed faster. However, it's unclear when those 74 // text drawing can proceed faster. However, it's unclear when those
(...skipping 27 matching lines...) Expand all
102 font->platformData().setupPaint(&paint); 102 font->platformData().setupPaint(&paint);
103 gc->platformContext()->adjustTextRenderMode(&paint); 103 gc->platformContext()->adjustTextRenderMode(&paint);
104 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 104 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
105 105
106 if (isVertical) { 106 if (isVertical) {
107 SkPath path; 107 SkPath path;
108 for (int i = 0; i < numGlyphs; ++i) { 108 for (int i = 0; i < numGlyphs; ++i) {
109 path.reset(); 109 path.reset();
110 path.moveTo(vPosBegin[i]); 110 path.moveTo(vPosBegin[i]);
111 path.lineTo(vPosEnd[i]); 111 path.lineTo(vPosEnd[i]);
112 platformContext->drawTextOnPath(glyphs + i, 2, path, 0, paint); 112 platformContext->drawTextOnPath(glyphs + i, 2, path, textRect, 0 , paint);
113 } 113 }
114 } else 114 } else
115 platformContext->drawPosText(glyphs, numGlyphs << 1, pos, paint); 115 platformContext->drawPosText(glyphs, numGlyphs << 1, pos, textRect, paint);
116 } 116 }
117 117
118 if ((textMode & TextModeStroke) 118 if ((textMode & TextModeStroke)
119 && gc->platformContext()->getStrokeStyle() != NoStroke 119 && gc->platformContext()->getStrokeStyle() != NoStroke
120 && gc->platformContext()->getStrokeThickness() > 0) { 120 && gc->platformContext()->getStrokeThickness() > 0) {
121 121
122 SkPaint paint; 122 SkPaint paint;
123 gc->platformContext()->setupPaintForStroking(&paint, 0, 0); 123 gc->platformContext()->setupPaintForStroking(&paint, 0, 0);
124 font->platformData().setupPaint(&paint); 124 font->platformData().setupPaint(&paint);
125 gc->platformContext()->adjustTextRenderMode(&paint); 125 gc->platformContext()->adjustTextRenderMode(&paint);
126 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 126 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
127 127
128 if (textMode & TextModeFill) { 128 if (textMode & TextModeFill) {
129 // If we also filled, we don't want to draw shadows twice. 129 // If we also filled, we don't want to draw shadows twice.
130 // See comment in FontChromiumWin.cpp::paintSkiaText() for more deta ils. 130 // See comment in FontChromiumWin.cpp::paintSkiaText() for more deta ils.
131 // Since we use the looper for shadows, we remove it (if any) now. 131 // Since we use the looper for shadows, we remove it (if any) now.
132 paint.setLooper(0); 132 paint.setLooper(0);
133 } 133 }
134 134
135 if (isVertical) { 135 if (isVertical) {
136 SkPath path; 136 SkPath path;
137 for (int i = 0; i < numGlyphs; ++i) { 137 for (int i = 0; i < numGlyphs; ++i) {
138 path.reset(); 138 path.reset();
139 path.moveTo(vPosBegin[i]); 139 path.moveTo(vPosBegin[i]);
140 path.lineTo(vPosEnd[i]); 140 path.lineTo(vPosEnd[i]);
141 platformContext->drawTextOnPath(glyphs + i, 2, path, 0, paint); 141 platformContext->drawTextOnPath(glyphs + i, 2, path, textRect, 0 , paint);
142 } 142 }
143 } else 143 } else
144 platformContext->drawPosText(glyphs, numGlyphs << 1, pos, paint); 144 platformContext->drawPosText(glyphs, numGlyphs << 1, pos, textRect, paint);
145 } 145 }
146 } 146 }
147 147
148 static void setupForTextPainting(SkPaint* paint, SkColor color) 148 static void setupForTextPainting(SkPaint* paint, SkColor color)
149 { 149 {
150 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); 150 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
151 paint->setColor(color); 151 paint->setColor(color);
152 } 152 }
153 153
154 void Font::drawComplexText(GraphicsContext* gc, const TextRun& run, 154 void Font::drawComplexText(GraphicsContext* gc, const TextRun& run,
155 const FloatPoint& point, int from, int to) const 155 const FloatPoint& point, const FloatRect& textRect,
156 int from, int to) const
156 { 157 {
157 if (!run.length()) 158 if (!run.length())
158 return; 159 return;
159 160
160 TextDrawingModeFlags textMode = gc->platformContext()->getTextDrawingMode(); 161 TextDrawingModeFlags textMode = gc->platformContext()->getTextDrawingMode();
161 bool fill = textMode & TextModeFill; 162 bool fill = textMode & TextModeFill;
162 bool stroke = (textMode & TextModeStroke) 163 bool stroke = (textMode & TextModeStroke)
163 && gc->platformContext()->getStrokeStyle() != NoStroke 164 && gc->platformContext()->getStrokeStyle() != NoStroke
164 && gc->platformContext()->getStrokeThickness() > 0; 165 && gc->platformContext()->getStrokeThickness() > 0;
165 166
166 if (!fill && !stroke) 167 if (!fill && !stroke)
167 return; 168 return;
168 169
169 SkPaint strokePaint, fillPaint; 170 SkPaint strokePaint, fillPaint;
170 if (fill) { 171 if (fill) {
171 gc->platformContext()->setupPaintForFilling(&fillPaint); 172 gc->platformContext()->setupPaintForFilling(&fillPaint);
172 setupForTextPainting(&fillPaint, gc->fillColor().rgb()); 173 setupForTextPainting(&fillPaint, gc->fillColor().rgb());
173 } 174 }
174 if (stroke) { 175 if (stroke) {
175 gc->platformContext()->setupPaintForStroking(&strokePaint, 0, 0); 176 gc->platformContext()->setupPaintForStroking(&strokePaint, 0, 0);
176 setupForTextPainting(&strokePaint, gc->strokeColor().rgb()); 177 setupForTextPainting(&strokePaint, gc->strokeColor().rgb());
177 } 178 }
178 179
179 GlyphBuffer glyphBuffer; 180 GlyphBuffer glyphBuffer;
180 HarfBuzzShaper shaper(this, run); 181 HarfBuzzShaper shaper(this, run);
181 shaper.setDrawRange(from, to); 182 shaper.setDrawRange(from, to);
182 if (!shaper.shape(&glyphBuffer)) 183 if (!shaper.shape(&glyphBuffer))
183 return; 184 return;
184 FloatPoint adjustedPoint = shaper.adjustStartPoint(point); 185 FloatPoint adjustedPoint = shaper.adjustStartPoint(point);
185 drawGlyphBuffer(gc, run, glyphBuffer, adjustedPoint); 186 drawGlyphBuffer(gc, run, glyphBuffer, adjustedPoint, textRect);
186 } 187 }
187 188
188 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const 189 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, const FloatRect& /* textRect */, int /* from */, int /* to */) const
189 { 190 {
190 notImplemented(); 191 notImplemented();
191 } 192 }
192 193
193 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const 194 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const
194 { 195 {
195 HarfBuzzShaper shaper(this, run); 196 HarfBuzzShaper shaper(this, run);
196 if (!shaper.shape()) 197 if (!shaper.shape())
197 return 0; 198 return 0;
198 return shaper.totalWidth(); 199 return shaper.totalWidth();
(...skipping 14 matching lines...) Expand all
213 const FloatPoint& point, int height, 214 const FloatPoint& point, int height,
214 int from, int to) const 215 int from, int to) const
215 { 216 {
216 HarfBuzzShaper shaper(this, run); 217 HarfBuzzShaper shaper(this, run);
217 if (!shaper.shape()) 218 if (!shaper.shape())
218 return FloatRect(); 219 return FloatRect();
219 return shaper.selectionRect(point, height, from, to); 220 return shaper.selectionRect(point, height, from, to);
220 } 221 }
221 222
222 } // namespace WebCore 223 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698