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

Side by Side Diff: src/core/SkBBoxRecord.cpp

Issue 247983003: Revert of make drawText calls non-virtual, to ease SkFont and TextBlob (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 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
« no previous file with comments | « src/core/SkBBoxRecord.h ('k') | src/core/SkCanvas.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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBBoxRecord.h" 9 #include "SkBBoxRecord.h"
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 } 78 }
79 79
80 void SkBBoxRecord::clear(SkColor color) { 80 void SkBBoxRecord::clear(SkColor color) {
81 SkISize size = this->getDeviceSize(); 81 SkISize size = this->getDeviceSize();
82 SkRect bbox = {0, 0, SkIntToScalar(size.width()), SkIntToScalar(size.height( ))}; 82 SkRect bbox = {0, 0, SkIntToScalar(size.width()), SkIntToScalar(size.height( ))};
83 this->handleBBox(bbox); 83 this->handleBBox(bbox);
84 INHERITED::clear(color); 84 INHERITED::clear(color);
85 } 85 }
86 86
87 void SkBBoxRecord::onDrawText(const void* text, size_t byteLength, SkScalar x, S kScalar y, 87 void SkBBoxRecord::drawText(const void* text, size_t byteLength, SkScalar x, SkS calar y,
88 const SkPaint& paint) { 88 const SkPaint& paint) {
89 SkRect bbox; 89 SkRect bbox;
90 paint.measureText(text, byteLength, &bbox); 90 paint.measureText(text, byteLength, &bbox);
91 SkPaint::FontMetrics metrics; 91 SkPaint::FontMetrics metrics;
92 paint.getFontMetrics(&metrics); 92 paint.getFontMetrics(&metrics);
93 93
94 // Vertical and aligned text need to be offset 94 // Vertical and aligned text need to be offset
95 if (paint.isVerticalText()) { 95 if (paint.isVerticalText()) {
96 SkScalar h = bbox.fBottom - bbox.fTop; 96 SkScalar h = bbox.fBottom - bbox.fTop;
97 if (paint.getTextAlign() == SkPaint::kCenter_Align) { 97 if (paint.getTextAlign() == SkPaint::kCenter_Align) {
98 bbox.fTop -= h / 2; 98 bbox.fTop -= h / 2;
(...skipping 22 matching lines...) Expand all
121 // incorrect on most platforms (too small in Linux, never even set in Window s). 121 // incorrect on most platforms (too small in Linux, never even set in Window s).
122 SkScalar pad = (metrics.fBottom - metrics.fTop) / 2; 122 SkScalar pad = (metrics.fBottom - metrics.fTop) / 2;
123 bbox.fLeft -= pad; 123 bbox.fLeft -= pad;
124 bbox.fRight += pad; 124 bbox.fRight += pad;
125 125
126 bbox.fLeft += x; 126 bbox.fLeft += x;
127 bbox.fRight += x; 127 bbox.fRight += x;
128 bbox.fTop += y; 128 bbox.fTop += y;
129 bbox.fBottom += y; 129 bbox.fBottom += y;
130 if (this->transformBounds(bbox, &paint)) { 130 if (this->transformBounds(bbox, &paint)) {
131 INHERITED::onDrawText(text, byteLength, x, y, paint); 131 INHERITED::drawText(text, byteLength, x, y, paint);
132 } 132 }
133 } 133 }
134 134
135 void SkBBoxRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar to p, 135 void SkBBoxRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar to p,
136 const SkPaint* paint) { 136 const SkPaint* paint) {
137 SkRect bbox = {left, top, left + bitmap.width(), top + bitmap.height()}; 137 SkRect bbox = {left, top, left + bitmap.width(), top + bitmap.height()};
138 if (this->transformBounds(bbox, paint)) { 138 if (this->transformBounds(bbox, paint)) {
139 INHERITED::drawBitmap(bitmap, left, top, paint); 139 INHERITED::drawBitmap(bitmap, left, top, paint);
140 } 140 }
141 } 141 }
(...skipping 16 matching lines...) Expand all
158 } 158 }
159 } 159 }
160 160
161 void SkBBoxRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 161 void SkBBoxRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
162 const SkRect& dst, const SkPaint* paint) { 162 const SkRect& dst, const SkPaint* paint) {
163 if (this->transformBounds(dst, paint)) { 163 if (this->transformBounds(dst, paint)) {
164 INHERITED::drawBitmapNine(bitmap, center, dst, paint); 164 INHERITED::drawBitmapNine(bitmap, center, dst, paint);
165 } 165 }
166 } 166 }
167 167
168 void SkBBoxRecord::onDrawPosText(const void* text, size_t byteLength, const SkPo int pos[], 168 void SkBBoxRecord::drawPosText(const void* text, size_t byteLength,
169 const SkPaint& paint) { 169 const SkPoint pos[], const SkPaint& paint) {
170 SkRect bbox; 170 SkRect bbox;
171 bbox.set(pos, paint.countText(text, byteLength)); 171 bbox.set(pos, paint.countText(text, byteLength));
172 SkPaint::FontMetrics metrics; 172 SkPaint::FontMetrics metrics;
173 paint.getFontMetrics(&metrics); 173 paint.getFontMetrics(&metrics);
174 bbox.fTop += metrics.fTop; 174 bbox.fTop += metrics.fTop;
175 bbox.fBottom += metrics.fBottom; 175 bbox.fBottom += metrics.fBottom;
176 176
177 // pad on left and right by half of max vertical glyph extents 177 // pad on left and right by half of max vertical glyph extents
178 SkScalar pad = (metrics.fTop - metrics.fBottom) / 2; 178 SkScalar pad = (metrics.fTop - metrics.fBottom) / 2;
179 bbox.fLeft += pad; 179 bbox.fLeft += pad;
180 bbox.fRight -= pad; 180 bbox.fRight -= pad;
181 181
182 if (this->transformBounds(bbox, &paint)) { 182 if (this->transformBounds(bbox, &paint)) {
183 INHERITED::onDrawPosText(text, byteLength, pos, paint); 183 INHERITED::drawPosText(text, byteLength, pos, paint);
184 } 184 }
185 } 185 }
186 186
187 void SkBBoxRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkS calar xpos[], 187 void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkSca lar xpos[],
188 SkScalar constY, const SkPaint& paint) { 188 SkScalar constY, const SkPaint& paint) {
189 size_t numChars = paint.countText(text, byteLength); 189 size_t numChars = paint.countText(text, byteLength);
190 if (numChars == 0) { 190 if (numChars == 0) {
191 return; 191 return;
192 } 192 }
193 193
194 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); 194 const SkFlatData* flatPaintData = this->getFlatPaintData(paint);
195 WriteTopBot(paint, *flatPaintData); 195 WriteTopBot(paint, *flatPaintData);
196 196
197 SkScalar top = flatPaintData->topBot()[0]; 197 SkScalar top = flatPaintData->topBot()[0];
198 SkScalar bottom = flatPaintData->topBot()[1]; 198 SkScalar bottom = flatPaintData->topBot()[1];
(...skipping 29 matching lines...) Expand all
228 } 228 }
229 229
230 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 230 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
231 const SkPaint* paint) { 231 const SkPaint* paint) {
232 SkRect bbox; 232 SkRect bbox;
233 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height())); 233 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height()));
234 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored 234 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored
235 INHERITED::drawSprite(bitmap, left, top, paint); 235 INHERITED::drawSprite(bitmap, left, top, paint);
236 } 236 }
237 237
238 void SkBBoxRecord::onDrawTextOnPath(const void* text, size_t byteLength, const S kPath& path, 238 void SkBBoxRecord::drawTextOnPath(const void* text, size_t byteLength,
239 const SkMatrix* matrix, const SkPaint& paint ) { 239 const SkPath& path, const SkMatrix* matrix,
240 const SkPaint& paint) {
240 SkRect bbox = path.getBounds(); 241 SkRect bbox = path.getBounds();
241 SkPaint::FontMetrics metrics; 242 SkPaint::FontMetrics metrics;
242 paint.getFontMetrics(&metrics); 243 paint.getFontMetrics(&metrics);
243 244
244 // pad out all sides by the max glyph height above baseline 245 // pad out all sides by the max glyph height above baseline
245 SkScalar pad = metrics.fTop; 246 SkScalar pad = metrics.fTop;
246 bbox.fLeft += pad; 247 bbox.fLeft += pad;
247 bbox.fRight -= pad; 248 bbox.fRight -= pad;
248 bbox.fTop += pad; 249 bbox.fTop += pad;
249 bbox.fBottom -= pad; 250 bbox.fBottom -= pad;
250 251
251 if (this->transformBounds(bbox, &paint)) { 252 if (this->transformBounds(bbox, &paint)) {
252 INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint); 253 INHERITED::drawTextOnPath(text, byteLength, path, matrix, paint);
253 } 254 }
254 } 255 }
255 256
256 void SkBBoxRecord::drawVertices(VertexMode mode, int vertexCount, 257 void SkBBoxRecord::drawVertices(VertexMode mode, int vertexCount,
257 const SkPoint vertices[], const SkPoint texs[], 258 const SkPoint vertices[], const SkPoint texs[],
258 const SkColor colors[], SkXfermode* xfer, 259 const SkColor colors[], SkXfermode* xfer,
259 const uint16_t indices[], int indexCount, 260 const uint16_t indices[], int indexCount,
260 const SkPaint& paint) { 261 const SkPaint& paint) {
261 SkRect bbox; 262 SkRect bbox;
262 bbox.set(vertices, vertexCount); 263 bbox.set(vertices, vertexCount);
(...skipping 29 matching lines...) Expand all
292 } 293 }
293 294
294 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { 295 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) {
295 this->getTotalMatrix().mapRect(&outBounds); 296 this->getTotalMatrix().mapRect(&outBounds);
296 this->handleBBox(outBounds); 297 this->handleBBox(outBounds);
297 return true; 298 return true;
298 } 299 }
299 300
300 return false; 301 return false;
301 } 302 }
OLDNEW
« no previous file with comments | « src/core/SkBBoxRecord.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698