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: Mon, 03 Nov 2003 08:34:04 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue-reports
Branch:         
Changes by:     Jan Ischebeck <address@hidden>  03/11/03 08:34:03

Modified files:
        src/adapters/filters/SimpleTabulation/tabulator: Adapter.py 
        src/adapters/filters/SimpleTabulation/tabulator/formatters: 
                                                                    pdf.py 
                                                                    csv.py 
                                                                    html.py 
                                                                    text.py 

Log message:
        make tabulator formatting adapter unicode aware:
        - add output encoding setting
        - move unicode -> local encoding conversion into formatters

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

Patches:
Index: gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/Adapter.py
diff -c 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/Adapter.py:1.6 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/Adapter.py:1.7
*** gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/Adapter.py:1.6 
Mon Feb 17 02:32:54 2003
--- gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/Adapter.py     
Mon Nov  3 08:34:01 2003
***************
*** 69,75 ****
  
      infile = open(self.infile,'r')
  
!     self.formatter = module.DirectFormatter(outfile, stylesheet)
  
      # Create a parser
      parser = xml.sax.make_parser()
--- 69,75 ----
  
      infile = open(self.infile,'r')
  
!     self.formatter = module.DirectFormatter(outfile, stylesheet, 
self.parameters)
  
      # Create a parser
      parser = xml.sax.make_parser()
***************
*** 135,141 ****
  
  
    def characters(self, text):
!     self._text += text.encode(gConfig('textEncoding'))
  
  
    def endElement(self, name):
--- 135,141 ----
  
  
    def characters(self, text):
!     self._text += text
  
  
    def endElement(self, name):
***************
*** 171,183 ****
        self.formatter.EndTable()
        
      elif name == "sectionTitle":
!       self.formatter.EndSectionTitle(GTypecast.text(self._text))
        
      elif name == "section":
        self.formatter.EndSection()
        
      elif name == "reportTitle":
!       self.formatter.EndReportTitle(GTypecast.text(self._text))
        
      elif name == "report":
        self.formatter.EndReport()
--- 171,183 ----
        self.formatter.EndTable()
        
      elif name == "sectionTitle":
!       self.formatter.EndSectionTitle(self._text)
        
      elif name == "section":
        self.formatter.EndSection()
        
      elif name == "reportTitle":
!       self.formatter.EndReportTitle(self._text)
        
      elif name == "report":
        self.formatter.EndReport()
Index: 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/csv.py
diff -c 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/csv.py:1.2
 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/csv.py:1.3
*** 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/csv.py:1.2
  Wed Jan  1 19:45:49 2003
--- 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/csv.py  
    Mon Nov  3 08:34:02 2003
***************
*** 32,37 ****
--- 32,44 ----
    def __init__(self, destination, stylesheet, options={}):
      self.dest = destination
      self.options = options
+     try: 
+       self.encoding = options['encoding']
+     except:
+       self.encoding = gConfig('textEncoding')
+ 
+   def writeout(self, text):
+     self.dest.write(text.encode(self.encoding,'replace'))
  
    def BeginReport(self):
      pass
***************
*** 67,73 ****
      self._head = []
  
    def EndTableHead(self):
!     self.dest.write('%s\n' % ','.join(self._head))
  
    def BeginColHead(self):
      pass
--- 74,80 ----
      self._head = []
  
    def EndTableHead(self):
!     self.writeout('%s\n' % ','.join(self._head))
  
    def BeginColHead(self):
      pass
***************
*** 79,85 ****
      self._row = []
  
    def EndRow(self):
!     self.dest.write('%s\n' % ','.join(self._row))
  
    def BeginCol(self):
      pass
--- 86,92 ----
      self._row = []
  
    def EndRow(self):
!     self.writeout('%s\n' % ','.join(self._row))
  
    def BeginCol(self):
      pass
Index: 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/html.py
diff -c 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/html.py:1.4
 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/html.py:1.5
*** 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/html.py:1.4
 Tue Jun 10 13:45:42 2003
--- 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/html.py 
    Mon Nov  3 08:34:02 2003
***************
*** 33,42 ****
      self.dest = destination
      self.options = options
  
