<br/> work in progress
authorandy
Fri, 21 Jul 2006 08:48:41 +0000
changeset 2663 927cc273c5a5
parent 2662 0a5217162c3f
child 2664 c9faa3a99e93
<br/> work in progress
reportlab/platypus/paragraph.py
reportlab/platypus/paraparser.py
reportlab/test/test_platypus_paraparser.py
--- a/reportlab/platypus/paragraph.py	Wed Jul 19 13:36:26 2006 +0000
+++ b/reportlab/platypus/paragraph.py	Fri Jul 21 08:48:41 2006 +0000
@@ -257,6 +257,10 @@
                 n = 0
         elif hasattr(f,'cbDefn'):
             W.append((f,''))
+        elif getattr(f, 'lineBreak', False) == True:
+            #pass the frag through.  The line breaker will scan for it.
+            W.append((f,''))
+            
 
     if W!=[]:
         W.insert(0,n)
@@ -680,8 +684,9 @@
                     newWidth = currentWidth + spaceWidth + wordWidth
                 else:
                     newWidth = currentWidth
+                #if (not getattr(f, 'lineBreak','False')) and (newWidth<=maxWidth or n==0):
                 if newWidth<=maxWidth or n==0:
-                    # fit one more on this line
+                    # fit one more word on this line
                     n += 1
                     maxSize = max(maxSize,f.fontSize)
                     nText = w[1][1]
@@ -712,7 +717,7 @@
                         maxSize = max(maxSize,g.fontSize)
 
                     currentWidth = newWidth
-                else:
+                else:  #either it won't fit, or it's a lineBreak tag
                     if currentWidth>self.width: self.width = currentWidth
                     #end of line
                     lines.append(FragLine(extraSpace=(maxWidth - currentWidth),wordCount=n,
--- a/reportlab/platypus/paraparser.py	Wed Jul 19 13:36:26 2006 +0000
+++ b/reportlab/platypus/paraparser.py	Fri Jul 21 08:48:41 2006 +0000
@@ -481,6 +481,15 @@
     def end_font(self):
         self._pop()
 
+    def start_br(self, attr):
+        #just do the trick to make sure there is no content
+        self._push(_selfClosingTag='br', lineBreak=True, text='')
+
+    def end_br(self):
+        frag = self._pop(_selfClosingTag='br', lineBreak=True)
+        self.fragList.append(frag)
+
+
     def _initial_frag(self,attr,attrMap,bullet=0):
         style = self._style
         if attr!={}:
@@ -611,6 +620,7 @@
         self.handle_data('')
         self._pop()
 
+
     #---------------------------------------------------------------
     def _push(self,**attr):
         frag = copy.copy(self._stack[-1])
@@ -665,9 +675,9 @@
 
         frag = copy.copy(self._stack[-1])
         if hasattr(frag,'cbDefn'):
-            if data!='': syntax_error('Only <onDraw> tag allowed')
+            if data!='': self._syntax_error('Only <onDraw> tag allowed')
         elif hasattr(frag,'_selfClosingTag'):
-            if data!='': syntax_error('No content allowed in %s tag' % frag._selfClosingTag)
+            if data!='': self._syntax_error('No content allowed in %s tag' % frag._selfClosingTag)
             return
         else:
             # if sub and super are both on they will cancel each other out
@@ -905,3 +915,6 @@
     check_text('''Here comes <FONT FACE="Helvetica" SIZE="14pt">Helvetica 14</FONT> with <STRONG>strong</STRONG> <EM>emphasis</EM>.''')
     check_text('''Here comes <font face="Helvetica" size="14pt">Helvetica 14</font> with <Strong>strong</Strong> <em>emphasis</em>.''')
     check_text('''Here comes <font face="Courier" size="3cm">Courier 3cm</font> and normal again.''')
+    #AR 14-Jul-2006: test <br/> tag
+    check_text('''Before the break <br/>the middle line <br/> and the last line.''')
+    
\ No newline at end of file
--- a/reportlab/test/test_platypus_paraparser.py	Wed Jul 19 13:36:26 2006 +0000
+++ b/reportlab/test/test_platypus_paraparser.py	Fri Jul 21 08:48:41 2006 +0000
@@ -80,6 +80,12 @@
         fragList = ParaParser().parse(txt, self.style)[1]
         assert fragList[0].text == txt
 
+    def testBr(self):
+        txt = u"Hello <br/> World"
+        fragList = ParaParser().parse(txt, self.style)[1]
+        print fragList
+##        self.assertEquals(map(lambda x:x.text, fragList), [u'Hello ',u'Bold',u' World'])
+##        self.assertEquals(fragList[1].fontName, 'Times-Bold')
 
 
 def makeSuite():