Chromium Code Reviews| 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_S); | |
| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 SkScalar y = path_elements[++i].arg; | 217 SkScalar y = path_elements[++i].arg; |
| 216 path.rLineTo(0, y); | 218 path.rLineTo(0, y); |
| 217 break; | 219 break; |
| 218 } | 220 } |
| 219 | 221 |
| 220 case CUBIC_TO: { | 222 case CUBIC_TO: { |
| 221 SkScalar x1 = path_elements[++i].arg; | 223 SkScalar x1 = path_elements[++i].arg; |
| 222 SkScalar y1 = path_elements[++i].arg; | 224 SkScalar y1 = path_elements[++i].arg; |
| 223 SkScalar x2 = path_elements[++i].arg; | 225 SkScalar x2 = path_elements[++i].arg; |
| 224 SkScalar y2 = path_elements[++i].arg; | 226 SkScalar y2 = path_elements[++i].arg; |
| 225 SkScalar x3 = path_elements[++i].arg; | 227 SkScalar x = path_elements[++i].arg; |
|
Evan Stade
2016/09/01 20:21:22
why the name change?
tdanderson
2016/09/01 20:45:00
For naming consistency with the SVG spec.
Evan Stade
2016/09/01 20:53:22
that was not my goal in choosing these variable na
tdanderson
2016/09/02 16:40:49
OK, I'll change them back.
| |
| 226 SkScalar y3 = path_elements[++i].arg; | 228 SkScalar y = path_elements[++i].arg; |
| 227 path.cubicTo(x1, y1, x2, y2, x3, y3); | 229 path.cubicTo(x1, y1, x2, y2, x, y); |
| 228 break; | 230 break; |
| 229 } | 231 } |
| 230 | 232 |
| 231 case R_CUBIC_TO: { | 233 case R_CUBIC_TO: { |
| 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 x = path_elements[++i].arg; |
| 237 SkScalar y3 = path_elements[++i].arg; | 239 SkScalar y = path_elements[++i].arg; |
| 238 path.rCubicTo(x1, y1, x2, y2, x3, y3); | 240 path.rCubicTo(x1, y1, x2, y2, x, y); |
| 239 break; | 241 break; |
| 240 } | 242 } |
| 241 | 243 |
| 244 case CUBIC_TO_S: { | |
|
Evan Stade
2016/09/01 20:21:22
we don't want/need an R_ version?
tdanderson
2016/09/01 20:45:00
That case is handled in the skiafy script.
Evan Stade
2016/09/01 20:53:22
ok. Could you name it SHORTHAND_CUBIC_TO or someth
tdanderson
2016/09/02 16:40:49
Done.
| |
| 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 SkScalar delta_x = 0; | |
| 252 SkScalar delta_y = 0; | |
| 253 if (previous_command_type == CUBIC_TO || | |
| 254 previous_command_type == R_CUBIC_TO || | |
| 255 previous_command_type == CUBIC_TO_S) { | |
| 256 delta_x = path_elements[i - 2].arg - path_elements[i - 4].arg; | |
|
Evan Stade
2016/09/01 20:21:22
this makes me a little uncomfortable. Can we use S
tdanderson
2016/09/01 20:45:00
What worries you about this? Even if getPoint() is
Evan Stade
2016/09/01 20:53:22
I dunno, I just dislike negative signs in an array
tdanderson
2016/09/02 16:40:49
Sorry, it looks like I was mistaken. Changed in th
| |
| 257 delta_y = path_elements[i - 1].arg - path_elements[i - 3].arg; | |
| 258 } | |
| 259 | |
| 260 SkPoint last_point; | |
| 261 path.getLastPt(&last_point); | |
| 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 x = path_elements[++i].arg; | |
| 268 SkScalar y = path_elements[++i].arg; | |
| 269 path.cubicTo(x1, y1, x2, y2, x, y); | |
| 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 |