docs/userguide/ch2_graphics.py
author aaron_watters
Thu, 13 Jul 2000 14:40:49 +0000
changeset 374 1342601fdc4a
parent 364 21f5c8641230
child 397 d2e12adb2496
permissions -rw-r--r--
minor edits, filled in some blanks
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
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    56
are many different settings available.  If you are new to Python
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    57
or can't wait to produce some output, you can skip ahead, but
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    58
come back later and read this!""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    59
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    60
disc("""First of all, we will look at the constructor
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    61
arguments for the canvas:""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    62
eg("""    def __init__(self,filename,
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    63
                 pagesize=(595.27,841.89),
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    64
                 bottomup = 1,
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    65
                 pageCompression=0,
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    66
                 encoding=pdfdoc.DEFAULT_ENCODING,
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    67
                 verbosity=0):
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    68
                 """)
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    69
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    70
disc("""The $filename$ argument controls the
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    71
name of the final PDF file.  You
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    72
may also pass in any open file object (such as $sys.stdout$, the python process standard output)
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    73
and the PDF document will be written to that.  Since PDF
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    74
is a binary format, you should take care when writing other
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    75
stuff before or after it; you can't deliver PDF documents
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    76
inline in the middle of an HTML page!""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    77
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    78
disc("""The $pagesize$ argument is a tuple of two numbers
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    79
in points (1/72 of an inch). The canvas defaults to $A4$ (an international standard
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    80
page size which differs from the American standard page size of $letter$),
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    81
but it is better to explicitly specify it.  Most common page
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    82
sizes are found in the library module $reportlab.lib.pagesizes$,
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    83
so you can use expressions like""")
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    84
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    85
eg("""from reportlab.lib.pagesizes import letter, A4
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    86
myCanvas = Canvas('myfile.pdf', pagesize=letter)
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    87
width, height = pagesize.letter  #keep for later
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    88
""")
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    89
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    90
pencilnote()
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    91
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    92
disc("""If you have problems printing your document make sure you
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    93
are using the right page size (usually either $A4$ or $letter$).
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    94
Some printers do not work well with pages that are too large or too small.""")
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    95
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    96
disc("""Very often, you will want to calculate things based on
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
    97
the page size.  In the example above we extracted the width and
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    98
height.  Later in the program we may use the $width$ variable to 
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
    99
define a right margin as $width - inch$ rather than using
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   100
a constant.  By using variables the margin will still make sense even 
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   101
if the page size changes.""")
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   102
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   103
disc("""The $bottomup$ argument
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   104
switches coordinate systems.  Some graphics systems (like PDF
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   105
and PostScript) place (0,0) at the bottom left of the page
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   106
others (like many graphical user interfaces [GUI's]) place the origen at the top left.  The
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   107
$bottomup$ argument is deprecated and may be dropped in future""")
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   108
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   109
todo("""Need to see if it really works for all tasks, and if not
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   110
     then get rid of it""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   111
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   112
disc("""The $pageCompression$ option determines whether the stream
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   113
of PDF operations for each page is compressed.  By default
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   114
page streams are not compressed, because the compression slows the file generation process.
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   115
If output size is important set $pageCompression=1$, but remember that, compressed documents will
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   116
be smaller, but slower to generate.  Note that images are <i>always</i> compressed, and this option
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   117
will only save space if you have a very large amount of text and vector graphics
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   118
on each page.""")
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   119
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   120
disc("""The $encoding$ argument determines which font encoding
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   121
is used for the standard fonts; this should correspond to
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   122
the encoding on your system.  It has two values at present:
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   123
$pdfdoc.WINANSI_ENCODING$ or $pdfdoc.MACROMAN_ENCODING$.  The
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   124
$pdfdoc.DEFAULT_ENCODING$ above points to the former, which
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   125
is standard on Windows and many Unices (including Linux). If
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   126
you are a Mac user and want to make a global change, modify the
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   127
line at the top of <i>reportlab/pdfbase/pdfdoc.py</i> to switch it
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   128
over.""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   129
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   130
disc("""We plan to add support for encodings on a per-font
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   131
basis in future, so you can explicitly add in new fonts
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   132
and say how the data is to be encoded.  It is your responsibility
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   133
to ensure that your string data is in an encoding matching that
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   134
of the font.  If conversions are needed, the Unicode library
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   135
in Python 1.6 can be of great help.""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   136
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   137
disc("""The demo script $reportlab/demos/stdfonts.py$
347
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   138
will print out two test documents showing all code points
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   139
in all fonts, so you can look up characters.  Special
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   140
characters can be inserted into string commands with
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   141
the usual octal escape sequence; for example \\101 = 'A'.""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   142
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   143
disc("""The $verbosity$ argument determines how much log
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   144
information is printed.  By default, it is zero to assist
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   145
applications which want to capture PDF from standard output.
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   146
With a value of 1, you will get a confirmation message
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   147
each time a document is generated.  Higher numbers may
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   148
give more output in future.""")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   149
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   150
todo("to do - all the info functions and other non-drawing stuff")
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   151
     
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   152
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   153
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   154
35eda3272102 Added canvas init arguments
andy_robinson
parents: 341
diff changeset
   155
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   156
todo("""Cover all constructor arguments, and setAuthor etc.""")
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
heading2("Drawing Operations")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   159
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   160
Suppose the $hello$ function referenced above is implemented as
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   161
follows (we will not explain each of the operations in detail
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   162
yet).
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   165
eg(examples.testhello)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   166
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   167
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   168
Examining this code notice that there are essentially two types
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   169
of operations performed using a canvas.  The first type draws something
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   170
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
   171
type changes the state of the canvas such as
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   172
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
   173
type and size.  
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   176
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   177
If we imagine the program as a painter working on
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   178
the canvas the "draw" operations apply paint to the canvas using
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   179
the current set of tools (colors, line styles, fonts, etcetera)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   180
and the "state change" operations change one of the current tools
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   181
(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
   182
the current font to $Times-Roman$ in 15 points, for example).
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   183
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   184
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   185
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   186
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
   187
the following graphics.
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
illust(examples.hello, '"Hello World" in pdfgen')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   191
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   192
heading3("About the demos in this document")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   193
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   194
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   195
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
   196
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
   197
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
   198
and %s inches tall. The demo displays show the actual output of the demo code.
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   199
For convenience the size of the output has been reduced slightly.
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   200
""" % (examplefunctionxinches, examplefunctionyinches))
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   201
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   202
heading2('The tools: the "draw" operations')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   203
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   204
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   205
This section briefly lists the tools available to the program
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   206
for painting information onto a page using the canvas interface.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   207
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
   208
here for easy reference and for summary purposes.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   209
""")
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("Line methods")
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.line(x1,y1,x2,y2)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   214
eg("""canvas.lines(linelist)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   215
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   216
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   217
The line methods draw straight line segments on the canvas.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   218
""")
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("Shape methods")
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.grid(xlist, ylist) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   223
eg("""canvas.bezier(x1, y1, x2, y2, x3, y3, x4, y4)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   224
eg("""canvas.arc(x1,y1,x2,y2) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   225
eg("""canvas.rect(x, y, width, height, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   226
eg("""canvas.ellipse(x, y, width, height, stroke=1, fill=0)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   227
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
   228
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
   229
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
   230
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   231
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   232
The shape methods draw common complex shapes on the canvas.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   233
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   234
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   235
heading3("String drawing methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   236
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   237
eg("""canvas.drawString(x, y, text):""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   238
eg("""canvas.drawRightString(x, y, text) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   239
eg("""canvas.drawCentredString(x, y, text)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   240
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   241
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   242
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
   243
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   244
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   245
heading3("The text object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   246
eg("""textobject = canvas.beginText(x, y) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   247
eg("""canvas.drawText(textobject) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   248
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   249
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   250
Text objects are used to format text in ways that
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   251
are not supported directly by the $canvas$ interface.
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   252
A program creates a text object from the $canvas$ using $beginText$
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   253
and then formats text by invoking $textobject$ methods.
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   254
Finally the $textobject$ is drawn onto the canvas using
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   255
$drawText$.
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   256
""")
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
heading3("The path object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   259
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   260
eg("""path = canvas.beginPath() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   261
eg("""canvas.drawPath(path, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   262
eg("""canvas.clipPath(path, stroke=1, fill=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   263
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   264
disc("""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   265
Path objects are similar to text objects: they provide dedicated control
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   266
for performing complex graphical drawing not directly provided by the
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   267
canvas interface.  A program creates a path object using $beginPath$
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   268
populates the path with graphics using the methods of the path object
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   269
and then draws the path on the canvas using $drawPath$.""")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   270
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   271
disc("""It is also possible
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   272
to use a path as a "clipping region" using the $clipPath$ method -- for example a circular path
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   273
can be used to clip away the outer parts of a rectangular image leaving
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   274
only a circular part of the image visible on the page. 
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   275
""")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   276
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   277
heading3("Image methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   278
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   279
eg("""canvas.drawInlineImage(self, image, x,y, width=None,height=None) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   280
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   281
disc("""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   282
The $drawInlineImage$ method places an image on the canvas.
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   283
""")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   284
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   285
pencilnote()
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   286
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   287
disc("""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   288
You need the Python Imaging Library (PIL) to use images with the ReportLab package.
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   289
""")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   290
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   291
heading3("Ending a page")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   292
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   293
eg("""canvas.showPage()""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   294
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   295
disc("""The $showPage$ method finishes the current page.  All additional drawing will
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   296
be done on another page.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   297
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   298
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   299
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   300
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
   301
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
   302
must be set up again before the program proceeds with drawing!""")
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
heading2('The toolbox: the "state change" operations')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   305
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   306
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   307
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
   308
program
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   309
for painting information onto a page using the $canvas$ interface.
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   310
These too will be discussed in detail in later sections.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   311
""")
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
heading3("Changing Colors")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   314
eg("""canvas.setFillColorCMYK(c, m, y, k) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   315
eg("""canvas.setStrikeColorCMYK(c, m, y, k) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   316
eg("""canvas.setFillColorRGB(r, g, b) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   317
eg("""canvas.setStrokeColorRGB(r, g, b) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   318
eg("""canvas.setFillColor(acolor) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   319
eg("""canvas.setStrokeColor(acolor) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   320
eg("""canvas.setFillGray(gray) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   321
eg("""canvas.setStrokeGray(gray) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   322
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   323
disc("""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   324
PDF supports three different color models: gray level, additive (red/green/blue or RGB), and
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   325
subtractive with darkness parameter (cyan/magenta/yellow/darkness or CMYK).
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   326
The ReportLab packages also provide named colors such as $lawngreen$.  There are two
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   327
basic color parameters in the graphics state: the $Fill$ color for the interior of graphic
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   328
figures and the $Stroke$ color for the boundary of graphic figures.  The above methods
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   329
support setting the fill or stroke color using any of the four color specifications.
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   330
""")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   331
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   332
heading3("Changing Fonts")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   333
eg("""canvas.setFont(psfontname, size, leading = None) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   334
374
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   335
disc("""
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   336
The $setFont$ method changes the current text font to a given type and size.
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   337
The $leading$ parameter specifies the distance down to move when advancing from
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   338
one text line to the next.
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   339
""")
1342601fdc4a minor edits, filled in some blanks
aaron_watters
parents: 364
diff changeset
   340
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   341
heading3("Changing Graphical Line Styles")
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
eg("""canvas.setLineWidth(width) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   344
eg("""canvas.setLineCap(mode) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   345
eg("""canvas.setLineJoin(mode) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   346
eg("""canvas.setMiterLimit(limit) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   347
eg("""canvas.setDash(self, array=[], phase=0) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   348
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   349
disc("""
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   350
Lines drawn in PDF can be presented in a number of graphical styles.
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   351
Lines can have different widths, they can end in differing cap styles,
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   352
they can meet in different join styles, and they can be continuous or
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   353
they can be dotted or dashed.  The above methods adjust these various parameters.""")
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   354
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   355
heading3("Changing Geometry")
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
eg("""canvas.setPageSize(pair) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   358
eg("""canvas.transform(a,b,c,d,e,f): """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   359
eg("""canvas.translate(dx, dy) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   360
eg("""canvas.scale(x, y) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   361
eg("""canvas.rotate(theta) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   362
eg("""canvas.skew(alpha, beta) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   363
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   364
disc("""
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   365
All PDF drawings fit into a specified page size.  Elements drawn outside of the specified
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   366
page size are not visible.  Furthermore all drawn elements are passed through an affine
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   367
transformation which may adjust their location and/or distort their appearence.  The
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   368
$setPageSize$ method adjusts the current page size.  The $transform$, $translate$, $scale$,
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   369
$rotate$, and $skew$ methods add additional transformations to the current transformation.
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   370
It is important to remember that these transformations are <i>incremental</i> -- a new
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   371
transform modifies the current transform (but does not replace it).
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   372
""")
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   373
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   374
heading3("State control")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   375
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   376
eg("""canvas.saveState() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   377
eg("""canvas.restoreState() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   378
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   379
disc("""
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   380
Very often it is important to save the current font, graphics transform, line styles and
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   381
other graphics state in order to restore them later. The $saveState$ method marks the
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   382
current graphics state for later restoration by a matching $restoreState$.  Note that
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   383
the save and restore method invokation must match -- a restore call restores the state to
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   384
the most recently saved state which hasn't been restored yet.  
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   385
You cannot save the state on one page and restore
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   386
it on the next, however -- no state is preserved between pages.""")
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   387
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   388
heading2("Other $canvas$ methods.")
341
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
disc("""
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   391
Not all methods of the $canvas$ object fit into the "tool" or "toolbox"
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   392
categories.  Below are some of the misfits, included here for completeness.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   393
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   394
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   395
eg("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   396
 canvas.setAuthor()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   397
 canvas.addOutlineEntry(title, key, level=0, closed=None)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   398
 canvas.setTitle(title)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   399
 canvas.setSubject(subj)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   400
 canvas.pageHasData()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   401
 canvas.showOutline()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   402
 canvas.bookmarkPage(name)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   403
 canvas.bookmarkHorizontalAbsolute(name, yhorizontal)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   404
 canvas.doForm()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   405
 canvas.beginForm(name, lowerx=0, lowery=0, upperx=None, uppery=None)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   406
 canvas.endForm()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   407
 canvas.linkAbsolute(contents, destinationname, Rect=None, addtopage=1, name=None, **kw)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   408
 canvas.getPageNumber()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   409
 canvas.addLiteral()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   410
 canvas.getAvailableFonts()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   411
 canvas.stringWidth(self, text, fontName, fontSize, encoding=None)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   412
 canvas.setPageCompression(onoff=1)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   413
 canvas.setPageTransition(self, effectname=None, duration=1, 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   414
                        direction=0,dimension='H',motion='I')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   415
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   416
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   417
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   418
heading2('Coordinates (default user space)')
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   421
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
   422
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
   423
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
   424
the right 4.5 inches and up one inch.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   425
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   426
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   427
disc("""For example, the following function draws
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   428
a number of elements on a $canvas$.""")
341
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
eg(examples.testcoords)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   431
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   432
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
   433
left corner.  Executing the $coords$ function in the default user space
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   434
(for the "demo minipage") we obtain the following.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   435
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   436
illust(examples.coords, 'The Coordinate System')
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
heading3("Moving the origin: the $translate$ method")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   439
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   440
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
   441
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
   442
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
   443
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   444
disc("""For example the following translate function first moves
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   445
the origin before drawing the same objects as shown above.""")
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
eg(examples.testtranslate)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   448
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   449
disc("""This produces the following.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   450
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   451
illust(examples.translate, "Moving the origin: the $translate$ method")
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   454
#illust(NOP) # execute some code
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   455
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   456
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   457
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   458
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   459
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   460
<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
   461
or parts of objects "off the page".
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   462
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
   463
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
   464
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
   465
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   466
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   467
heading3("Shrinking and growing: the scale operation")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   468
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   469
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
   470
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
   471
^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
   472
$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
   473
$dx$ and $dy$ are different.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   474
""")
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
eg(examples.testscale)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   477
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   478
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
   479
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   480
illust(examples.scale, "Scaling the coordinate system")
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
#illust(NOP) # execute some code
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
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   486
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   487
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   488
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
   489
or may cause objects to "shrink to nothing." """)
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
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
   492
operations are important.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   493
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   494
eg(examples.testscaletranslate)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   495
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   496
disc("""This example function first saves the current $canvas$ state
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   497
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
   498
restores the state (effectively removing the effects of the scaling and
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   499
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
   500
Observe the effect below.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   501
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   502
illust(examples.scaletranslate, "Scaling and Translating")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   503
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   504
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   505
#illust(NOP) # execute some code
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
pencilnote()
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   510
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
   511
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
   512
scaled microscopic units
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   513
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
   514
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
   515
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
   516
such as these scale and translate
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   517
the units externally before rendering them using the canvas.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   518
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   519
heading3("Saving and restoring the $canvas$ state: $saveState$ and $restoreState$")
341
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
disc("""
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   522
The $scaletranslate$ function used an important feature of the $canvas$ object:
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   523
the ability to save and restore the current parameters of the $canvas$.
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   524
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
   525
an $canvas.restoreState()$ operations all changes of font, color, line style,
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   526
scaling, translation, or other aspects of the $canvas$ graphics state can be
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   527
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
   528
calls must match: a stray save or restore operation may cause unexpected
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   529
and undesirable behavior.  Also, remember that <i>no</i> $canvas$ state is
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   530
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
   531
across page breaks.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   532
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   533
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   534
heading3("Mirror image")
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   537
It is interesting although perhaps not terribly useful to note that
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   538
scale factors can be negative.  For example the following function
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   539
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   540
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   541
eg(examples.testmirror)
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   544
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
   545
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   546
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   547
illust(examples.mirror, "Mirror Images")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   548
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   549
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   550
Notice that the text strings are painted backwards.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   551
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   552
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   553
heading2("Colors")
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   556
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
   557
module, by red/green/blue (additive, $RGB$) value,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   558
by cyan/magenta/yellow/darkness (subtractive, $CMYK$), or by gray level.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   559
The $colors$ function below exercises each of the four methods.
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
eg(examples.testcolors)
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   565
The $RGB$ or additive color specification follows the way a computer
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   566
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
   567
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
   568
$(1,1,1)$.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   569
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   570
disc("""The $CMYK$ or subtractive method follows the way a printer
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   571
mixes three pigments (cyan, magenta, and yellow) to form colors.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   572
Because mixing chemicals is more difficult than combining light there
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   573
is a fourth parameter for darkness.  For example a chemical
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   574
combination of the $CMY$ pigments generally never makes a perfect
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   575
black -- instead producing a muddy color -- so, to get black printers
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   576
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
   577
$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
   578
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
   579
and better control when printed.
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   582
illust(examples.colors, "Color Models")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   583
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   584
heading2('Painting back to front')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   585
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   586
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   587
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
   588
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
   589
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
   590
paints a white text over the base.
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   593
eg(examples.testspumoni)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   594
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   595
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   596
The word "SPUMONI" is painted in white over the colored rectangles,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   597
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
   598
the word.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   599
""")
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
illust(examples.spumoni, "Painting over colors")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   602
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   603
disc("""
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   604
The last letters of the word are not visible because the default $canvas$
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   605
background is white and painting white letters over a white background
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   606
leaves no visible effect.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   607
""")
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   610
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
   611
in very many layers in $pdfgen$ -- there are fewer physical limitations
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   612
than there are when dealing with physical paints.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   613
""")
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
eg(examples.testspumoni2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   616
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   617
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   618
The $spumoni2$ function layers an ice cream cone over the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   619
$spumoni$ drawing.  Note that different parts of the cone
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   620
and scoops layer over eachother as well.
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.spumoni2, "building up a drawing in layers")
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   625
heading2('Fonts and text objects')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   626
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   627
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   628
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
   629
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
   630
size of text and how to place text on the page.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   631
""")
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
eg(examples.testtextsize)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   634
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   635
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   636
The $textsize$ function generates the following page.
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   639
illust(examples.textsize, "text in different fonts and sizes")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   640
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   641
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   642
A number of different fonts are always available in $pdfgen$.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   643
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   644
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   645
eg(examples.testfonts)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   646
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   647
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   648
The $fonts$ function lists the fonts that are always available.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   649
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
   650
are guaranteed to be present in Acrobat Reader.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   651
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   652
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   653
illust(examples.fonts, "the 14 standard fonts")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   654
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   655
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   656
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
   657
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
   658
""")
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
heading2("Text object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   661
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   662
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   663
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
   664
The text object interface provides detailed control of text layout parameters
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   665
not available directly at the $canvas$ level.  In addition, it results in smaller
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   666
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
   667
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   668
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   669
eg("""textobject.setTextOrigin(x,y)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   670
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   671
eg("""textobject.setTextTransform(a,b,c,d,e,f)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   672
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   673
eg("""textobject.moveCursor(dx, dy) # from start of current LINE""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   674
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   675
eg("""(x,y) = textobject.getCursor()""")
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("""x = textobject.getX(); y = textobject.getY()""")
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
eg("""textobject.setFont(psfontname, size, leading = None)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   680
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   681
eg("""textobject.textOut(text)""")
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
eg("""textobject.textLine(text='')""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   684
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   685
eg("""textobject.textLines(stuff, trim=1)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   686
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   687
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   688
The text object methods shown above relate to basic text geometry.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   689
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   690
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   691
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   692
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
   693
text is drawn.  For example the $setTextOrigin$ places the cursor
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   694
in a known position and the $textLine$ and $textLines$ methods move
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   695
the text cursor down past the lines that have been missing.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   696
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   697
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   698
eg(examples.testcursormoves1)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   699
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   700
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   701
The $cursormoves$ function relies on the automatic
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   702
movement of the text cursor for placing text after the origin
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   703
has been set.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   704
""")
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
illust(examples.cursormoves1, "How the text cursor moves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   707
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   708
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   709
It is also possible to control the movement of the cursor
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   710
more explicitly by using the $moveCursor$ method (which moves
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   711
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
   712
NOT the current cursor, and which also has positive ^y^ offsets
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   713
move <i>down</i> (in contrast to the normal geometry where
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   714
positive ^y^ usually moves up.
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   717
eg(examples.testcursormoves2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   718
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   719
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   720
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
   721
to the $textLine$ function which does move down.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   722
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   723
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   724
illust(examples.cursormoves2, "How the text cursor moves again")
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
heading3("Character Spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   727
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   728
eg("""textobject.setCharSpace(charSpace)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   729
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   730
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
   731
spacing.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   732
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   733
eg(examples.testcharspace)
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
disc("""The 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   736
$charspace$ function exercises various spacing settings.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   737
It produces the following page.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   738
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   739
illust(examples.charspace, "Adjusting inter-character spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   740
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   741
heading3("Word Spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   742
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   743
eg("""textobject.setWordSpace(wordSpace)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   744
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   745
disc("The $setWordSpace$ method adjusts the space between word.")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   746
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   747
eg(examples.testwordspace)
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
disc("""The $wordspace$ function shows what various word space settings
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   750
look like below.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   751
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   752
illust(examples.wordspace, "Adjusting word spacing")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   753
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   754
heading3("Horizontal Scaling")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   755
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   756
eg("""textobject.setHorizScale(horizScale)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   757
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   758
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
   759
$setHorizScale$ method.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   760
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   761
eg(examples.testhorizontalscale)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   762
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   763
disc("""The horizontal scaling parameter ^horizScale^
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   764
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
   765
shown below looks skinny.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   766
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   767
illust(examples.horizontalscale, "adjusting horizontal text scaling")
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
heading3("Interline spacing (Leading)")
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
eg("""textobject.setLeading(leading)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   772
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   773
disc("""The vertical offset between the point at which one
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   774
line starts and where the next starts is called the leading
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   775
offset.  The $setLeading$ method adjusts the leading offset.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   776
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   777
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   778
eg(examples.testleading)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   779
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   780
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
   781
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
   782
in the previous line.""")
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
illust(examples.leading, "adjusting the leading")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   785
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   786
heading3("Other text object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   787
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   788
eg("""textobject.setTextRenderMode(mode)""")
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
disc("""The $setTextRenderMode$ method allows text to be used
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   791
as a forground for clipping background drawings, for example.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   792
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   793
eg("""textobject.setRise(rise)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   794
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   795
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   796
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
   797
(for creating superscripts or subscripts, for example).
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   800
eg("""textobject.setFillColor(aColor); 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   801
textobject.setStrokeColor(self, aColor) 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   802
# and similar""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   803
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   804
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   805
These color change operations change the <font color=darkviolet>color</font> of the text and are otherwise
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   806
similar to the color methods for the $canvas$ object.""")
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   807
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   808
heading2('Paths and Lines')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   809
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   810
disc("""Just as textobjects are designed for the dedicated presentation
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   811
of text, path objects are designed for the dedicated construction of
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   812
graphical figures.  When path objects are drawn onto a $canvas$ they are
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   813
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
   814
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
   815
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
   816
not; and so forth.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   817
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   818
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   819
For example the $star$ function uses a path object
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   820
to draw a star
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   821
""")
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(examples.teststar)
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   826
The $star$ function has been designed to be useful in illustrating
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   827
various line style parameters supported by $pdfgen$.
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
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   830
illust(examples.star, "line style parameters")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   831
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   832
heading3("Line join settings")
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
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   835
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
   836
a square or a rounded vertex.
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
eg(examples.testjoins)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   840
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   841
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   842
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
   843
it cannot be seen clearly for thin lines.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   844
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   845
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   846
illust(examples.joins, "different line join styles")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   847
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   848
heading3("Line cap settings")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   849
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   850
disc("""The line cap setting, adjusted using the $setLineCap$ method,
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   851
determines whether a terminating line
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   852
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
   853
or a half circle over the vertex.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   854
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   855
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   856
eg(examples.testcaps)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   857
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   858
disc("""The line cap setting, like the line join setting, is only clearly
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   859
visible when the lines are thick.""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   860
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   861
illust(examples.caps, "line cap settings")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   862
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   863
heading3("Dashes and broken lines")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   864
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   865
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   866
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
   867
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   868
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   869
eg(examples.testdashes)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   870
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   871
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   872
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
   873
or they can be specified in a complex repeating pattern.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   874
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   875
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   876
illust(examples.dashes, "some dash patterns")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   877
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   878
heading3("Creating complex figures with path objects")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   879
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   880
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   881
Combinations of lines, curves, arcs and other figures
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   882
can be combined into a single figure using path objects.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   883
For example the function shown below constructs two path
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   884
objects using lines and curves.  
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   885
This function will be used later on as part of a
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   886
pencil icon construction.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   887
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   888
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   889
eg(examples.testpenciltip)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   890
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   891
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   892
Note that the interior of the pencil tip is filled
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   893
as one object even though it is constructed from
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   894
several lines and curves.  The pencil lead is then
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   895
drawn over it using a new path object.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   896
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   897
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   898
illust(examples.penciltip, "a pencil tip")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   899
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   900
heading2('Rectangles, circles, ellipses')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   901
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   902
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   903
The $pdfgen$ module supports a number of generally useful shapes
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   904
such as rectangles, rounded rectangles, ellipses, and circles.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   905
Each of these figures can be used in path objects or can be drawn
352
088c93328100 random modificatoins and expansions
aaron_watters
parents: 347
diff changeset
   906
directly on a $canvas$.  For example the $pencil$ function below
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   907
draws a pencil icon using rectangles and rounded rectangles with
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   908
various fill colors and a few other annotations.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   909
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   910
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   911
eg(examples.testpencil)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   912
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   913
pencilnote()
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   914
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   915
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   916
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
   917
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
   918
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
   919
and the "tip" paints over part of the yellow rectangle.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   920
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   921
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   922
illust(examples.pencil, "a whole pencil")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   923
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   924
heading2('Bezier curves')
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   925
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   926
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   927
Programs that wish to construct figures with curving borders
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   928
generally use Bezier curves to form the borders.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   929
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   930
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   931
eg(examples.testbezier)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   932
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   933
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   934
A Bezier curve is specified by four control points 
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   935
$(x1,y1)$, $(x2,y2)$, $(x3,y3)$, $(x4,y4)$.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   936
The curve starts at $(x1,y1)$ and ends at $(x4,y4)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   937
and the line segment from $(x1,y1)$ to $(x2,y2)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   938
and the line segment from $(x3,y3)$ to $(x4,y4)$
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   939
both form tangents to the curve.  Furthermore the
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   940
curve is entirely contained in the convex figure with vertices
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   941
at the control points.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   942
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   943
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   944
illust(examples.bezier, "basic bezier curves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   945
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   946
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   947
The drawing above (the output of $testbezier$) shows
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   948
a bezier curves, the tangent lines defined by the control points
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   949
and the convex figure with vertices at the control points.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   950
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   951
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   952
heading3("Smoothly joining bezier curve sequences")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   953
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   954
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   955
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
   956
single smooth curve.  To construct a larger smooth curve from
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   957
several bezier curves make sure that the tangent lines to adjacent
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   958
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
   959
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   960
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   961
eg(examples.testbezier2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   962
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   963
disc("""
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   964
The figure created by $testbezier2$ describes a smooth
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   965
complex curve because adjacent tangent lines "line up" as
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   966
illustrated below.
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   967
""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   968
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   969
illust(examples.bezier2, "bezier curves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   970
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   971
heading2("Path object methods")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   972
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   973
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   974
Path objects build complex graphical figures by setting
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   975
the "pen" or "brush" at a start point on the canvas and drawing
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   976
lines or curves to additional points on the canvas.  Most operations
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   977
apply paint on the canvas starting at the end point of the last
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   978
operation and leave the brush at a new end point.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   979
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   980
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   981
eg("""pathobject.moveTo(x,y)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   982
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   983
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   984
The $moveTo$ method lifts the brush (ending any current sequence
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   985
of lines or curves if there is one) and replaces the brush at the
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   986
new ^(x,y)^ location on the canvas to start a new path sequence.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   987
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   988
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   989
eg("""pathobject.lineTo(x,y)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   990
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   991
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   992
The $lineTo$ method paints straight line segment from the current brush
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   993
location to the new ^(x,y)^ location.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   994
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   995
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   996
eg("""pathobject.curveTo(x1, y1, x2, y2, x3, y3) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
   997
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   998
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
   999
The $curveTo$ method starts painting a Bezier curve beginning at
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1000
the current brush location, using ^(x1,y1)^, ^(x2,y2)^, and ^(x3,y3)^
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1001
as the other three control points, leaving the brush on ^(x3,y3)^.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1002
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1003
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1004
eg("""pathobject.arc(x1,y1, x2,y2, startAng=0, extent=90) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1005
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1006
eg("""pathobject.arcTo(x1,y1, x2,y2, startAng=0, extent=90) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1007
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1008
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1009
The $arc$ and $arcTo$ methods paint partial ellipses.  The $arc$ method first "lifts the brush"
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1010
and starts a new shape sequence.  The $arcTo$ method joins the start of 
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1011
the partial ellipse to the current
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1012
shape sequence by line segment before drawing the partial ellipse.  The points
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1013
^(x1,y1)^ and ^(x2,y2)^ define opposite corner points of a rectangle enclosing
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1014
the ellipse.  The $startAng$ is an angle (in degrees) specifying where to begin
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1015
the partial ellipse where the 0 angle is the midpoint of the right border of the enclosing
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1016
rectangle (when ^(x1,y1)^ is the lower left corner and ^(x2,y2)^ is the upper
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1017
right corner).  The $extent$ is the angle in degrees to traverse on the ellipse.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1018
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1019
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1020
eg(examples.testarcs)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1021
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1022
disc("""The $arcs$ function above exercises the two partial ellipse methods.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1023
It produces the following drawing.""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1024
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1025
illust(examples.arcs, "arcs in path objects")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1026
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1027
eg("""pathobject.rect(x, y, width, height) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1028
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1029
disc("""The $rect$ method draws a rectangle with lower left corner
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1030
at ^(x,y)^ of the specified ^width^ and ^height^.""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1031
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1032
eg("""pathobject.ellipse(x, y, width, height)""")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1033
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1034
disc("""The $ellipse$ method
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1035
draws an ellipse enclosed in the rectange with lower left corner
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1036
at ^(x,y)^ of the specified ^width^ and ^height^.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1037
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1038
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1039
eg("""pathobject.circle(x_cen, y_cen, r) """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1040
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1041
disc("""The $circle$ method
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1042
draws a circle centered at ^(x_cen, y_cen)^ with radius ^r^.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1043
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1044
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1045
eg(examples.testvariousshapes)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1046
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1047
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1048
The $variousshapes$ function above shows a rectangle, circle and ellipse
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1049
placed in a frame of reference grid.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1050
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1051
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1052
illust(examples.variousshapes, "rectangles, circles, ellipses in path objects")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1053
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1054
eg("""pathobject.close() """)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1055
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1056
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1057
The $close$ method closes the current graphical figure
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1058
by painting a line segment from the last point of the figure
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1059
to the starting point of the figure (the the most
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1060
recent point where the brush was placed on the paper by $moveTo$
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1061
or $arc$ or other placement operations).
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1062
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1063
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1064
eg(examples.testclosingfigures)
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1065
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1066
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1067
The $closingfigures$ function illustrates the
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1068
effect of closing or not closing figures including a line
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1069
segment and a partial ellipse.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1070
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1071
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1072
illust(examples.closingfigures, "closing and not closing pathobject figures")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1073
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1074
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1075
Closing or not closing graphical figures effects only the stroked outline
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1076
of a figure, not the filling of the figure as illustrated above.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1077
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1078
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1079
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1080
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1081
For a more extensive example of drawing using a path object
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1082
examine the $hand$ function.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1083
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1084
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1085
eg(examples.testhand)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1086
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1087
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1088
In debug mode (the default) the $hand$ function shows the tangent line segments
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1089
to the bezier curves used to compose the figure.  Note that where the segments
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1090
line up the curves join smoothly, but where they do not line up the curves show
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1091
a "sharp edge".
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1092
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1093
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1094
illust(examples.hand, "an outline of a hand using bezier curves")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1095
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1096
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1097
Used in non-debug mode the $hand$ function only shows the
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1098
Bezier curves.  With the $fill$ parameter set the figure is
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1099
filled using the current fill color.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1100
""")
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1101
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1102
eg(examples.testhand2)
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1103
364
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1104
disc("""
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1105
Note that the "stroking" of the border draws over the interior fill where
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1106
they overlap.
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1107
""")
21f5c8641230 more text, more pdfgen examples
aaron_watters
parents: 352
diff changeset
  1108
341
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1109
illust(examples.hand2, "the finished hand, filled")
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1110
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1111
27c68d524504 Broke up the user guide into chapters.
andy_robinson
parents:
diff changeset
  1112
##### FILL THEM IN