commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/reports/src/adapters/filters/SimpleTabulat...


From: Jan Ischebeck
Subject: gnue/reports/src/adapters/filters/SimpleTabulat...
Date: Thu, 29 May 2003 15:48:34 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jan Ischebeck <address@hidden>  03/05/29 15:48:34

Modified files:
        reports/src/adapters/filters/SimpleTabulation/tabulator/formatters: 
                                                                            
pdf.py 

Log message:
        add support for ttf fonts and CJK reports (through utf-8 encoding)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: 
gnue/reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py
diff -c 
gnue/reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py:1.4
 
gnue/reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py:1.5
*** 
gnue/reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py:1.4
  Wed Jan  1 21:36:52 2003
--- 
gnue/reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py  
    Thu May 29 15:48:33 2003
***************
*** 45,64 ****
  from reportlab.lib import colors
  from reportlab.lib.units import cm
  
  PAGE_WIDTH = defaultPageSize[0]
  PAGE_HEIGHT = defaultPageSize[1]
  
  class DirectFormatter:
  
    def __init__(self, destination, stylesheet, options={}):
      self.dest = destination
-     self.options = options
  
      self._reporttitle = ''
      self._sectiontitle = ''
      # TODO
      # self.stylesheet = stylesheet
  
  
    # Used to paint non-flowing (i.e standard) parts of pages
    def myPages(self, canvas, doc):
--- 45,112 ----
  from reportlab.lib import colors
  from reportlab.lib.units import cm
  
+ # Truetype font support
+ from reportlab.pdfbase import pdfmetrics
+ from reportlab.pdfbase.ttfonts import TTFont
+ from reportlab.lib.fonts import addMapping
+ 
  PAGE_WIDTH = defaultPageSize[0]
  PAGE_HEIGHT = defaultPageSize[1]
  
+ font_to_filename = { 'ArialUnicodeMS' : 'arialuni.ttf',
+                      'Arial'          : 'Arial.ttf',
+                      'ArialI'         : 'Arial_Italic.ttf',
+                      'ArialB'         : 'Arial_Italic.ttf',
+                      'ArialBI'        : 'Arial_Bold_Italic.ttf',
+                      'PMingLiU'       : 'pmingliu.ttf',
+                      'SimSun'         : 'simsun.ttf',
+                      'ZenKai-Medium'  : 'bkai00mp.ttf'
+ # TODO: add more fonts / move to other place, possibly join with code in
+ #       Universal/ps
+ }
+ 
+ 
  class DirectFormatter:
  
    def __init__(self, destination, stylesheet, options={}):
      self.dest = destination
  
      self._reporttitle = ''
      self._sectiontitle = ''
      # TODO
      # self.stylesheet = stylesheet
  
+     # TODO: make that all configurable
+     self.fontdir = '/usr/share/fonts/truetype/'
+ 
+     self.font = 'Helvetica'
+     self.boldfont = 'Helvetica-Bold'
+ 
+     #self.font = 'Arial'
+     #self.boldfont = 'Arial'
+     
+     #self.font = 'ArialUnicodeMS'
+     #self.boldfont = 'ArialUnicodeMS'
+     
+     #self.font = 'SimSun'
+ 
+     self.loadFont(self.font)
+     self.loadFont(self.boldfont)
+ 
+   def loadFont(self,name):
+     if font_to_filename.has_key(name):
+       try:
+         pdfmetrics.registerFont(TTFont(name, self.fontdir + \
+                                        font_to_filename[name]))
+         addMapping(name, 0, 0, name)
+       except Exception,msg:
+         print _("Error occured loading font %s (%s).") % (name,msg)
+         sys.exit(0)
+     
+     # TODO: do we need more mappings?
+     #addMapping('Arial', 0, 1, 'ArialI')
+     #addMapping('Arial', 1, 0, 'ArialB')
+     #addMapping('Arial', 1, 1, 'ArialBI')
  
    # Used to paint non-flowing (i.e standard) parts of pages
    def myPages(self, canvas, doc):
***************
*** 87,93 ****
      Style = [elem for elem in self._tableStyle]
      Style.append(('BACKGROUND', (0,0), (-1,-1), colors.black))
      Style.append(('TEXTCOLOR', (0,0), (-1,-1), colors.white))
! 
      t = Table([self._tableHead], colWidths=self._colwidth, style=Style)
      f2.addFromList([t], canvas)
  
--- 135,142 ----
      Style = [elem for elem in self._tableStyle]
      Style.append(('BACKGROUND', (0,0), (-1,-1), colors.black))
      Style.append(('TEXTCOLOR', (0,0), (-1,-1), colors.white))
!     Style.append(('FONTNAME', (0,0), (-1,-1), self.font))
!     
      t = Table([self._tableHead], colWidths=self._colwidth, style=Style)
      f2.addFromList([t], canvas)
  
***************
*** 155,160 ****
--- 204,210 ----
      self._tableStyle = []
      for i in range(self._numCols):
        self._tableStyle.append(('ALIGN', (i, 0), (i, 0), 
self._tableAlign[i].upper()))
+       self._tableStyle.append(('FONTNAME', (0,0), (-1,-1), self.font))
        self._colwidth[i] = (self._doc.width/self._headwidth)*self._colwidth[i]
        
      self._oddStyle = [elem for elem in self._tableStyle]
***************
*** 163,169 ****
      
      self._subtotalStyle = [elem for elem in self._tableStyle]
      self._subtotalStyle.append(('LINEABOVE', (0,0), (-1,-1), 0.25, 
colors.black))
!     self._subtotalStyle.append(('FONTNAME', (0,0), (-1,-1), 'Helvetica-Bold'))
  
    def BeginColHead(self):
      pass
--- 213,219 ----
      
      self._subtotalStyle = [elem for elem in self._tableStyle]
      self._subtotalStyle.append(('LINEABOVE', (0,0), (-1,-1), 0.25, 
colors.black))
!     self._subtotalStyle.append(('FONTNAME', (0,0), (-1,-1), self.boldfont))
  
    def BeginColHead(self):
      pass




reply via email to

[Prev in Thread] Current Thread [Next in Thread]