src/reportlab/graphics/testshapes.py
author robin
Thu, 24 Oct 2019 16:07:15 +0100
changeset 4551 d357e2acc856
parent 4528 e09377955af8
child 4567 5612ef8ef0a8
permissions -rw-r--r--
improve usage of eval/exec; version --> 3.5.32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
     1
#!/bin/env python
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4303
diff changeset
     2
#Copyright ReportLab Europe Ltd. 2000-2017
817
8c3a399effda License text changes
rgbecker
parents: 590
diff changeset
     3
#see license.txt for license details
4528
e09377955af8 try to eliminate changed bitbucket.org references
robin
parents: 4370
diff changeset
     4
#history https://hg.reportlab.com/hg-public/reportlab/log/tip/src/reportlab/graphics/testshapes.py
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
     5
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
     6
# testshapes.py - draws shapes onto a PDF canvas.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
     7
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2977
diff changeset
     8
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2977
diff changeset
     9
__version__ = ''' $Id $ '''
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2977
diff changeset
    10
__doc__='''Execute this script to see some test drawings.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    11
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    12
This contains a number of routines to generate test drawings
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    13
for reportlab/graphics.  For now many of them are contrived,
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    14
but we will expand them to try and trip up any parser.
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    15
Feel free to add more.
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2977
diff changeset
    16
'''
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    17
4303
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
    18
import os, sys, base64
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    19
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    20
from reportlab.lib import colors
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    21
from reportlab.lib.units import cm
3987
15e61bdd4aa5 testshapes.py: fix sample texts
robin
parents: 3975
diff changeset
    22
from reportlab.lib.utils import asNative
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    23
from reportlab.pdfgen.canvas import Canvas
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    24
from reportlab.pdfbase.pdfmetrics import stringWidth
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    25
from reportlab.platypus import Flowable
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    26
from reportlab.graphics.shapes import *
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    27
from reportlab.graphics.renderPDF import _PDFRenderer
2207
6271525c4f68 Allow for bad fonts in getDrawing13
rgbecker
parents: 2184
diff changeset
    28
