OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 bool isVerticalLine = (p1.x() == p2.x()); | 497 bool isVerticalLine = (p1.x() == p2.x()); |
498 int width = roundf(strokeThickness()); | 498 int width = roundf(strokeThickness()); |
499 | 499 |
500 // We know these are vertical or horizontal lines, so the length will just | 500 // We know these are vertical or horizontal lines, so the length will just |
501 // be the sum of the displacement component vectors give or take 1 - | 501 // be the sum of the displacement component vectors give or take 1 - |
502 // probably worth the speed up of no square root, which also won't be exact. | 502 // probably worth the speed up of no square root, which also won't be exact. |
503 FloatSize disp = p2 - p1; | 503 FloatSize disp = p2 - p1; |
504 int length = SkScalarRoundToInt(disp.width() + disp.height()); | 504 int length = SkScalarRoundToInt(disp.width() + disp.height()); |
505 PaintFlags flags(immutableState()->strokeFlags(length)); | 505 PaintFlags flags(immutableState()->strokeFlags(length)); |
506 | 506 |
507 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) { | 507 if (getStrokeStyle() == DashedStroke || |
508 (getStrokeStyle() == DottedStroke && width <= 3)) { | |
f(malita)
2017/03/03 15:34:08
Same question about 3.
| |
508 // Do a rect fill of our endpoints. This ensures we always have the | 509 // Do a rect fill of our endpoints. This ensures we always have the |
509 // appearance of being a border. We then draw the actual dotted/dashed | 510 // appearance of being a border. We then draw the actual dotted/dashed |
510 // line. | 511 // line. |
511 SkRect r1, r2; | 512 SkRect r1, r2; |
512 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); | 513 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); |
513 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); | 514 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); |
514 | 515 |
515 if (isVerticalLine) { | 516 if (isVerticalLine) { |
516 r1.offset(-width / 2, 0); | 517 r1.offset(-width / 2, 0); |
517 r2.offset(-width / 2, -width); | 518 r2.offset(-width / 2, -width); |
518 } else { | 519 } else { |
519 r1.offset(0, -width / 2); | 520 r1.offset(0, -width / 2); |
520 r2.offset(-width, -width / 2); | 521 r2.offset(-width, -width / 2); |
521 } | 522 } |
522 PaintFlags fillFlags; | 523 PaintFlags fillFlags; |
523 fillFlags.setColor(flags.getColor()); | 524 fillFlags.setColor(flags.getColor()); |
524 drawRect(r1, fillFlags); | 525 drawRect(r1, fillFlags); |
525 drawRect(r2, fillFlags); | 526 drawRect(r2, fillFlags); |
527 } else if (getStrokeStyle() == DottedStroke) { | |
528 // We draw thick dotted lines with 0 length dash strokes and round endcaps, | |
529 // producing circles. The endcaps extend beyond the line's endpoints, | |
530 // so move the start and end in. | |
531 if (isVerticalLine) { | |
532 p1.setY(p1.y() + width / 2.f); | |
533 p2.setY(p2.y() - width / 2.f); | |
534 } else { | |
535 p1.setX(p1.x() + width / 2.f); | |
536 p2.setX(p2.x() - width / 2.f); | |
537 } | |
526 } | 538 } |
527 | 539 |
528 adjustLineToPixelBoundaries(p1, p2, width, penStyle); | 540 adjustLineToPixelBoundaries(p1, p2, width, penStyle); |
529 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), flags); | 541 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), flags); |
530 } | 542 } |
531 | 543 |
532 namespace { | 544 namespace { |
533 | 545 |
534 #if !OS(MACOSX) | 546 #if !OS(MACOSX) |
535 | 547 |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1294 | 1306 |
1295 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, | 1307 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, |
1296 FloatPoint& p2, | 1308 FloatPoint& p2, |
1297 float strokeWidth, | 1309 float strokeWidth, |
1298 StrokeStyle penStyle) { | 1310 StrokeStyle penStyle) { |
1299 // For odd widths, we add in 0.5 to the appropriate x/y so that the float | 1311 // For odd widths, we add in 0.5 to the appropriate x/y so that the float |
1300 // arithmetic works out. For example, with a border width of 3, WebKit will | 1312 // arithmetic works out. For example, with a border width of 3, WebKit will |
1301 // pass us (y1+y2)/2, e.g., (50+53)/2 = 103/2 = 51 when we want 51.5. It is | 1313 // pass us (y1+y2)/2, e.g., (50+53)/2 = 103/2 = 51 when we want 51.5. It is |
1302 // always true that an even width gave us a perfect position, but an odd width | 1314 // always true that an even width gave us a perfect position, but an odd width |
1303 // gave us a position that is off by exactly 0.5. | 1315 // gave us a position that is off by exactly 0.5. |
1304 if (penStyle == DottedStroke || penStyle == DashedStroke) { | 1316 if (penStyle == DashedStroke || |
1317 (penStyle == DottedStroke && strokeWidth <= 3)) { | |
f(malita)
2017/03/03 15:34:08
Same. Let's at least add a helper to encapsulate
Stephen Chennney
2017/03/03 22:19:23
Helper done.
| |
1305 if (p1.x() == p2.x()) { | 1318 if (p1.x() == p2.x()) { |
1306 p1.setY(p1.y() + strokeWidth); | 1319 p1.setY(p1.y() + strokeWidth); |
1307 p2.setY(p2.y() - strokeWidth); | 1320 p2.setY(p2.y() - strokeWidth); |
1308 } else { | 1321 } else { |
1309 p1.setX(p1.x() + strokeWidth); | 1322 p1.setX(p1.x() + strokeWidth); |
1310 p2.setX(p2.x() - strokeWidth); | 1323 p2.setX(p2.x() - strokeWidth); |
1311 } | 1324 } |
1312 } | 1325 } |
1313 | 1326 |
1314 if (static_cast<int>(strokeWidth) % 2) { // odd | 1327 if (static_cast<int>(strokeWidth) % 2) { // odd |
(...skipping 24 matching lines...) Expand all Loading... | |
1339 break; | 1352 break; |
1340 default: | 1353 default: |
1341 NOTREACHED(); | 1354 NOTREACHED(); |
1342 break; | 1355 break; |
1343 } | 1356 } |
1344 | 1357 |
1345 return nullptr; | 1358 return nullptr; |
1346 } | 1359 } |
1347 | 1360 |
1348 } // namespace blink | 1361 } // namespace blink |
OLD | NEW |