OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkStrokeRec.h" | 8 #include "SkStrokeRec.h" |
9 #include "SkPaintDefaults.h" | 9 #include "SkPaintDefaults.h" |
10 | 10 |
11 // must be < 0, since ==0 means hairline, and >0 means normal stroke | 11 // must be < 0, since ==0 means hairline, and >0 means normal stroke |
12 #define kStrokeRec_FillStyleWidth (-SK_Scalar1) | 12 #define kStrokeRec_FillStyleWidth (-SK_Scalar1) |
13 | 13 |
14 SkStrokeRec::SkStrokeRec(InitStyle s) { | 14 SkStrokeRec::SkStrokeRec(InitStyle s) { |
| 15 fResScale = 1; |
15 fWidth = (kFill_InitStyle == s) ? kStrokeRec_FillStyleWidth : 0; | 16 fWidth = (kFill_InitStyle == s) ? kStrokeRec_FillStyleWidth : 0; |
16 fMiterLimit = SkPaintDefaults_MiterLimit; | 17 fMiterLimit = SkPaintDefaults_MiterLimit; |
17 fCap = SkPaint::kDefault_Cap; | 18 fCap = SkPaint::kDefault_Cap; |
18 fJoin = SkPaint::kDefault_Join; | 19 fJoin = SkPaint::kDefault_Join; |
19 fStrokeAndFill = false; | 20 fStrokeAndFill = false; |
20 } | 21 } |
21 | 22 |
22 SkStrokeRec::SkStrokeRec(const SkStrokeRec& src) { | 23 SkStrokeRec::SkStrokeRec(const SkStrokeRec& src) { |
23 memcpy(this, &src, sizeof(src)); | 24 memcpy(this, &src, sizeof(src)); |
24 } | 25 } |
25 | 26 |
26 SkStrokeRec::SkStrokeRec(const SkPaint& paint) { | 27 SkStrokeRec::SkStrokeRec(const SkPaint& paint, SkScalar resScale) { |
27 this->init(paint, paint.getStyle()); | 28 this->init(paint, paint.getStyle(), resScale); |
28 } | 29 } |
29 | 30 |
30 SkStrokeRec::SkStrokeRec(const SkPaint& paint, SkPaint::Style styleOverride) { | 31 SkStrokeRec::SkStrokeRec(const SkPaint& paint, SkPaint::Style styleOverride, SkS
calar resScale) { |
31 this->init(paint, styleOverride); | 32 this->init(paint, styleOverride, resScale); |
32 } | 33 } |
33 | 34 |
34 void SkStrokeRec::init(const SkPaint& paint, SkPaint::Style style) { | 35 void SkStrokeRec::init(const SkPaint& paint, SkPaint::Style style, SkScalar resS
cale) { |
| 36 fResScale = resScale; |
| 37 |
35 switch (style) { | 38 switch (style) { |
36 case SkPaint::kFill_Style: | 39 case SkPaint::kFill_Style: |
37 fWidth = kStrokeRec_FillStyleWidth; | 40 fWidth = kStrokeRec_FillStyleWidth; |
38 fStrokeAndFill = false; | 41 fStrokeAndFill = false; |
39 break; | 42 break; |
40 case SkPaint::kStroke_Style: | 43 case SkPaint::kStroke_Style: |
41 fWidth = paint.getStrokeWidth(); | 44 fWidth = paint.getStrokeWidth(); |
42 fStrokeAndFill = false; | 45 fStrokeAndFill = false; |
43 break; | 46 break; |
44 case SkPaint::kStrokeAndFill_Style: | 47 case SkPaint::kStrokeAndFill_Style: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (fWidth <= 0) { // hairline or fill | 104 if (fWidth <= 0) { // hairline or fill |
102 return false; | 105 return false; |
103 } | 106 } |
104 | 107 |
105 SkStroke stroker; | 108 SkStroke stroker; |
106 stroker.setCap(fCap); | 109 stroker.setCap(fCap); |
107 stroker.setJoin(fJoin); | 110 stroker.setJoin(fJoin); |
108 stroker.setMiterLimit(fMiterLimit); | 111 stroker.setMiterLimit(fMiterLimit); |
109 stroker.setWidth(fWidth); | 112 stroker.setWidth(fWidth); |
110 stroker.setDoFill(fStrokeAndFill); | 113 stroker.setDoFill(fStrokeAndFill); |
| 114 stroker.setResScale(fResScale); |
111 #if QUAD_STROKE_APPROXIMATION | 115 #if QUAD_STROKE_APPROXIMATION |
112 stroker.setError(1); | 116 stroker.setError(1); |
113 #endif | 117 #endif |
114 stroker.strokePath(src, dst); | 118 stroker.strokePath(src, dst); |
115 return true; | 119 return true; |
116 } | 120 } |
117 | 121 |
118 void SkStrokeRec::applyToPaint(SkPaint* paint) const { | 122 void SkStrokeRec::applyToPaint(SkPaint* paint) const { |
119 if (fWidth < 0) { // fill | 123 if (fWidth < 0) { // fill |
120 paint->setStyle(SkPaint::kFill_Style); | 124 paint->setStyle(SkPaint::kFill_Style); |
121 return; | 125 return; |
122 } | 126 } |
123 | 127 |
124 paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kS
troke_Style); | 128 paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kS
troke_Style); |
125 paint->setStrokeWidth(fWidth); | 129 paint->setStrokeWidth(fWidth); |
126 paint->setStrokeMiter(fMiterLimit); | 130 paint->setStrokeMiter(fMiterLimit); |
127 paint->setStrokeCap(fCap); | 131 paint->setStrokeCap(fCap); |
128 paint->setStrokeJoin(fJoin); | 132 paint->setStrokeJoin(fJoin); |
129 } | 133 } |
OLD | NEW |