Draw 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)
| 932 | x += cw + gx |
| 933 | |
| 934 | def drawBaselines(self, e, origin, background=False): |
| 935 | """Draw baseline grid if self.showBaselineGrid is True and there is a |
| 936 | baseline defined > 0. Use the color from style values viewGridStrokeX |
| 937 | and viewGridStrokeWidthX to make a difference with the baselines drawn |
| 938 | by Text with style values baselineColor and baselineWidth. |
| 939 | |
| 940 | In this method is called by an element, instead of self, the show |
| 941 | attribute is a way to overwrite the setting of self.showBaselineGrid |
| 942 | |
| 943 | NOTE: Text elements have their own baseline drawing method. |
| 944 | |
| 945 | >>> from pagebot import getContext |
| 946 | >>> context = getContext() |
| 947 | >>> from pagebot.elements.element import Element |
| 948 | >>> from pagebot.style import getRootStyle |
| 949 | >>> from pagebot.document import Document |
| 950 | >>> style = getRootStyle() # Get default values |
| 951 | >>> e = Element(style=style) # Works on generic elements as well as pages. |
| 952 | >>> doc = Document(name='TestDoc', startPage=50, autoPages=100, context=context) |
| 953 | >>> pages = doc.pages |
| 954 | >>> len(pages) |
| 955 | 100 |
| 956 | >>> page = doc[50] |
| 957 | >>> page |
| 958 | <Page #50 default (1000pt, 1000pt)> |
| 959 | >>> view = doc.view |
| 960 | >>> view = PageView(context=context, style=style) |
| 961 | >>> view.showBaselineGrid = [BASE_LINE, BASE_INDEX_LEFT, BASE_Y_LEFT] |
| 962 | >>> #view.drawBaselines(e, pt(0, 0)) |
| 963 | >>> doc.build() |
| 964 | """ |
| 965 | show = e.showBaselineGrid or self.showBaselineGrid |
| 966 | |
| 967 | # Sets the default, in case not drawing or show is True. |
| 968 | if not show: |
| 969 | return |
| 970 | |
| 971 | context = self.context |
| 972 | p = pointOffset(e.origin, origin) |
| 973 | p = self._applyScale(e, p) |
| 974 | |
| 975 | # Ignore z-axis for now. |
| 976 | px, py, _ = e._applyAlignment(p) |
| 977 | |
| 978 | # Get the baseline grid of this element. |
| 979 | baselineGrid = e.baselineGrid |
| 980 | |
| 981 | # Index size depends on baseline. |
| 982 | indexFontSize = max(9, min(16, baselineGrid*0.5)) |
| 983 | |
| 984 | # Gutter between index marker and element padding |
| 985 | indexGutter = baselineGrid/4 |
| 986 | |
| 987 | # Collect all baseline positions on e. |
| 988 | baselineYs = [] |
| 989 | |
| 990 | # Page origin is at the bottom. |
| 991 | startY = e.h - (e.baselineGridStart or e.pt) |
no test coverage detected