OLD | NEW |
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 fColorFilter = NULL; | 63 fColorFilter = NULL; |
64 fRasterizer = NULL; | 64 fRasterizer = NULL; |
65 fLooper = NULL; | 65 fLooper = NULL; |
66 fImageFilter = NULL; | 66 fImageFilter = NULL; |
67 fAnnotation = NULL; | 67 fAnnotation = NULL; |
68 fWidth = 0; | 68 fWidth = 0; |
69 #endif | 69 #endif |
70 | 70 |
71 fTextSize = SkPaintDefaults_TextSize; | 71 fTextSize = SkPaintDefaults_TextSize; |
72 fTextScaleX = SK_Scalar1; | 72 fTextScaleX = SK_Scalar1; |
73 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | |
74 fHintingScaleFactor = SK_Scalar1; | |
75 #endif | |
76 fColor = SK_ColorBLACK; | 73 fColor = SK_ColorBLACK; |
77 fMiterLimit = SkPaintDefaults_MiterLimit; | 74 fMiterLimit = SkPaintDefaults_MiterLimit; |
78 fFlags = SkPaintDefaults_Flags; | 75 fFlags = SkPaintDefaults_Flags; |
79 fCapType = kDefault_Cap; | 76 fCapType = kDefault_Cap; |
80 fJoinType = kDefault_Join; | 77 fJoinType = kDefault_Join; |
81 fTextAlign = kLeft_Align; | 78 fTextAlign = kLeft_Align; |
82 fStyle = kFill_Style; | 79 fStyle = kFill_Style; |
83 fTextEncoding = kUTF8_TextEncoding; | 80 fTextEncoding = kUTF8_TextEncoding; |
84 fHinting = SkPaintDefaults_Hinting; | 81 fHinting = SkPaintDefaults_Hinting; |
85 fPrivFlags = 0; | 82 fPrivFlags = 0; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 void SkPaint::setTextScaleX(SkScalar scaleX) { | 379 void SkPaint::setTextScaleX(SkScalar scaleX) { |
383 GEN_ID_INC_EVAL(scaleX != fTextScaleX); | 380 GEN_ID_INC_EVAL(scaleX != fTextScaleX); |
384 fTextScaleX = scaleX; | 381 fTextScaleX = scaleX; |
385 } | 382 } |
386 | 383 |
387 void SkPaint::setTextSkewX(SkScalar skewX) { | 384 void SkPaint::setTextSkewX(SkScalar skewX) { |
388 GEN_ID_INC_EVAL(skewX != fTextSkewX); | 385 GEN_ID_INC_EVAL(skewX != fTextSkewX); |
389 fTextSkewX = skewX; | 386 fTextSkewX = skewX; |
390 } | 387 } |
391 | 388 |
392 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | |
393 void SkPaint::setHintingScaleFactor(SkScalar hintingScaleFactor) { | |
394 GEN_ID_INC_EVAL(hintingScaleFactor != fHintingScaleFactor); | |
395 fHintingScaleFactor = hintingScaleFactor; | |
396 } | |
397 #endif | |
398 | |
399 void SkPaint::setTextEncoding(TextEncoding encoding) { | 389 void SkPaint::setTextEncoding(TextEncoding encoding) { |
400 if ((unsigned)encoding <= kGlyphID_TextEncoding) { | 390 if ((unsigned)encoding <= kGlyphID_TextEncoding) { |
401 GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); | 391 GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); |
402 fTextEncoding = encoding; | 392 fTextEncoding = encoding; |
403 } else { | 393 } else { |
404 #ifdef SK_REPORT_API_RANGE_CHECK | 394 #ifdef SK_REPORT_API_RANGE_CHECK |
405 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); | 395 SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); |
406 #endif | 396 #endif |
407 } | 397 } |
408 } | 398 } |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1577 |
1588 SkTypeface* typeface = paint.getTypeface(); | 1578 SkTypeface* typeface = paint.getTypeface(); |
1589 if (NULL == typeface) { | 1579 if (NULL == typeface) { |
1590 typeface = SkTypeface::GetDefaultTypeface(); | 1580 typeface = SkTypeface::GetDefaultTypeface(); |
1591 } | 1581 } |
1592 rec->fOrigFontID = typeface->uniqueID(); | 1582 rec->fOrigFontID = typeface->uniqueID(); |
1593 rec->fFontID = rec->fOrigFontID; | 1583 rec->fFontID = rec->fOrigFontID; |
1594 rec->fTextSize = paint.getTextSize(); | 1584 rec->fTextSize = paint.getTextSize(); |
1595 rec->fPreScaleX = paint.getTextScaleX(); | 1585 rec->fPreScaleX = paint.getTextScaleX(); |
1596 rec->fPreSkewX = paint.getTextSkewX(); | 1586 rec->fPreSkewX = paint.getTextSkewX(); |
1597 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | |
1598 rec->fHintingScaleFactor = paint.getHintingScaleFactor(); | |
1599 #endif | |
1600 | 1587 |
1601 if (deviceMatrix) { | 1588 if (deviceMatrix) { |
1602 rec->fPost2x2[0][0] = sk_relax(deviceMatrix->getScaleX()); | 1589 rec->fPost2x2[0][0] = sk_relax(deviceMatrix->getScaleX()); |
1603 rec->fPost2x2[0][1] = sk_relax(deviceMatrix->getSkewX()); | 1590 rec->fPost2x2[0][1] = sk_relax(deviceMatrix->getSkewX()); |
1604 rec->fPost2x2[1][0] = sk_relax(deviceMatrix->getSkewY()); | 1591 rec->fPost2x2[1][0] = sk_relax(deviceMatrix->getSkewY()); |
1605 rec->fPost2x2[1][1] = sk_relax(deviceMatrix->getScaleY()); | 1592 rec->fPost2x2[1][1] = sk_relax(deviceMatrix->getScaleY()); |
1606 } else { | 1593 } else { |
1607 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; | 1594 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; |
1608 rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0; | 1595 rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0; |
1609 } | 1596 } |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 } | 2038 } |
2052 | 2039 |
2053 | 2040 |
2054 if (buffer.isOrderedBinaryBuffer()) { | 2041 if (buffer.isOrderedBinaryBuffer()) { |
2055 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2042 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
2056 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); | 2043 uint32_t* ptr = buffer.getOrderedBinaryBuffer()->reserve(kPODPaintSize); |
2057 | 2044 |
2058 ptr = write_scalar(ptr, this->getTextSize()); | 2045 ptr = write_scalar(ptr, this->getTextSize()); |
2059 ptr = write_scalar(ptr, this->getTextScaleX()); | 2046 ptr = write_scalar(ptr, this->getTextScaleX()); |
2060 ptr = write_scalar(ptr, this->getTextSkewX()); | 2047 ptr = write_scalar(ptr, this->getTextSkewX()); |
2061 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | 2048 // Dummy value for obsolete hinting scale factor. TODO: remove with nex
t picture version |
2062 ptr = write_scalar(ptr, this->getHintingScaleFactor()); | |
2063 #else | |
2064 // Dummy value. | |
2065 ptr = write_scalar(ptr, SK_Scalar1); | 2049 ptr = write_scalar(ptr, SK_Scalar1); |
2066 #endif | |
2067 ptr = write_scalar(ptr, this->getStrokeWidth()); | 2050 ptr = write_scalar(ptr, this->getStrokeWidth()); |
2068 ptr = write_scalar(ptr, this->getStrokeMiter()); | 2051 ptr = write_scalar(ptr, this->getStrokeMiter()); |
2069 *ptr++ = this->getColor(); | 2052 *ptr++ = this->getColor(); |
2070 // previously flags:16, textAlign:8, flatFlags:8 | 2053 // previously flags:16, textAlign:8, flatFlags:8 |
2071 // now flags:16, hinting:4, textAlign:4, flatFlags:8 | 2054 // now flags:16, hinting:4, textAlign:4, flatFlags:8 |
2072 *ptr++ = (this->getFlags() << 16) | | 2055 *ptr++ = (this->getFlags() << 16) | |
2073 // hinting added later. 0 in this nibble means use the default. | 2056 // hinting added later. 0 in this nibble means use the default. |
2074 ((this->getHinting()+1) << 12) | | 2057 ((this->getHinting()+1) << 12) | |
2075 (this->getTextAlign() << 8) | | 2058 (this->getTextAlign() << 8) | |
2076 flatFlags; | 2059 flatFlags; |
2077 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(), | 2060 *ptr++ = pack_4(this->getStrokeCap(), this->getStrokeJoin(), |
2078 this->getStyle(), this->getTextEncoding()); | 2061 this->getStyle(), this->getTextEncoding()); |
2079 } else { | 2062 } else { |
2080 buffer.writeScalar(fTextSize); | 2063 buffer.writeScalar(fTextSize); |
2081 buffer.writeScalar(fTextScaleX); | 2064 buffer.writeScalar(fTextScaleX); |
2082 buffer.writeScalar(fTextSkewX); | 2065 buffer.writeScalar(fTextSkewX); |
2083 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | 2066 // Dummy value for obsolete hinting scale factor. TODO: remove with nex
t picture version |
2084 buffer.writeScalar(fHintingScaleFactor); | |
2085 #else | |
2086 // Dummy value. | |
2087 buffer.writeScalar(SK_Scalar1); | 2067 buffer.writeScalar(SK_Scalar1); |
2088 #endif | |
2089 buffer.writeScalar(fWidth); | 2068 buffer.writeScalar(fWidth); |
2090 buffer.writeScalar(fMiterLimit); | 2069 buffer.writeScalar(fMiterLimit); |
2091 buffer.writeColor(fColor); | 2070 buffer.writeColor(fColor); |
2092 buffer.writeUInt(fFlags); | 2071 buffer.writeUInt(fFlags); |
2093 buffer.writeUInt(fHinting); | 2072 buffer.writeUInt(fHinting); |
2094 buffer.writeUInt(fTextAlign); | 2073 buffer.writeUInt(fTextAlign); |
2095 buffer.writeUInt(flatFlags); | 2074 buffer.writeUInt(flatFlags); |
2096 | 2075 |
2097 buffer.writeUInt(fCapType); | 2076 buffer.writeUInt(fCapType); |
2098 buffer.writeUInt(fJoinType); | 2077 buffer.writeUInt(fJoinType); |
(...skipping 25 matching lines...) Expand all Loading... |
2124 uint8_t flatFlags = 0; | 2103 uint8_t flatFlags = 0; |
2125 if (buffer.isOrderedBinaryBuffer()) { | 2104 if (buffer.isOrderedBinaryBuffer()) { |
2126 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); | 2105 SkASSERT(SkAlign4(kPODPaintSize) == kPODPaintSize); |
2127 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz
e); | 2106 const void* podData = buffer.getOrderedBinaryBuffer()->skip(kPODPaintSiz
e); |
2128 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); | 2107 const uint32_t* pod = reinterpret_cast<const uint32_t*>(podData); |
2129 | 2108 |
2130 // the order we read must match the order we wrote in flatten() | 2109 // the order we read must match the order we wrote in flatten() |
2131 this->setTextSize(read_scalar(pod)); | 2110 this->setTextSize(read_scalar(pod)); |
2132 this->setTextScaleX(read_scalar(pod)); | 2111 this->setTextScaleX(read_scalar(pod)); |
2133 this->setTextSkewX(read_scalar(pod)); | 2112 this->setTextSkewX(read_scalar(pod)); |
2134 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | |
2135 this->setHintingScaleFactor(read_scalar(pod)); | |
2136 #else | |
2137 // Skip the hinting scalar factor, which is not supported. | 2113 // Skip the hinting scalar factor, which is not supported. |
2138 read_scalar(pod); | 2114 read_scalar(pod); |
2139 #endif | |
2140 this->setStrokeWidth(read_scalar(pod)); | 2115 this->setStrokeWidth(read_scalar(pod)); |
2141 this->setStrokeMiter(read_scalar(pod)); | 2116 this->setStrokeMiter(read_scalar(pod)); |
2142 this->setColor(*pod++); | 2117 this->setColor(*pod++); |
2143 | 2118 |
2144 // previously flags:16, textAlign:8, flatFlags:8 | 2119 // previously flags:16, textAlign:8, flatFlags:8 |
2145 // now flags:16, hinting:4, textAlign:4, flatFlags:8 | 2120 // now flags:16, hinting:4, textAlign:4, flatFlags:8 |
2146 uint32_t tmp = *pod++; | 2121 uint32_t tmp = *pod++; |
2147 this->setFlags(tmp >> 16); | 2122 this->setFlags(tmp >> 16); |
2148 | 2123 |
2149 // hinting added later. 0 in this nibble means use the default. | 2124 // hinting added later. 0 in this nibble means use the default. |
2150 uint32_t hinting = (tmp >> 12) & 0xF; | 2125 uint32_t hinting = (tmp >> 12) & 0xF; |
2151 this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(h
inting-1)); | 2126 this->setHinting(0 == hinting ? kNormal_Hinting : static_cast<Hinting>(h
inting-1)); |
2152 | 2127 |
2153 this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF)); | 2128 this->setTextAlign(static_cast<Align>((tmp >> 8) & 0xF)); |
2154 | 2129 |
2155 flatFlags = tmp & 0xFF; | 2130 flatFlags = tmp & 0xFF; |
2156 | 2131 |
2157 tmp = *pod++; | 2132 tmp = *pod++; |
2158 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); | 2133 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); |
2159 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); | 2134 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); |
2160 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); | 2135 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); |
2161 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); | 2136 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); |
2162 } else { | 2137 } else { |
2163 this->setTextSize(buffer.readScalar()); | 2138 this->setTextSize(buffer.readScalar()); |
2164 this->setTextScaleX(buffer.readScalar()); | 2139 this->setTextScaleX(buffer.readScalar()); |
2165 this->setTextSkewX(buffer.readScalar()); | 2140 this->setTextSkewX(buffer.readScalar()); |
2166 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR | |
2167 this->setHintingScaleFactor(buffer.readScalar()); | |
2168 #else | |
2169 // Skip the hinting scalar factor, which is not supported. | 2141 // Skip the hinting scalar factor, which is not supported. |
2170 buffer.readScalar(); | 2142 buffer.readScalar(); |
2171 #endif | |
2172 this->setStrokeWidth(buffer.readScalar()); | 2143 this->setStrokeWidth(buffer.readScalar()); |
2173 this->setStrokeMiter(buffer.readScalar()); | 2144 this->setStrokeMiter(buffer.readScalar()); |
2174 this->setColor(buffer.readColor()); | 2145 this->setColor(buffer.readColor()); |
2175 this->setFlags(buffer.readUInt()); | 2146 this->setFlags(buffer.readUInt()); |
2176 this->setHinting(static_cast<SkPaint::Hinting>(buffer.readUInt())); | 2147 this->setHinting(static_cast<SkPaint::Hinting>(buffer.readUInt())); |
2177 this->setTextAlign(static_cast<SkPaint::Align>(buffer.readUInt())); | 2148 this->setTextAlign(static_cast<SkPaint::Align>(buffer.readUInt())); |
2178 flatFlags = buffer.readUInt(); | 2149 flatFlags = buffer.readUInt(); |
2179 | 2150 |
2180 this->setStrokeCap(static_cast<SkPaint::Cap>(buffer.readUInt())); | 2151 this->setStrokeCap(static_cast<SkPaint::Cap>(buffer.readUInt())); |
2181 this->setStrokeJoin(static_cast<SkPaint::Join>(buffer.readUInt())); | 2152 this->setStrokeJoin(static_cast<SkPaint::Join>(buffer.readUInt())); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2602 case SkXfermode::kPlus_Mode: | 2573 case SkXfermode::kPlus_Mode: |
2603 return 0 == this->getAlpha(); | 2574 return 0 == this->getAlpha(); |
2604 case SkXfermode::kDst_Mode: | 2575 case SkXfermode::kDst_Mode: |
2605 return true; | 2576 return true; |
2606 default: | 2577 default: |
2607 break; | 2578 break; |
2608 } | 2579 } |
2609 } | 2580 } |
2610 return false; | 2581 return false; |
2611 } | 2582 } |
OLD | NEW |