!     self._reporttitle = ''
!     self._sectiontitle = ''
      self.stylesheet = stylesheet
  
    def BeginReport(self):
      try:
        css = open(self.stylesheet,'r')
--- 33,50 ----
      self.dest = destination
      self.options = options
  
!     self._reporttitle = u''
!     self._sectiontitle = u''
      self.stylesheet = stylesheet
  
+     try: 
+       self.encoding = options['encoding']
+     except:
+       self.encoding = gConfig('textEncoding')
+ 
+   def writeout(self, text):
+     self.writeout(text.encode(self.encoding,'replace'))
+ 
    def BeginReport(self):
      try:
        css = open(self.stylesheet,'r')
***************
*** 49,71 ****
      if css:
        css.close()
      
!     self.dest.write('<html>\n')
!     self.dest.write('  <head>\n')
!     self.dest.write('    <meta http-equiv="Content-Type" content="text/html; 
charset=UTF-8"/>\n')
!     self.dest.write('    <style>\n%s    </style>\n' % style)
!     self.dest.write( '  </head>\n')
!     self.dest.write('  <body>\n')
  
    def EndReport(self):
!     self.dest.write('  </body>\n')
!     self.dest.write('</html>')
      
    def BeginReportTitle(self):
      pass
  
    def EndReportTitle(self, reporttitle):
      self._reporttitle = reporttitle
!     self.dest.write('  <h1>%s</h1>\n<hr>\n' % self._reporttitle)
  
    def BeginSection(self):
      pass
--- 57,79 ----
      if css:
        css.close()
      
!     self.writeout('<html>\n')
!     self.writeout('  <head>\n')
!     self.writeout('    <meta http-equiv="Content-Type" content="text/html; 
charset=%s"/>\n' % self.encoding)
!     self.writeout('    <style>\n%s    </style>\n' % style)
!     self.writeout('  </head>\n')
!     self.writeout('  <body>\n')
  
    def EndReport(self):
!     self.writeout('  </body>\n')
!     self.writeout('</html>')
      
    def BeginReportTitle(self):
      pass
  
    def EndReportTitle(self, reporttitle):
      self._reporttitle = reporttitle
!     self.writeout('  <h1>%s</h1>\n<hr>\n' % 
self._reporttitle.encode(gConfig('textEncoding'),'replace'))
  
    def BeginSection(self):
      pass
***************
*** 78,128 ****
      
    def EndSectionTitle(self, sectiontitle):
      self._sectiontitle = sectiontitle
!     self.dest.write('  <h2>%s</h2>\n' % self._sectiontitle)
  
    def BeginTable(self):
      self._odd = 1
!     self.dest.write('    <table>\n')
  
    def EndTable(self):
!     self.dest.write('    </table>\n')
  
    def BeginTableHead(self):
      self._colalign = []
!     self.dest.write('      <tr>\n')
  
    def EndTableHead(self):
!     self.dest.write('      </tr>\n')
  
    def BeginColHead(self):
!     self.dest.write('        <th ')
  
    def EndColHead(self, colhead, width, alignment=None):
      self._colalign.append(alignment)
!     self.dest.write('align="%s">%s</th>\n' % (alignment, colhead))
  
    def BeginRow(self, rowtype=None):
      self._rowtype = rowtype
      if self._rowtype == 'subtotal':
!       self.dest.write('      <tr class="subtotal">\n')
      else:
        if self._odd:
!         self.dest.write('      <tr class="odditem">\n')
        else:
!         self.dest.write('      <tr class="item">\n')
  
    def EndRow(self, rowtype=None):
      self._odd = not self._odd
!     self.dest.write('      </tr>\n')
  
    def BeginCol(self):
      if self._rowtype == 'subtotal':
!       self.dest.write('        <td class="subtotal" ')
      else:
!       self.dest.write('        <td class="item" ')
  
    def EndCol(self, col, index):
!     self.dest.write('align="%s">%s</td>\n' % (self._colalign[index], col))
  
  
  STYLE = """body {
--- 86,138 ----
      
    def EndSectionTitle(self, sectiontitle):
      self._sectiontitle = sectiontitle
!     self.writeout('  <h2>%s</h2>\n' % 
self._sectiontitle.encode(gConfig('textEncoding'),'replace'))
  
    def BeginTable(self):
      self._odd = 1
!     self.writeout('    <table>\n')
  
    def EndTable(self):
!     self.writeout('    </table>\n')
  
    def BeginTableHead(self):
      self._colalign = []
!     self.writeout('      <tr>\n')
  
    def EndTableHead(self):
!     self.writeout('      </tr>\n')
  
    def BeginColHead(self):
!     self.writeout('        <th ')
  
    def EndColHead(self, colhead, width, alignment=None):
      self._colalign.append(alignment)
!     self.writeout('align="%s">%s</th>\n' % (alignment,
!                                               
colhead.encode(gConfig('textEncoding'),'replace')))
  
    def BeginRow(self, rowtype=None):
      self._rowtype = rowtype
      if self._rowtype == 'subtotal':
!       self.writeout('      <tr class="subtotal">\n')
      else:
        if self._odd:
!         self.writeout('      <tr class="odditem">\n')
        else:
!         self.writeout('      <tr class="item">\n')
  
    def EndRow(self, rowtype=None):
      self._odd = not self._odd
!     self.writeout('      </tr>\n')
  
    def BeginCol(self):
      if self._rowtype == 'subtotal':
!       self.writeout('        <td class="subtotal" ')
      else:
!       self.writeout('        <td class="item" ')
  
    def EndCol(self, col, index):
!     self.writeout('align="%s">%s</td>\n' % (self._colalign[index],
!                                               
col.encode(gConfig('textEncoding'),'replace')))
  
  
  STYLE = """body {
Index: 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py
diff -c 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py:1.7
 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py:1.8
*** 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py:1.7
  Fri Oct 31 13:06:16 2003
--- 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/pdf.py  
    Mon Nov  3 08:34:02 2003
***************
*** 66,72 ****
                       '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
  }
--- 66,72 ----
                       'ArialBI'        : 'Arial_Bold_Italic.ttf',
                       'PMingLiU'       : 'pmingliu.ttf',
                       'SimSun'         : 'simsun.ttf',
!                      'ZenKai-Medium'  : 'arphic/bkai00mp.ttf'
  # TODO: add more fonts / move to other place, possibly join with code in
  #       Universal/ps
  }
***************
*** 79,90 ****
  
      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'
  
--- 79,89 ----
  
      self._reporttitle = ''
      self._sectiontitle = ''
  
      # TODO: make that all configurable
      self.fontdir = '/usr/share/fonts/truetype/'
  
+     # standart settings
      self.font = 'Helvetica'
      self.boldfont = 'Helvetica-Bold'
  
***************
*** 96,101 ****
--- 95,103 ----
      
      #self.font = 'SimSun'
  
+     #self.font = 'ZenKai-Medium'
+     #self.boldfont = 'ZenKai-Medium'
+ 
      self.loadFont(self.font)
      self.loadFont(self.boldfont)
  
***************
*** 126,132 ****
                      self._doc.width+2*cm, 2.5*cm, 
                      leftPadding=0, bottomPadding=0, rightPadding=0, 
topPadding=0, 
                      id='title', showBoundary=0)
