[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8115 - trunk/gnue-common/src/printing/pdftable
From: |
jamest |
Subject: |
[gnue] r8115 - trunk/gnue-common/src/printing/pdftable |
Date: |
Tue, 6 Dec 2005 19:37:57 -0600 (CST) |
Author: jamest
Date: 2005-12-06 19:37:56 -0600 (Tue, 06 Dec 2005)
New Revision: 8115
Modified:
trunk/gnue-common/src/printing/pdftable/pdftable.py
Log:
moved font defs to a dict and allow them to be set
added a set hightlight function
added ability to shut off borders per row
Modified: trunk/gnue-common/src/printing/pdftable/pdftable.py
===================================================================
--- trunk/gnue-common/src/printing/pdftable/pdftable.py 2005-12-06 21:25:33 UTC
(rev 8114)
+++ trunk/gnue-common/src/printing/pdftable/pdftable.py 2005-12-07 01:37:56 UTC
(rev 8115)
@@ -57,24 +57,23 @@
# ----------------------------------------------------------------------------
# Some sample font definitions
-#
-# TODO: This really needs handled in a more flexible mannor.
# ----------------------------------------------------------------------------
- # Font name Pt Size Vert Spacing
-dataFont = ('Times-Roman', 10, 11)
-subtotalFont = ('Times-Bold', 10, 12)
-tableHeaderFont = ('Times-Bold', 10, 12)
+fontDefs = { # Font name Pt Size Vert Spacing
+ 'dataFont' : ('Times-Roman', 10, 11),
+ 'subtotalFont' : ('Times-Bold', 10, 12),
+ 'tableHeaderFont' : ('Times-Bold', 10, 12),
+
+ 'titleFont' : ('Helvetica-Bold', 14, 14),
+ 'title2Font' : ('Helvetica', 12, 14),
+ 'title3Font' : ('Helvetica-Oblique',12, 14),
+ 'repeatTitleFont' : ('Helvetica-Oblique', 9, 10),
+ 'footerFont' : ('Times-Roman', 9, 10),
+
+ 'subtitleFont' : ('Times-Bold', 12, 13),
+ 'subtitleLabelFont' : ('Times-Roman', 12, 13),
+ 'subtitleContinueFont' : ('Times-Italic', 10, 13),
+}
-titleFont = ('Helvetica-Bold', 14, 14)
-title2Font = ('Helvetica', 12, 14)
-title3Font = ('Helvetica-Oblique',12, 14)
-repeatTitleFont = ('Helvetica-Oblique', 9, 10)
-footerFont = ('Times-Roman', 9, 10)
-
-subtitleFont = ('Times-Bold', 12, 13)
-subtitleLabelFont = ('Times-Roman', 12, 13)
-subtitleContinueFont = ('Times-Italic', 10, 13)
-
# ----------------------------------------------------------------------------
# Sample Color settings
#
@@ -99,7 +98,7 @@
topmargin = .75*inch
# This is nothing but voodoo guesses...
-# Greatly depends on pointsize of dataFont
+# Greatly depends on pointsize of fontDefs['dataFont']
# TODO: This should probably be computed based on width of a "0"
# TODO: and the width of the report. But, eh, this works for now...
maxColsForPortraitNonscaled = 100 # Number of columns before we start
scaling down
@@ -316,7 +315,7 @@
# --------------------------------------------------------------------------
# Add data row
# --------------------------------------------------------------------------
- def addRow(self, data, style="Data"):
+ def addRow(self, data, style="Data", displayBorders=True):
"""
Adds a row of data to the current section
@@ -324,6 +323,9 @@
@param style: The format style to use to render the row.
These are currently hardcoded into this class and include
Data (default), Subtotal, Total
+ @param displayBorders: Boolean that controls if a borders will be drawn
for this
+ row. Makes it easy to produce a "blank" row for
spacing
+ output
"""
canvas = self.canvas
@@ -331,10 +333,10 @@
self.y -= 4 * self.scale
if style in ("Subtotal","Total"):
- font, size, tracking = subtotalFont
+ font, size, tracking = fontDefs['subtotalFont']
fontWidth = self.subtotalFontWidth
else:
- font, size, tracking = dataFont
+ font, size, tracking = fontDefs['dataFont']
fontWidth = self.dataFontWidth
size = size * self.scale
@@ -396,25 +398,26 @@
color, lines=0)
# Column border support
- leftBorder = self._currentSection['columnLeftBorder'][i]
- if leftBorder:
- canvas.setLineWidth(leftBorder*self.scale)
- canvas.line(hlx1, boxy, hlx1, boxy + boxh)
-
- rightBorder =self._currentSection['columnRightBorder'][i]
- if rightBorder:
- canvas.setLineWidth(rightBorder*self.scale)
- canvas.line(hlx2, boxy, hlx2, boxy + boxh)
-
- topBorder =self._currentSection['columnTopBorder'][i]
- if topBorder:
- canvas.setLineWidth(topBorder*self.scale)
- canvas.line(hlx1, boxy + boxh, hlx2, boxy + boxh)
-
- bottomBorder = self._currentSection['columnBottomBorder'][i]
- if bottomBorder:
- canvas.setLineWidth(bottomBorder*self.scale)
- canvas.line(hlx1, boxy, hlx2, boxy)
+ if displayBorders:
+ leftBorder = self._currentSection['columnLeftBorder'][i]
+ if leftBorder:
+ canvas.setLineWidth(leftBorder*self.scale)
+ canvas.line(hlx1, boxy, hlx1, boxy + boxh)
+
+ rightBorder =self._currentSection['columnRightBorder'][i]
+ if rightBorder:
+ canvas.setLineWidth(rightBorder*self.scale)
+ canvas.line(hlx2, boxy, hlx2, boxy + boxh)
+
+ topBorder =self._currentSection['columnTopBorder'][i]
+ if topBorder:
+ canvas.setLineWidth(topBorder*self.scale)
+ canvas.line(hlx1, boxy + boxh, hlx2, boxy + boxh)
+
+ bottomBorder = self._currentSection['columnBottomBorder'][i]
+ if bottomBorder:
+ canvas.setLineWidth(bottomBorder*self.scale)
+ canvas.line(hlx1, boxy, hlx2, boxy)
if col:
align= self._currentSection['columnAligns'][i]
@@ -483,7 +486,7 @@
Private function that creates the footer containing the time/page #
"""
canvas = self.canvas
- font, size, tracking = footerFont
+ font, size, tracking = fontDefs['footerFont']
canvas.setFont(font, size)
canvas.drawString(leftmargin, topmargin, self.timestamp)
canvas.drawRightString(self.width - leftmargin, topmargin, "Page %s" %
self.page)
@@ -497,7 +500,7 @@
Private function that creates a full (first page) header on a new page.
"""
canvas = self.canvas
- self.y -= titleFont[2]
+ self.y -= fontDefs['titleFont'][2]
for text, fontspec in self._titleList:
if text:
font, size, tracking = fontspec
@@ -514,7 +517,7 @@
Private function that creates a short ( non first page) header on a new
page.
"""
canvas = self.canvas
- font, size, tracking = repeatTitleFont
+ font, size, tracking = fontDefs['repeatTitleFont']
self. y -= size
canvas.setFont(font, size)
canvas.drawString(leftmargin, self.y, self._titleList[0][0])
@@ -534,16 +537,16 @@
if not self.subtitle:
return
- self.y -= subtitleFont[2]
+ self.y -= fontDefs['subtitleFont'][2]
- font, size, tracking = subtitleLabelFont
+ font, size, tracking = fontDefs['subtitleLabelFont']
text = canvas.beginText(leftmargin, self.y)
for l in self.subtitle.split():
boldOff = 0
if l[0] == '*':
l = l[1:]
- font, size, tracking = subtitleFont
+ font, size, tracking = fontDefs['subtitleFont']
if l[-1] == '*':
boldOff = 1
@@ -552,11 +555,11 @@
text.setFont(font, size)
text.textOut(l+ ' ')
if boldOff:
- font, size, tracking = subtitleLabelFont
+ font, size, tracking = fontDefs['subtitleLabelFont']
text.textOut(' ')
if self.continued:
- font2, size2, tracking2 = subtitleContinueFont
+ font2, size2, tracking2 = fontDefs['subtitleContinueFont']
text.setFont(font2, size2)
text.textOut("(Continued)")
@@ -575,7 +578,7 @@
numRows = len(self._currentSection['headerList'])
- font, size, tracking = tableHeaderFont
+ font, size, tracking = fontDefs['tableHeaderFont']
size = size * self.scale
tracking = tracking * self.scale
canvas.setFont(font, size)
@@ -676,10 +679,10 @@
self.canvas = canvas.Canvas(self.file,
pagesize=self.pageOrient(self.pageSize))
- font, size, leading = dataFont
+ font, size, leading = fontDefs['dataFont']
self.dataFontWidth = getFont(font).stringWidth
- font, size, leading = subtotalFont
+ font, size, leading = fontDefs['subtotalFont']
self.subtotalFontWidth = getFont(font).stringWidth
# This is not scaled down according to self.scale...
@@ -691,3 +694,12 @@
self._currentSection['columnCoords'].append ( ( x, x+colSize ) )
x += colSize + self.columnGap
+ def setHighlightColorHex(self, hexColor):
+ global highlightColor
+ highlightColor = colors.HexColor(hexColor)
+
+ def setFont(self, fontStyle, settings):
+ global fontDefs
+ assert fontStyle in fontDefs.keys(), 'Invalid font style: %s'
+
+ fontDefs[fontStyle] = settings
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8115 - trunk/gnue-common/src/printing/pdftable,
jamest <=