docs/userguide/ch2_graphics.py
author andy_robinson
Mon, 10 Jul 2000 14:20:15 +0000
changeset 341 27c68d524504
child 347 35eda3272102
permissions -rw-r--r--
Broke up the user guide into chapters.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     1
#ch2_graphics
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     2
from genuserguide import *
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     3
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     4
heading1("Graphics and Text with $pdfgen$")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     5
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     6
heading2("Basic Concepts")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     7
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     8
The $pdfgen$ package is the lowest level interface for
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
     9
generating PDF documents.  A $pdfgen$ program is essentially
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    10
a sequence of instructions for "painting" a document onto
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    11
a sequence of pages.  The interface object which provides the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    12
painting operations is the $pdfgen canvas$.  
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    13
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    14
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    15
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    16
The canvas should be thought of as a sheet of white paper
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    17
with points on the sheet identified using Cartesian ^(X,Y)^ coordinates
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    18
which by default have the ^(0,0)^ origin point at the lower
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    19
left corner of the page.  Furthermore the first coordinate ^x^
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    20
goes to the right and the second coordinate ^y^ goes up, by
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    21
default.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    22
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    23
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    24
A simple example
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    25
program that uses a canvas follows.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    26
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    27
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    28
eg("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    29
    from reportlab.pdfgen import canvas
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    30
    c = canvas.Canvas("hello.pdf")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    31
    hello(c)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    32
    c.showPage()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    33
    c.save()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    34
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    35
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    36
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    37
The above code creates a $canvas$ object which will generate
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    38
a PDF file named $hello.pdf$ in the current working directory.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    39
It then calls the $hello$ function passing the $canvas$ as an argument.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    40
Finally the $showPage$ method saves the current page of the canvas
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    41
and the $save$ method stores the file and closes the canvas.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    42
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    43
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    44
The $showPage$ method causes the $canvas$ to stop drawing on the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    45
current page and any further operations will draw on a subsequent
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    46
page (if there are any further operations -- if not no
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    47
new page is created).  The $save$ method must be called after the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    48
construction of the document is complete -- it generates the PDF
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    49
document, which is the whole purpose of the $canvas$ object.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    50
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    51
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    52
heading2("More about the Canvas")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    53
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    54
Before describing the drawing operations, we will digress to cover
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    55
some of the things which can be done to configure a canvas.  There
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    56
are many different settings available.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    57
todo("""Cover all constructor arguments, and setAuthor etc.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    58
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    59
heading2("Drawing Operations")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    60
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    61
Suppose the $hello$ function referenced above is implemented as
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    62
follows (we will not explain each of the operations in detail
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    63
yet).
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    64
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    65
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    66
eg(examples.testhello)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    67
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    68
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    69
Examining this code notice that there are essentially two types
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    70
of operations performed using a canvas.  The first type draws something
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    71
on the page such as a text string or a rectangle or a line.  The second
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    72
type changes the state of the canvas such as
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    73
changing the current fill or stroke color or changing the current font
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    74
type and size.  
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    75
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    76
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    77
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    78
If we imagine the program as a painter working on
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    79
the canvas the "draw" operations apply paint to the canvas using
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    80
the current set of tools (colors, line styles, fonts, etcetera)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    81
and the "state change" operations change one of the current tools
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    82
(changing the fill color from whatever it was to blue, or changing
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    83
the current font to $Times-Roman$ in 15 points, for example).
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    84
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    85
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    86
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    87
The document generated by the "hello world" program listed above would contain
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    88
the following graphics.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    89
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    90
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    91
illust(examples.hello, '"Hello World" in pdfgen')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    92
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    93
heading3("About the demos in this document")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    94
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    95
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    96
This document contains demonstrations of the code discussed like the one shown
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    97
in the rectangle above.  These demos are drawn on a "tiny page" embedded
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    98
within the real pages of the guide.  The tiny pages are %s inches wide
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
    99
and %s inches tall. The demo displays show the actual output of the demo code.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   100
""" % (examplefunctionxinches, examplefunctionyinches))
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   101
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   102
heading2('The tools: the "draw" operations')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   103
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   104
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   105
This section briefly lists the tools available to the program
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   106
for painting information onto a page using the canvas interface.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   107
These will be discussed in detail in later sections.  They are listed
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   108
here for easy reference and for summary purposes.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   109
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   110
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   111
heading3("Line methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   112
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   113
eg("""canvas.line(x1,y1,x2,y2)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   114
eg("""canvas.lines(linelist)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   115
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   116
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   117
The line methods draw straight line segments on the canvas.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   118
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   119
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   120
heading3("Shape methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   121
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   122
eg("""canvas.grid(xlist, ylist) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   123
eg("""canvas.bezier(x1, y1, x2, y2, x3, y3, x4, y4)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   124
eg("""canvas.arc(x1,y1,x2,y2) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   125
eg("""canvas.rect(x, y, width, height, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   126
eg("""canvas.ellipse(x, y, width, height, stroke=1, fill=0)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   127
eg("""canvas.wedge(x1,y1, x2,y2, startAng, extent, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   128
eg("""canvas.circle(x_cen, y_cen, r, stroke=1, fill=0)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   129
eg("""canvas.roundRect(x, y, width, height, radius, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   130
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   131
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   132
The shape methods draw common complex shapes on the canvas.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   133
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   134
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   135
heading3("String drawing methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   136
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   137
eg("""canvas.drawString(x, y, text):""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   138
eg("""canvas.drawRightString(x, y, text) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   139
eg("""canvas.drawCentredString(x, y, text)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   140
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   141
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   142
The draw string methods draw single lines of text on the canvas.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   143
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   144
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   145
heading3("The text object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   146
eg("""textobject = canvas.beginText(x, y) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   147
eg("""canvas.drawText(textobject) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   148
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   149
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   150
Text objects are used to format text in ways that
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   151
are not supported directly by the canvas interface.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   152
A program creates a text object from the canvas using beginText
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   153
and then formats text by invoking textobject methods.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   154
Finally the textobject is drawn onto the canvas using
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   155
drawText.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   156
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   157
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   158
heading3("The path object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   159
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   160
eg("""path = canvas.beginPath() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   161
eg("""canvas.drawPath(path, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   162
eg("""canvas.clipPath(path, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   163
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   164
heading3("Image methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   165
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   166
eg("""canvas.drawInlineImage(self, image, x,y, width=None,height=None) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   167
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   168
heading3("Ending a page")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   169
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   170
eg("""canvas.showPage()""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   171
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   172
disc("""The showPage method finishes the current page.  All additional drawing will
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   173
be done on another page.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   174
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   175
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   176
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   177
disc("""Warning!  All state changes (font changes, color settings, geometry transforms, etcetera)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   178
are FORGOTTEN when you advance to a new page in $pdfgen$.  Any state settings you wish to preserve
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   179
must be set up again before the program proceeds with drawing!""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   180
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   181
heading2('The toolbox: the "state change" operations')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   182
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   183
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   184
This section briefly lists the ways to switch the tools used by the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   185
program
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   186
for painting information onto a page using the canvas interface.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   187
These too will be discussed in detail in later sections.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   188
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   189
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   190
heading3("Changing Colors")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   191
eg("""canvas.setFillColorCMYK(c, m, y, k) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   192
eg("""canvas.setStrikeColorCMYK(c, m, y, k) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   193
eg("""canvas.setFillColorRGB(r, g, b) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   194
eg("""canvas.setStrokeColorRGB(r, g, b) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   195
eg("""canvas.setFillColor(acolor) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   196
eg("""canvas.setStrokeColor(acolor) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   197
eg("""canvas.setFillGray(gray) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   198
eg("""canvas.setStrokeGray(gray) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   199
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   200
heading3("Changing Fonts")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   201
eg("""canvas.setFont(psfontname, size, leading = None) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   202
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   203
heading3("Changing Graphical Styles")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   204
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   205
eg("""canvas.setLineWidth(width) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   206
eg("""canvas.setLineCap(mode) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   207
eg("""canvas.setLineJoin(mode) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   208
eg("""canvas.setMiterLimit(limit) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   209
eg("""canvas.setDash(self, array=[], phase=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   210
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   211
heading3("Changing Geometry")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   212
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   213
eg("""canvas.setPageSize(pair) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   214
eg("""canvas.transform(a,b,c,d,e,f): """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   215
eg("""canvas.translate(dx, dy) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   216
eg("""canvas.scale(x, y) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   217
eg("""canvas.rotate(theta) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   218
eg("""canvas.skew(alpha, beta) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   219
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   220
heading3("State control")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   221
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   222
eg("""canvas.saveState() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   223
eg("""canvas.restoreState() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   224
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   225
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   226
heading2("Other canvas methods.")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   227
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   228
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   229
Not all methods of the canvas object fit into the "tool" or "toolbox"
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   230
categories.  Below are some of the misfits, included here for completeness.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   231
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   232
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   233
eg("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   234
 canvas.setAuthor()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   235
 canvas.addOutlineEntry(title, key, level=0, closed=None)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   236
 canvas.setTitle(title)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   237
 canvas.setSubject(subj)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   238
 canvas.pageHasData()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   239
 canvas.showOutline()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   240
 canvas.bookmarkPage(name)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   241
 canvas.bookmarkHorizontalAbsolute(name, yhorizontal)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   242
 canvas.doForm()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   243
 canvas.beginForm(name, lowerx=0, lowery=0, upperx=None, uppery=None)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   244
 canvas.endForm()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   245
 canvas.linkAbsolute(contents, destinationname, Rect=None, addtopage=1, name=None, **kw)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   246
 canvas.getPageNumber()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   247
 canvas.addLiteral()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   248
 canvas.getAvailableFonts()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   249
 canvas.stringWidth(self, text, fontName, fontSize, encoding=None)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   250
 canvas.setPageCompression(onoff=1)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   251
 canvas.setPageTransition(self, effectname=None, duration=1, 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   252
                        direction=0,dimension='H',motion='I')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   253
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   254
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   255
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   256
heading2('Coordinates (default user space)')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   257
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   258
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   259
By default locations on a page are identified by a pair of numbers.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   260
For example the pair $(4.5*inch, 1*inch)$ identifies the location
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   261
found on the page by starting at the lower left corner and moving to
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   262
the right 4.5 inches and up one inch.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   263
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   264
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   265
disc("""For example, the following function draws
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   266
a number of elements on a canvas.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   267
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   268
eg(examples.testcoords)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   269
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   270
disc("""In the default user space the "origin" ^(0,0)^ point is at the lower
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   271
left corner.  Executing the $coords$ function in the default user space
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   272
(for the "demo minipage") we obtain the following.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   273
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   274
illust(examples.coords, 'The Coordinate System')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   275
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   276
heading3("Moving the origin: the $translate$ method")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   277
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   278
disc("""Often it is useful to "move the origin" to a new point off
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   279
the lower left corner.  The $canvas.translate(^x,y^)$ method moves the origin
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   280
for the current page to the point currently identified by ^(x,y)^.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   281
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   282
disc("""For example the following translate function first moves
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   283
the origin before drawing the same objects as shown above.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   284
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   285
eg(examples.testtranslate)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   286
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   287
disc("""This produces the following.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   288
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   289
illust(examples.translate, "Moving the origin: the $translate$ method")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   290
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   291
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   292
#illust(NOP) # execute some code
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   293
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   294
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   295
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   296
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   297
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   298
<i>Note:</i> As illustrated in the example it is perfectly possible to draw objects 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   299
or parts of objects "off the page".
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   300
In particular a common confusing bug is a translation operation that translates the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   301
entire drawing off the visible area of the page.  If a program produces a blank page
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   302
it is possible that all the drawn objects are off the page.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   303
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   304
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   305
heading3("Shrinking and growing: the scale operation")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   306
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   307
disc("""Another important operation is scaling.  The scaling operation $canvas.scale(^dx,dy^)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   308
stretches or shrinks the ^x^ and ^y^ dimensions by the ^dx^, ^dy^ factors respectively.  Often
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   309
^dx^ and ^dy^ are the same -- for example to reduce a drawing by half in all dimensions use
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   310
$dx = dy = 0.5$.  However for the purposes of illustration we show an example where
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   311
$dx$ and $dy$ are different.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   312
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   313
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   314
eg(examples.testscale)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   315
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   316
disc("""This produces a "short and fat" reduced version of the previously displayed operations.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   317
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   318
illust(examples.scale, "Scaling the coordinate system")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   319
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   320
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   321
#illust(NOP) # execute some code
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   322
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   323
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   324
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   325
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   326
disc("""<i>Note:</i> scaling may also move objects or parts of objects off the page,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   327
or may cause objects to "shrink to nothing." """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   328
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   329
disc("""Scaling and translation can be combined, but the order of the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   330
operations are important.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   331
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   332
eg(examples.testscaletranslate)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   333
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   334
disc("""This example function first saves the current canvas state
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   335
and then does a $scale$ followed by a $translate$.  Afterward the function
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   336
restores the state (effectively removing the effects of the scaling and
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   337
translation) and then does the <i>same</i> operations in a different order.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   338
Observe the effect below.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   339
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   340
illust(examples.scaletranslate, "Scaling and Translating")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   342
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   343
#illust(NOP) # execute some code
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   344
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   345
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   346
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   347
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   348
disc("""<em>Note:</em> scaling shrinks or grows everything including line widths
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   349
so using the canvas.scale method to render a microscopic drawing in 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   350
scaled microscopic units
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   351
may produce a blob (because all line widths will get expanded a huge amount).  
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   352
Also rendering an aircraft wing in meters scaled to centimeters may cause the lines
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   353
to shrink to the point where they disappear.  For engineering or scientific purposes
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   354
such as these scale and translate
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   355
the units externally before rendering them using the canvas.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   356
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   357
heading3("Saving and restoring the canvas state: $saveState$ and $restoreState$")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   358
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   359
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   360
The $scaletranslate$ function used an important feature of the canvas object:
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   361
the ability to save and restore the current parameters of the canvas.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   362
By enclosing a sequence of operations in a matching pair of $canvas.saveState()$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   363
an $canvas.restoreState()$ operations all changes of font, color, line style,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   364
scaling, translation, or other aspects of the canvas graphics state can be
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   365
restored to the state at the point of the $saveState()$.  Remember that the save/restore
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   366
calls must match: a stray save or restore operation may cause unexpected
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   367
and undesirable behavior.  Also, remember that <i>no</i> canvas state is
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   368
preserved across page breaks, and the save/restore mechanism does not work
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   369
across page breaks.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   370
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   371
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   372
heading3("Mirror image")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   373
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   374
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   375
It is interesting although perhaps not terribly useful to note that
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   376
scale factors can be negative.  For example the following function
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   377
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   378
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   379
eg(examples.testmirror)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   380
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   381
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   382
creates a mirror image of the elements drawn by the $coord$ function.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   383
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   384
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   385
illust(examples.mirror, "Mirror Images")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   386
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   387
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   388
Notice that the text strings are painted backwards.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   389
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   390
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   391
heading2("Colors")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   392
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   393
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   394
There are four way to specify colors in $pdfgen$: by name (using the $color$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   395
module, by red/green/blue (additive, $RGB$) value,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   396
by cyan/magenta/yellow/darkness (subtractive, $CMYK$), or by gray level.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   397
The $colors$ function below exercises each of the four methods.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   398
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   399
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   400
eg(examples.testcolors)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   401
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   402
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   403
The $RGB$ or additive color specification follows the way a computer
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   404
screen adds different levels of the red, green, or blue light to make
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   405
any color, where white is formed by turning all three lights on full
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   406
$(1,1,1)$.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   407
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   408
disc("""The $CMYK$ or subtractive method follows the way a printer
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   409
mixes three pigments (cyan, magenta, and yellow) to form colors.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   410
Because mixing chemicals is more difficult than combining light there
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   411
is a fourth parameter for darkness.  For example a chemical
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   412
combination of the $CMY$ pigments generally never makes a perfect
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   413
black -- instead producing a muddy color -- so, to get black printers
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   414
don't use the $CMY$ pigments but use a direct black ink.  Because
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   415
$CMYK$ maps more directly to the way printer hardware works it may
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   416
be the case that colors specified in $CMYK$ will provide better fidelity
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   417
and better control when printed.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   418
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   419
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   420
illust(examples.colors, "Color Models")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   421
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   422
heading2('Painting back to front')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   423
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   424
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   425
Objects may be painted over other objects to good effect in $pdfgen$.  As
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   426
in painting with oils the object painted last will show up on top.  For
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   427
example, the $spumoni$ function below paints up a base of colors and then
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   428
paints a white text over the base.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   429
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   430
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   431
eg(examples.testspumoni)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   432
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   433
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   434
The word "SPUMONI" is painted in white over the colored rectangles,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   435
with the apparent effect of "removing" the color inside the body of
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   436
the word.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   437
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   438
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   439
illust(examples.spumoni, "Painting over colors")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   440
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   441
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   442
The last letters of the word are not visible because the default canvas
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   443
background is white and painting white letters over a white background
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   444
leaves no visible effect.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   445
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   446
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   447
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   448
This method of building up complex paintings in layers can be done
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   449
in very many layers in $pdfgen$ -- there are fewer physical limitations
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   450
than there are when dealing with physical paints.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   451
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   452
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   453
eg(examples.testspumoni2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   454
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   455
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   456
The $spumoni2$ function layers an ice cream cone over the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   457
$spumoni$ drawing.  Note that different parts of the cone
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   458
and scoops layer over eachother as well.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   459
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   460
illust(examples.spumoni2, "building up a drawing in layers")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   461
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   462
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   463
heading2('Fonts and text objects')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   464
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   465
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   466
Text may be drawn in many different colors, fonts, and sizes in $pdfgen$.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   467
The $textsize$ function demonstrates how to change the color and font and
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   468
size of text and how to place text on the page.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   469
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   470
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   471
eg(examples.testtextsize)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   472
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   473
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   474
The $textsize$ function generates the following page.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   475
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   476
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   477
illust(examples.textsize, "text in different fonts and sizes")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   478
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   479
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   480
A number of different fonts are always available in $pdfgen$.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   481
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   482
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   483
eg(examples.testfonts)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   484
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   485
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   486
The $fonts$ function lists the fonts that are always available.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   487
These don;t need to be stored in a PDF document, since they
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   488
are guaranteed to be present in Acrobat Reader.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   489
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   490
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   491
illust(examples.fonts, "the 14 standard fonts")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   492
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   493
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   494
In the near future we will add the ability to embed other fonts
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   495
within a PDF file.  However, this will add a little to file size.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   496
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   497
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   498
heading2("Text object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   499
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   500
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   501
For the dedicated presentation of text in a PDF document, use a text object.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   502
The text object interface provides detailed control of text layout parameters
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   503
not available directly at the canvas level.  In addition, it results in smaller
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   504
PDF that will render faster than many separate calls to the $drawString$ methods.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   505
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   506
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   507
eg("""textobject.setTextOrigin(x,y)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   508
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   509
eg("""textobject.setTextTransform(a,b,c,d,e,f)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   510
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   511
eg("""textobject.moveCursor(dx, dy) # from start of current LINE""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   512
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   513
eg("""(x,y) = textobject.getCursor()""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   514
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   515
eg("""x = textobject.getX(); y = textobject.getY()""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   516
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   517
eg("""textobject.setFont(psfontname, size, leading = None)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   518
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   519
eg("""textobject.textOut(text)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   520
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   521
eg("""textobject.textLine(text='')""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   522
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   523
eg("""textobject.textLines(stuff, trim=1)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   524
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   525
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   526
The text object methods shown above relate to basic text geometry.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   527
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   528
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   529
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   530
A text object maintains a text cursor which moves about the page when 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   531
text is drawn.  For example the $setTextOrigin$ places the cursor
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   532
in a known position and the $textLine$ and $textLines$ methods move
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   533
the text cursor down past the lines that have been missing.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   534
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   535
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   536
eg(examples.testcursormoves1)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   537
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   538
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   539
The $cursormoves$ function relies on the automatic
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   540
movement of the text cursor for placing text after the origin
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   541
has been set.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   542
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   543
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   544
illust(examples.cursormoves1, "How the text cursor moves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   545
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   546
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   547
It is also possible to control the movement of the cursor
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   548
more explicitly by using the $moveCursor$ method (which moves
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   549
the cursor as an offset from the start of the current <i>line</i>
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   550
NOT the current cursor, and which also has positive ^y^ offsets
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   551
move <i>down</i> (in contrast to the normal geometry where
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   552
positive ^y^ usually moves up.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   553
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   554
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   555
eg(examples.testcursormoves2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   556
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   557
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   558
Here the $textOut$ does not move the down a line in contrast
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   559
to the $textLine$ function which does move down.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   560
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   561
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   562
illust(examples.cursormoves2, "How the text cursor moves again")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   563
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   564
heading3("Character Spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   565
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   566
eg("""textobject.setCharSpace(charSpace)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   567
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   568
disc("""The $setCharSpace$ method adjusts one of the parameters of text -- the inter-character
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   569
spacing.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   570
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   571
eg(examples.testcharspace)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   572
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   573
disc("""The 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   574
$charspace$ function exercises various spacing settings.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   575
It produces the following page.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   576
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   577
illust(examples.charspace, "Adjusting inter-character spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   578
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   579
heading3("Word Spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   580
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   581
eg("""textobject.setWordSpace(wordSpace)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   582
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   583
disc("The $setWordSpace$ method adjusts the space between word.")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   584
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   585
eg(examples.testwordspace)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   586
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   587
disc("""The $wordspace$ function shows what various word space settings
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   588
look like below.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   589
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   590
illust(examples.wordspace, "Adjusting word spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   591
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   592
heading3("Horizontal Scaling")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   593
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   594
eg("""textobject.setHorizScale(horizScale)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   595
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   596
disc("""Lines of text can be stretched or shrunken horizontally by the 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   597
$setHorizScale$ method.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   598
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   599
eg(examples.testhorizontalscale)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   600
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   601
disc("""The horizontal scaling parameter ^horizScale^
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   602
is given in percentages (with 100 as the default), so the 80 setting
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   603
shown below looks skinny.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   604
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   605
illust(examples.horizontalscale, "adjusting horizontal text scaling")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   606
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   607
heading3("Interline spacing (Leading)")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   608
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   609
eg("""textobject.setLeading(leading)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   610
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   611
disc("""The vertical offset between the point at which one
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   612
line starts and where the next starts is called the leading
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   613
offset.  The $setLeading$ method adjusts the leading offset.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   614
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   615
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   616
eg(examples.testleading)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   617
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   618
disc("""As shown below if the leading offset is set too small
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   619
characters of one line my write over the bottom parts of characters
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   620
in the previous line.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   621
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   622
illust(examples.leading, "adjusting the leading")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   623
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   624
heading3("Other text object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   625
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   626
eg("""textobject.setTextRenderMode(mode)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   627
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   628
disc("""The $setTextRenderMode$ method allows text to be used
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   629
as a forground for clipping background drawings, for example.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   630
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   631
eg("""textobject.setRise(rise)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   632
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   633
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   634
The $setRise$ method <super>raises</super> or <sub>lowers</sub> text on the line
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   635
(for creating superscripts or subscripts, for example).
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   636
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   637
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   638
eg("""textobject.setFillColor(aColor); 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   639
textobject.setStrokeColor(self, aColor) 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   640
# and similar""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   641
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   642
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   643
These color change operations change the <font color=darkviolet>color</font> of the text and are otherwise
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   644
similar to the color methods for the canvas object.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   645
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   646
heading2('Paths and Lines')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   647
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   648
disc("""Just as textobjects are designed for the dedicated presentation
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   649
of text, path objects are designed for the dedicated construction of
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   650
graphical figures.  When path objects are drawn onto a canvas they are
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   651
are drawn as one figure (like a rectangle) and the mode of drawing
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   652
for the entire figure can be adjusted: the lines of the figure can
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   653
be drawn (stroked) or not; the interior of the figure can be filled or
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   654
not; and so forth.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   655
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   656
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   657
For example the $star$ function uses a path object
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   658
to draw a star
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   659
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   660
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   661
eg(examples.teststar)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   662
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   663
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   664
The $star$ function has been designed to be useful in illustrating
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   665
various line style parameters supported by $pdfgen$.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   666
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   667
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   668
illust(examples.star, "line style parameters")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   669
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   670
heading3("Line join settings")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   671
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   672
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   673
The $setLineJoin$ method can adjust whether line segments meet in a point
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   674
a square or a rounded vertex.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   675
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   676
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   677
eg(examples.testjoins)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   678
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   679
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   680
The line join setting is only really of interest for thick lines because
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   681
it cannot be seen clearly for thin lines.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   682
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   683
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   684
illust(examples.joins, "different line join styles")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   685
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   686
heading3("Line cap settings")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   687
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   688
disc("""The line cap setting, adjusted using the $setLineCap$ method,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   689
determines whether a terminating line
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   690
ends in a square exactly at the vertex, a square over the vertex
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   691
or a half circle over the vertex.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   692
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   693
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   694
eg(examples.testcaps)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   695
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   696
disc("""The line cap setting, like the line join setting, is only
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   697
visible when the lines are thick.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   698
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   699
illust(examples.caps, "line cap settings")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   700
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   701
heading3("Dashes and broken lines")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   702
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   703
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   704
The $setDash$ method allows lines to be broken into dots or dashes.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   705
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   706
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   707
eg(examples.testdashes)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   708
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   709
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   710
The patterns for the dashes or dots can be in a simple on/off repeating pattern
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   711
or they can be specified in a complex repeating pattern.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   712
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   713
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   714
illust(examples.dashes, "some dash patterns")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   715
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   716
heading3("Creating complex figures with path objects")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   717
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   718
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   719
Combinations of lines, curves, arcs and other figures
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   720
can be combined into a single figure using path objects.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   721
For example the function shown below constructs two path
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   722
objects using lines and curves.  
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   723
This function will be used later on as part of a
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   724
pencil icon construction.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   725
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   726
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   727
eg(examples.testpenciltip)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   728
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   729
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   730
Note that the interior of the pencil tip is filled
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   731
as one object even though it is constructed from
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   732
several lines and curves.  The pencil lead is then
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   733
drawn over it using a new path object.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   734
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   735
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   736
illust(examples.penciltip, "a pencil tip")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   737
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   738
heading2('Rectangles, circles, ellipses')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   739
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   740
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   741
The $pdfgen$ module supports a number of generally useful shapes
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   742
such as rectangles, rounded rectangles, ellipses, and circles.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   743
Each of these figures can be used in path objects or can be drawn
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   744
directly on a canvas.  For example the $pencil$ function below
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   745
draws a pencil icon using rectangles and rounded rectangles with
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   746
various fill colors and a few other annotations.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   747
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   748
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   749
eg(examples.testpencil)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   750
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   751
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   752
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   753
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   754
Note that this function is used to create the "margin pencil" to the left.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   755
Also note that the order in which the elements are drawn are important
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   756
because, for example, the white rectangles "erase" parts of a black rectangle
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   757
and the "tip" paints over part of the yellow rectangle.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   758
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   759
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   760
illust(examples.pencil, "a whole pencil")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   761
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   762
heading2('Bezier curves')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   763
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   764
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   765
Programs that wish to construct figures with curving borders
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   766
generally use Bezier curves to form the borders.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   767
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   768
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   769
eg(examples.testbezier)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   770
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   771
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   772
A Bezier curve is specified by four control points 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   773
$(x1,y1)$, $(x2,y2)$, $(x3,y3)$, $(x4,y4)$.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   774
The curve starts at $(x1,y1)$ and ends at $(x4,y4)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   775
and the line segment from $(x1,y1)$ to $(x2,y2)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   776
and the line segment from $(x3,y3)$ to $(x4,y4)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   777
both form tangents to the curve.  Furthermore the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   778
curve is entirely contained in the convex figure with vertices
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   779
at the control points.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   780
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   781
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   782
illust(examples.bezier, "basic bezier curves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   783
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   784
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   785
The drawing above (the output of $testbezier$) shows
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   786
a bezier curves, the tangent lines defined by the control points
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   787
and the convex figure with vertices at the control points.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   788
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   789
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   790
heading3("Smoothly joining bezier curve sequences")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   791
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   792
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   793
It is often useful to join several bezier curves to form a
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   794
single smooth curve.  To construct a larger smooth curve from
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   795
several bezier curves make sure that the tangent lines to adjacent
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   796
bezier curves that join at a control point lie on the same line.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   797
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   798
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   799
eg(examples.testbezier2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   800
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   801
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   802
The figure created by $testbezier2$ describes a smooth
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   803
complex curve because adjacent tangent lines "line up" as
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   804
illustrated below.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   805
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   806
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   807
illust(examples.bezier2, "bezier curves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   808
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   809
heading2("Path object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   810
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   811
eg("""pathobject.moveTo(x,y)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   812
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   813
eg("""pathobject.lineTo(x,y)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   814
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   815
eg("""pathobject.curveTo(x1, y1, x2, y2, x3, y3) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   816
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   817
eg("""pathobject.arc(x1,y1, x2,y2, startAng=0, extent=90) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   818
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   819
eg("""pathobject.arcTo(x1,y1, x2,y2, startAng=0, extent=90) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   820
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   821
eg("""pathobject.rect(x, y, width, height) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   822
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   823
eg("""pathobject.ellipse(x, y, width, height)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   824
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   825
eg("""pathobject.circle(x_cen, y_cen, r) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   826
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   827
eg("""pathobject.close() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   828
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   829
eg(examples.testhand)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   830
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   831
illust(examples.hand, "an outline of a hand using bezier curves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   832
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   833
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   834
eg(examples.testhand2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   835
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   836
illust(examples.hand2, "the finished hand, filled")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   837
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   838
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   839
##### FILL THEM IN