import unittest
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    29
3368
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    30
_FONTS = ['Times-Roman','Vera','Times-BoldItalic',]
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    31
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    32
def _setup():
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    33
    from reportlab.pdfbase import pdfmetrics, ttfonts
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    34
    pdfmetrics.registerFont(ttfonts.TTFont("Vera", "Vera.ttf"))
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    35
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBd", "VeraBd.ttf"))
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    36
    pdfmetrics.registerFont(ttfonts.TTFont("VeraIt", "VeraIt.ttf"))
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    37
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBI", "VeraBI.ttf"))
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    38
    F = ['Times-Roman','Courier','Helvetica','Vera', 'VeraBd', 'VeraIt', 'VeraBI']
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    39
    if sys.platform=='win32':
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    40
        for name, ttf in [
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    41
            ('Adventurer Light SF','Advlit.ttf'),('ArialMS','ARIAL.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    42
            ('Arial Unicode MS', 'ARIALUNI.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    43
            ('Book Antiqua','BKANT.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    44
            ('Century Gothic','GOTHIC.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    45
            ('Comic Sans MS', 'COMIC.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    46
            ('Elementary Heavy SF Bold','Vwagh.ttf'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    47
            ('Firenze SF','flot.ttf'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    48
            ('Garamond','GARA.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    49
            ('Jagger','Rols.ttf'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    50
            ('Monotype Corsiva','MTCORSVA.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    51
            ('Seabird SF','seag.ttf'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    52
            ('Tahoma','TAHOMA.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    53
            ('VerdanaMS','VERDANA.TTF'),
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    54
            ]:
4302
f3ff56a22b2e bump version --> 3.3.25
robin
parents: 4252
diff changeset
    55
            for D in (r'c:\WINNT',r'c:\Windows'):
3368
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    56
                fn = os.path.join(D,'Fonts',ttf)
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    57
                if os.path.isfile(fn):
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    58
                    try:
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    59
                        f = ttfonts.TTFont(name, fn)
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    60
                        pdfmetrics.registerFont(f)
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    61
                        F.append(name)
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    62
                    except:
afa025c34493 reportlab: new base font mechanism more fully applied
rgbecker
parents: 3115
diff changeset
    63
                        pass
3502
b2c9927314fc color fixes
rgbecker
parents: 3372
diff changeset
    64
    return F
b2c9927314fc color fixes
rgbecker
parents: 3372
diff changeset
    65
3637
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    66
def resetFonts():
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    67
    for f in _setup():
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    68
        if f not in _FONTS:
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    69
            _FONTS.append(f)
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    70
from reportlab.rl_config import register_reset
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    71
register_reset(resetFonts)
d9cc2ec146df fixes to testshapes & pdfform resetting contributed by Stephan Richter <srichter@cosmos.phy.tufts.edu>
rgbecker
parents: 3617
diff changeset
    72
resetFonts()
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    73
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    74
#########################################################
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    75
#
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    76
#   Collections of shape drawings.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    77
#
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
    78
#########################################################
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    79
def getFailedDrawing(funcName):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    80
    """Generate a drawing in case something goes really wrong.
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    81
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    82
    This will create a drawing to be displayed whenever some
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    83
    other drawing could not be executed, because the generating
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    84
    function does something terribly wrong! The box contains
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    85
    an attention triangle, plus some error message.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    86
    """
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    87
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    88
    D = Drawing(400, 200)
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    89
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    90
    points = [200,170, 140,80, 260,80]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    91
    D.add(Polygon(points,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    92
                  strokeWidth=0.5*cm,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    93
                  strokeColor=colors.red,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    94
                  fillColor=colors.yellow))
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
    95
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    96
    s = String(200, 40,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    97
               "Error in generating function '%s'!" % funcName,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    98
               textAnchor='middle')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
    99
    D.add(s)
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   100
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   101
    return D
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   102
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   103
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   104
# These are the real drawings to be eye-balled.
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   105
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   106
def getDrawing01():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   107
    """Hello World, on a rectangular background.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   108
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   109
    The rectangle's fillColor is yellow.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   110
    The string's fillColor is red.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   111
    """
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   112
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   113
    D = Drawing(400, 200)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   114
    D.add(Rect(50, 50, 300, 100, fillColor=colors.yellow))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   115
    D.add(String(180,100, 'Hello World', fillColor=colors.red))
3987
15e61bdd4aa5 testshapes.py: fix sample texts
robin
parents: 3975
diff changeset
   116
    D.add(String(180,86, b'Special characters \xc2\xa2\xc2\xa9\xc2\xae\xc2\xa3\xce\xb1\xce\xb2', fillColor=colors.red))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   117
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   118
    return D
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   119
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   120
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   121
def getDrawing02():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   122
    """Various Line shapes.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   123
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   124
    The lines are blue and their strokeWidth is 5 mm.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   125
    One line has a strokeDashArray set to [5, 10, 15].
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   126
    """
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   127
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   128
    D = Drawing(400, 200)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   129
    D.add(Line(50,50, 300,100,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   130
               strokeColor=colors.blue,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   131
               strokeWidth=0.5*cm,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   132
               ))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   133
    D.add(Line(50,100, 300,50,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   134
               strokeColor=colors.blue,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   135
               strokeWidth=0.5*cm,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   136
               strokeDashArray=[5, 10, 15],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   137
               ))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   138
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   139
    #x = 1/0 # Comment this to see the actual drawing!
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   140
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   141
    return D
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   142
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   143
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   144
def getDrawing03():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   145
    """Text strings in various sizes and different fonts.
578
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   146
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   147
    Font size increases from 12 to 36 and from bottom left
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   148
    to upper right corner.  The first ones should be in
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   149
    Times-Roman.  Finally, a solitary Courier string at
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   150
    the top right corner.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   151
    """
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   152
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   153
    D = Drawing(400, 200)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   154
    for size in range(12, 36, 4):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   155
        D.add(String(10+size*2,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   156
                     10+size*2,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   157
                     'Hello World',
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   158
                     fontName=_FONTS[0],
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   159
                     fontSize=size))
578
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   160
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   161
    D.add(String(150, 150,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   162
                 'Hello World',
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   163
                 fontName=_FONTS[1],
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   164
                 fontSize=36))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   165
    return D
578
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   166
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   167
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   168
def getDrawing04():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   169
    """Text strings in various colours.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   170
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   171
    Colours are blue, yellow and red from bottom left
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   172
    to upper right.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   173
    """
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   174
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   175
    D = Drawing(400, 200)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   176
    i = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   177
    for color in (colors.blue, colors.yellow, colors.red):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   178
        D.add(String(50+i*30, 50+i*30,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   179
                     'Hello World', fillColor=color))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   180
        i = i + 1
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   181
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   182
    return D
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   183
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   184
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   185
def getDrawing05():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   186
    """Text strings with various anchors (alignments).
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   187
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   188
    Text alignment conforms to the anchors in the left column.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   189
    """
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   190
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   191
    D = Drawing(400, 200)
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   192
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   193
    lineX = 250
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   194
    D.add(Line(lineX,10, lineX,190, strokeColor=colors.gray))
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   195
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   196
    y = 130
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   197
    for anchor in ('start', 'middle', 'end'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   198
        D.add(String(lineX, y, 'Hello World', textAnchor=anchor))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   199
        D.add(String(50, y, anchor + ':'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   200
        y = y - 30
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   201
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   202
    return D
576
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   203
ff0d6f4de1b8 Added some String shapes.
dinu_gherman
parents: 575
diff changeset
   204
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   205
def getDrawing06():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   206
    """This demonstrates all the basic shapes at once.
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   207
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   208
    There are no groups or references.
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   209
    Each solid shape should have a green fill.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   210
    """
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   211
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   212
    green = colors.green
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   213
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   214
    D = Drawing(400, 200) #, fillColor=green)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   215
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   216
    D.add(Line(10,10, 390,190))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   217
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   218
    D.add(Circle(100,100,20, fillColor=green))
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   219
    D.add(Circle(200,100,40, fillColor=green))
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   220
    D.add(Circle(300,100,30, fillColor=green))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   221
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   222
    D.add(Wedge(330,100,40, -10,40, fillColor=green))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   223
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   224
    D.add(PolyLine([120,10, 130,20, 140,10, 150,20, 160,10,
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   225
                    170,20, 180,10, 190,20, 200,10], fillColor=green))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   226
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   227
    D.add(Polygon([300,20, 350,20, 390,80, 300,75, 330,40], fillColor=green))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   228
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   229
    D.add(Ellipse(50,150, 40, 20, fillColor=green))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   230
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   231
    D.add(Rect(120,150, 60,30,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   232
               strokeWidth=10,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   233
               strokeColor=colors.yellow,
3115
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   234
               fillColor=green))  #square corners
049d6a82b49a renderSVG.py: add a unit (px) to fontSizes following suggestion by PJACock
rgbecker
parents: 3066
diff changeset
   235
    D.add(Rect(220, 150, 60, 30, 10, 10, fillColor=green))  #round corners
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   236
3372
f7e0bd8a7e70 testshapes.py: fix drawing 06
rgbecker
parents: 3368
diff changeset
   237
    D.add(String(10,50, 'Basic Shapes', fillColor=colors.black, fontName='Helvetica'))
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   238
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   239
    return D
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   240
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   241
def getDrawing07():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   242
    """This tests the ability to translate and rotate groups.  The first set of axes should be
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   243
    near the bottom left of the drawing.  The second should be rotated counterclockwise
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   244
    by 15 degrees.  The third should be rotated by 30 degrees."""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   245
    D = Drawing(400, 200)
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   246
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   247
    Axis = Group(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   248
        Line(0,0,100,0), #x axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   249
        Line(0,0,0,50),   # y axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   250
        Line(0,10,10,10), #ticks on y axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   251
        Line(0,20,10,20),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   252
        Line(0,30,10,30),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   253
        Line(0,40,10,40),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   254
        Line(10,0,10,10), #ticks on x axis
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   255
        Line(20,0,20,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   256
        Line(30,0,30,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   257
        Line(40,0,40,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   258
        Line(50,0,50,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   259
        Line(60,0,60,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   260
        Line(70,0,70,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   261
        Line(80,0,80,10),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   262
        Line(90,0,90,10),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   263
        String(20, 35, 'Axes', fill=colors.black)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   264
        )
578
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   265
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   266
    firstAxisGroup = Group(Axis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   267
    firstAxisGroup.translate(10,10)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   268
    D.add(firstAxisGroup)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   269
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   270
    secondAxisGroup = Group(Axis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   271
    secondAxisGroup.translate(150,10)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   272
    secondAxisGroup.rotate(15)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   273
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   274
    D.add(secondAxisGroup)
578
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   275
f797bf806ee5 Added group tests, fixed font bug, resynched with Dinu
andy_robinson
parents: 577
diff changeset
   276
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   277
    thirdAxisGroup = Group(Axis, transform=mmult(translate(300,10), rotate(30)))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   278
    D.add(thirdAxisGroup)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   279
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   280
    return D
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   281
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   282
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   283
def getDrawing08():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   284
    """This tests the ability to scale coordinates. The bottom left set of axes should be
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   285
    near the bottom left of the drawing.  The bottom right should be stretched vertically
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   286
    by a factor of 2.  The top left one should be stretched horizontally by a factor of 2.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   287
    The top right should have the vertical axiss leaning over to the right by 30 degrees."""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   288
    D = Drawing(400, 200)
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   289
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   290
    Axis = Group(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   291
        Line(0,0,100,0), #x axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   292
        Line(0,0,0,50),   # y axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   293
        Line(0,10,10,10), #ticks on y axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   294
        Line(0,20,10,20),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   295
        Line(0,30,10,30),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   296
        Line(0,40,10,40),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   297
        Line(10,0,10,10), #ticks on x axis
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   298
        Line(20,0,20,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   299
        Line(30,0,30,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   300
        Line(40,0,40,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   301
        Line(50,0,50,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   302
        Line(60,0,60,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   303
        Line(70,0,70,10),
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   304
        Line(80,0,80,10),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   305
        Line(90,0,90,10),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   306
        String(20, 35, 'Axes', fill=colors.black)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   307
        )
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   308
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   309
    firstAxisGroup = Group(Axis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   310
    firstAxisGroup.translate(10,10)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   311
    D.add(firstAxisGroup)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   312
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   313
    secondAxisGroup = Group(Axis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   314
    secondAxisGroup.translate(150,10)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   315
    secondAxisGroup.scale(1,2)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   316
    D.add(secondAxisGroup)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   317
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   318
    thirdAxisGroup = Group(Axis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   319
    thirdAxisGroup.translate(10,125)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   320
    thirdAxisGroup.scale(2,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   321
    D.add(thirdAxisGroup)
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   322
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   323
    fourthAxisGroup = Group(Axis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   324
    fourthAxisGroup.translate(250,125)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   325
    fourthAxisGroup.skew(30,0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   326
    D.add(fourthAxisGroup)
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   327
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   328
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   329
    return D
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   330
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   331
def getDrawing09():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   332
    """This tests rotated strings
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   333
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   334
    Some renderers will have a separate mechanism for font drawing.  This test
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   335
    just makes sure strings get transformed the same way as regular graphics."""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   336
    D = Drawing(400, 200)
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   337
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   338
    fontName = _FONTS[0]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   339
    fontSize = 12
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   340
    text = "I should be totally horizontal and enclosed in a box"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   341
    textWidth = stringWidth(text, fontName, fontSize)
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   342
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   343
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   344
    g1 = Group(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   345
            String(20, 20, text, fontName=fontName, fontSize = fontSize),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   346
            Rect(18, 18, textWidth + 4, fontSize + 4, fillColor=None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   347
            )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   348
    D.add(g1)
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   349
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   350
    text = "I should slope up by 15 degrees, so my right end is higher than my left"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   351
    textWidth = stringWidth(text, fontName, fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   352
    g2 = Group(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   353
            String(20, 20, text, fontName=fontName, fontSize = fontSize),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   354
            Rect(18, 18, textWidth + 4, fontSize + 4, fillColor=None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   355
            )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   356
    g2.translate(0, 50)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   357
    g2.rotate(15)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   358
    D.add(g2)
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   359
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   360
    return D
580
62e61180ae41 Added postscript renderer and tests, fixed renderer bugs
andy_robinson
parents: 578
diff changeset
   361
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   362
def getDrawing10():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   363
    """This tests nested groups with multiple levels of coordinate transformation.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   364
    Each box should be staggered up and to the right, moving by 25 points each time."""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   365
    D = Drawing(400, 200)
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   366
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   367
    fontName = _FONTS[0]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   368
    fontSize = 12
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   369
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   370
    g1 = Group(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   371
            Rect(0, 0, 100, 20, fillColor=colors.yellow),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   372
            String(5, 5, 'Text in the box', fontName=fontName, fontSize = fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   373
            )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   374
    D.add(g1)
587
5ae563fe5235 Fixed group transform bug and added tests
andy_robinson
parents: 585
diff changeset
   375
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   376
    g2 = Group(g1, transform = translate(25,25))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   377
    D.add(g2)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   378
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   379
    g3 = Group(g2, transform = translate(25,25))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   380
    D.add(g3)
590
03d231a6765d Working on chart framework
andy_robinson
parents: 587
diff changeset
   381
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   382
    g4 = Group(g3, transform = translate(25,25))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   383
    D.add(g4)
590
03d231a6765d Working on chart framework
andy_robinson
parents: 587
diff changeset
   384
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   385
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   386
    return D
585
e0144950b3e2 Fixes to CTM to support bitmap renderer; extra string rotation
andy_robinson
parents: 580
diff changeset
   387
3975
4a3599863c11 eliminate from . imports in favour of absolutes to allow running modules
robin
parents: 3721
diff changeset
   388
from reportlab.graphics.widgets.signsandsymbols import SmileyFace
817
8c3a399effda License text changes
rgbecker
parents: 590
diff changeset
   389
def getDrawing11():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   390
    '''test of anchoring'''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   391
    def makeSmiley(x, y, size, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   392
        "Make a smiley data item representation."
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   393
        d = size
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   394
        s = SmileyFace()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   395
        s.fillColor = color
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   396
        s.x = x-d
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   397
        s.y = y-d
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   398
        s.size = d*2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   399
        return s
817
8c3a399effda License text changes
rgbecker
parents: 590
diff changeset
   400
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   401
    D = Drawing(400, 200) #, fillColor=colors.purple)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   402
    g = Group(transform=(1,0,0,1,0,0))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   403
    g.add(makeSmiley(100,100,10,colors.red))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   404
    g.add(Line(90,100,110,100,strokeColor=colors.green))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   405
    g.add(Line(100,90,100,110,strokeColor=colors.green))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   406
    D.add(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   407
    g = Group(transform=(2,0,0,2,100,-100))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   408
    g.add(makeSmiley(100,100,10,colors.blue))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   409
    g.add(Line(90,100,110,100,strokeColor=colors.green))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   410
    g.add(Line(100,90,100,110,strokeColor=colors.green))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   411
    D.add(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   412
    g = Group(transform=(2,0,0,2,0,0))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   413
    return D
817
8c3a399effda License text changes
rgbecker
parents: 590
diff changeset
   414
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   415
1445
5b53cd8bd2ef Added Paul Winkler's font test
rgbecker
parents: 1240
diff changeset
   416
def getDrawing12():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   417
    """Text strings in a non-standard font.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   418
    All that is required is to place the .afm and .pfb files
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   419
    on the font patch given in rl_config.py,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   420
    for example in reportlab/lib/fonts/.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   421
    """
2977
beca8d75f400 reportlab: remove LetErrorRobot-Chrome, rina & luxi. Add DarkGardenMK and fix tests
rgbecker
parents: 2964
diff changeset
   422
    faceName = "DarkGardenMK"
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   423
    D = Drawing(400, 200)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   424
    for size in range(12, 36, 4):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   425
        D.add(String(10+size*2,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   426
                     10+size*2,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   427
                     'Hello World',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   428
                     fontName=faceName,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   429
                     fontSize=size))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   430
    return D
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   431
2143
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   432
def getDrawing13():
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   433
    'Test Various TTF Fonts'
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   434
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   435
    def drawit(F,w=400,h=200,fontSize=12,slack=2,gap=5):
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   436
        D = Drawing(w,h)
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   437
        th = 2*gap + fontSize*1.2
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   438
        gh = gap + .2*fontSize
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   439
        y = h
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   440
        maxx = 0
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   441
        for fontName in F:
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   442
            y -= th
3987
15e61bdd4aa5 testshapes.py: fix sample texts
robin
parents: 3975
diff changeset
   443
            text = fontName+asNative(b': I should be totally horizontal and enclosed in a box and end in alphabetagamma \xc2\xa2\xc2\xa9\xc2\xae\xc2\xa3\xca\xa5\xd0\x96\xd6\x83\xd7\x90\xd9\x82\xe0\xa6\x95\xce\xb1\xce\xb2\xce\xb3')
2143
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   444
            textWidth = stringWidth(text, fontName, fontSize)
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   445
            maxx = max(maxx,textWidth+20)
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   446
            D.add(
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   447
                Group(Rect(8, y-gh, textWidth + 4, th, strokeColor=colors.red, strokeWidth=.5, fillColor=colors.lightgrey),
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   448
                    String(10, y, text, fontName=fontName, fontSize = fontSize)))
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   449
            y -= 5
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   450
        return maxx, h-y+gap, D
3502
b2c9927314fc color fixes
rgbecker
parents: 3372
diff changeset
   451
    maxx, maxy, D = drawit(_FONTS)
b2c9927314fc color fixes
rgbecker
parents: 3372
diff changeset
   452
    if maxx>400 or maxy>200: _,_,D = drawit(_FONTS,maxx,maxy)
2143
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   453
    return D
5d4b69337969 move drawing 13 to testshapes
rgbecker
parents: 2112
diff changeset
   454
4303
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   455
def smallArrow():
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   456
    '''create a small PIL image'''
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   457
    from reportlab.graphics.renderPM import _getImage
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   458
    from reportlab.lib.utils import getBytesIO
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   459
    b = base64.decodestring(b'''R0lGODdhCgAHAIMAAP/////29v/d3f+ysv9/f/9VVf9MTP8iIv8ICP8AAAAAAAAAAAAAAAAAAAAA
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   460
AAAAACwAAAAACgAHAAAIMwABCBxIsKABAQASFli4MAECAgEAJJhIceKBAQkyasx4YECBjx8TICAQ
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   461
AIDJkwYEAFgZEAA7''')
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   462
    return _getImage().open(getBytesIO(b))
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   463
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   464
def getDrawing14():
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   465
    '''test shapes.Image'''
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   466
    from reportlab.graphics.shapes import Image
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   467
    D = Drawing(400, 200)
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   468
    im0 = smallArrow()
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   469
    D.add(Image(x=0,y=0,width=None,height=None,path=im0))
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   470
    im1 = smallArrow()
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   471
    D.add(Image(x=400-20,y=200-14,width=20,height=14,path=im1))
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   472
    return D
1dbe6269e831 improved support for images in renderPM/renderSVG bug report from Claude Paroz; version --> 3.3.26
robin
parents: 4302
diff changeset
   473
2184
928f35c56a19 Attempt to control ttf usage
rgbecker
parents: 2143
diff changeset
   474
def getAllFunctionDrawingNames(doTTF=1):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   475
    "Get a list of drawing function names from somewhere."
1445
5b53cd8bd2ef Added Paul Winkler's font test
rgbecker
parents: 1240
diff changeset
   476
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   477
    funcNames = []
1445
5b53cd8bd2ef Added Paul Winkler's font test
rgbecker
parents: 1240
diff changeset
   478
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   479
    # Here we get the names from the global name space.
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   480
    symbols = list(globals().keys())
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   481
    symbols.sort()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   482
    for funcName in symbols:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   483
        if funcName[0:10] == 'getDrawing':
2184
928f35c56a19 Attempt to control ttf usage
rgbecker
parents: 2143
diff changeset
   484
            if doTTF or funcName!='getDrawing13':
928f35c56a19 Attempt to control ttf usage
rgbecker
parents: 2143
diff changeset
   485
                funcNames.append(funcName)
1445
5b53cd8bd2ef Added Paul Winkler's font test
rgbecker
parents: 1240
diff changeset
   486
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   487
    return funcNames
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   488
960
91add7248c5f Added locals & globals to the eval
rgbecker
parents: 939
diff changeset
   489
def _evalFuncDrawing(name, D, l=None, g=None):
4551
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4528
diff changeset
   490
    if g is None: g = globals()
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4528
diff changeset
   491
    if l is None: l = locals()
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4528
diff changeset
   492
    func = l.get(name,g.get(name,None))
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2547
diff changeset
   493
    try:
4551
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4528
diff changeset
   494
        d = func()
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2547
diff changeset
   495
    except:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2547
diff changeset
   496
        d = getFailedDrawing(name)
4551
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4528
diff changeset
   497
    D.append((d, getattr(func,'.__doc__',''), name[3:]))
939
cebd2d1df445 Improvements to testshapse.py
rgbecker
parents: 892
diff changeset
   498
2184
928f35c56a19 Attempt to control ttf usage
rgbecker
parents: 2143
diff changeset
   499
def getAllTestDrawings(doTTF=1):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   500
    D = []
2184
928f35c56a19 Attempt to control ttf usage
rgbecker
parents: 2143
diff changeset
   501
    for f in getAllFunctionDrawingNames(doTTF=doTTF):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   502
        _evalFuncDrawing(f,D)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   503
    return D
939
cebd2d1df445 Improvements to testshapse.py
rgbecker
parents: 892
diff changeset
   504
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   505
def writePDF(drawings):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   506
    "Create and save a PDF file containing some drawings."
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   507
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   508
    pdfPath = os.path.splitext(sys.argv[0])[0] + '.pdf'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   509
    c = Canvas(pdfPath)
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   510
    c.setFont(_FONTS[0], 32)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   511
    c.drawString(80, 750, 'ReportLab Graphics-Shapes Test')
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   512
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   513
    # Print drawings in a loop, with their doc strings.
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   514
    c.setFont(_FONTS[0], 12)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   515
    y = 740
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   516
    i = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   517
    for (drawing, docstring, funcname) in drawings:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   518
        if y < 300:  # Allows 5-6 lines of text.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   519
            c.showPage()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   520
            y = 740
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   521
        # Draw a title.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   522
        y = y - 30
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   523
        c.setFont(_FONTS[2],12)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   524
        c.drawString(80, y, '%s (#%d)' % (funcname, i))
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   525
        c.setFont(_FONTS[0],12)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   526
        y = y - 14
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   527
        textObj = c.beginText(80, y)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   528
        textObj.textLines(docstring)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   529
        c.drawText(textObj)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   530
        y = textObj.getY()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   531
        y = y - drawing.height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   532
        drawing.drawOn(c, 80, y)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   533
        i = i + 1
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   534
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   535
    c.save()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3637
diff changeset
   536
    print('wrote %s ' % pdfPath)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   537
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   538
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   539
class ShapesTestCase(unittest.TestCase):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   540
    "Test generating all kinds of shapes."
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   541
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   542
    def setUp(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   543
        "Prepare some things before the tests start."
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   544
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   545
        self.funcNames = getAllFunctionDrawingNames()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   546
        self.drawings = []
575
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   547
5fcd7ec22f20 Initial checkin.
dinu_gherman
parents:
diff changeset
   548
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   549
    def tearDown(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   550
        "Do what has to be done after the tests are over."
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   551
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   552
        writePDF(self.drawings)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   553
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   554
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   555
    # This should always succeed. If each drawing would be
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   556
    # wrapped in a dedicated test method like this one, it
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   557
    # would be possible to have a count for wrong tests
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   558
    # as well... Something like this is left for later...
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   559
    def testAllDrawings(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   560
        "Make a list of drawings."
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   561
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   562
        for f in self.funcNames:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   563
            if f[0:10] == 'getDrawing':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   564
                # Make an instance and get its doc string.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   565
                # If that fails, use a default error drawing.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   566
                _evalFuncDrawing(f,self.drawings)
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   567
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   568
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   569
def makeSuite():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   570
    "Make a test suite for unit testing."
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   571
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   572
    suite = unittest.TestSuite()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   573
    suite.addTest(ShapesTestCase('testAllDrawings'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1445
diff changeset
   574
    return suite
577
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   575
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   576
4b3dd4eeb0e1 Added unit testing plus error drawing.
dinu_gherman
parents: 576
diff changeset
   577
if __name__ == "__main__":
2112
8281bbabfd67 Added _FONTS
rgbecker
parents: 1683
diff changeset
   578
    unittest.TextTestRunner().run(makeSuite())