src/reportlab/graphics/barcode/test.py
author robin
Thu, 24 Oct 2019 16:07:15 +0100
changeset 4551 d357e2acc856
parent 4294 55c8019c775e
permissions -rw-r--r--
improve usage of eval/exec; version --> 3.5.32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     1
#!/usr/pkg/bin/python
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     2
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     3
import os, sys, time
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     4
4551
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4294
diff changeset
     5
from reportlab import Version as __RL_Version__
2592
fd998519b2ed barcode: fix to import from reportlab
rgbecker
parents: 2587
diff changeset
     6
from reportlab.graphics.barcode.common import *
fd998519b2ed barcode: fix to import from reportlab
rgbecker
parents: 2587
diff changeset
     7
from reportlab.graphics.barcode.code39 import *
fd998519b2ed barcode: fix to import from reportlab
rgbecker
parents: 2587
diff changeset
     8
from reportlab.graphics.barcode.code93 import *
fd998519b2ed barcode: fix to import from reportlab
rgbecker
parents: 2587
diff changeset
     9
from reportlab.graphics.barcode.code128 import *
fd998519b2ed barcode: fix to import from reportlab
rgbecker
parents: 2587
diff changeset
    10
from reportlab.graphics.barcode.usps import *
2674
c398c40b66f4 usps4s.py: working fourstate
rgbecker
parents: 2592
diff changeset
    11
from reportlab.graphics.barcode.usps4s import USPS_4State
4224
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
    12
from reportlab.graphics.barcode.qr import QrCodeWidget
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    13
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    14
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    15
from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle, Preformatted, PageBreak
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    16
from reportlab.lib.units import inch, cm
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    17
from reportlab.lib import colors
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    18
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    19
from reportlab.pdfgen.canvas import Canvas
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    20
from reportlab.lib.styles import getSampleStyleSheet
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    21
from reportlab.platypus.paragraph import Paragraph
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    22
from reportlab.platypus.frames import Frame
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    23
from reportlab.platypus.flowables import XBox, KeepTogether
4224
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
    24
from reportlab.graphics.shapes import Drawing, Rect, Line
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    25
3669
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
    26
