author | rgbecker |
Tue, 15 Feb 2000 15:47:10 +0000 | |
changeset 6 | eb791971b252 |
parent 5 | 5e321293413b |
child 7 | ca9eb4f68eab |
--- a/reportlab/README.pdfgen.txt Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/README.pdfgen.txt Tue Feb 15 15:47:10 2000 +0000 @@ -1,25 +1,25 @@ -Unpack pdfgen.zip to some directory, say d:\ReportLab. - -Create a .pth file, say platypus.pth in your Python -home directory. It should have one line: -d:/ReportLab - -Then pdfbase, pdfgen and platypus are available packages. - -Modifying existing code to work with the package structure: - -import pdfmetrics -> from pdfbase import pdfmetrics -import pdfutils -> from pdfbase import pdfutils -import pdfdoc -> from pdfbase import pdfdoc - -import pdfgeom -> from pdfgen import pdfgeom - -import pdfgen -> from pdfgen import canvas - -> from pdfgen import pathobject - -> from pdfgen import textobject - # then pdfgen.Canvas -> canvas.Canvas - # pdfgen.PDFPathObject -> pathobject.PDFPathObject - # pdfgen.PDFTextObject -> textobject.PDFTextObject - -import platypus -> from platypus import layout - from platypus import tables \ No newline at end of file +Unpack pdfgen.zip to some directory, say d:\ReportLab. + +Create a .pth file, say platypus.pth in your Python +home directory. It should have one line: +d:/ReportLab + +Then pdfbase, pdfgen and platypus are available packages. + +Modifying existing code to work with the package structure: + +import pdfmetrics -> from pdfbase import pdfmetrics +import pdfutils -> from pdfbase import pdfutils +import pdfdoc -> from pdfbase import pdfdoc + +import pdfgeom -> from pdfgen import pdfgeom + +import pdfgen -> from pdfgen import canvas + -> from pdfgen import pathobject + -> from pdfgen import textobject + # then pdfgen.Canvas -> canvas.Canvas + # pdfgen.PDFPathObject -> pathobject.PDFPathObject + # pdfgen.PDFTextObject -> textobject.PDFTextObject + +import platypus -> from platypus import layout + from platypus import tables
--- a/reportlab/pdfbase/__init__.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfbase/__init__.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,1 +1,37 @@ -#dummy +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: __init__.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: __init__.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ '''
--- a/reportlab/pdfbase/pdfdoc.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfbase/pdfdoc.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,4 +1,40 @@ -#pdfdoc.py +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: pdfdoc.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: pdfdoc.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' """ PDFgen is a library to generate PDF files containing text and graphics. It is the foundation for a complete reporting solution in Python. @@ -10,8 +46,6 @@ pdfgen.py calls this and provides a 'canvas' object to handle page marking operators. piddlePDF calls pdfgen and offers a high-level interface. -(C) Copyright Andy Robinson 1998-1999 - 2000-10-13 gmcm Packagize """
--- a/reportlab/pdfbase/pdfmetrics.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfbase/pdfmetrics.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,4 +1,40 @@ -#fontmetrics.py - part of PDFgen - copyright Andy Robinson 1999 +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: pdfmetrics.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: pdfmetrics.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' """This contains pre-canned text metrics for the PDFgen package, and may also be used for any other PIDDLE back ends or packages which use the standard Type 1 postscript fonts. @@ -19,9 +55,6 @@ (with the proper Postscript capitalisation) to ascents and descents. I ought to sort out the fontname case issue and the resolution of PIDDLE fonts to Postscript font names within this module, but have not yet done so. - - -13th June 1999 """ import string
--- a/reportlab/pdfbase/pdfutils.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfbase/pdfutils.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,3 +1,40 @@ +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: pdfutils.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: pdfutils.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' # pdfutils.py - everything to do with images, streams, # compression, and some constants
--- a/reportlab/pdfgen/__init__.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfgen/__init__.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,1 +1,37 @@ -#dummy +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: __init__.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: __init__.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ '''
--- a/reportlab/pdfgen/canvas.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfgen/canvas.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,4 +1,40 @@ -#pdfgen.py +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: canvas.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: canvas.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' """ PDFgen is a library to generate PDF files containing text and graphics. It is the foundation for a complete reporting solution in Python. It is also the @@ -7,31 +43,12 @@ Documentation is a little slim right now; run then look at testpdfgen.py to get a clue. ----------- Licence Terms (same as the Python license) ----------------- -(C) Copyright Robinson Analytics 1998-1999. - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, provided -that the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation, and that the name of Robinson Analytics not be used -in advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ROBINSON ANALYTICS LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, -IN NO EVENT SHALL ROBINSON ANALYTICS BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -Progress Reports: -8.83, 2000-01-13, gmcm: - Packagizing: - renamed from pdfgen.py to canvas.py - broke out PDFTextObject to textobject.py - broke out PDFPathObject to pathobject.py +Progress Reports: +8.83, 2000-01-13, gmcm: + Packagizing: + renamed from pdfgen.py to canvas.py + broke out PDFTextObject to textobject.py + broke out PDFPathObject to pathobject.py placed all three in a package directory named pdfgen 0.82, 1999-10-27, AR: Fixed some bugs on printing to Postscript. Added 'Text Object' @@ -45,8 +62,6 @@ Adding RoundRect; changed all format strings to use %0.2f instead of %s, so we don't get exponentials in the output. 0.8,1999-10-07, AR: all changed! - - """ ## 0.81 1999-10-13: ## @@ -64,8 +79,8 @@ from pdfbase import pdfutils from pdfbase import pdfdoc from pdfbase import pdfmetrics -import pdfgeom -import pathobject +import pdfgeom +import pathobject import textobject # Robert Kern
--- a/reportlab/pdfgen/pathobject.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfgen/pathobject.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,34 +1,51 @@ -#pathobject.py +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: pathobject.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: pathobject.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' """ -PDFPathObject is an efficient way to draw paths on a Canvas. Do not -instantiate directly, obtain one from the Canvas instead. - ----------- Licence Terms (same as the Python license) ----------------- -(C) Copyright Robinson Analytics 1998-1999. - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, provided -that the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation, and that the name of Robinson Analytics not be used -in advertising or publicity pertaining to distribution of the software -without specific, written prior permission. +PDFPathObject is an efficient way to draw paths on a Canvas. Do not +instantiate directly, obtain one from the Canvas instead. -ROBINSON ANALYTICS LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, -IN NO EVENT SHALL ROBINSON ANALYTICS BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. +Progress Reports: +8.83, 2000-01-13, gmcm: + created from pdfgen.py +""" +import string +import pdfgeom -Progress Reports: -8.83, 2000-01-13, gmcm: - created from pdfgen.py -""" -import string -import pdfgeom - class PDFPathObject: """Represents a graphic path. There are certain 'modes' to PDF drawing, and making a separate object to expose Path operations
--- a/reportlab/pdfgen/pdfgeom.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfgen/pdfgeom.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,4 +1,40 @@ -# pdfgeom.py +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: pdfgeom.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: pdfgeom.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' """ This module includes any mathematical methods needed for PIDDLE. It should have no dependencies beyond the Python library.
--- a/reportlab/pdfgen/test/testpdfgen.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfgen/test/testpdfgen.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,3 +1,41 @@ +#!/bin/env python +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: testpdfgen.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: testpdfgen.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' #tests and documents new low-level canvas import string from pdfgen import canvas # gmcm 2000/10/13, pdfgen now a package @@ -573,4 +611,4 @@ d.draw(c, inch, 9 * inch) if __name__ == "__main__": - run() \ No newline at end of file + run()
--- a/reportlab/pdfgen/textobject.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/pdfgen/textobject.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,33 +1,50 @@ -#textobject.py +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: textobject.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: textobject.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' """ -PDFTextObject is an efficient way to add text to a Canvas. Do not -instantiate directly, obtain one from the Canvas instead. - ----------- Licence Terms (same as the Python license) ----------------- -(C) Copyright Robinson Analytics 1998-1999. +PDFTextObject is an efficient way to add text to a Canvas. Do not +instantiate directly, obtain one from the Canvas instead. -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, provided -that the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation, and that the name of Robinson Analytics not be used -in advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -ROBINSON ANALYTICS LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, -IN NO EVENT SHALL ROBINSON ANALYTICS BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -Progress Reports: -8.83, 2000-01-13, gmcm: - created from pdfgen.py -""" +Progress Reports: +8.83, 2000-01-13, gmcm: + created from pdfgen.py +""" import string -from types import * +from types import * class PDFTextObject: """PDF logically separates text and graphics drawing; you can @@ -200,4 +217,4 @@ else: self._y = self._y + self._leading self._x = self._x0 - \ No newline at end of file +
--- a/reportlab/platypus/__init__.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/platypus/__init__.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,1 +1,38 @@ -#dummy +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: __init__.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: __init__.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' +
--- a/reportlab/platypus/layout.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/platypus/layout.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,14 +1,46 @@ +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: layout.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: layout.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' #platypus - Page Layout And TYPography Using Scripts - # a page layout API on top of PDFgen -# copyright Robinson Analytics 1999 -# under the terms of the Python license. +#currently working on paragraph wrapping stuff. - -#currently working on paragraph wrapping stuff. - -# 200-10-13 gmcm -# packagizing +# 200-10-13 gmcm +# packagizing # rewrote grid stuff - now in tables.py import string @@ -120,8 +152,8 @@ 'rightPadding':6, 'topPadding':3, 'bottomPadding':3, - 'firstLineIndent':0, - 'color':(1,1,1), + 'firstLineIndent':0, + 'color':(1,1,1), 'alignment': 'LEFT', } @@ -135,7 +167,7 @@ print pPre = ParagraphStyle('Literal', pNormal) pPre.fontName = 'Courier' - pPre.listAttrs() + pPre.listAttrs() return pNormal, pPre def getSampleStyleSheet(): @@ -565,171 +597,171 @@ self.drawWidth, self.drawHeight ) -## -##class BaseGrid(Drawable): -## """Base class for all further grids. Currently -## just lays out the lines. Every table is created -## with a list of column and row sizes, and drawn -## at a given x and y coordinate. The assumption -## is that you know the size and number of rows -## before you start, and never change it - this is -## for printing after all.""" -## #inherit from Drawable when I am reunited with my code -## -## def __init__(self, colWidths, rowHeights): -## assert len(colWidths) > 1, "Must have at least 1 column width" -## assert len(rowHeights) > 1, "Must have at least 1 row height" -## -## #user specifies top row height first, but we want reverse order - fix -## tmp = list(rowHeights) -## tmp.reverse() -## rowHeights = tuple(tmp) -## -## #work out width and height, and keep the x and y lines handy -## self._height = 0 -## self._horzLines = [self._height] -## for h in rowHeights: -## self._height = self._height + h -## self._horzLines.append(self._height) -## self._horzLines.reverse() -## -## self._width = 0 -## self._vertLines = [self._width] -## for w in colWidths: -## self._width = self._width + w -## self._vertLines.append(self._width) -## -## self._rowHeights = rowHeights -## self._colWidths = colWidths -## self._rows = len(self._rowHeights) -## self._cols = len(self._colWidths) -## self._right = self._width #obviously, since origin is (0,0), but -## self._top = self._height #makes some code clearer. -## -## def wrap(self, availWidth, availHeight): -## #nice and easy, since they are predetermined size -## self.availWidth = availWidth -## return (self._width, self._height) -## -## -## def draw(self): -## """Just does the basic grid in current line -## styles. Centre it in the frame for now""" -## nudge = 0.5 * (self.availWidth - self._width) -## self.canv.translate(nudge, 0) -## y = 0 -## self.canv.setLineWidth(0.1) -## self.canv.line(0, y, self._width, y) -## for dy in self._rowHeights: -## y = y + dy -## self.canv.line(0, y, self._width, y) -## -## x = 0 -## self.canv.line(x, 0, x, self._height) -## for dx in self._colWidths: -## x = x + dx -## self.canv.line(x, 0, x, self._height) -## -## -##class TextGrid(BaseGrid): -## """A TextGrid allows one string per (or object, which will -## be converted with str()) per cell. Each cell has a set of -## properties which may be set individually, and which draw the -## text. Prepare a matrix of your data and pass it to the -## constructor.""" -## def __init__(self, colWidths, rowHeights, data): -## BaseGrid.__init__(self, colWidths, rowHeights) -## -## #check the data is square and matches -## assert len(data) == len(rowHeights), "Data error - %d rows in data but %d in grid" % (len(data), len(self._rowHeights)) -## cols = len(colWidths) -## for i in range(len(data)): -## assert len(data[i]) == cols, "Not enough data points in row %d!" % i -## -## #OK, keep it -## self._data = data -## -## #keeping line properties for each segment would get complex, -## #so we keep a list of line drawing instructions -## self._lineSegments = [] -## -## #space to hold cell properties -## self._cellStyles = {} -## self._defaultCellStyle = CellStyle('<generic>') #make a style on the fly -## -## def addLines(self, col1, row1, col2, row2, width=1): -## """Adds line segments to be drawn later on. You may use negative -## indices for any number. The four coords you give specify a sub-grid -## within the main one which will be drawn as specified.""" -## -## # turn all args to positive numbers -## if col1 < 0: -## col1 = self._cols + 1 + col1 -## if row1 < 0: -## row1 = self._rows + 1 + row1 -## if col2 < 0: -## col2 = self._cols + 1 + col2 -## if row2 < 0: -## row2 = self._rows + 1 + row2 -## -## assert 0 <= col1 <= self._cols, "Illegal Column Index" -## assert 0 <= row1 <= self._rows, "Illegal Row Index" -## assert 0 <= col2 <= self._cols, "Illegal Column Index" -## assert 0 <= row2 <= self._rows, "Illegal Row Index" -## -## -## self._lineSegments.append(col1, row1, col2, row2, width) -## -## -## def draw(self): -## nudge = 0.5 * (self.availWidth - self._width) -## self.canv.translate(nudge, 0) -## self.drawLines() -## self.drawText() -## -## def drawLines(self): -## """Called by draw, does all the line segments""" -## for (col1, row1, col2, row2, width) in self._lineSegments: -## self.canv.setLineWidth(width) -## #work out the row and column coordinates -## -## #draw the verticals if there are any -## if row1 <> row2: -## for col in range(col1, col2+1): -## x1 = self._vertLines[col] -## y1 = self._horzLines[row1] -## x2 = self._vertLines[col] -## y2 = self._horzLines[row2] -## self.canv.line(x1, y1, x2, y2) -## -## #draw the horizontals if there are any -## if col1 <> col2: -## for row in range(row1, row2+1): -## x1 = self._vertLines[col1] -## y1 = self._horzLines[row] -## x2 = self._vertLines[col2] -## y2 = self._horzLines[row] -## self.canv.line(x1, y1, x2, y2) -## -## def getCellRect(self, col, row): -## """Returns the bounding rectangle for a cell""" -## left = self._vertLines[col] -## bottom = self._horzLines[row+1] -## right = self._vertLines[col+1] -## top = self._horzLines[row] -## return (left, bottom, right, top) -## -## -## def drawText(self): -## """Called by Draw, does the strings. No format options yet""" -## #cheat and pick a font -## self.canv.setFont('Times-Roman', 10, 12) -## -## for col in range(self._cols): -## for row in range(self._rows): -## (left, bottom, right, top) = self.getCellRect(col, row) -## self.canv.drawString(left+6, bottom + 3, str(self._data[row][col])) -## +## +##class BaseGrid(Drawable): +## """Base class for all further grids. Currently +## just lays out the lines. Every table is created +## with a list of column and row sizes, and drawn +## at a given x and y coordinate. The assumption +## is that you know the size and number of rows +## before you start, and never change it - this is +## for printing after all.""" +## #inherit from Drawable when I am reunited with my code +## +## def __init__(self, colWidths, rowHeights): +## assert len(colWidths) > 1, "Must have at least 1 column width" +## assert len(rowHeights) > 1, "Must have at least 1 row height" +## +## #user specifies top row height first, but we want reverse order - fix +## tmp = list(rowHeights) +## tmp.reverse() +## rowHeights = tuple(tmp) +## +## #work out width and height, and keep the x and y lines handy +## self._height = 0 +## self._horzLines = [self._height] +## for h in rowHeights: +## self._height = self._height + h +## self._horzLines.append(self._height) +## self._horzLines.reverse() +## +## self._width = 0 +## self._vertLines = [self._width] +## for w in colWidths: +## self._width = self._width + w +## self._vertLines.append(self._width) +## +## self._rowHeights = rowHeights +## self._colWidths = colWidths +## self._rows = len(self._rowHeights) +## self._cols = len(self._colWidths) +## self._right = self._width #obviously, since origin is (0,0), but +## self._top = self._height #makes some code clearer. +## +## def wrap(self, availWidth, availHeight): +## #nice and easy, since they are predetermined size +## self.availWidth = availWidth +## return (self._width, self._height) +## +## +## def draw(self): +## """Just does the basic grid in current line +## styles. Centre it in the frame for now""" +## nudge = 0.5 * (self.availWidth - self._width) +## self.canv.translate(nudge, 0) +## y = 0 +## self.canv.setLineWidth(0.1) +## self.canv.line(0, y, self._width, y) +## for dy in self._rowHeights: +## y = y + dy +## self.canv.line(0, y, self._width, y) +## +## x = 0 +## self.canv.line(x, 0, x, self._height) +## for dx in self._colWidths: +## x = x + dx +## self.canv.line(x, 0, x, self._height) +## +## +##class TextGrid(BaseGrid): +## """A TextGrid allows one string per (or object, which will +## be converted with str()) per cell. Each cell has a set of +## properties which may be set individually, and which draw the +## text. Prepare a matrix of your data and pass it to the +## constructor.""" +## def __init__(self, colWidths, rowHeights, data): +## BaseGrid.__init__(self, colWidths, rowHeights) +## +## #check the data is square and matches +## assert len(data) == len(rowHeights), "Data error - %d rows in data but %d in grid" % (len(data), len(self._rowHeights)) +## cols = len(colWidths) +## for i in range(len(data)): +## assert len(data[i]) == cols, "Not enough data points in row %d!" % i +## +## #OK, keep it +## self._data = data +## +## #keeping line properties for each segment would get complex, +## #so we keep a list of line drawing instructions +## self._lineSegments = [] +## +## #space to hold cell properties +## self._cellStyles = {} +## self._defaultCellStyle = CellStyle('<generic>') #make a style on the fly +## +## def addLines(self, col1, row1, col2, row2, width=1): +## """Adds line segments to be drawn later on. You may use negative +## indices for any number. The four coords you give specify a sub-grid +## within the main one which will be drawn as specified.""" +## +## # turn all args to positive numbers +## if col1 < 0: +## col1 = self._cols + 1 + col1 +## if row1 < 0: +## row1 = self._rows + 1 + row1 +## if col2 < 0: +## col2 = self._cols + 1 + col2 +## if row2 < 0: +## row2 = self._rows + 1 + row2 +## +## assert 0 <= col1 <= self._cols, "Illegal Column Index" +## assert 0 <= row1 <= self._rows, "Illegal Row Index" +## assert 0 <= col2 <= self._cols, "Illegal Column Index" +## assert 0 <= row2 <= self._rows, "Illegal Row Index" +## +## +## self._lineSegments.append(col1, row1, col2, row2, width) +## +## +## def draw(self): +## nudge = 0.5 * (self.availWidth - self._width) +## self.canv.translate(nudge, 0) +## self.drawLines() +## self.drawText() +## +## def drawLines(self): +## """Called by draw, does all the line segments""" +## for (col1, row1, col2, row2, width) in self._lineSegments: +## self.canv.setLineWidth(width) +## #work out the row and column coordinates +## +## #draw the verticals if there are any +## if row1 <> row2: +## for col in range(col1, col2+1): +## x1 = self._vertLines[col] +## y1 = self._horzLines[row1] +## x2 = self._vertLines[col] +## y2 = self._horzLines[row2] +## self.canv.line(x1, y1, x2, y2) +## +## #draw the horizontals if there are any +## if col1 <> col2: +## for row in range(row1, row2+1): +## x1 = self._vertLines[col1] +## y1 = self._horzLines[row] +## x2 = self._vertLines[col2] +## y2 = self._horzLines[row] +## self.canv.line(x1, y1, x2, y2) +## +## def getCellRect(self, col, row): +## """Returns the bounding rectangle for a cell""" +## left = self._vertLines[col] +## bottom = self._horzLines[row+1] +## right = self._vertLines[col+1] +## top = self._horzLines[row] +## return (left, bottom, right, top) +## +## +## def drawText(self): +## """Called by Draw, does the strings. No format options yet""" +## #cheat and pick a font +## self.canv.setFont('Times-Roman', 10, 12) +## +## for col in range(self._cols): +## for row in range(self._rows): +## (left, bottom, right, top) = self.getCellRect(col, row) +## self.canv.drawString(left+6, bottom + 3, str(self._data[row][col])) +## class Spacer(Drawable): """A spacer just takes up space and doesn't draw anything - it can ensure a gap between objects.""" @@ -1046,4 +1078,4 @@ if __name__ == '__main__': - run() \ No newline at end of file + run()
--- a/reportlab/platypus/tables.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/platypus/tables.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,13 +1,50 @@ -""" -Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in -row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the -color and weight of the lines (if any), and the font, alignment and padding of the text. -""" -import layout -import operator - -_stringtype = type('') - +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: tables.py,v $ +# Revision 1.2 2000/02/15 15:47:09 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: tables.py,v 1.2 2000/02/15 15:47:09 rgbecker Exp $ ''' +""" +Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in +row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the +color and weight of the lines (if any), and the font, alignment and padding of the text. +""" +import layout +import operator + +_stringtype = type('') + class CellStyle(layout.PropertySet): defaults = { 'fontname':'Times-Roman', @@ -17,432 +54,430 @@ 'rightPadding':6, 'topPadding':3, 'bottomPadding':3, - 'firstLineIndent':0, - 'color':(0,0,0), - 'alignment': 'LEFT', + 'firstLineIndent':0, + 'color':(0,0,0), + 'alignment': 'LEFT', 'background': (1,1,1), } - -class TableStyle: - def __init__(self, cmds=None): - self._cmds = cmds - if cmds is None: - self._cmds = [] - def add(self, *cmd): - self._cmds.append(cmd) - def getCommands(self): - return self._cmds - -class Table(layout.Drawable): - def __init__(self, colWidths, rowHeights, data): - if not colWidths: - raise ValueError, "Table must have at least 1 column" - if not rowHeights: - raise ValueError, "Table must have at least 1 row" - nrows = self._nrows = len(rowHeights) - if len(data) != nrows: - raise ValueError, "Data error - %d rows in data but %d in grid" % (len(data), nrows) - ncols = self._ncols = len(colWidths) - for i in range(nrows): - if len(data[i]) != ncols: - raise ValueError, "Not enough data points in row %d!" % i - self._rowHeights = rowHeights - self._colWidths = colWidths - self._cellvalues = data - dflt = CellStyle('<default>') - self._cellstyles = [None]*nrows - for i in range(nrows): - self._cellstyles[i] = [dflt]*ncols - self._bkgrndcmds = [] - self._linecmds = [] - height = self._height = reduce(operator.add, rowHeights, 0) - self._rowpositions = [height] # index 0 is actually topline; we skip when processing cells - for h in rowHeights: - height = height - h - self._rowpositions.append(height) - assert height == 0 - width = 0 - self._colpositions = [0] #index -1 is right side boundary; we skip when processing cells - for w in colWidths: - width = width + w - self._colpositions.append(width) - self._width = width + +class TableStyle: + def __init__(self, cmds=None): + self._cmds = cmds + if cmds is None: + self._cmds = [] + def add(self, *cmd): + self._cmds.append(cmd) + def getCommands(self): + return self._cmds + +class Table(layout.Drawable): + def __init__(self, colWidths, rowHeights, data): + if not colWidths: + raise ValueError, "Table must have at least 1 column" + if not rowHeights: + raise ValueError, "Table must have at least 1 row" + nrows = self._nrows = len(rowHeights) + if len(data) != nrows: + raise ValueError, "Data error - %d rows in data but %d in grid" % (len(data), nrows) + ncols = self._ncols = len(colWidths) + for i in range(nrows): + if len(data[i]) != ncols: + raise ValueError, "Not enough data points in row %d!" % i + self._rowHeights = rowHeights + self._colWidths = colWidths + self._cellvalues = data + dflt = CellStyle('<default>') + self._cellstyles = [None]*nrows + for i in range(nrows): + self._cellstyles[i] = [dflt]*ncols + self._bkgrndcmds = [] + self._linecmds = [] + height = self._height = reduce(operator.add, rowHeights, 0) + self._rowpositions = [height] # index 0 is actually topline; we skip when processing cells + for h in rowHeights: + height = height - h + self._rowpositions.append(height) + assert height == 0 + width = 0 + self._colpositions = [0] #index -1 is right side boundary; we skip when processing cells + for w in colWidths: + width = width + w + self._colpositions.append(width) + self._width = width self._curweight = self._curcolor = self._curcellstyle = None - - def setStyle(self, tblstyle): - for cmd in tblstyle.getCommands(): - if cmd[0] == 'BACKGROUND': - self._bkgrndcmds.append(cmd) - elif _isLineCommand(cmd): - self._linecmds.append(cmd) - else: - (op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:] - if sc < 0: sc = sc + self._ncols - if ec < 0: ec = ec + self._ncols - if sr < 0: sr = sr + self._nrows - if er < 0: er = er + self._nrows - for i in range(sr, er+1): - for j in range(sc, ec+1): - _setCellStyle(self._cellstyles, i, j, op, values) - - def _drawLines(self): - for op, (sc, sr), (ec, er), weight, color in self._linecmds: - if sc < 0: sc = sc + self._ncols - if ec < 0: ec = ec + self._ncols - if sr < 0: sr = sr + self._nrows - if er < 0: er = er + self._nrows - if op == 'GRID': - self._drawBox( (sc, sr), (ec, er), weight, color) - self._drawInnerGrid( (sc, sr), (ec, er), weight, color) - elif op in ('BOX', 'OUTLINE',): - self._drawBox( (sc, sr), (ec, er), weight, color) - elif op == 'INNERGRID': - self._drawInnerGrid( (sc, sr), (ec, er), weight, color) - elif op == 'LINEBELOW': - self._drawHLines((sc, sr+1), (ec, er+1), weight, color) - elif op == 'LINEABOVE': - self._drawHLines((sc, sr), (ec, er), weight, color) - elif op == 'LINEBEFORE': - self._drawVLines((sc, sr), (ec, er), weight, color) - elif op == 'LINEAFTER': - self._drawVLines((sc+1, sr), (ec+1, er), weight, color) - else: - raise ValueError, "Unknown line style %s" % op - self._curcolor = None - - def _drawBox(self, (sc, sr), (ec, er), weight, color): - self._drawHLines((sc, sr), (ec, sr), weight, color) - self._drawHLines((sc, er+1), (ec, er+1), weight, color) - self._drawVLines((sc, sr), (sc, er), weight, color) - self._drawVLines((ec+1, sr), (ec+1, er), weight, color) - def _drawInnerGrid(self, (sc, sr), (ec, er), weight, color): - self._drawHLines((sc, sr+1), (ec, er), weight, color) - self._drawVLines((sc+1, sr), (ec, er), weight, color) - def _prepLine(self, weight, color): - if type(color) is _stringtype: - color = COLORS.get(color, (0,0,0)) - if color != self._curcolor: - apply(self.canv.setStrokeColorRGB, color) - self._curcolor = color - if weight != self._curweight: - self.canv.setLineWidth(weight) - self._curweight = weight - def _drawHLines(self, (sc, sr), (ec, er), weight, color): - self._prepLine(weight, color) - scp = self._colpositions[sc] - ecp = self._colpositions[ec+1] - for rowpos in self._rowpositions[sr:er+1]: - self.canv.line(scp, rowpos, ecp, rowpos) - def _drawVLines(self, (sc, sr), (ec, er), weight, color): - self._prepLine(weight, color) - srp = self._rowpositions[sr] - erp = self._rowpositions[er+1] - for colpos in self._colpositions[sc:ec+1]: - self.canv.line(colpos, srp, colpos, erp) - + + def setStyle(self, tblstyle): + for cmd in tblstyle.getCommands(): + if cmd[0] == 'BACKGROUND': + self._bkgrndcmds.append(cmd) + elif _isLineCommand(cmd): + self._linecmds.append(cmd) + else: + (op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:] + if sc < 0: sc = sc + self._ncols + if ec < 0: ec = ec + self._ncols + if sr < 0: sr = sr + self._nrows + if er < 0: er = er + self._nrows + for i in range(sr, er+1): + for j in range(sc, ec+1): + _setCellStyle(self._cellstyles, i, j, op, values) + + def _drawLines(self): + for op, (sc, sr), (ec, er), weight, color in self._linecmds: + if sc < 0: sc = sc + self._ncols + if ec < 0: ec = ec + self._ncols + if sr < 0: sr = sr + self._nrows + if er < 0: er = er + self._nrows + if op == 'GRID': + self._drawBox( (sc, sr), (ec, er), weight, color) + self._drawInnerGrid( (sc, sr), (ec, er), weight, color) + elif op in ('BOX', 'OUTLINE',): + self._drawBox( (sc, sr), (ec, er), weight, color) + elif op == 'INNERGRID': + self._drawInnerGrid( (sc, sr), (ec, er), weight, color) + elif op == 'LINEBELOW': + self._drawHLines((sc, sr+1), (ec, er+1), weight, color) + elif op == 'LINEABOVE': + self._drawHLines((sc, sr), (ec, er), weight, color) + elif op == 'LINEBEFORE': + self._drawVLines((sc, sr), (ec, er), weight, color) + elif op == 'LINEAFTER': + self._drawVLines((sc+1, sr), (ec+1, er), weight, color) + else: + raise ValueError, "Unknown line style %s" % op + self._curcolor = None + + def _drawBox(self, (sc, sr), (ec, er), weight, color): + self._drawHLines((sc, sr), (ec, sr), weight, color) + self._drawHLines((sc, er+1), (ec, er+1), weight, color) + self._drawVLines((sc, sr), (sc, er), weight, color) + self._drawVLines((ec+1, sr), (ec+1, er), weight, color) + def _drawInnerGrid(self, (sc, sr), (ec, er), weight, color): + self._drawHLines((sc, sr+1), (ec, er), weight, color) + self._drawVLines((sc+1, sr), (ec, er), weight, color) + def _prepLine(self, weight, color): + if type(color) is _stringtype: + color = COLORS.get(color, (0,0,0)) + if color != self._curcolor: + apply(self.canv.setStrokeColorRGB, color) + self._curcolor = color + if weight != self._curweight: + self.canv.setLineWidth(weight) + self._curweight = weight + def _drawHLines(self, (sc, sr), (ec, er), weight, color): + self._prepLine(weight, color) + scp = self._colpositions[sc] + ecp = self._colpositions[ec+1] + for rowpos in self._rowpositions[sr:er+1]: + self.canv.line(scp, rowpos, ecp, rowpos) + def _drawVLines(self, (sc, sr), (ec, er), weight, color): + self._prepLine(weight, color) + srp = self._rowpositions[sr] + erp = self._rowpositions[er+1] + for colpos in self._colpositions[sc:ec+1]: + self.canv.line(colpos, srp, colpos, erp) + def wrap(self, availWidth, availHeight): #nice and easy, since they are predetermined size self.availWidth = availWidth return (self._width, self._height) - + def draw(self): nudge = 0.5 * (self.availWidth - self._width) - self.canv.translate(nudge, 0) - self._drawBkgrnd() + self.canv.translate(nudge, 0) + self._drawBkgrnd() self._drawLines() - for row, rowstyle, rowpos, rowheight in map(None, self._cellvalues, self._cellstyles, self._rowpositions[1:], self._rowHeights): - for cellval, cellstyle, colpos, colwidth in map(None, row, rowstyle, self._colpositions[:-1], self._colWidths): - self._drawCell(cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)) - - def _drawBkgrnd(self): - for cmd, (sc, sr), (ec, er), color in self._bkgrndcmds: - if sc < 0: sc = sc + self._ncols - if ec < 0: ec = ec + self._ncols - if sr < 0: sr = sr + self._nrows - if er < 0: er = er + self._nrows - if type(color) is _stringtype: - color = COLORS.get(values[0], (1,1,1)) - x0 = self._colpositions[sc] - y0 = self._rowpositions[sr] - x1 = self._colpositions[ec+1] - y1 = self._rowpositions[er+1] - apply(self.canv.setFillColorRGB, color) - self.canv.rect(x0, y0, x1-x0, y1-y0,stroke=0,fill=1) - def _drawCell(self, cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)): - #print "cellstyle is ", repr(cellstyle), id(cellstyle) - if self._curcellstyle is not cellstyle: - cur = self._curcellstyle - if cur is None or cellstyle.color != cur.color: - #print "setting cell color to %s" % `cellstyle.color` - apply(self.canv.setFillColorRGB, cellstyle.color) - if cur is None or cellstyle.leading != cur.leading or cellstyle.fontname != cur.fontname or cellstyle.fontsize != cur.fontsize: - #print "setting font: %s, %s, %s" % (cellstyle.fontname, cellstyle.fontsize, cellstyle.leading) - self.canv.setFont(cellstyle.fontname, cellstyle.fontsize, cellstyle.leading) - self._curcellstyle = cellstyle - just = cellstyle.alignment - #print "alignment is ", just - if just == 'LEFT': - draw = self.canv.drawString - x = colpos + cellstyle.leftPadding - elif just in ('CENTRE', 'CENTER'): - draw = self.canv.drawCentredString - x = colpos + colwidth * 0.5 - else: - draw = self.canv.drawRightString - x = colpos + colwidth - cellstyle.rightPadding - y = rowpos + cellstyle.bottomPadding - if type(cellval) is _stringtype: - val = cellval - else: - val = str(cellval) - draw(x, y, val) - -# for text, -# drawCentredString(self, x, y, text) where x is center -# drawRightString(self, x, y, text) where x is right -# drawString(self, x, y, text) where x is left - -LINECOMMANDS = ( - 'GRID', 'BOX', 'OUTLINE', 'INNERGRID', 'LINEBELOW', 'LINEABOVE', 'LINEBEFORE', 'LINEAFTER', ) - -COLORS = { - 'BLACK': (0,0,0), - 'RED': (1,0,0), - 'GREEN': (0,1,0), - 'BLUE': (0,0,1), - 'WHITE':(1,1,1), - } - -def _isLineCommand(cmd): - return cmd[0] in LINECOMMANDS - -def _setCellStyle(cellstyles, i, j, op, values): - new = CellStyle('<%d, %d>' % (i,j), cellstyles[i][j]) - cellstyles[i][j] = new - if op == 'FONT': - new.fontname = values[0] - new.fontsize = values[1] - elif op == 'TEXTCOLOR': - if type(values[0]) is _stringtype: - new.color = COLORS.get(values[0], (0,0,0)) - else: - new.color = values[0] - elif op in ('ALIGN', 'ALIGNMENT'): - new.alignment = values[0] - elif op == 'LEFTPADDING': - new.leftPadding = values[0] - elif op == 'RIGHTPADDING': - new.rightPadding = values[0] - elif op == 'TOPPADDING': - new.topPadding = values[0] - elif op == 'BOTTOMPADDING': - new.bottomPadding = values[0] - -GRID_STYLE = TableStyle( - [('GRID', (0,0), (-1,-1), 0.25, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) -BOX_STYLE = TableStyle( - [('BOX', (0,0), (-1,-1), 0.50, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) -LABELED_GRID_STYLE = TableStyle( - [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), - ('BOX', (0,0), (-1,-1), 2, 'BLACK'), - ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), - ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) -COLORED_GRID_STYLE = TableStyle( - [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), - ('BOX', (0,0), (-1,-1), 2, 'RED'), - ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), - ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) -LIST_STYLE = TableStyle( - [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), - ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), - ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) - -def test(): - rowheights = (24, 16, 16, 16, 16) - colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) - data = ( - ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), - ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), - ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), - ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), - ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') - ) + for row, rowstyle, rowpos, rowheight in map(None, self._cellvalues, self._cellstyles, self._rowpositions[1:], self._rowHeights): + for cellval, cellstyle, colpos, colwidth in map(None, row, rowstyle, self._colpositions[:-1], self._colWidths): + self._drawCell(cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)) + + def _drawBkgrnd(self): + for cmd, (sc, sr), (ec, er), color in self._bkgrndcmds: + if sc < 0: sc = sc + self._ncols + if ec < 0: ec = ec + self._ncols + if sr < 0: sr = sr + self._nrows + if er < 0: er = er + self._nrows + if type(color) is _stringtype: + color = COLORS.get(values[0], (1,1,1)) + x0 = self._colpositions[sc] + y0 = self._rowpositions[sr] + x1 = self._colpositions[ec+1] + y1 = self._rowpositions[er+1] + apply(self.canv.setFillColorRGB, color) + self.canv.rect(x0, y0, x1-x0, y1-y0,stroke=0,fill=1) + def _drawCell(self, cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)): + #print "cellstyle is ", repr(cellstyle), id(cellstyle) + if self._curcellstyle is not cellstyle: + cur = self._curcellstyle + if cur is None or cellstyle.color != cur.color: + #print "setting cell color to %s" % `cellstyle.color` + apply(self.canv.setFillColorRGB, cellstyle.color) + if cur is None or cellstyle.leading != cur.leading or cellstyle.fontname != cur.fontname or cellstyle.fontsize != cur.fontsize: + #print "setting font: %s, %s, %s" % (cellstyle.fontname, cellstyle.fontsize, cellstyle.leading) + self.canv.setFont(cellstyle.fontname, cellstyle.fontsize, cellstyle.leading) + self._curcellstyle = cellstyle + just = cellstyle.alignment + #print "alignment is ", just + if just == 'LEFT': + draw = self.canv.drawString + x = colpos + cellstyle.leftPadding + elif just in ('CENTRE', 'CENTER'): + draw = self.canv.drawCentredString + x = colpos + colwidth * 0.5 + else: + draw = self.canv.drawRightString + x = colpos + colwidth - cellstyle.rightPadding + y = rowpos + cellstyle.bottomPadding + if type(cellval) is _stringtype: + val = cellval + else: + val = str(cellval) + draw(x, y, val) + +# for text, +# drawCentredString(self, x, y, text) where x is center +# drawRightString(self, x, y, text) where x is right +# drawString(self, x, y, text) where x is left + +LINECOMMANDS = ( + 'GRID', 'BOX', 'OUTLINE', 'INNERGRID', 'LINEBELOW', 'LINEABOVE', 'LINEBEFORE', 'LINEAFTER', ) + +COLORS = { + 'BLACK': (0,0,0), + 'RED': (1,0,0), + 'GREEN': (0,1,0), + 'BLUE': (0,0,1), + 'WHITE':(1,1,1), + } + +def _isLineCommand(cmd): + return cmd[0] in LINECOMMANDS + +def _setCellStyle(cellstyles, i, j, op, values): + new = CellStyle('<%d, %d>' % (i,j), cellstyles[i][j]) + cellstyles[i][j] = new + if op == 'FONT': + new.fontname = values[0] + new.fontsize = values[1] + elif op == 'TEXTCOLOR': + if type(values[0]) is _stringtype: + new.color = COLORS.get(values[0], (0,0,0)) + else: + new.color = values[0] + elif op in ('ALIGN', 'ALIGNMENT'): + new.alignment = values[0] + elif op == 'LEFTPADDING': + new.leftPadding = values[0] + elif op == 'RIGHTPADDING': + new.rightPadding = values[0] + elif op == 'TOPPADDING': + new.topPadding = values[0] + elif op == 'BOTTOMPADDING': + new.bottomPadding = values[0] + +GRID_STYLE = TableStyle( + [('GRID', (0,0), (-1,-1), 0.25, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) +BOX_STYLE = TableStyle( + [('BOX', (0,0), (-1,-1), 0.50, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) +LABELED_GRID_STYLE = TableStyle( + [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), + ('BOX', (0,0), (-1,-1), 2, 'BLACK'), + ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), + ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) +COLORED_GRID_STYLE = TableStyle( + [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), + ('BOX', (0,0), (-1,-1), 2, 'RED'), + ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), + ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) +LIST_STYLE = TableStyle( + [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), + ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), + ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) + +def test(): + rowheights = (24, 16, 16, 16, 16) + colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) + data = ( + ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), + ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), + ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), + ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), + ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') + ) doc = layout.SimpleFlowDocument('testtables.pdf', platypus.DEFAULT_PAGE_SIZE, 1) - styleSheet = layout.getSampleStyleSheet() - lst = [] - lst.append(layout.Paragraph("Tables", styleSheet['Heading1'])) - lst.append(layout.Paragraph(__doc__, styleSheet['BodyText'])) - lst.append(layout.Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" - colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) - rowheights = (24, 16, 16, 16, 16) - data = ( - ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), - ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), - ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), - ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), - ('Hats', 893, 912, '1,212', 643, 789, 159, - 888, '1,298', 832, 453, '1,344','2,843') - ) - t = Table(colwidths, rowheights, data) - """, styleSheet['Code'], dedent=4)) - lst.append(layout.Paragraph(""" - You can then give the Table a TableStyle object to control its format. The first TableStyle used was - created as follows: - """, styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" -GRID_STYLE = TableStyle( - [('GRID', (0,0), (-1,-1), 0.25, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) - """, styleSheet['Code'])) - lst.append(layout.Paragraph(""" - TableStyles are created by passing in a list of commands. There are two types of commands - line commands - and cell formatting commands. In all cases, the first three elements of a command are the command name, - the starting cell and the ending cell. - """, styleSheet['BodyText'])) - lst.append(layout.Paragraph(""" - Line commands always follow this with the weight and color of the desired lines. Colors can be names, - or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line - command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE - and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and - INNERGRID. - """, styleSheet['BodyText'])) - lst.append(layout.Paragraph(""" - Cell formatting commands are: - """, styleSheet['BodyText'])) - lst.append(layout.Paragraph(""" - FONT - takes fontname, fontsize and (optional) leading. - """, styleSheet['Definition'])) - lst.append(layout.Paragraph(""" - TEXTCOLOR - takes a color name or (R,G,B) tuple. - """, styleSheet['Definition'])) - lst.append(layout.Paragraph(""" - ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT and CENTRE (or CENTER). - """, styleSheet['Definition'])) - lst.append(layout.Paragraph(""" - LEFTPADDING - defaults to 6. - """, styleSheet['Definition'])) - lst.append(layout.Paragraph(""" - RIGHTPADDING - defaults to 6. - """, styleSheet['Definition'])) - lst.append(layout.Paragraph(""" - BOTTOMPADDING - defaults to 3. - """, styleSheet['Definition'])) - lst.append(layout.Paragraph(""" - A tablestyle is applied to a table by calling Table.setStyle(tablestyle). - """, styleSheet['BodyText'])) - t = Table(colwidths, rowheights, data) - t.setStyle(GRID_STYLE) - lst.append(layout.PageBreak()) - lst.append(layout.Paragraph("This is GRID_STYLE\n", styleSheet['BodyText'])) - lst.append(t) - - t = Table(colwidths, rowheights, data) - t.setStyle(BOX_STYLE) - lst.append(layout.Paragraph("This is BOX_STYLE\n", styleSheet['BodyText'])) - lst.append(t) - lst.append(layout.Paragraph(""" - It was created as follows: - """, styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" -BOX_STYLE = TableStyle( - [('BOX', (0,0), (-1,-1), 0.50, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) - """, styleSheet['Code'])) - - t = Table(colwidths, rowheights, data) - t.setStyle(LABELED_GRID_STYLE) - lst.append(layout.Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText'])) - lst.append(t) - lst.append(layout.Paragraph(""" - It was created as follows: - """, styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" -LABELED_GRID_STYLE = TableStyle( - [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), - ('BOX', (0,0), (-1,-1), 2, 'BLACK'), - ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), - ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) - """, styleSheet['Code'])) - lst.append(layout.PageBreak()) - - t = Table(colwidths, rowheights, data) - t.setStyle(COLORED_GRID_STYLE) - lst.append(layout.Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText'])) - lst.append(t) - lst.append(layout.Paragraph(""" - It was created as follows: - """, styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" -COLORED_GRID_STYLE = TableStyle( - [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), - ('BOX', (0,0), (-1,-1), 2, 'RED'), - ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), - ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) - """, styleSheet['Code'])) - - t = Table(colwidths, rowheights, data) - t.setStyle(LIST_STYLE) - lst.append(layout.Paragraph("This is LIST_STYLE\n", styleSheet['BodyText'])) - lst.append(t) - lst.append(layout.Paragraph(""" - It was created as follows: - """, styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" -LIST_STYLE = TableStyle( - [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), - ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), - ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT')] - ) - """, styleSheet['Code'])) - - t = Table(colwidths, rowheights, data) - ts = TableStyle( - [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), - ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), - ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT'), - ('TEXTCOLOR', (0,1), (0,-1), 'RED'), - ('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))] - ) - t.setStyle(ts) - lst.append(layout.Paragraph("This is a custom style\n", styleSheet['BodyText'])) - lst.append(t) - lst.append(layout.Paragraph(""" - It was created as follows: - """, styleSheet['BodyText'])) - lst.append(layout.Preformatted(""" - ts = TableStyle( - [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), - ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), - ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), - ('ALIGN', (1,1), (-1,-1), 'RIGHT'), - ('TEXTCOLOR', (0,1), (0,-1), 'RED'), - ('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))] - ) - """, styleSheet['Code'])) - doc.build(lst) - -if __name__ == '__main__': - test() - - \ No newline at end of file + styleSheet = layout.getSampleStyleSheet() + lst = [] + lst.append(layout.Paragraph("Tables", styleSheet['Heading1'])) + lst.append(layout.Paragraph(__doc__, styleSheet['BodyText'])) + lst.append(layout.Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" + colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) + rowheights = (24, 16, 16, 16, 16) + data = ( + ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), + ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), + ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), + ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), + ('Hats', 893, 912, '1,212', 643, 789, 159, + 888, '1,298', 832, 453, '1,344','2,843') + ) + t = Table(colwidths, rowheights, data) + """, styleSheet['Code'], dedent=4)) + lst.append(layout.Paragraph(""" + You can then give the Table a TableStyle object to control its format. The first TableStyle used was + created as follows: + """, styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" +GRID_STYLE = TableStyle( + [('GRID', (0,0), (-1,-1), 0.25, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) + """, styleSheet['Code'])) + lst.append(layout.Paragraph(""" + TableStyles are created by passing in a list of commands. There are two types of commands - line commands + and cell formatting commands. In all cases, the first three elements of a command are the command name, + the starting cell and the ending cell. + """, styleSheet['BodyText'])) + lst.append(layout.Paragraph(""" + Line commands always follow this with the weight and color of the desired lines. Colors can be names, + or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line + command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE + and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and + INNERGRID. + """, styleSheet['BodyText'])) + lst.append(layout.Paragraph(""" + Cell formatting commands are: + """, styleSheet['BodyText'])) + lst.append(layout.Paragraph(""" + FONT - takes fontname, fontsize and (optional) leading. + """, styleSheet['Definition'])) + lst.append(layout.Paragraph(""" + TEXTCOLOR - takes a color name or (R,G,B) tuple. + """, styleSheet['Definition'])) + lst.append(layout.Paragraph(""" + ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT and CENTRE (or CENTER). + """, styleSheet['Definition'])) + lst.append(layout.Paragraph(""" + LEFTPADDING - defaults to 6. + """, styleSheet['Definition'])) + lst.append(layout.Paragraph(""" + RIGHTPADDING - defaults to 6. + """, styleSheet['Definition'])) + lst.append(layout.Paragraph(""" + BOTTOMPADDING - defaults to 3. + """, styleSheet['Definition'])) + lst.append(layout.Paragraph(""" + A tablestyle is applied to a table by calling Table.setStyle(tablestyle). + """, styleSheet['BodyText'])) + t = Table(colwidths, rowheights, data) + t.setStyle(GRID_STYLE) + lst.append(layout.PageBreak()) + lst.append(layout.Paragraph("This is GRID_STYLE\n", styleSheet['BodyText'])) + lst.append(t) + + t = Table(colwidths, rowheights, data) + t.setStyle(BOX_STYLE) + lst.append(layout.Paragraph("This is BOX_STYLE\n", styleSheet['BodyText'])) + lst.append(t) + lst.append(layout.Paragraph(""" + It was created as follows: + """, styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" +BOX_STYLE = TableStyle( + [('BOX', (0,0), (-1,-1), 0.50, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) + """, styleSheet['Code'])) + + t = Table(colwidths, rowheights, data) + t.setStyle(LABELED_GRID_STYLE) + lst.append(layout.Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText'])) + lst.append(t) + lst.append(layout.Paragraph(""" + It was created as follows: + """, styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" +LABELED_GRID_STYLE = TableStyle( + [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), + ('BOX', (0,0), (-1,-1), 2, 'BLACK'), + ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), + ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) + """, styleSheet['Code'])) + lst.append(layout.PageBreak()) + + t = Table(colwidths, rowheights, data) + t.setStyle(COLORED_GRID_STYLE) + lst.append(layout.Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText'])) + lst.append(t) + lst.append(layout.Paragraph(""" + It was created as follows: + """, styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" +COLORED_GRID_STYLE = TableStyle( + [('INNERGRID', (0,0), (-1,-1), 0.25, 'BLACK'), + ('BOX', (0,0), (-1,-1), 2, 'RED'), + ('LINEBELOW', (0,0), (-1,0), 2, 'BLACK'), + ('LINEAFTER', (0,0), (0,-1), 2, 'BLACK'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) + """, styleSheet['Code'])) + + t = Table(colwidths, rowheights, data) + t.setStyle(LIST_STYLE) + lst.append(layout.Paragraph("This is LIST_STYLE\n", styleSheet['BodyText'])) + lst.append(t) + lst.append(layout.Paragraph(""" + It was created as follows: + """, styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" +LIST_STYLE = TableStyle( + [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), + ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), + ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')] + ) + """, styleSheet['Code'])) + + t = Table(colwidths, rowheights, data) + ts = TableStyle( + [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), + ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), + ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT'), + ('TEXTCOLOR', (0,1), (0,-1), 'RED'), + ('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))] + ) + t.setStyle(ts) + lst.append(layout.Paragraph("This is a custom style\n", styleSheet['BodyText'])) + lst.append(t) + lst.append(layout.Paragraph(""" + It was created as follows: + """, styleSheet['BodyText'])) + lst.append(layout.Preformatted(""" + ts = TableStyle( + [('LINEABOVE', (0,0), (-1,0), 2, 'GREEN'), + ('LINEABOVE', (0,1), (-1,-1), 0.25, 'BLACK'), + ('LINEBELOW', (0,-1), (-1,-1), 2, 'GREEN'), + ('ALIGN', (1,1), (-1,-1), 'RIGHT'), + ('TEXTCOLOR', (0,1), (0,-1), 'RED'), + ('BACKGROUND', (0,0), (-1,0), (0,0.7,0.7))] + ) + """, styleSheet['Code'])) + doc.build(lst) + +if __name__ == '__main__': + test()
--- a/reportlab/platypus/test/testplatypus.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/platypus/test/testplatypus.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,3 +1,42 @@ +#!/bin/env python +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: testplatypus.py,v $ +# Revision 1.2 2000/02/15 15:47:10 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: testplatypus.py,v 1.2 2000/02/15 15:47:10 rgbecker Exp $ ''' + #tests and documents Page Layout API """This is not obvious so here's a brief explanation. This module is both the test script and user guide for layout. Each page has two frames on it: @@ -424,4 +463,4 @@ if __name__ == "__main__": - run() \ No newline at end of file + run()
--- a/reportlab/platypus/test/testtables.py Tue Feb 15 15:15:37 2000 +0000 +++ b/reportlab/platypus/test/testtables.py Tue Feb 15 15:47:10 2000 +0000 @@ -1,9 +1,47 @@ -from platypus import layout -from platypus import tables - -INCH = 72 +#!/bin/env python +############################################################################### +# +# ReportLab Public License Version 1.0 +# +# Except for the change of names the spirit and intention of this +# license is the same as that of Python +# +# (C) Copyright ReportLab Inc. 1998-2000. +# +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, provided +# that the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Robinson Analytics not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# +# Disclaimer +# +# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT +# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +############################################################################### +# $Log: testtables.py,v $ +# Revision 1.2 2000/02/15 15:47:10 rgbecker +# Added license, __version__ and Logi comment +# +__version__=''' $Id: testtables.py,v 1.2 2000/02/15 15:47:10 rgbecker Exp $ ''' +from platypus import layout +from platypus import tables -def getTable(): +INCH = 72 + +def getTable(): t = tables.Table( (72,36,36,36,36), (24, 16,16,18), @@ -11,49 +49,49 @@ ('Quarter 1',100,200,300,400), ('Quarter 2',100,400,600,800), ('Total',300,600,900,'1,200')) - ) + ) return t - -def makeStyles(): - styles = [] - for i in range(5): - styles.append(tables.TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'), - ('ALIGN', (0,0), (-1,0), 'CENTRE') ])) - for style in styles[1:]: - style.add('GRID', (0,0), (-1,-1), 0.25, 'BLACK') - for style in styles[2:]: - style.add('LINEBELOW', (0,0), (-1,0), 2, 'BLACK') - for style in styles[3:]: - style.add('LINEABOVE', (0, -1), (-1,-1), 2, 'RED') - styles[-1].add('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)) + +def makeStyles(): + styles = [] + for i in range(5): + styles.append(tables.TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'), + ('ALIGN', (0,0), (-1,0), 'CENTRE') ])) + for style in styles[1:]: + style.add('GRID', (0,0), (-1,-1), 0.25, 'BLACK') + for style in styles[2:]: + style.add('LINEBELOW', (0,0), (-1,0), 2, 'BLACK') + for style in styles[3:]: + style.add('LINEABOVE', (0, -1), (-1,-1), 2, 'RED') + styles[-1].add('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)) return styles - -def run(): - doc = layout.SimpleFlowDocument('testtables.pdf', (8.5*INCH, 11*INCH), 1) - styles = makeStyles() - lst = [] - for style in styles: - t = getTable() - t.setStyle(style) -## print '--------------' -## for rowstyle in t._cellstyles: -## for s in rowstyle: -## print s.alignment - lst.append(t) - lst.append(layout.Spacer(0,12)) - doc.build(lst) - -run() - -#LINEABOVE -#LINEBELOW -#LINEBEFORE -#LINEAFTER -#GRID -#BOX -#INNERGRID ?? - -#FONT -#TEXTCOLOR -#ALIGNMENT -#PADDING \ No newline at end of file + +def run(): + doc = layout.SimpleFlowDocument('testtables.pdf', (8.5*INCH, 11*INCH), 1) + styles = makeStyles() + lst = [] + for style in styles: + t = getTable() + t.setStyle(style) +## print '--------------' +## for rowstyle in t._cellstyles: +## for s in rowstyle: +## print s.alignment + lst.append(t) + lst.append(layout.Spacer(0,12)) + doc.build(lst) + +run() + +#LINEABOVE +#LINEBELOW +#LINEBEFORE +#LINEAFTER +#GRID +#BOX +#INNERGRID ?? + +#FONT +#TEXTCOLOR +#ALIGNMENT +#PADDING