OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 SkPDFScalar::Append(ctl2Y, content); | 88 SkPDFScalar::Append(ctl2Y, content); |
89 content->writeText(" "); | 89 content->writeText(" "); |
90 } | 90 } |
91 SkPDFScalar::Append(dstX, content); | 91 SkPDFScalar::Append(dstX, content); |
92 content->writeText(" "); | 92 content->writeText(" "); |
93 SkPDFScalar::Append(dstY, content); | 93 SkPDFScalar::Append(dstY, content); |
94 content->writeText(" "); | 94 content->writeText(" "); |
95 content->writeText(cmd.c_str()); | 95 content->writeText(cmd.c_str()); |
96 } | 96 } |
97 | 97 |
| 98 static void append_quad(const SkPoint quad[], SkWStream* content) { |
| 99 SkPoint cubic[4]; |
| 100 SkConvertQuadToCubic(quad, cubic); |
| 101 SkPDFUtils::AppendCubic(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY, |
| 102 cubic[3].fX, cubic[3].fY, content); |
| 103 } |
| 104 |
98 // static | 105 // static |
99 void SkPDFUtils::AppendRectangle(const SkRect& rect, SkWStream* content) { | 106 void SkPDFUtils::AppendRectangle(const SkRect& rect, SkWStream* content) { |
100 // Skia has 0,0 at top left, pdf at bottom left. Do the right thing. | 107 // Skia has 0,0 at top left, pdf at bottom left. Do the right thing. |
101 SkScalar bottom = SkMinScalar(rect.fBottom, rect.fTop); | 108 SkScalar bottom = SkMinScalar(rect.fBottom, rect.fTop); |
102 | 109 |
103 SkPDFScalar::Append(rect.fLeft, content); | 110 SkPDFScalar::Append(rect.fLeft, content); |
104 content->writeText(" "); | 111 content->writeText(" "); |
105 SkPDFScalar::Append(bottom, content); | 112 SkPDFScalar::Append(bottom, content); |
106 content->writeText(" "); | 113 content->writeText(" "); |
107 SkPDFScalar::Append(rect.width(), content); | 114 SkPDFScalar::Append(rect.width(), content); |
(...skipping 15 matching lines...) Expand all Loading... |
123 kNonSingleLine_SkipFillState = 2, | 130 kNonSingleLine_SkipFillState = 2, |
124 }; | 131 }; |
125 SkipFillState fillState = kEmpty_SkipFillState; | 132 SkipFillState fillState = kEmpty_SkipFillState; |
126 if (paintStyle != SkPaint::kFill_Style) { | 133 if (paintStyle != SkPaint::kFill_Style) { |
127 fillState = kNonSingleLine_SkipFillState; | 134 fillState = kNonSingleLine_SkipFillState; |
128 } | 135 } |
129 SkPoint lastMovePt = SkPoint::Make(0,0); | 136 SkPoint lastMovePt = SkPoint::Make(0,0); |
130 SkDynamicMemoryWStream currentSegment; | 137 SkDynamicMemoryWStream currentSegment; |
131 SkPoint args[4]; | 138 SkPoint args[4]; |
132 SkPath::Iter iter(path, false); | 139 SkPath::Iter iter(path, false); |
133 for (SkPath::Verb verb = iter.next(args); | 140 for (SkPath::Verb verb = iter.next(args); verb != SkPath::kDone_Verb; verb =
iter.next(args)) { |
134 verb != SkPath::kDone_Verb; | |
135 verb = iter.next(args)) { | |
136 // args gets all the points, even the implicit first point. | 141 // args gets all the points, even the implicit first point. |
137 switch (verb) { | 142 switch (verb) { |
138 case SkPath::kMove_Verb: | 143 case SkPath::kMove_Verb: |
139 MoveTo(args[0].fX, args[0].fY, ¤tSegment); | 144 MoveTo(args[0].fX, args[0].fY, ¤tSegment); |
140 lastMovePt = args[0]; | 145 lastMovePt = args[0]; |
141 fillState = kEmpty_SkipFillState; | 146 fillState = kEmpty_SkipFillState; |
142 break; | 147 break; |
143 case SkPath::kLine_Verb: | 148 case SkPath::kLine_Verb: |
144 AppendLine(args[1].fX, args[1].fY, ¤tSegment); | 149 AppendLine(args[1].fX, args[1].fY, ¤tSegment); |
145 if (fillState == kEmpty_SkipFillState) { | 150 if (fillState == kEmpty_SkipFillState) { |
146 if (args[0] != lastMovePt) { | 151 if (args[0] != lastMovePt) { |
147 fillState = kSingleLine_SkipFillState; | 152 fillState = kSingleLine_SkipFillState; |
148 } | 153 } |
149 } else if (fillState == kSingleLine_SkipFillState) { | 154 } else if (fillState == kSingleLine_SkipFillState) { |
150 fillState = kNonSingleLine_SkipFillState; | 155 fillState = kNonSingleLine_SkipFillState; |
151 } | 156 } |
152 break; | 157 break; |
153 case SkPath::kQuad_Verb: { | 158 case SkPath::kQuad_Verb: |
154 SkPoint cubic[4]; | 159 append_quad(args, ¤tSegment); |
155 SkConvertQuadToCubic(args, cubic); | |
156 AppendCubic(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY, | |
157 cubic[3].fX, cubic[3].fY, ¤tSegment); | |
158 fillState = kNonSingleLine_SkipFillState; | 160 fillState = kNonSingleLine_SkipFillState; |
159 break; | 161 break; |
160 } | 162 case SkPath::kConic_Verb: { |
| 163 const SkScalar tol = SK_Scalar1 / 4; |
| 164 SkAutoConicToQuads converter; |
| 165 const SkPoint* quads = converter.computeQuads(args, iter.conicWe
ight(), tol); |
| 166 for (int i = 0; i < converter.countQuads(); ++i) { |
| 167 append_quad(&quads[i * 2], ¤tSegment); |
| 168 } |
| 169 } break; |
161 case SkPath::kCubic_Verb: | 170 case SkPath::kCubic_Verb: |
162 AppendCubic(args[1].fX, args[1].fY, args[2].fX, args[2].fY, | 171 AppendCubic(args[1].fX, args[1].fY, args[2].fX, args[2].fY, |
163 args[3].fX, args[3].fY, ¤tSegment); | 172 args[3].fX, args[3].fY, ¤tSegment); |
164 fillState = kNonSingleLine_SkipFillState; | 173 fillState = kNonSingleLine_SkipFillState; |
165 break; | 174 break; |
166 case SkPath::kClose_Verb: | 175 case SkPath::kClose_Verb: |
167 if (fillState != kSingleLine_SkipFillState) { | 176 if (fillState != kSingleLine_SkipFillState) { |
168 ClosePath(¤tSegment); | 177 ClosePath(¤tSegment); |
169 SkData* data = currentSegment.copyToData(); | 178 SkData* data = currentSegment.copyToData(); |
170 content->write(data->data(), data->size()); | 179 content->write(data->data(), data->size()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // color (SCN, scn) | 249 // color (SCN, scn) |
241 SkString resourceName = SkPDFResourceDict::getResourceName( | 250 SkString resourceName = SkPDFResourceDict::getResourceName( |
242 SkPDFResourceDict::kPattern_ResourceType, | 251 SkPDFResourceDict::kPattern_ResourceType, |
243 objectIndex); | 252 objectIndex); |
244 content->writeText("/Pattern CS/Pattern cs/"); | 253 content->writeText("/Pattern CS/Pattern cs/"); |
245 content->writeText(resourceName.c_str()); | 254 content->writeText(resourceName.c_str()); |
246 content->writeText(" SCN/"); | 255 content->writeText(" SCN/"); |
247 content->writeText(resourceName.c_str()); | 256 content->writeText(resourceName.c_str()); |
248 content->writeText(" scn\n"); | 257 content->writeText(" scn\n"); |
249 } | 258 } |
OLD | NEW |