Set the color for global or the color of the formatted string. >>> from pagebot.toolbox.color import color >>> from pagebot import getContext >>> context = getContext() >>> context.newPage(420, 420) >>> context.stroke(color(0.5)) # Same as setStrokeColor
(self, c, w=0.5)
| 573 | setFillColor = fill |
| 574 | |
| 575 | def stroke(self, c, w=0.5): |
| 576 | """Set the color for global or the color of the formatted string. |
| 577 | |
| 578 | >>> from pagebot.toolbox.color import color |
| 579 | >>> from pagebot import getContext |
| 580 | >>> context = getContext() |
| 581 | >>> context.newPage(420, 420) |
| 582 | >>> context.stroke(color(0.5)) # Same as setStrokeColor |
| 583 | >>> context.stroke(color('red')) |
| 584 | >>> context.stroke(inheritColor) |
| 585 | >>> context.stroke(noColor) |
| 586 | >>> context.stroke(0.5) |
| 587 | """ |
| 588 | if c is None: |
| 589 | c = noColor |
| 590 | elif isinstance(c, (tuple, list)): |
| 591 | c = color(*c) |
| 592 | elif isinstance(c, (int, float)): |
| 593 | c = color(c) |
| 594 | |
| 595 | msg = 'BaseContext.stroke: %s should be of type Color' |
| 596 | assert isinstance(c, Color), (msg % c) |
| 597 | |
| 598 | if c is inheritColor: |
| 599 | # Keep color setting as it is. |
| 600 | pass |
| 601 | |
| 602 | if c is noColor: |
| 603 | self.b.stroke(None) # Set color to no-color |
| 604 | elif c.isCmyk: |
| 605 | # DrawBot.stroke has slight API differences compared to |
| 606 | # FormattedString stroke(). |
| 607 | cc, cm, cy, ck = c.cmyk |
| 608 | self.b.cmykStroke(cc, cm, cy, ck, alpha=c.a) |
| 609 | else: |
| 610 | # DrawBot.stroke has slight API differences compared to |
| 611 | # FormattedString stroke(). Convert to RGB, whatever the color type. |
| 612 | r, g, b = c.rgb |
| 613 | self.b.stroke(r, g, b, alpha=c.a) |
| 614 | |
| 615 | if w is not None: |
| 616 | self.strokeWidth(w) |
| 617 | |
| 618 | setStrokeColor = stroke |
| 619 |
no test coverage detected