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

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

Issue 14940018: we only need one fontmetrics, since the paint (and fontcache) now know explicitly (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: 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
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | src/core/SkScalerContext.h » ('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 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
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 "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkAnnotation.h" 10 #include "SkAnnotation.h"
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 } 1196 }
1197 1197
1198 // return the number of bytes measured 1198 // return the number of bytes measured
1199 return (kForward_TextBufferDirection == tbd) ? 1199 return (kForward_TextBufferDirection == tbd) ?
1200 text - stop + length : stop - text + length; 1200 text - stop + length : stop - text + length;
1201 } 1201 }
1202 1202
1203 /////////////////////////////////////////////////////////////////////////////// 1203 ///////////////////////////////////////////////////////////////////////////////
1204 1204
1205 static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) { 1205 static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) {
1206 *(SkPaint::FontMetrics*)context = cache->getFontMetricsY(); 1206 *(SkPaint::FontMetrics*)context = cache->getFontMetrics();
1207 return false; // don't detach the cache 1207 return false; // don't detach the cache
1208 } 1208 }
1209 1209
1210 static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc, 1210 static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc,
1211 void* context) { 1211 void* context) {
1212 SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context); 1212 SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context);
1213 } 1213 }
1214 1214
1215 SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { 1215 SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const {
1216 SkScalar scale = 0; 1216 SkScalar scale = 0;
1217 SkAutoRestorePaintTextSizeAndFrame restore(this); 1217 SkAutoRestorePaintTextSizeAndFrame restore(this);
1218 1218
1219 if (this->isLinearText()) { 1219 if (this->isLinearText()) {
1220 scale = fTextSize / kCanonicalTextSizeForPaths; 1220 scale = fTextSize / kCanonicalTextSizeForPaths;
1221 // this gets restored by restore 1221 // this gets restored by restore
1222 ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths)) ; 1222 ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths)) ;
1223 } 1223 }
1224 1224
1225 SkMatrix zoomMatrix, *zoomPtr = NULL; 1225 SkMatrix zoomMatrix, *zoomPtr = NULL;
1226 if (zoom) { 1226 if (zoom) {
1227 zoomMatrix.setScale(zoom, zoom); 1227 zoomMatrix.setScale(zoom, zoom);
1228 zoomPtr = &zoomMatrix; 1228 zoomPtr = &zoomMatrix;
1229 } 1229 }
1230 1230
1231 #if 0
1232 SkAutoGlyphCache autoCache(*this, zoomPtr);
1233 SkGlyphCache* cache = autoCache.getCache();
1234 const FontMetrics& my = cache->getFontMetricsY();
1235 #endif
1236 FontMetrics storage; 1231 FontMetrics storage;
1237 if (NULL == metrics) { 1232 if (NULL == metrics) {
1238 metrics = &storage; 1233 metrics = &storage;
1239 } 1234 }
1240 1235
1241 this->descriptorProc(NULL, zoomPtr, FontMetricsDescProc, metrics, true); 1236 this->descriptorProc(NULL, zoomPtr, FontMetricsDescProc, metrics, true);
1242 1237
1243 if (scale) { 1238 if (scale) {
1244 metrics->fTop = SkScalarMul(metrics->fTop, scale); 1239 metrics->fTop = SkScalarMul(metrics->fTop, scale);
1245 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); 1240 metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
1246 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); 1241 metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
1247 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); 1242 metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
1248 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); 1243 metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
1244 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
1245 metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
1246 metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
1247 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
1249 } 1248 }
1250 return metrics->fDescent - metrics->fAscent + metrics->fLeading; 1249 return metrics->fDescent - metrics->fAscent + metrics->fLeading;
1251 } 1250 }
1252 1251
1253 /////////////////////////////////////////////////////////////////////////////// 1252 ///////////////////////////////////////////////////////////////////////////////
1254 1253
1255 static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) { 1254 static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) {
1256 bounds->set(g.fLeft * scale, 1255 bounds->set(g.fLeft * scale,
1257 g.fTop * scale, 1256 g.fTop * scale,
1258 (g.fLeft + g.fWidth) * scale, 1257 (g.fLeft + g.fWidth) * scale,
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 if (firstTime) { 2566 if (firstTime) {
2568 *dst = r; 2567 *dst = r;
2569 } else { 2568 } else {
2570 dst->join(r); 2569 dst->join(r);
2571 } 2570 }
2572 } else { 2571 } else {
2573 break; 2572 break;
2574 } 2573 }
2575 } 2574 }
2576 } 2575 }
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | src/core/SkScalerContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698