Draws baseline grid if self.showBaselineGrid is True and there is a baseline defined > 0. Use the color from style values viewGridStrokeX and viewGridStrokeWidthX to make a difference with the baselines drawn by Text with style values baselineColor and baselineWidth.
(self, e, origin, background=False)
| 713 | x += cw + gx |
| 714 | |
| 715 | def drawBaselines(self, e, origin, background=False): |
| 716 | """Draws baseline grid if self.showBaselineGrid is True and there is a |
| 717 | baseline defined > 0. Use the color from style values viewGridStrokeX |
| 718 | and viewGridStrokeWidthX to make a difference with the baselines drawn |
| 719 | by Text with style values baselineColor and baselineWidth. |
| 720 | |
| 721 | If this method is called by an element instead of self, the show |
| 722 | attribute is a way to overwrite the setting of self.showBaselineGrid. |
| 723 | |
| 724 | >>> from pagebot import getContext |
| 725 | >>> context = getContext() |
| 726 | >>> from pagebot.elements.element import Element |
| 727 | >>> from pagebot.style import getRootStyle |
| 728 | >>> from pagebot.elements.views.pageview import PageView |
| 729 | >>> style = getRootStyle() # Get default values |
| 730 | >>> #style['font'] = 'PageBot-Regular' |
| 731 | >>> #style = dict(font='PageBot-Regular', baselineGrid=1) |
| 732 | >>> e = Element(style=style) # Works on generic elements as well as pages. |
| 733 | >>> view = PageView(context=context, style=style) |
| 734 | >>> view.showBaselineGrid = [BASE_LINE, BASE_INDEX_LEFT, BASE_Y_LEFT] |
| 735 | >>> view.drawBaselines(e, pt(0, 0)) |
| 736 | """ |
| 737 | show = e.showBaselineGrid or self.showBaselineGrid |
| 738 | |
| 739 | # Sets the default, in case not drawing or show is True |
| 740 | if not show: |
| 741 | return |
| 742 | |
| 743 | p = pointOffset(e.origin, origin) |
| 744 | p = self._applyScale(e, p) |
| 745 | # Ignore z-axis for now. |
| 746 | px, py, _ = e._applyAlignment(p) |
| 747 | |
| 748 | # Get the baseline grid of this element. |
| 749 | baselineGrid = e.baselineGrid |
| 750 | # Index size depends on baseline. |
| 751 | indexFontSize = max(9, min(16, baselineGrid*0.5)) |
| 752 | # Gutter between index marker and element padding. |
| 753 | indexGutter = baselineGrid/4 |
| 754 | |
| 755 | startY = e.baselineGridStart |
| 756 | if startY is None: |
| 757 | # Otherwise use the top padding as start Y. |
| 758 | startY = e.pt |
| 759 | |
| 760 | # Assumes origin at bottom for self.context drawing. |
| 761 | oy = e.h - startY |
| 762 | |
| 763 | line = 0 # Line index |
| 764 | baselineColor = e.css('baselineColor', color(0,7)) |
| 765 | baselineWidth = e.css('baselineWidth', 0.5) |
| 766 | |
| 767 | # Format of line numbers. |
| 768 | style = dict(font=e.css('viewMarkerFont'), xTextAlign=RIGHT, |
| 769 | fontSize=indexFontSize, stroke=noColor, textFill=baselineColor) |
| 770 | self.context.fill(noColor) |
| 771 | self.context.stroke(baselineColor, baselineWidth) |
| 772 |
no test coverage detected