dabo Commit
Revision 6076
Date: 2010-10-05 16:56:06 -0700 (Tue, 05 Oct 2010)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6076
Changed:
U trunk/dabo/lib/reportWriter.py
U trunk/dabo/settings.py
Log:
ReportWriter patch by Jacek, that addresses unicode issues and adds a way to
register
TrueType Font files and directories. Thanks! Trac #1382
Diff:
Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py 2010-10-05 21:47:01 UTC (rev 6075)
+++ trunk/dabo/lib/reportWriter.py 2010-10-05 23:56:06 UTC (rev 6076)
@@ -56,6 +56,10 @@
from dabo.lib.caselessDict import CaselessDict
from reportlab.lib.utils import ImageReader
from dabo.lib.utils import ustr, resolvePathAndUpdate
+from reportlab.pdfbase.pdfmetrics import registerFont
+from reportlab.pdfbase.ttfonts import TTFont, TTFError
+from reportlab.pdfbase.pdfmetrics import getRegisteredFontNames
+from reportlab.rl_config import TTFSearchPath
import Image as PILImage
import reportUtils
@@ -73,6 +77,28 @@
ParaClass = platypus.Paragraph
+def addReportTTFontFilePath(paths):
+ if isinstance(paths, basestring):
+ paths = (paths,)
+ for path in paths:
+ TTFSearchPath.append(path)
+
+
+if dabo.reportTTFontFilePath:
+ addReportTTFontFilePath(dabo.reportTTFontFilePath)
+
+
+def addReportTTFontFilePath(paths):
+ if isinstance(paths, basestring):
+ paths = (paths,)
+ for path in paths:
+ TTFSearchPath.append(path)
+
+
+if dabo.reportTTFontFilePath:
+ addReportTTFontFilePath(dabo.reportTTFontFilePath)
+
+
## Can't use None for uninitialized group values, because None
## could be a meaningful value in the dataset.
UNINITIALIZED_VALUE = 'UNINITIALIZED_f49dc68b-1e4c-43ad-81c1-227c1e4f59e6'
@@ -108,7 +134,29 @@
# callback to the rw to draw the cached pagecount strings
self.__rw.drawPageCounts(page, len(self.__saved_page_states))
+ def setFont(self, psfontname, size, leading=None):
+ if psfontname not in getRegisteredFontNames():
+ if psfontname in dabo.reportTTFontFileMap:
+ psfontfile =
dabo.reportTTFontFileMap[psfontname]
+ else:
+ psfontfile = "%s.ttf" % psfontname
+ try:
+ registerFont(TTFont(psfontname, psfontfile))
+ except TTFError:
+ dabo.log.info(_("Font file can not be found:
%s") % psfontfile)
+ canvas.Canvas.setFont(self, psfontname, size, leading)
+ def setFont(self, psfontname, size, leading=None):
+ if psfontname not in getRegisteredFontNames():
+ if psfontname in dabo.reportTTFontFileMap:
+ psfontfile =
dabo.reportTTFontFileMap[psfontname]
+ else:
+ psfontfile = "%s.ttf" % psfontname
+ try:
+ registerFont(TTFont(psfontname, psfontfile))
+ except TTFError:
+ dabo.log.info(_("Font file can not be found:
%s") % psfontfile)
+ canvas.Canvas.setFont(self, psfontname, size, leading)
class ReportObjectCollection(list):
"""Abstract ordered list of things like variables, groups, and band
objects."""
@@ -1330,13 +1378,18 @@
s = obj.getProp("expr", returnException=True)
if s is None:
- s = self.NoneDisplay
- if isinstance(s, basestring):
+ s = self.NoneDisplay
+ if isinstance(s, unicode):
+ pass
+ elif isinstance(s, str):
try:
- s = s.encode(self.Encoding)
+ s = unicode(s, "utf-8")
except UnicodeDecodeError:
- # s must have already been encoded, and
the default encoding is ascii.
- pass
+ try:
+ s = unicode(s, self.Encoding)
+ except UnicodeDecodeError:
+ # s must have already been
encoded, and the default encoding is ascii.
+ pass
else:
s = unicode(s)
func(posx, 0, s)
@@ -2543,7 +2596,7 @@
except AttributeError:
ret = _("< None >")
return ret
-
+
def _setNoneDisplay(self, val):
self._noneDisplay = val
Modified: trunk/dabo/settings.py
===================================================================
--- trunk/dabo/settings.py 2010-10-05 21:47:01 UTC (rev 6075)
+++ trunk/dabo/settings.py 2010-10-05 23:56:06 UTC (rev 6076)
@@ -201,6 +201,9 @@
dbConsoleFormat = dbFileFormat = "%(asctime)s - %(levelname)s - %(message)s"
dbMaxLogFileSize = 5242880 # 5 MB
+# Report fonts configuration.
+reportTTFontFilePath = None
+reportTTFontFileMap = {}
### Settings - end
_______________________________________________
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]