!     p1 = Paragraph(self._reporttitle, getSampleStyleSheet()["Title"])
  
      canvas.setStrokeColor(colors.grey)
      canvas.line(self._doc.leftMargin-cm, 
self._doc.bottomMargin+self._doc.height+1.0*cm,
--- 128,137 ----
                      self._doc.width+2*cm, 2.5*cm, 
                      leftPadding=0, bottomPadding=0, rightPadding=0, 
topPadding=0, 
                      id='title', showBoundary=0)
!     
!     titlestyle = getSampleStyleSheet()["Title"]
!     titlestyle.fontName=self.font
!     p1 = Paragraph(self._reporttitle, titlestyle)
  
      canvas.setStrokeColor(colors.grey)
      canvas.line(self._doc.leftMargin-cm, 
self._doc.bottomMargin+self._doc.height+1.0*cm,
***************
*** 175,181 ****
      
      
    def EndReportTitle(self, reporttitle):
!     self._reporttitle = reporttitle
  
  
    def BeginSection(self):
--- 180,186 ----
      
      
    def EndReportTitle(self, reporttitle):
!     self._reporttitle = reporttitle.encode('utf-8')
  
  
    def BeginSection(self):
***************
*** 191,197 ****
      
      
    def EndSectionTitle(self, sectiontitle):
!     self._sectiontitle = sectiontitle
  
  
    def BeginTable(self):
--- 196,202 ----
      
      
    def EndSectionTitle(self, sectiontitle):
!     self._sectiontitle = sectiontitle.encode('utf-8')
  
  
    def BeginTable(self):
***************
*** 229,235 ****
  
  
    def EndColHead(self, colhead, width, alignment=None):
!     self._tableHead.append(colhead)
      self._tableAlign.append(alignment)
      self._colwidth.append(width)
      self._headwidth += width
--- 234,240 ----
  
  
    def EndColHead(self, colhead, width, alignment=None):
!     self._tableHead.append(colhead.encode('utf-8'))
      self._tableAlign.append(alignment)
      self._colwidth.append(width)
      self._headwidth += width
***************
*** 258,264 ****
  
  
    def EndCol(self, col, index):
!     self._row.append(col)
   
  
  
--- 263,269 ----
  
  
    def EndCol(self, col, index):
!     self._row.append(col.encode('utf-8'))
   
  
  
Index: 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/text.py
diff -c 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/text.py:1.2
 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/text.py:1.3
*** 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/text.py:1.2
 Wed Jan  1 19:45:49 2003
--- 
gnue-reports/src/adapters/filters/SimpleTabulation/tabulator/formatters/text.py 
    Mon Nov  3 08:34:03 2003
***************
*** 33,40 ****
      self.dest = destination
      self.options = options
  
!     self._reporttitle = ''
!     self._sectiontitle = ''
  
  
    def BeginReport(self):
--- 33,48 ----
      self.dest = destination
      self.options = options
  
!     self._reporttitle = u''
!     self._sectiontitle = u''
!     
!     try: 
!       self.encoding = options['encoding']
!     except:
!       self.encoding = gConfig('textEncoding')
! 
!   def writeout(self, text):
!     self.dest.write(text.encode(self.encoding,'replace'))
  
  
    def BeginReport(self):
***************
*** 85,96 ****
  
  
    def EndTableHead(self):
!     self.dest.write('%s\n' % self._reporttitle.center(self._headwidth))
!     self.dest.write('%s\n' % 
('='*len(self._reporttitle)).center(self._headwidth))
!     self.dest.write('%s\n\n' % self._sectiontitle.center(self._headwidth))
  
!     self.dest.write('%s\n' % ''.join(self._head))
!     self.dest.write('%s\n' % ('='*self._headwidth))
  
  
    def BeginColHead(self):
--- 93,104 ----
  
  
    def EndTableHead(self):
!     self.writeout('%s\n' % self._reporttitle.center(self._headwidth))
!     self.writeout('%s\n' % 
('='*len(self._reporttitle)).center(self._headwidth))
!     self.writeout('%s\n\n' % self._sectiontitle.center(self._headwidth))
  
!     self.writeout('%s\n' % ''.join(self._head))
!     self.writeout('%s\n' % ('='*self._headwidth))
  
  
    def BeginColHead(self):
***************
*** 117,126 ****
  
    def EndRow(self):
      if self._rowtype == 'subtotal':
!       self.dest.write('%s\n' % ('-'*self._headwidth))
!     self.dest.write('%s\n' % ''.join(self._row))
      if self._rowtype == 'subtotal':
!       self.dest.write('\n')
  
  
    def BeginCol(self):
--- 125,136 ----
  
    def EndRow(self):
      if self._rowtype == 'subtotal':
!       self.writeout('%s\n' % ('-'*self._headwidth))
!       
!     self.writeout('%s\n' % ''.join(self._row))
!     
      if self._rowtype == 'subtotal':
!       self.writeout('\n')
  
  
    def BeginCol(self):




reply via email to

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