OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/paint_vector_icon.h" | 5 #include "ui/gfx/paint_vector_icon.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <tuple> | 8 #include <tuple> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 RETURN_IF_IS(ARC_TO); | 41 RETURN_IF_IS(ARC_TO); |
42 RETURN_IF_IS(R_ARC_TO); | 42 RETURN_IF_IS(R_ARC_TO); |
43 RETURN_IF_IS(LINE_TO); | 43 RETURN_IF_IS(LINE_TO); |
44 RETURN_IF_IS(R_LINE_TO); | 44 RETURN_IF_IS(R_LINE_TO); |
45 RETURN_IF_IS(H_LINE_TO); | 45 RETURN_IF_IS(H_LINE_TO); |
46 RETURN_IF_IS(R_H_LINE_TO); | 46 RETURN_IF_IS(R_H_LINE_TO); |
47 RETURN_IF_IS(V_LINE_TO); | 47 RETURN_IF_IS(V_LINE_TO); |
48 RETURN_IF_IS(R_V_LINE_TO); | 48 RETURN_IF_IS(R_V_LINE_TO); |
49 RETURN_IF_IS(CUBIC_TO); | 49 RETURN_IF_IS(CUBIC_TO); |
50 RETURN_IF_IS(R_CUBIC_TO); | 50 RETURN_IF_IS(R_CUBIC_TO); |
51 RETURN_IF_IS(CUBIC_TO_SHORTHAND); | |
51 RETURN_IF_IS(CIRCLE); | 52 RETURN_IF_IS(CIRCLE); |
52 RETURN_IF_IS(ROUND_RECT); | 53 RETURN_IF_IS(ROUND_RECT); |
53 RETURN_IF_IS(CLOSE); | 54 RETURN_IF_IS(CLOSE); |
54 RETURN_IF_IS(CANVAS_DIMENSIONS); | 55 RETURN_IF_IS(CANVAS_DIMENSIONS); |
55 RETURN_IF_IS(CLIP); | 56 RETURN_IF_IS(CLIP); |
56 RETURN_IF_IS(DISABLE_AA); | 57 RETURN_IF_IS(DISABLE_AA); |
57 RETURN_IF_IS(FLIPS_IN_RTL); | 58 RETURN_IF_IS(FLIPS_IN_RTL); |
58 RETURN_IF_IS(END); | 59 RETURN_IF_IS(END); |
59 #undef RETURN_IF_IS | 60 #undef RETURN_IF_IS |
60 | 61 |
(...skipping 23 matching lines...) Expand all Loading... | |
84 int dip_size, | 85 int dip_size, |
85 SkColor color) { | 86 SkColor color) { |
86 SkPath path; | 87 SkPath path; |
87 path.setFillType(SkPath::kEvenOdd_FillType); | 88 path.setFillType(SkPath::kEvenOdd_FillType); |
88 | 89 |
89 int canvas_size = kReferenceSizeDip; | 90 int canvas_size = kReferenceSizeDip; |
90 std::vector<SkPath> paths; | 91 std::vector<SkPath> paths; |
91 std::vector<SkPaint> paints; | 92 std::vector<SkPaint> paints; |
92 SkRect clip_rect = SkRect::MakeEmpty(); | 93 SkRect clip_rect = SkRect::MakeEmpty(); |
93 bool flips_in_rtl = false; | 94 bool flips_in_rtl = false; |
95 CommandType previous_command_type = NEW_PATH; | |
94 | 96 |
95 for (size_t i = 0; path_elements[i].type != END; i++) { | 97 for (size_t i = 0; path_elements[i].type != END; i++) { |
96 if (paths.empty() || path_elements[i].type == NEW_PATH) { | 98 if (paths.empty() || path_elements[i].type == NEW_PATH) { |
97 paths.push_back(SkPath()); | 99 paths.push_back(SkPath()); |
98 paths.back().setFillType(SkPath::kEvenOdd_FillType); | 100 paths.back().setFillType(SkPath::kEvenOdd_FillType); |
99 | 101 |
100 paints.push_back(SkPaint()); | 102 paints.push_back(SkPaint()); |
101 paints.back().setColor(color); | 103 paints.back().setColor(color); |
102 paints.back().setAntiAlias(true); | 104 paints.back().setAntiAlias(true); |
103 paints.back().setStrokeCap(SkPaint::kRound_Cap); | 105 paints.back().setStrokeCap(SkPaint::kRound_Cap); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 SkScalar x1 = path_elements[++i].arg; | 234 SkScalar x1 = path_elements[++i].arg; |
233 SkScalar y1 = path_elements[++i].arg; | 235 SkScalar y1 = path_elements[++i].arg; |
234 SkScalar x2 = path_elements[++i].arg; | 236 SkScalar x2 = path_elements[++i].arg; |
235 SkScalar y2 = path_elements[++i].arg; | 237 SkScalar y2 = path_elements[++i].arg; |
236 SkScalar x3 = path_elements[++i].arg; | 238 SkScalar x3 = path_elements[++i].arg; |
237 SkScalar y3 = path_elements[++i].arg; | 239 SkScalar y3 = path_elements[++i].arg; |
238 path.rCubicTo(x1, y1, x2, y2, x3, y3); | 240 path.rCubicTo(x1, y1, x2, y2, x3, y3); |
239 break; | 241 break; |
240 } | 242 } |
241 | 243 |
244 case CUBIC_TO_SHORTHAND: { | |
245 // Compute the first control point (|x1| and |y1|) as the reflection | |
246 // of the second control point on the previous command relative to | |
247 // the current point. If there is no previous command or if the | |
248 // previous command is not a cubic Bezier curve, the first control | |
249 // point is coincident with the current point. Refer to the SVG | |
250 // path specs for further details. | |
251 SkPoint last_point; | |
252 path.getLastPt(&last_point); | |
253 SkScalar delta_x = 0; | |
254 SkScalar delta_y = 0; | |
255 if (previous_command_type == CUBIC_TO || | |
Evan Stade
2016/09/07 16:34:22
it seems there's no easy way to get the last verb
| |
256 previous_command_type == R_CUBIC_TO || | |
257 previous_command_type == CUBIC_TO_SHORTHAND) { | |
258 SkPoint last_control_point = path.getPoint(path.countPoints() - 2); | |
259 delta_x = last_point.fX - last_control_point.fX; | |
260 delta_y = last_point.fY - last_control_point.fY; | |
261 } | |
262 | |
263 SkScalar x1 = last_point.fX + delta_x; | |
264 SkScalar y1 = last_point.fY + delta_y; | |
265 SkScalar x2 = path_elements[++i].arg; | |
266 SkScalar y2 = path_elements[++i].arg; | |
267 SkScalar x3 = path_elements[++i].arg; | |
268 SkScalar y3 = path_elements[++i].arg; | |
269 path.cubicTo(x1, y1, x2, y2, x3, y3); | |
270 break; | |
271 } | |
272 | |
242 case CIRCLE: { | 273 case CIRCLE: { |
243 SkScalar x = path_elements[++i].arg; | 274 SkScalar x = path_elements[++i].arg; |
244 SkScalar y = path_elements[++i].arg; | 275 SkScalar y = path_elements[++i].arg; |
245 SkScalar r = path_elements[++i].arg; | 276 SkScalar r = path_elements[++i].arg; |
246 path.addCircle(x, y, r); | 277 path.addCircle(x, y, r); |
247 break; | 278 break; |
248 } | 279 } |
249 | 280 |
250 case ROUND_RECT: { | 281 case ROUND_RECT: { |
251 SkScalar x = path_elements[++i].arg; | 282 SkScalar x = path_elements[++i].arg; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 | 315 |
285 case FLIPS_IN_RTL: { | 316 case FLIPS_IN_RTL: { |
286 flips_in_rtl = true; | 317 flips_in_rtl = true; |
287 break; | 318 break; |
288 } | 319 } |
289 | 320 |
290 case END: | 321 case END: |
291 NOTREACHED(); | 322 NOTREACHED(); |
292 break; | 323 break; |
293 } | 324 } |
325 | |
326 previous_command_type = command_type; | |
294 } | 327 } |
295 | 328 |
296 gfx::ScopedRTLFlipCanvas scoped_rtl_flip_canvas(canvas, canvas_size, | 329 gfx::ScopedRTLFlipCanvas scoped_rtl_flip_canvas(canvas, canvas_size, |
297 flips_in_rtl); | 330 flips_in_rtl); |
298 | 331 |
299 if (dip_size != canvas_size) { | 332 if (dip_size != canvas_size) { |
300 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(canvas_size); | 333 SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(canvas_size); |
301 canvas->sk_canvas()->scale(scale, scale); | 334 canvas->sk_canvas()->scale(scale, scale); |
302 } | 335 } |
303 | 336 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 } | 594 } |
562 | 595 |
563 ImageSkia CreateVectorIconFromSource(const std::string& source, | 596 ImageSkia CreateVectorIconFromSource(const std::string& source, |
564 int dip_size, | 597 int dip_size, |
565 SkColor color) { | 598 SkColor color) { |
566 return ImageSkia(new VectorIconSourceLegacy(source, dip_size, color), | 599 return ImageSkia(new VectorIconSourceLegacy(source, dip_size, color), |
567 gfx::Size(dip_size, dip_size)); | 600 gfx::Size(dip_size, dip_size)); |
568 } | 601 } |
569 | 602 |
570 } // namespace gfx | 603 } // namespace gfx |
OLD | NEW |