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

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

Issue 152073003: Adding code to calculate Underline Thickness from Font Metrics, this will be useful when Skia is us… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixing comments, adding bitfield to FontMetrics Created 6 years, 10 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
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 30 matching lines...) Expand all
41 //#define SK_REPORT_API_RANGE_CHECK 41 //#define SK_REPORT_API_RANGE_CHECK
42 42
43 #ifdef SK_BUILD_FOR_ANDROID 43 #ifdef SK_BUILD_FOR_ANDROID
44 #define GEN_ID_INC fGenerationID++ 44 #define GEN_ID_INC fGenerationID++
45 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } 45 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; }
46 #else 46 #else
47 #define GEN_ID_INC 47 #define GEN_ID_INC
48 #define GEN_ID_INC_EVAL(expression) 48 #define GEN_ID_INC_EVAL(expression)
49 #endif 49 #endif
50 50
51 #define setFontMetricsBitSet(__fObject, __bitSet) \
52 { \
53 if(__fObject != NULL) { \
54 __fObject->fFontMetricsFlag |= __bitSet; \
55 } \
56 }
57
51 SkPaint::SkPaint() { 58 SkPaint::SkPaint() {
52 // since we may have padding, we zero everything so that our memcmp() call 59 // since we may have padding, we zero everything so that our memcmp() call
53 // in operator== will work correctly. 60 // in operator== will work correctly.
54 // with this, we can skip 0 and null individual initializations 61 // with this, we can skip 0 and null individual initializations
55 sk_bzero(this, sizeof(*this)); 62 sk_bzero(this, sizeof(*this));
56 63
57 #if 0 // not needed with the bzero call above 64 #if 0 // not needed with the bzero call above
58 fTypeface = NULL; 65 fTypeface = NULL;
59 fTextSkewX = 0; 66 fTextSkewX = 0;
60 fPathEffect = NULL; 67 fPathEffect = NULL;
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 zoomMatrix.setScale(zoom, zoom); 1285 zoomMatrix.setScale(zoom, zoom);
1279 zoomPtr = &zoomMatrix; 1286 zoomPtr = &zoomMatrix;
1280 } 1287 }
1281 1288
1282 FontMetrics storage; 1289 FontMetrics storage;
1283 if (NULL == metrics) { 1290 if (NULL == metrics) {
1284 metrics = &storage; 1291 metrics = &storage;
1285 } 1292 }
1286 1293
1287 paint.descriptorProc(NULL, zoomPtr, FontMetricsDescProc, metrics, true); 1294 paint.descriptorProc(NULL, zoomPtr, FontMetricsDescProc, metrics, true);
1295 metrics->fFontMetricsFlag = 0;
1288 1296
1289 if (scale) { 1297 if (scale) {
1290 metrics->fTop = SkScalarMul(metrics->fTop, scale); 1298 if( (metrics->fTop = SkScalarMul(metrics->fTop, scale)) ) { setFontMetri csBitSet(metrics, kFontMetrics_Top); };
1291 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); 1299 if( (metrics->fAscent = SkScalarMul(metrics->fAscent, scale)) ) { setFon tMetricsBitSet(metrics, kFontMetrics_Ascent); };
1292 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); 1300 if( (metrics->fDescent = SkScalarMul(metrics->fDescent, scale)) ) { setF ontMetricsBitSet(metrics, kFontMetrics_Descent); };
1293 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); 1301 if( (metrics->fBottom = SkScalarMul(metrics->fBottom, scale)) ) { setFon tMetricsBitSet(metrics, kFontMetrics_Bottom); };
1294 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); 1302 if( (metrics->fLeading = SkScalarMul(metrics->fLeading, scale)) ) { setF ontMetricsBitSet(metrics, kFontMetrics_Leading); };
1295 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); 1303 if( (metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale) ) ) { setFontMetricsBitSet(metrics, kFontMetrics_AvgCharWidth); };
1296 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); 1304 if( (metrics->fXMin = SkScalarMul(metrics->fXMin, scale)) ) { setFontMet ricsBitSet(metrics, kFontMetrics_XMin); };
1297 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); 1305 if( (metrics->fXMax = SkScalarMul(metrics->fXMax, scale)) ) { setFontMet ricsBitSet(metrics, kFontMetrics_XMax); };
1298 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); 1306 if( (metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale)) ) { setF ontMetricsBitSet(metrics, kFontMetrics_XHeight); };
1307 if( (metrics->fUnderlineThickness = SkScalarMul(metrics->fUnderlineThick ness, scale)) ) { setFontMetricsBitSet(metrics, kFontMetrics_UnderlineThickness) ; };
1308 if( (metrics->fUnderlinePosition = SkScalarMul(metrics->fUnderlinePositi on, scale)) ) { setFontMetricsBitSet(metrics, kFontMetrics_UnderlinePosition); } ;
1299 } 1309 }
1300 return metrics->fDescent - metrics->fAscent + metrics->fLeading; 1310 return metrics->fDescent - metrics->fAscent + metrics->fLeading;
1301 } 1311 }
1302 1312
1303 /////////////////////////////////////////////////////////////////////////////// 1313 ///////////////////////////////////////////////////////////////////////////////
1304 1314
1305 static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) { 1315 static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) {
1306 bounds->set(g.fLeft * scale, 1316 bounds->set(g.fLeft * scale,
1307 g.fTop * scale, 1317 g.fTop * scale,
1308 (g.fLeft + g.fWidth) * scale, 1318 (g.fLeft + g.fWidth) * scale,
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 this->getMaskFilter()->computeFastBounds(*storage, storage); 2260 this->getMaskFilter()->computeFastBounds(*storage, storage);
2251 } 2261 }
2252 2262
2253 if (this->getImageFilter()) { 2263 if (this->getImageFilter()) {
2254 this->getImageFilter()->computeFastBounds(*storage, storage); 2264 this->getImageFilter()->computeFastBounds(*storage, storage);
2255 } 2265 }
2256 2266
2257 return *storage; 2267 return *storage;
2258 } 2268 }
2259 2269
2270 bool SkPaint::isFontMetricsBitSet(FontMetrics * fObject, FontMetricsBitSet bitSe t) const
2271 {
2272 if(fObject != NULL) {
2273 return SkToBool(fObject->fFontMetricsFlag & bitSet);
2274 }
2275 return false;
2276 }
2277
2260 #ifdef SK_DEVELOPER 2278 #ifdef SK_DEVELOPER
2261 void SkPaint::toString(SkString* str) const { 2279 void SkPaint::toString(SkString* str) const {
2262 str->append("<dl><dt>SkPaint:</dt><dd><dl>"); 2280 str->append("<dl><dt>SkPaint:</dt><dd><dl>");
2263 2281
2264 SkTypeface* typeface = this->getTypeface(); 2282 SkTypeface* typeface = this->getTypeface();
2265 if (NULL != typeface) { 2283 if (NULL != typeface) {
2266 SkDynamicMemoryWStream ostream; 2284 SkDynamicMemoryWStream ostream;
2267 typeface->serialize(&ostream); 2285 typeface->serialize(&ostream);
2268 SkAutoTUnref<SkData> data(ostream.copyToData()); 2286 SkAutoTUnref<SkData> data(ostream.copyToData());
2269 2287
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 case SkXfermode::kPlus_Mode: 2561 case SkXfermode::kPlus_Mode:
2544 return 0 == this->getAlpha(); 2562 return 0 == this->getAlpha();
2545 case SkXfermode::kDst_Mode: 2563 case SkXfermode::kDst_Mode:
2546 return true; 2564 return true;
2547 default: 2565 default:
2548 break; 2566 break;
2549 } 2567 }
2550 } 2568 }
2551 return false; 2569 return false;
2552 } 2570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698