Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44183e1

Browse files
Merging examples and adding some color.
1 parent a1eb7cd commit 44183e1

5 files changed

Lines changed: 36 additions & 88 deletions

File tree

Basics/E01_Basics/E06_Elements.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717
# Test handling of pages in a document.
1818
#
19+
1920
from pagebot.contexts import getContext
2021
from pagebot.document import Document
2122
from pagebot.elements import *
@@ -28,11 +29,21 @@
2829
from pagebot.toolbox.transformer import path2FileName
2930
from 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.
3233
W, H = pt(800), pt(600)
3334
FILENAME = path2FileName(__file__)
3435
fontName = 'PageBot-Regular'
3536
SQ = 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

3748
def 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+
113126
for contextName in ('DrawBot', 'Flat'):
114127
draw(contextName)

Basics/E01_Basics/E07_BezierCurve.py

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
# Supporting Flat, xxyxyz.org/flat
1313
# -----------------------------------------------------------------------------
1414
#
15-
# E08_ExportOptions.py
15+
# E07_ExportOptions.py
1616
#
1717
# Shows how to start a document and export it to PNG and
1818
# PDF in the simplest steps.
1919
#
2020
# TODO: Floating on second line does not seem to work currently
21+
2122
from pagebot import getContext
2223
from pagebot.constants import EXPORT
2324
from pagebot.document import Document
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
# Supporting Flat, xxyxyz.org/flat
1313
# -----------------------------------------------------------------------------
1414
#
15-
# E09_Pages.py
15+
# E08_Pages.py
1616
#
1717
# Test handling of pages in a document.
1818
#
19+
1920
from pagebot.contexts import getContext
2021
from pagebot.document import Document
2122
from pagebot.elements import *

Basics/E01_Basics/_RunAll.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828
import E04_Units
2929
import E05_Fonts
3030
import E06_Elements
31-
import E07_BezierPath
32-
import E08_ExportOptions
33-
import E09_Pages
31+
import E07_ExportOptions
32+
import E08_Pages

0 commit comments

Comments
 (0)