MCPcopy Create free account
hub / github.com/PageBot/PageBot / drawBaselines

Method drawBaselines

Lib/pagebot/elements/views/pageview.py:934–1064  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 2

drawPageMetaInfoMethod · 0.95

Calls 12

pointOffsetFunction · 0.90
_applyScaleMethod · 0.80
_applyAlignmentMethod · 0.80
newStringMethod · 0.80
appendMethod · 0.45
getMethod · 0.45
cssMethod · 0.45
fillMethod · 0.45
strokeMethod · 0.45
textBoxMethod · 0.45
lineMethod · 0.45
rectMethod · 0.45

Tested by

no test coverage detected