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

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

Issue 288923006: hack to expand 'pad' to account for very wide glyphs (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: apply hack to drawPosText and drawPosTextH Created 6 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
« no previous file with comments | « no previous file | 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 /* 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Hack to work-around https://code.google.com/p/chromium/issues/detail?id=37378 5
169 // This logic assums that 'pad' is enough to add to the left and right to accoun t for
170 // big glyphs. For the font in question (a logo font) the glyphs is much wider t han just
171 // the pointsize (approx 3x wider).
172 // As a temp work-around, we scale-up pad.
173 // A more correct fix might be to add fontmetrics.fMaxX, but we don't have that value in hand
174 // at the moment, and (possibly) the value in the font may not be accurate (but who knows).
175 //
176 static SkScalar hack_373785_amend_pad(SkScalar pad) {
177 return pad * 4;
178 }
179
168 void SkBBoxRecord::onDrawPosText(const void* text, size_t byteLength, const SkPo int pos[], 180 void SkBBoxRecord::onDrawPosText(const void* text, size_t byteLength, const SkPo int pos[],
169 const SkPaint& paint) { 181 const SkPaint& paint) {
170 SkRect bbox; 182 SkRect bbox;
171 bbox.set(pos, paint.countText(text, byteLength)); 183 bbox.set(pos, paint.countText(text, byteLength));
172 SkPaint::FontMetrics metrics; 184 SkPaint::FontMetrics metrics;
173 paint.getFontMetrics(&metrics); 185 paint.getFontMetrics(&metrics);
174 bbox.fTop += metrics.fTop; 186 bbox.fTop += metrics.fTop;
175 bbox.fBottom += metrics.fBottom; 187 bbox.fBottom += metrics.fBottom;
176 188
177 // pad on left and right by half of max vertical glyph extents 189 // pad on left and right by half of max vertical glyph extents
178 SkScalar pad = (metrics.fTop - metrics.fBottom) / 2; 190 SkScalar pad = (metrics.fTop - metrics.fBottom) / 2;
191 pad = hack_373785_amend_pad(pad);
179 bbox.fLeft += pad; 192 bbox.fLeft += pad;
180 bbox.fRight -= pad; 193 bbox.fRight -= pad;
181 194
182 if (this->transformBounds(bbox, &paint)) { 195 if (this->transformBounds(bbox, &paint)) {
183 INHERITED::onDrawPosText(text, byteLength, pos, paint); 196 INHERITED::onDrawPosText(text, byteLength, pos, paint);
184 } 197 }
185 } 198 }
186 199
187 void SkBBoxRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkS calar xpos[], 200 void SkBBoxRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkS calar xpos[],
188 SkScalar constY, const SkPaint& paint) { 201 SkScalar constY, const SkPaint& paint) {
(...skipping 16 matching lines...) Expand all
205 for (size_t i = 0; i < numChars; ++i) { 218 for (size_t i = 0; i < numChars; ++i) {
206 if (xpos[i] < bbox.fLeft) { 219 if (xpos[i] < bbox.fLeft) {
207 bbox.fLeft = xpos[i]; 220 bbox.fLeft = xpos[i];
208 } 221 }
209 if (xpos[i] > bbox.fRight) { 222 if (xpos[i] > bbox.fRight) {
210 bbox.fRight = xpos[i]; 223 bbox.fRight = xpos[i];
211 } 224 }
212 } 225 }
213 226
214 // pad horizontally by max glyph height 227 // pad horizontally by max glyph height
228 pad = hack_373785_amend_pad(pad);
215 bbox.fLeft += pad; 229 bbox.fLeft += pad;
216 bbox.fRight -= pad; 230 bbox.fRight -= pad;
217 231
218 bbox.fTop = top + constY; 232 bbox.fTop = top + constY;
219 bbox.fBottom = bottom + constY; 233 bbox.fBottom = bottom + constY;
220 234
221 if (!this->transformBounds(bbox, &paint)) { 235 if (!this->transformBounds(bbox, &paint)) {
222 return; 236 return;
223 } 237 }
224 // This is the equivalent of calling: 238 // This is the equivalent of calling:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 306 }
293 307
294 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { 308 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) {
295 this->getTotalMatrix().mapRect(&outBounds); 309 this->getTotalMatrix().mapRect(&outBounds);
296 this->handleBBox(outBounds); 310 this->handleBBox(outBounds);
297 return true; 311 return true;
298 } 312 }
299 313
300 return false; 314 return false;
301 } 315 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698