4 """ |
4 """ |
5 __version__='''$Id: test_platypus_indents.py 3660 2010-02-08 18:17:33Z damian $''' |
5 __version__='''$Id: test_platypus_indents.py 3660 2010-02-08 18:17:33Z damian $''' |
6 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation |
6 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation |
7 setOutDir(__name__) |
7 setOutDir(__name__) |
8 import sys, os, random |
8 import sys, os, random |
9 from string import split, strip, join, whitespace |
|
10 from operator import truth |
9 from operator import truth |
11 from types import StringType, ListType |
10 from types import StringType, ListType |
12 import unittest |
11 import unittest |
13 from reportlab.pdfbase.pdfmetrics import stringWidth |
12 from reportlab.pdfbase.pdfmetrics import stringWidth |
14 from reportlab.platypus.paraparser import ParaParser |
13 from reportlab.platypus.paraparser import ParaParser |
99 #see license.txt for license details |
98 #see license.txt for license details |
100 #history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/xpreformatted.py |
99 #history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/xpreformatted.py |
101 __version__=''' $Id: xpreformatted.py 3866 2011-06-27 13:08:20Z rgbecker $ ''' |
100 __version__=''' $Id: xpreformatted.py 3866 2011-06-27 13:08:20Z rgbecker $ ''' |
102 __doc__='''A 'rich preformatted text' widget allowing internal markup''' |
101 __doc__='''A 'rich preformatted text' widget allowing internal markup''' |
103 |
102 |
104 import string |
|
105 from types import StringType, ListType |
103 from types import StringType, ListType |
106 from reportlab.lib import PyFontify |
104 from reportlab.lib import PyFontify |
107 from paragraph import Paragraph, cleanBlockQuotedText, _handleBulletWidth, ParaLines, _getFragWords, stringWidth, _sameFrag, getAscentDescent, imgVRange, imgNormV |
105 from paragraph import Paragraph, cleanBlockQuotedText, _handleBulletWidth, ParaLines, _getFragWords, stringWidth, _sameFrag, getAscentDescent, imgVRange, imgNormV |
108 from flowables import _dedenter |
106 from flowables import _dedenter |
109 |
107 |
110 class XPreformatted(Paragraph): |
108 class XPreformatted(Paragraph): |
111 def __init__(self, text, style, bulletText = None, frags=None, caseSensitive=1, dedent=0): |
109 def __init__(self, text, style, bulletText = None, frags=None, caseSensitive=1, dedent=0): |
112 self.caseSensitive = caseSensitive |
110 self.caseSensitive = caseSensitive |
113 cleaner = lambda text, dedent=dedent: string.join(_dedenter(text or '',dedent),'\\n') |
111 cleaner = lambda text, dedent=dedent: ,'\\n'.join(_dedenter(text or '',dedent)) |
114 self._setup(text, style, bulletText, frags, cleaner) |
112 self._setup(text, style, bulletText, frags, cleaner) |
115 |
113 |
116 def breakLines(self, width): |
114 def breakLines(self, width): |
117 if type(width) != ListType: maxWidths = [width] |
115 if type(width) != ListType: maxWidths = [width] |
118 else: maxWidths = width |
116 else: maxWidths = width |
136 if hasattr(f,'text'): |
134 if hasattr(f,'text'): |
137 fontSize = f.fontSize |
135 fontSize = f.fontSize |
138 fontName = f.fontName |
136 fontName = f.fontName |
139 ascent, descent = getAscentDescent(fontName,fontSize) |
137 ascent, descent = getAscentDescent(fontName,fontSize) |
140 kind = 0 |
138 kind = 0 |
141 L=string.split(f.text, '\\n') |
139 L=f.text.split('\\n') |
142 for l in L: |
140 for l in L: |
143 currentWidth = stringWidth(l,fontName,fontSize) |
141 currentWidth = stringWidth(l,fontName,fontSize) |
144 requiredWidth = max(currentWidth,requiredWidth) |
142 requiredWidth = max(currentWidth,requiredWidth) |
145 extraSpace = maxWidth-currentWidth |
143 extraSpace = maxWidth-currentWidth |
146 lines.append((extraSpace,string.split(l,' '),currentWidth)) |
144 lines.append((extraSpace,l.split(' '),currentWidth)) |
147 lineno = lineno+1 |
145 lineno = lineno+1 |
148 maxWidth = lineno<len(maxWidths) and maxWidths[lineno] or maxWidths[-1] |
146 maxWidth = lineno<len(maxWidths) and maxWidths[lineno] or maxWidths[-1] |
149 blPara = f.clone(kind=kind, lines=lines,ascent=ascent,descent=descent,fontSize=fontSize) |
147 blPara = f.clone(kind=kind, lines=lines,ascent=ascent,descent=descent,fontSize=fontSize) |
150 else: |
148 else: |
151 kind = f.kind |
149 kind = f.kind |