from reportlab.graphics.barcode import getCodes, getCodeNames, createBarcodeDrawing, createBarcodeImageInMemory
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    27
def run():
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    28
    styles = getSampleStyleSheet()
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    29
    styleN = styles['Normal']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    30
    styleH = styles['Heading1']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    31
    story = []
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    32
    storyAdd = story.append
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    33
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    34
    #for codeNames in code
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    35
    storyAdd(Paragraph('I2of5', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    36
    storyAdd(I2of5(1234, barWidth = inch*0.02, checksum=0))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    37
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    38
    storyAdd(Paragraph('MSI', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    39
    storyAdd(MSI(1234))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    40
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    41
    storyAdd(Paragraph('Codabar', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    42
    storyAdd(Codabar("A012345B", barWidth = inch*0.02))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    43
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    44
    storyAdd(Paragraph('Code 11', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    45
    storyAdd(Code11("01234545634563"))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    46
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    47
    storyAdd(Paragraph('Code 39', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    48
    storyAdd(Standard39("A012345B%R"))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    49
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    50
    storyAdd(Paragraph('Extended Code 39', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    51
    storyAdd(Extended39("A012345B}"))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    52
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    53
    storyAdd(Paragraph('Code93', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    54
    storyAdd(Standard93("CODE 93"))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    55
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    56
    storyAdd(Paragraph('Extended Code93', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    57
    storyAdd(Extended93("L@@K! Code 93 :-)")) #, barWidth=0.005 * inch))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    58
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    59
    storyAdd(Paragraph('Code 128', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    60
    storyAdd(Code128("AB-12345678"))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    61
4235
bc4e916892fd add barcode contributions from Kyle MacFarlane @ bitbucket; version -->3.2.10
robin
parents: 4224
diff changeset
    62
    storyAdd(Paragraph('Code 128 Auto', styleN))
bc4e916892fd add barcode contributions from Kyle MacFarlane @ bitbucket; version -->3.2.10
robin
parents: 4224
diff changeset
    63
    storyAdd(Code128Auto("AB-12345678"))
bc4e916892fd add barcode contributions from Kyle MacFarlane @ bitbucket; version -->3.2.10
robin
parents: 4224
diff changeset
    64
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    65
    storyAdd(Paragraph('USPS FIM', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    66
    storyAdd(FIM("A"))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    67
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    68
    storyAdd(Paragraph('USPS POSTNET', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    69
    storyAdd(POSTNET('78247-1043'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    70
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    71
    storyAdd(Paragraph('USPS 4 State', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    72
    storyAdd(USPS_4State('01234567094987654321','01234567891'))
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    73
2592
fd998519b2ed barcode: fix to import from reportlab
rgbecker
parents: 2587
diff changeset
    74
    from reportlab.graphics.barcode import createBarcodeDrawing
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    75
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    76
    storyAdd(Paragraph('EAN13', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    77
    storyAdd(createBarcodeDrawing('EAN13', value='123456789012'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    78
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    79
    storyAdd(Paragraph('EAN13 quiet=False', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    80
    storyAdd(createBarcodeDrawing('EAN13', value='123456789012', quiet=False))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    81
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    82
    storyAdd(Paragraph('EAN8', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    83
    storyAdd(createBarcodeDrawing('EAN8', value='1234567'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    84
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    85
    storyAdd(PageBreak())
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    86
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    87
    storyAdd(Paragraph('EAN5 price=True', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    88
    storyAdd(createBarcodeDrawing('EAN5', value='11299', price=True))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    89
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    90
    storyAdd(Paragraph('EAN5 price=True quiet=False', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    91
    storyAdd(createBarcodeDrawing('EAN5', value='11299', price=True, quiet=False))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    92
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    93
    storyAdd(Paragraph('EAN5 price=False', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    94
    storyAdd(createBarcodeDrawing('EAN5', value='11299', price=False))
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    95
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    96
    storyAdd(Paragraph('ISBN alone', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    97
    storyAdd(createBarcodeDrawing('ISBN', value='9781565924796'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    98
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
    99
    storyAdd(Paragraph('ISBN  with ean5 price', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   100
    storyAdd(createBarcodeDrawing('ISBN', value='9781565924796',price='01299'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   101
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   102
    storyAdd(Paragraph('ISBN  with ean5 price, quiet=False', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   103
    storyAdd(createBarcodeDrawing('ISBN', value='9781565924796',price='01299',quiet=False))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   104
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   105
    storyAdd(Paragraph('UPCA', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   106
    storyAdd(createBarcodeDrawing('UPCA', value='03600029145'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   107
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   108
    storyAdd(Paragraph('USPS_4State', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   109
    storyAdd(createBarcodeDrawing('USPS_4State', value='01234567094987654321',routing='01234567891'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   110
4224
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   111
    storyAdd(Paragraph('QR', styleN))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   112
    storyAdd(createBarcodeDrawing('QR', value='01234567094987654321'))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   113
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   114
    storyAdd(Paragraph('QR', styleN))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   115
    storyAdd(createBarcodeDrawing('QR', value='01234567094987654321',x=30,y=50))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   116
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   117
    storyAdd(Paragraph('QR in drawing at (0,0)', styleN))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   118
    d = Drawing(100,100)
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   119
    d.add(Rect(0,0,100,100,strokeWidth=1,strokeColor=colors.red,fillColor=None))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   120
    d.add(QrCodeWidget(value='01234567094987654321'))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   121
    storyAdd(d)
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   122
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   123
    storyAdd(Paragraph('QR in drawing at (10,10)', styleN))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   124
    d = Drawing(100,100)
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   125
    d.add(Rect(0,0,100,100,strokeWidth=1,strokeColor=colors.red,fillColor=None))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   126
    d.add(Line(7.5,10,12.5,10,strokeWidth=0.5,strokeColor=colors.blue))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   127
    d.add(Line(10,7.5, 10, 12.5,strokeWidth=0.5,strokeColor=colors.blue))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   128
    d.add(QrCodeWidget(value='01234567094987654321',x=10,y=10))
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   129
    storyAdd(d)
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   130
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   131
    storyAdd(Paragraph('Label Size', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   132
    storyAdd(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"'))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   133
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   134
    storyAdd(Paragraph('Label Size', styleN))
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   135
    storyAdd(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"'))
4224
f5326e699996 attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents: 4222
diff changeset
   136
    
4222
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   137
760cfe8a8b27 fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents: 3721
diff changeset
   138
    SimpleDocTemplate('out.pdf').build(story)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3669
diff changeset
   139
    print('saved out.pdf')
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   140
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   141
def fullTest(fileName="test_full.pdf"):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   142
    """Creates large-ish test document with a variety of parameters"""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   143
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   144
    story = []
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   145
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   146
    styles = getSampleStyleSheet()
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   147
    styleN = styles['Normal']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   148
    styleH = styles['Heading1']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   149
    styleH2 = styles['Heading2']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   150
    story = []
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   151
4551
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4294
diff changeset
   152
    story.append(Paragraph('ReportLab %s Barcode Test Suite - full output' % __RL_Version__,styleH))
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4294
diff changeset
   153
    story.append(Paragraph('Generated at %s' % time.ctime(time.time()), styleN))
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   154
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   155
    story.append(Paragraph('About this document', styleH2))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   156
    story.append(Paragraph('History and Status', styleH2))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   157
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   158
    story.append(Paragraph("""
4551
d357e2acc856 improve usage of eval/exec; version --> 3.5.32
robin
parents: 4294
diff changeset
   159
        This is the test suite and docoumentation for the ReportLab open source barcode API.
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   160
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   161
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   162
    story.append(Paragraph("""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   163
        Several years ago Ty Sarna contributed a barcode module to the ReportLab community.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   164
        Several of the codes were used by him in hiw work and to the best of our knowledge
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   165
        this was correct.  These were written as flowable objects and were available in PDFs,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   166
        but not in our graphics framework.  However, we had no knowledge of barcodes ourselves
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   167
        and did not advertise or extend the package.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   168
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   169
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   170
    story.append(Paragraph("""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   171
        We "wrapped" the barcodes to be usable within our graphics framework; they are now available
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   172
        as Drawing objects which can be rendered to EPS files or bitmaps.  For the last 2 years this
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   173
        has been available in our Diagra and Report Markup Language products.  However, we did not
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   174
        charge separately and use was on an "as is" basis.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   175
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   176
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   177
    story.append(Paragraph("""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   178
        A major licensee of our technology has kindly agreed to part-fund proper productisation
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   179
        of this code on an open source basis in Q1 2006.  This has involved addition of EAN codes
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   180
        as well as a proper testing program.  Henceforth we intend to publicise the code more widely,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   181
        gather feedback, accept contributions of code and treat it as "supported".  
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   182
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   183
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   184
    story.append(Paragraph("""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   185
        This involved making available both downloads and testing resources.  This PDF document
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   186
        is the output of the current test suite.  It contains codes you can scan (if you use a nice sharp
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   187
        laser printer!), and will be extended over coming weeks to include usage examples and notes on
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   188
        each barcode and how widely tested they are.  This is being done through documentation strings in
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   189
        the barcode objects themselves so should always be up to date.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   190
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   191
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   192
    story.append(Paragraph('Usage examples', styleH2))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   193
    story.append(Paragraph("""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   194
        To be completed
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   195
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   196
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   197
    story.append(Paragraph('The codes', styleH2))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   198
    story.append(Paragraph("""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   199
        Below we show a scannable code from each barcode, with and without human-readable text.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   200
        These are magnified about 2x from the natural size done by the original author to aid
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   201
        inspection.  This will be expanded to include several test cases per code, and to add
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   202
        explanations of checksums.  Be aware that (a) if you enter numeric codes which are too
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   203
        short they may be prefixed for you (e.g. "123" for an 8-digit code becomes "00000123"),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   204
        and that the scanned results and readable text will generally include extra checksums
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   205
        at the end.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   206
        """, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   207
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   208
    codeNames = getCodeNames()
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   209
    from reportlab.lib.utils import flatten
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   210
    width = [float(x[8:]) for x in sys.argv if x.startswith('--width=')]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   211
    height = [float(x[9:]) for x in sys.argv if x.startswith('--height=')]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   212
    isoScale = [int(x[11:]) for x in sys.argv if x.startswith('--isoscale=')]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   213
    options = {}
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   214
    if width: options['width'] = width[0]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   215
    if height: options['height'] = height[0]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   216
    if isoScale: options['isoScale'] = isoScale[0]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   217
    scales = [x[8:].split(',') for x in sys.argv if x.startswith('--scale=')]
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3669
diff changeset
   218
    scales = list(map(float,scales and flatten(scales) or [1]))
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3669
diff changeset
   219
    scales = list(map(float,scales and flatten(scales) or [1]))
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   220
    for scale in scales:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   221
        story.append(PageBreak())
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   222
        story.append(Paragraph('Scale = %.1f'%scale, styleH2))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   223
        story.append(Spacer(36, 12))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   224
        for codeName in codeNames:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   225
            s = [Paragraph('Code: ' + codeName, styleH2)]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   226
            for hr in (0,1):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   227
                s.append(Spacer(36, 12))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   228
                dr = createBarcodeDrawing(codeName, humanReadable=hr,**options)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   229
                dr.renderScale = scale
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   230
                s.append(dr)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   231
                s.append(Spacer(36, 12))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   232
            s.append(Paragraph('Barcode should say: ' + dr._bc.value, styleN))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   233
            story.append(KeepTogether(s))
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   234
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   235
    SimpleDocTemplate(fileName).build(story)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3669
diff changeset
   236
    print('created', fileName)
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   237
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   238
if __name__=='__main__':
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   239
    run()
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   240
    fullTest()
3669
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   241
    def createSample(name,memory):
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   242
        f = open(name,'wb')
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   243
        f.write(memory)
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   244
        f.close()
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   245
    createSample('test_cbcim.png',createBarcodeImageInMemory('EAN13', value='123456789012'))
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   246
    createSample('test_cbcim.gif',createBarcodeImageInMemory('EAN8', value='1234567', format='gif'))
4294
55c8019c775e added additonal test to barcode/test.py
robin
parents: 4235
diff changeset
   247
    createSample('test_cbcim.pdf',createBarcodeImageInMemory('UPCA', value='03600029145',format='pdf', barHeight=40))
3669
40848d552920 fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents: 3502
diff changeset
   248
    createSample('test_cbcim.tiff',createBarcodeImageInMemory('USPS_4State', value='01234567094987654321',routing='01234567891',format='tiff'))