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

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: fixed build on win and mac Created 7 years, 7 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return false; 53 return false;
54 } 54 }
55 55
56 bool Font::canExpandAroundIdeographsInComplexText() 56 bool Font::canExpandAroundIdeographsInComplexText()
57 { 57 {
58 return false; 58 return false;
59 } 59 }
60 60
61 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, 61 void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
62 const GlyphBuffer& glyphBuffer, int from, int numGlyphs, 62 const GlyphBuffer& glyphBuffer, int from, int numGlyphs,
63 const FloatPoint& point) const { 63 const FloatPoint& point, const FloatRect& textRect) const {
64 SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t)); // compile-time asse rt 64 SkASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t)); // compile-time asse rt
65 65
66 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); 66 const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
67 SkScalar x = SkFloatToScalar(point.x()); 67 SkScalar x = SkFloatToScalar(point.x());
68 SkScalar y = SkFloatToScalar(point.y()); 68 SkScalar y = SkFloatToScalar(point.y());
69 69
70 // FIXME: text rendering speed: 70 // FIXME: text rendering speed:
71 // Android has code in their WebCore fork to special case when the 71 // Android has code in their WebCore fork to special case when the
72 // GlyphBuffer has no advances other than the defaults. In that case the 72 // GlyphBuffer has no advances other than the defaults. In that case the
73 // text drawing can proceed faster. However, it's unclear when those 73 // text drawing can proceed faster. However, it's unclear when those
(...skipping 26 matching lines...) Expand all
100 font->platformData().setupPaint(&paint); 100 font->platformData().setupPaint(&paint);
101 gc->adjustTextRenderMode(&paint); 101 gc->adjustTextRenderMode(&paint);
102 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 102 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
103 103
104 if (isVertical) { 104 if (isVertical) {
105 SkPath path; 105 SkPath path;
106 for (int i = 0; i < numGlyphs; ++i) { 106 for (int i = 0; i < numGlyphs; ++i) {
107 path.reset(); 107 path.reset();
108 path.moveTo(vPosBegin[i]); 108 path.moveTo(vPosBegin[i]);
109 path.lineTo(vPosEnd[i]); 109 path.lineTo(vPosEnd[i]);
110 gc->drawTextOnPath(glyphs + i, 2, path, 0, paint); 110 gc->drawTextOnPath(glyphs + i, 2, path, textRect, 0, paint);
111 } 111 }
112 } else 112 } else
113 gc->drawPosText(glyphs, numGlyphs << 1, pos, paint); 113 gc->drawPosText(glyphs, numGlyphs << 1, pos, textRect, paint);
114 } 114 }
115 115
116 if ((textMode & TextModeStroke) 116 if ((textMode & TextModeStroke)
117 && gc->strokeStyleSkia() != NoStroke 117 && gc->strokeStyleSkia() != NoStroke
118 && gc->strokeThicknessSkia() > 0) { 118 && gc->strokeThicknessSkia() > 0) {
119 119
120 SkPaint paint; 120 SkPaint paint;
121 gc->setupPaintForStroking(&paint, 0, 0); 121 gc->setupPaintForStroking(&paint, 0, 0);
122 font->platformData().setupPaint(&paint); 122 font->platformData().setupPaint(&paint);
123 gc->adjustTextRenderMode(&paint); 123 gc->adjustTextRenderMode(&paint);
124 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 124 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
125 125
126 if (textMode & TextModeFill) { 126 if (textMode & TextModeFill) {
127 // If we also filled, we don't want to draw shadows twice. 127 // If we also filled, we don't want to draw shadows twice.
128 // See comment in FontChromiumWin.cpp::paintSkiaText() for more deta ils. 128 // See comment in FontChromiumWin.cpp::paintSkiaText() for more deta ils.
129 // Since we use the looper for shadows, we remove it (if any) now. 129 // Since we use the looper for shadows, we remove it (if any) now.
130 paint.setLooper(0); 130 paint.setLooper(0);
131 } 131 }
132 132
133 if (isVertical) { 133 if (isVertical) {
134 SkPath path; 134 SkPath path;
135 for (int i = 0; i < numGlyphs; ++i) { 135 for (int i = 0; i < numGlyphs; ++i) {
136 path.reset(); 136 path.reset();
137 path.moveTo(vPosBegin[i]); 137 path.moveTo(vPosBegin[i]);
138 path.lineTo(vPosEnd[i]); 138 path.lineTo(vPosEnd[i]);
139 gc->drawTextOnPath(glyphs + i, 2, path, 0, paint); 139 gc->drawTextOnPath(glyphs + i, 2, path, textRect, 0, paint);
140 } 140 }
141 } else 141 } else
142 gc->drawPosText(glyphs, numGlyphs << 1, pos, paint); 142 gc->drawPosText(glyphs, numGlyphs << 1, pos, textRect, paint);
143 } 143 }
144 } 144 }
145 145
146 static void setupForTextPainting(SkPaint* paint, SkColor color) 146 static void setupForTextPainting(SkPaint* paint, SkColor color)
147 { 147 {
148 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); 148 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
149 paint->setColor(color); 149 paint->setColor(color);
150 } 150 }
151 151
152 void Font::drawComplexText(GraphicsContext* gc, const TextRun& run, 152 void Font::drawComplexText(GraphicsContext* gc, const TextRunPaintInfo& runInfo, const FloatPoint& point) const
153 const FloatPoint& point, int from, int to) const
154 { 153 {
155 if (!run.length()) 154 if (!runInfo.run.length())
156 return; 155 return;
157 156
158 TextDrawingModeFlags textMode = gc->textDrawingModeSkia(); 157 TextDrawingModeFlags textMode = gc->textDrawingModeSkia();
159 bool fill = textMode & TextModeFill; 158 bool fill = textMode & TextModeFill;
160 bool stroke = (textMode & TextModeStroke) 159 bool stroke = (textMode & TextModeStroke)
161 && gc->strokeStyleSkia() != NoStroke 160 && gc->strokeStyleSkia() != NoStroke
162 && gc->strokeThicknessSkia() > 0; 161 && gc->strokeThicknessSkia() > 0;
163 162
164 if (!fill && !stroke) 163 if (!fill && !stroke)
165 return; 164 return;
166 165
167 SkPaint strokePaint, fillPaint; 166 SkPaint strokePaint, fillPaint;
168 if (fill) { 167 if (fill) {
169 gc->setupPaintForFilling(&fillPaint); 168 gc->setupPaintForFilling(&fillPaint);
170 setupForTextPainting(&fillPaint, gc->fillColor().rgb()); 169 setupForTextPainting(&fillPaint, gc->fillColor().rgb());
171 } 170 }
172 if (stroke) { 171 if (stroke) {
173 gc->setupPaintForStroking(&strokePaint, 0, 0); 172 gc->setupPaintForStroking(&strokePaint, 0, 0);
174 setupForTextPainting(&strokePaint, gc->strokeColor().rgb()); 173 setupForTextPainting(&strokePaint, gc->strokeColor().rgb());
175 } 174 }
176 175
177 GlyphBuffer glyphBuffer; 176 GlyphBuffer glyphBuffer;
178 HarfBuzzShaper shaper(this, run); 177 HarfBuzzShaper shaper(this, runInfo.run);
179 shaper.setDrawRange(from, to); 178 shaper.setDrawRange(runInfo.from, runInfo.to);
180 if (!shaper.shape(&glyphBuffer)) 179 if (!shaper.shape(&glyphBuffer))
181 return; 180 return;
182 FloatPoint adjustedPoint = shaper.adjustStartPoint(point); 181 FloatPoint adjustedPoint = shaper.adjustStartPoint(point);
183 drawGlyphBuffer(gc, run, glyphBuffer, adjustedPoint); 182 drawGlyphBuffer(gc, runInfo, glyphBuffer, adjustedPoint);
184 } 183 }
185 184
186 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const 185 void Font::drawEmphasisMarksForComplexText(GraphicsContext* /* context */, const TextRunPaintInfo& /* runInfo */, const AtomicString& /* mark */, const FloatPoi nt& /* point */) const
187 { 186 {
188 notImplemented(); 187 notImplemented();
189 } 188 }
190 189
191 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const 190 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* /* fallbackFonts */, GlyphOverflow* /* glyphOverflow */) const
192 { 191 {
193 HarfBuzzShaper shaper(this, run); 192 HarfBuzzShaper shaper(this, run);
194 if (!shaper.shape()) 193 if (!shaper.shape())
195 return 0; 194 return 0;
196 return shaper.totalWidth(); 195 return shaper.totalWidth();
(...skipping 14 matching lines...) Expand all
211 const FloatPoint& point, int height, 210 const FloatPoint& point, int height,
212 int from, int to) const 211 int from, int to) const
213 { 212 {
214 HarfBuzzShaper shaper(this, run); 213 HarfBuzzShaper shaper(this, run);
215 if (!shaper.shape()) 214 if (!shaper.shape())
216 return FloatRect(); 215 return FloatRect();
217 return shaper.selectionRect(point, height, from, to); 216 return shaper.selectionRect(point, height, from, to);
218 } 217 }
219 218
220 } // namespace WebCore 219 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/chromium/UniscribeHelper.cpp ('k') | Source/core/platform/graphics/mac/FontComplexTextMac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698