Sets the global fill color. >>> from pagebot.toolbox.color import color >>> from pagebot import getContext >>> context = getContext() >>> context.newPage(420, 420) >>> context.fill(color(0.5)) # Same as setFillColor >>> context.fill(color('red'))
(self, c)
| 532 | return self.b.blendMode(operation) |
| 533 | |
| 534 | def fill(self, c): |
| 535 | """Sets the global fill color. |
| 536 | |
| 537 | >>> from pagebot.toolbox.color import color |
| 538 | >>> from pagebot import getContext |
| 539 | >>> context = getContext() |
| 540 | >>> context.newPage(420, 420) |
| 541 | >>> context.fill(color(0.5)) # Same as setFillColor |
| 542 | >>> context.fill(color('red')) |
| 543 | >>> context.fill(inheritColor) |
| 544 | >>> context.fill(noColor) |
| 545 | >>> context.fill(0.5) |
| 546 | """ |
| 547 | if c is None: |
| 548 | c = noColor |
| 549 | elif isinstance(c, (tuple, list)): |
| 550 | c = color(*c) |
| 551 | elif isinstance(c, (int, float)): |
| 552 | c = color(c) |
| 553 | |
| 554 | msg = 'BaseContext.fill: %s should be of type Color' |
| 555 | assert isinstance(c, Color), (msg % c) |
| 556 | |
| 557 | if c is inheritColor: |
| 558 | # Keep color setting as it is. |
| 559 | pass |
| 560 | elif c is noColor: |
| 561 | self.b.fill(None) # Set color to no-color |
| 562 | elif c.isCmyk: |
| 563 | # DrawBot.fill has slight API differences compared to |
| 564 | # FormattedString fill(). |
| 565 | c_, m_, y_, k_ = c.cmyk |
| 566 | self.b.cmykFill(c_, m_, y_, k_, alpha=c.a) |
| 567 | else: |
| 568 | # DrawBot.fill has slight API differences compared to |
| 569 | # FormattedString fill(). Convert to RGB, whatever the color type. |
| 570 | r, g, b = c.rgb |
| 571 | self.b.fill(r, g, b, alpha=c.a) |
| 572 | |
| 573 | setFillColor = fill |
| 574 |