1616#
1717# Test handling of pages in a document.
1818#
19+
1920from pagebot .contexts import getContext
2021from pagebot .document import Document
2122from pagebot .elements import *
2829from pagebot .toolbox .transformer import path2FileName
2930from pagebot .toolbox .loremipsum import loremIpsum
3031
31- # Template for the export path, allowing to include context name
32+ # Template for the export path, allowing to include context name.
3233W , H = pt (800 ), pt (600 )
3334FILENAME = path2FileName (__file__ )
3435fontName = 'PageBot-Regular'
3536SQ = 50
37+ """Types of elements: rectangle, circle, text, polygon, curve, glyph."""
38+ N = 6
39+ F = 1.0 / N
40+
41+ def getColor (i ):
42+ r = F
43+ g = 1
44+ b = F / 2
45+ f = (i * r , i * g , i * b )
46+ return f
3647
3748def draw (contextName ):
3849 exportPath = '%s/%s-%s.pdf' % (EXPORT , FILENAME , contextName )
@@ -47,24 +58,27 @@ def draw(contextName):
4758 txt = loremIpsum (doShuffle = True )
4859 bs = context .newString (txt , dict (font = fontName , fontSize = pt (24 )))
4960
61+ # TODO: findFont instead.
62+ fontPath = getTestFontsPath () + '/google/roboto/Roboto-Medium.ttf'
63+ font = Font (fontPath )
64+
65+ '''Positions the elements to the top left of the page area. Notice that the
66+ (x, y) position is undefined, default is (0, 0), since it will be
67+ determined by the condition. Size measures can be any type of units. Their
68+ type is shown in the measured output.'''
5069 conditions = (Right2Right (), Float2Top (), Float2Left (), )
51- f = color (0.8 )
5270
53- '''Position rectangle in the center of the page area. Notice that the (x, y)
54- position is undefined, default is (0, 0), since will be filled by the
55- condition. Size measures can be any type of units. Their type is shown in
56- the measured output.'''
5771 options = dict (parent = page , showOrigin = True , showDimensions = True ,
5872 showElementInfo = True , showFlowConnections = True ,
59- conditions = conditions , fill = f , stroke = 0 , strokeWidth = 0.5 )
60-
61- rectangle = newRect (name = 'rect' , r = SQ ,** options )
62- textBox = newText (bs , name = 'text' , w = 2 * SQ , h = 2 * SQ , ** options )
63- newCircle (name = 'circle' , r = SQ , ** options )
73+ conditions = conditions , stroke = 0 , strokeWidth = 0.5 )
6474
75+ newRect (name = 'rect' , r = SQ , fill = getColor (1 ), ** options )
76+ newText (bs , name = 'text' , w = 2 * SQ , h = 2 * SQ , fill = getColor (2 ), ** options )
77+ newCircle (name = 'circle' , r = SQ , fill = getColor (3 ), ** options )
6578 points = [(0 , 0 ), (20 , 100 ), (40 , 0 ), (60 , 100 ), (80 , 0 ), (100 , 100 )]
66- newPolygon (name = 'polygon' , points = points , ** options )
79+ newPolygon (name = 'polygon' , points = points , fill = getColor ( 4 ), ** options )
6780
81+ # Bézier curve points.
6882 points = [(0 , 0 ),
6983 ((- 6.722045442950497 , 11.097045442950499 ), (- 4.847045442950498 ,
7084 12.972045442950499 ), (6.250000000000001 , 6.25 )),
@@ -99,16 +113,15 @@ def draw(contextName):
99113 ((104.84704544295052 , 87.0279545570495 ), (106.72204544295052 ,
100114 88.9029545570495 ), (100.00000000000001 , 100.0 )),
101115 ]
102- curve = newBezierCurve (closed = False , points = points , ** options )
103-
104- fontPath = getTestFontsPath () + '/google/roboto/Roboto-Medium.ttf'
105- font = Font (fontPath )
106- e = newGlyphPath (font ['Q' ], ** options )
107116
117+ newBezierCurve (closed = False , points = points , fill = getColor (5 ), ** options )
118+ newGlyphPath (font ['Q' ], fill = getColor (6 ), ** options )
108119 page .solve ()
109120
110121 # Export in _export folder that does not commit in Git. Force to export PDF.
111122 doc .export (exportPath )
112123
124+
125+
113126for contextName in ('DrawBot' , 'Flat' ):
114127 draw (contextName )
0 commit comments