dabo Commit
Revision 6561
Date: 2011-04-15 15:41:35 -0700 (Fri, 15 Apr 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6561
Changed:
U trunk/dabo/lib/reportWriter.py
Log:
Bad font names will no longer crash the reportWriter, they'll simply be
substituted with Helvetica, Helvetica-Bold, Helvetica-Oblique, or
Helvetica-BoldOblique.
We'll also write one line to the dabo error log for each encountered
substitution.
Diff:
Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py 2011-04-15 18:23:02 UTC (rev 6560)
+++ trunk/dabo/lib/reportWriter.py 2011-04-15 22:41:35 UTC (rev 6561)
@@ -94,10 +94,31 @@
CLASSES_TO_SKIP_DEF = ("Report", "Defaults")
PROPS_TO_SKIP_DEF = ("designerlock", "totalheight", "comment")
+substitutedFontNames = [] ## keep track of which fonts we've already
substituted, to limit logging
+
+
def toPropDict(dataType, default, doc):
return {"dataType": dataType, "default": default, "doc": doc}
+def getSubFont(fontName, subFontName="Helvetica"):
+ bold = oblique = False
+ if fontName and "Bold" in fontName:
+ bold = True
+ if fontName and ("Oblique" in fontName or "Italic" in fontName):
+ oblique = True
+ if bold or oblique:
+ subFontName += "-"
+ if bold:
+ subFontName += "Bold"
+ if oblique:
+ subFontName += "Oblique"
+ if subFontName not in substitutedFontNames:
+ dabo.log.error(_("Font '%s' not found. Substituting '%s'") %
(fontName, subFontName))
+ substitutedFontNames.append(subFontName)
+ return subFontName
+
+
def getFloatLeading(obj):
leading = obj.getProp("leading")
size = float(obj.getProp("fontsize"))
@@ -167,10 +188,12 @@
registerFont(TTFont(psfontname, psfontfile))
except TTFError:
dabo.log.info(_("Font file can not be found:
%s") % psfontfile)
- canvas.Canvas.setFont(self, psfontname, size, leading)
+ try:
+ canvas.Canvas.setFont(self, psfontname, size, leading)
+ except StandardError:
+ canvas.Canvas.setFont(self, getSubFont(psfontname),
size, leading)
-
class ReportObjectCollection(list):
"""Abstract ordered list of things like variables, groups, and band
objects."""
@@ -1459,9 +1482,7 @@
try:
c.setFont(fontName, fontSize)
except StandardError:
- # An unavailable fontName was likely specified.
The rw docs promise to
- # default to Helvetica in this case.
- c.setFont("Helvetica", fontSize)
+ c.setFont(getSubFont(fontName, "Helvetica"),
fontSize)
if borderWidth > 0:
stroke = 1
@@ -1762,6 +1783,13 @@
s.fontSize = fobject.getProp("fontSize")
s.fontName = fobject.getProp("fontName")
+ # If the specified font name isn't available, we need
to substitute
+ # the built-in type 1 Helvetica:
+ try:
+ test = ParaClass("", s)
+ except StandardError:
+ s.fontName = getSubFont(s.fontName)
+
if isinstance(fobject, (Memo, Paragraph)):
s.leading = getFloatLeading(fobject)
if isinstance(fobject, Paragraph):
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]