rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
self._seq = reportlab.lib.sequencer.getSequencer() self._reset(style)
def parse(self, text, style): """Given a formatted string will return a list of ParaFrag objects with their calculated widths. If errors occur None will be returned and the self.errors holds a list of the error messages. """
d = apply(os.path.join,string.split(p % D,'/'))
d = string.replace(p % D,'/',os.sep) print d
def _setOpt(name, value, conv=None): '''set a module level value from environ/default''' from os import environ ename = 'RL_'+name if environ.has_key(ename): value = environ[ename] if conv: value = conv(value) globals()[name] = value
s.size = size*w
s.size = size*w*2
def addStar(x,y,size,angle,g=g,w=s/20,x0=x,y0=y+s/2): s = Star() s.fillColor=colors.yellow s.angle = angle s.size = size*w s.x = x*w+x0 s.y = y*w+y0 g.add(s)
addStar(10,2,1,36.86989765) addStar(12,4,1,8.213210702) addStar(12,7,1,16.60154960) addStar(10,9,1,53.13010235)
addStar(10,1,1,36.86989765) addStar(12,3,1,8.213210702) addStar(12,6,1,16.60154960) addStar(10,8,1,53.13010235)
def addStar(x,y,size,angle,g=g,w=s/20,x0=x,y0=y+s/2): s = Star() s.fillColor=colors.yellow s.angle = angle s.size = size*w s.x = x*w+x0 s.y = y*w+y0 g.add(s)
if cmd[0] == 'BACKGROUND': self._bkgrndcmds.append(cmd) if cmd[0] == 'ROWBACKGROUNDS': self._bkgrndcmds.append(cmd) if cmd[0] == 'COLBACKGROUNDS':
if cmd[0] in ('BACKGROUND','ROWBACKGROUNDS','COLBACKGROUNDS'):
def _addCommand(self,cmd): if cmd[0] == 'BACKGROUND': self._bkgrndcmds.append(cmd) if cmd[0] == 'ROWBACKGROUNDS': self._bkgrndcmds.append(cmd) if cmd[0] == 'COLBACKGROUNDS': self._bkgrndcmds.append(cmd) elif cmd[0] == 'SPAN': self._spanCmds.append(cmd) elif _isLineCommand(cmd): # we expect op, start, stop, weight, colo...
elif cmd == 'BACKGROUND': canv.setFillColor(colors.toColor(arg)) canv.rect(x0, y0, w, h, stroke=0,fill=1)
def _drawBkgrnd(self): nrows = self._nrows ncols = self._ncols for cmd, (sc, sr), (ec, er), arg in self._bkgrndcmds: if sc < 0: sc = sc + ncols if ec < 0: ec = ec + ncols if sr < 0: sr = sr + nrows if er < 0: er = er + nrows x0 = self._colpositions[sc] y0 = self._rowpositions[sr] x1 = self._colpositions[min(ec+1,ncols)...
else: canv.setFillColor(colors.toColor(arg)) canv.rect(x0, y0, w, h, stroke=0,fill=1)
def _drawBkgrnd(self): nrows = self._nrows ncols = self._ncols for cmd, (sc, sr), (ec, er), arg in self._bkgrndcmds: if sc < 0: sc = sc + ncols if ec < 0: ec = ec + ncols if sr < 0: sr = sr + nrows if er < 0: er = er + nrows x0 = self._colpositions[sc] y0 = self._rowpositions[sr] x1 = self._colpositions[min(ec+1,ncols)...
path = os.path.basename(sys.argv[0]) path = os.path.splitext(path)[0] + "-%s.log" % expl
path = "test_docstrings-%s.log" % expl
def _writeLogFile(self, objType): "Write log file for different kind of documentable objects." cwd = os.getcwd()
lo = lo + ' bgCol= lineNum marcs help multiPage noOutline config= input= mode='
lo = lo + ' bgCol= verbose lineNum marcs help multiPage noOutline config= input= mode='
def updateWithContentsOfArgv(self, argv): "Update options as specified in a (command line) argument vector." # Specify accepted short option names (UNIX style). shortOpts = 'hv'
noValOpts = 'landscape stdout lineNum marcs help multiPage noOutline'
noValOpts = 'h v verbose landscape stdout lineNum marcs help multiPage noOutline'
def process(*args, **kwargs): "Provides a way of using py2pdf from within other Python scripts." noValOpts = 'landscape stdout lineNum marcs help multiPage noOutline' noValOpts = string.split(noValOpts, ' ') line = string.join(args, ' ') for k, v in kwargs.items(): if len(k) == 1: line = line + ' -%s=%s' % (k, v) eli...
line = string.join(args, ' ')
s = 'py2pdf.py'
def process(*args, **kwargs): "Provides a way of using py2pdf from within other Python scripts." noValOpts = 'landscape stdout lineNum marcs help multiPage noOutline' noValOpts = string.split(noValOpts, ' ') line = string.join(args, ' ') for k, v in kwargs.items(): if len(k) == 1: line = line + ' -%s=%s' % (k, v) eli...
line = line + ' -%s=%s' % (k, v)
s = s + ' -%s' % k if k not in noValOpts: s = s + ' %s' % v
def process(*args, **kwargs): "Provides a way of using py2pdf from within other Python scripts." noValOpts = 'landscape stdout lineNum marcs help multiPage noOutline' noValOpts = string.split(noValOpts, ' ') line = string.join(args, ' ') for k, v in kwargs.items(): if len(k) == 1: line = line + ' -%s=%s' % (k, v) eli...
if k in noValOpts: line = line + ' --%s' % k else: line = line + ' --%s=%s' % (k, v) print line
s = s + ' --%s' % k if k not in noValOpts: s = s + '=%s' % v s = s + ' ' + string.join(args, ' ') s = string.split(s, ' ') main(s)
def process(*args, **kwargs): "Provides a way of using py2pdf from within other Python scripts." noValOpts = 'landscape stdout lineNum marcs help multiPage noOutline' noValOpts = string.split(noValOpts, ' ') line = string.join(args, ' ') for k, v in kwargs.items(): if len(k) == 1: line = line + ' -%s=%s' % (k, v) eli...
if (h > self._aH and not trySplit):
if (not rl_config.allowTableBoundsErrors) and (h > self._aH and not trySplit):
def _add(self, flowable, canv, trySplit=0): """ Draws the flowable at the current position. Returns 1 if successful, 0 if it would not fit. Raises a LayoutError if the object is too wide, or if it is too high for a totally empty frame, to avoid infinite loops""" y = self._y p = self._y1p s = 0 if not self._atTop: s = f...
slf.contents.insert(i,n)
self.contents.insert(i,n)
def insert(self, i, n, name=None): 'Inserts sub-node n in contents at specified location' assert isValidChild(n), "Can only insert Shape or UserNode objects in a Group" if i<0: self.contents[i:i] =[n] else: slf.contents.insert(i,n) self._addNamedNode(name,n)
'fontname':'Times-Roman',
'fontName':'Times-Roman',
def prepareCanvas(self, canvas): """You can ask a LineStyle to set up the canvas for drawing the lines.""" canvas.setLineWidth(1) #etc. etc.
from string import letters as LETTERS, whitespace as WHITESPACE
from string import letters as LETTERS, whitespace as WHITESPACE, atoi
def Paragraph(text, style, bulletText=None, frags=None)
heightremaining = maxheight-leading
heightremaining = maxheight if leading: self.leading = leading
def format(self, maxwidth, maxheight, program, leading=0): "return program with line operations added if at least one line fits" # note: a generated formatted segment should not be formatted again startstate = self.__dict__.copy() #remainder = self.cleanProgram(program) remainder = program[:] #program1 = remainder[:] #...
textobject.setFont(self.fontName, self.fontSize)
def runOpCodes(self, program, canvas, textobject): "render the line(s)"
third element of the unnumberred list third element of the unnumberred list third element of the unnumberred list
third element of the unnumberred list &amp; third element of the unnumberred list &amp; third element of the unnumberred list &amp;exist; --> &exist;
def translate(self, nodetuple, controller, context, overrides): thepara = ("para", {}, [nodetuple], None) return theParaMapper.translate(thepara, controller, context, overrides)
parsedpara = rparsexml.parsexmlSimple(testparagraph)
parsedpara = rparsexml.parsexmlSimple(testparagraph,entityReplacer=None)
def test2(canv): #print test_program; return from reportlab.lib.units import inch from reportlab.lib.styles import ParagraphStyle from reportlab.lib import rparsexml parsedpara = rparsexml.parsexmlSimple(testparagraph) S = ParagraphStyle("Normal", None) P = Para(S, parsedpara) (w, h) = P.wrap(5*inch, 10*inch) print "wr...
greeks = { 'alpha':'a', 'beta':'b', 'chi':'c', 'Delta':'D', 'delta':'d', 'epsiv':'e', 'eta':'h', 'Gamma':'G', 'gamma':'g', 'iota':'i', 'kappa':'k', 'Lambda':'L', 'lambda':'l', 'mu':'m', 'nu':'n', 'Omega':'W', 'omega':'w', 'omicron':'x', 'Phi':'F', 'phi':'f', 'phiv':'j', 'Pi':'P', 'pi':'p', 'piv':'v', 'Psi':'Y', 'psi':'...
def handleSpecialCharacters(engine, text, program=None): from paraparser import greeks, symenc
def test2(canv): #print test_program; return from reportlab.lib.units import inch from reportlab.lib.styles import ParagraphStyle from reportlab.lib import rparsexml parsedpara = rparsexml.parsexmlSimple(testparagraph) S = ParagraphStyle("Normal", None) P = Para(S, parsedpara) (w, h) = P.wrap(5*inch, 10*inch) print "wr...
if greeks.has_key(name):
if name[0]==' try: if name[1] == 'x': n = atoi(name[2:], 16) else: n = atoi(name[1:]) except atoi_error: n = -1 if 0<=n<=255: fragment = chr(n)+fragment[semi+1:] elif symenc.has_key(n): fragment = fragment[semi+1:] (f,b,i) = engine.shiftfont(program, face="symbol") program.append(symenc[n]) engine.shiftfont(program, fa...
def handleSpecialCharacters(engine, text, program=None, greeks=greeks): from string import whitespace # add space prefix if space here if text[0:1] in whitespace: program.append(" ") #print "handling", repr(text) # shortcut if 0 and "&" not in text: result = [] for x in text.split(): result.append(x+" ") if result: las...
parsedpara = rparsexml.parsexmlSimple(text)
parsedpara = rparsexml.parsexmlSimple(text,entityReplacer=None)
def Paragraph(text, style, bulletText=None, frags=None, context=None): """ Paragraph(text, style, bulletText=None) intended to be like a platypus Paragraph but better. """ # if there is no & or < in text then use the fast paragraph if "&" not in text and "<" not in text: return FastPara(style, simpletext=text) else: # ...
if hasattr(self,'noImageCaching') and canvas.noImageCaching:
if hasattr(self,'noImageCaching') and self.noImageCaching \ or hasattr(canvas,'noImageCaching') and canvas.noImageCaching:
def drawInlineImage(self, canvas): #, image, x,y, width=None,height=None): """Draw an Image into the specified rectangle. If width and height are omitted, they are calculated from the image size. Also allow file names as well as images. This allows a caching mechanism"""
import string
from types import StringType, UnicodeType, InstanceType, TupleType, ListType, FloatType from string import letters as LETTERS, whitespace as WHITESPACE
def Paragraph(text, style, bulletText=None, frags=None)
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY
def format(self, maxwidth, maxheight, program, leading=0): "return program with line operations added if at least one line fits" # note: a generated formatted segment should not be formatted again startstate = self.__dict__.copy() #remainder = self.cleanProgram(program) remainder = program[:] #program1 = remainder[:] #...
raise ValueError, "indents %s %s too wide for space %s" % (self.indent, self.rightIndent, maxwidth)
raise ValueError, "indents %s %s too wide for space %s" % (self.indent, self.rightIndent, \ maxwidth)
def format(self, maxwidth, maxheight, program, leading=0): "return program with line operations added if at least one line fits" # note: a generated formatted segment should not be formatted again startstate = self.__dict__.copy() #remainder = self.cleanProgram(program) remainder = program[:] #program1 = remainder[:] #...
(lineIsFull, line, cursor, currentLength, usedIndent, maxLength, justStrings) = self.fitLine(remainder, maxwidth)
(lineIsFull, line, cursor, currentLength, \ usedIndent, maxLength, justStrings) = self.fitLine(remainder, maxwidth)
def format(self, maxwidth, maxheight, program, leading=0): "return program with line operations added if at least one line fits" # note: a generated formatted segment should not be formatted again startstate = self.__dict__.copy() #remainder = self.cleanProgram(program) remainder = program[:] #program1 = remainder[:] #...
from types import StringType, TupleType, InstanceType, FloatType
def fitLine(self, program, totalLength): "fit words (and other things) onto a line" # assuming word lengths and spaces have not been yet added # fit words onto a line up to maxlength, adding spaces and respecting extra space from types import StringType, TupleType, InstanceType, FloatType from reportlab.pdfbase.pdfmetr...
if topcode is StringType or topcode is InstanceType:
if topcode in (StringType, UnicodeType, InstanceType):
def fitLine(self, program, totalLength): "fit words (and other things) onto a line" # assuming word lengths and spaces have not been yet added # fit words onto a line up to maxlength, adding spaces and respecting extra space from types import StringType, TupleType, InstanceType, FloatType from reportlab.pdfbase.pdfmetr...
if type(colorname) is StringType:
if type(colorname) in (StringType, UnicodeType):
def fitLine(self, program, totalLength): "fit words (and other things) onto a line" # assuming word lengths and spaces have not been yet added # fit words onto a line up to maxlength, adding spaces and respecting extra space from types import StringType, TupleType, InstanceType, FloatType from reportlab.pdfbase.pdfmetr...
if type(fontsize) is StringType:
if type(fontsize) in (StringType, UnicodeType):
def fitLine(self, program, totalLength): "fit words (and other things) onto a line" # assuming word lengths and spaces have not been yet added # fit words onto a line up to maxlength, adding spaces and respecting extra space from types import StringType, TupleType, InstanceType, FloatType from reportlab.pdfbase.pdfmetr...
from types import StringType, InstanceType
def insertShift(self, line, shift): # insert shift just before first visible element in line from types import StringType, InstanceType result = [] first = 1 for e in line: te = type(e) if first and (te is StringType or te is InstanceType): result.append(shift) first = 0 result.append(e) return result
if first and (te is StringType or te is InstanceType):
if first and (te in (StringType, UnicodeType, InstanceType)):
def insertShift(self, line, shift): # insert shift just before first visible element in line from types import StringType, InstanceType result = [] first = 1 for e in line: te = type(e) if first and (te is StringType or te is InstanceType): result.append(shift) first = 0 result.append(e) return result
from types import InstanceType, StringType, TupleType, FloatType
def justifyAlign(self, line, lineLength, maxLength): diff = maxLength-lineLength # count EXPANDABLE SPACES AFTER THE FIRST VISIBLE from types import InstanceType, StringType, TupleType, FloatType spacecount = 0 visible = 0 for e in line: te = type(e) if te is FloatType and e>TOOSMALLSPACE and visible: spacecount = spac...
elif te is StringType or te is InstanceType:
elif te in (StringType, UnicodeType, InstanceType):
def justifyAlign(self, line, lineLength, maxLength): diff = maxLength-lineLength # count EXPANDABLE SPACES AFTER THE FIRST VISIBLE from types import InstanceType, StringType, TupleType, FloatType spacecount = 0 visible = 0 for e in line: te = type(e) if te is FloatType and e>TOOSMALLSPACE and visible: spacecount = spac...
if (te is InstanceType or te is StringType):
if (te in (StringType, UnicodeType, InstanceType)):
def justifyAlign(self, line, lineLength, maxLength): diff = maxLength-lineLength # count EXPANDABLE SPACES AFTER THE FIRST VISIBLE from types import InstanceType, StringType, TupleType, FloatType spacecount = 0 visible = 0 for e in line: te = type(e) if te is FloatType and e>TOOSMALLSPACE and visible: spacecount = spac...
from types import FloatType, StringType, InstanceType from string import join
def shrinkWrap(self, line): # for non justified text, collapse adjacent text/shift's into single operations #return line # for testing result = [] index = 0 maxindex = len(line) from types import FloatType, StringType, InstanceType from string import join while index<maxindex: e = line[index] te = type(e) if te is Stri...
if te is StringType and index<maxindex-1:
if te in (StringType, UnicodeType) and index<maxindex-1:
def shrinkWrap(self, line): # for non justified text, collapse adjacent text/shift's into single operations #return line # for testing result = [] index = 0 maxindex = len(line) from types import FloatType, StringType, InstanceType from string import join while index<maxindex: e = line[index] te = type(e) if te is Stri...
while index<maxindex and (tnexte is FloatType or tnexte is StringType):
while index<maxindex and (tnexte in (FloatType, StringType, UnicodeType)):
def shrinkWrap(self, line): # for non justified text, collapse adjacent text/shift's into single operations #return line # for testing result = [] index = 0 maxindex = len(line) from types import FloatType, StringType, InstanceType from string import join while index<maxindex: e = line[index] te = type(e) if te is Stri...
elif tnexte is StringType:
elif tnexte in (StringType, UnicodeType):
def shrinkWrap(self, line): # for non justified text, collapse adjacent text/shift's into single operations #return line # for testing result = [] index = 0 maxindex = len(line) from types import FloatType, StringType, InstanceType from string import join while index<maxindex: e = line[index] te = type(e) if te is Stri...
s = string.join(thestrings)
s = ' '.join(thestrings)
def shrinkWrap(self, line): # for non justified text, collapse adjacent text/shift's into single operations #return line # for testing result = [] index = 0 maxindex = len(line) from types import FloatType, StringType, InstanceType from string import join while index<maxindex: e = line[index] te = type(e) if te is Stri...
from types import FloatType, TupleType, StringType, InstanceType
def cleanProgram(self, line): "collapse adjacent spacings" #return line # for debugging result = [] last = 0 from types import FloatType, TupleType, StringType, InstanceType for e in line: if type(e) is FloatType: # switch to expandable space if appropriate if last<0 and e>0: last = -last if e<0 and last>0: e = -e last...
if tthis is StringType or tnext is StringType or this is InstanceType or tnext is InstanceType:
if tthis in (StringType, UnicodeType) or \ tnext in (StringType, UnicodeType) or \ this is InstanceType or tnext is InstanceType:
def cleanProgram(self, line): "collapse adjacent spacings" #return line # for debugging result = [] last = 0 from types import FloatType, TupleType, StringType, InstanceType for e in line: if type(e) is FloatType: # switch to expandable space if appropriate if last<0 and e>0: last = -last if e<0 and last>0: e = -e last...
from types import StringType, TupleType, InstanceType, FloatType
def runOpCodes(self, program, canvas, textobject): "render the line(s)" #import types from types import StringType, TupleType, InstanceType, FloatType escape = canvas._escape code = textobject._code startstate = self.__dict__.copy() font = None size = None # be sure to set them before using them (done lazily below) #te...
if topcode is StringType or topcode is InstanceType:
if topcode in (StringType, UnicodeType, InstanceType):
def runOpCodes(self, program, canvas, textobject): "render the line(s)" #import types from types import StringType, TupleType, InstanceType, FloatType escape = canvas._escape code = textobject._code startstate = self.__dict__.copy() font = None size = None # be sure to set them before using them (done lazily below) #te...
if topcode is StringType:
if topcode in (StringType, UnicodeType):
def runOpCodes(self, program, canvas, textobject): "render the line(s)" #import types from types import StringType, TupleType, InstanceType, FloatType escape = canvas._escape code = textobject._code startstate = self.__dict__.copy() font = None size = None # be sure to set them before using them (done lazily below) #te...
if type(colorname) is StringType:
if type(colorname) in (StringType, UnicodeType):
def runOpCodes(self, program, canvas, textobject): "render the line(s)" #import types from types import StringType, TupleType, InstanceType, FloatType escape = canvas._escape code = textobject._code startstate = self.__dict__.copy() font = None size = None # be sure to set them before using them (done lazily below) #te...
if type(fontsize) is StringType:
if type(fontsize) in (StringType, UnicodeType):
def runOpCodes(self, program, canvas, textobject): "render the line(s)" #import types from types import StringType, TupleType, InstanceType, FloatType escape = canvas._escape code = textobject._code startstate = self.__dict__.copy() font = None size = None # be sure to set them before using them (done lazily below) #te...
from types import StringType
def stringLine(line, length): "simple case: line with just strings and spacings which can be ignored" strings = [] from types import StringType for x in line: if type(x) is StringType: strings.append(x) text = string.join(strings) result = [text, float(length)] nextlinemark = ("nextLine", 0) if line and line[-1]==nextl...
if type(x) is StringType:
if type(x) in (StringType, UnicodeType):
def stringLine(line, length): "simple case: line with just strings and spacings which can be ignored" strings = [] from types import StringType for x in line: if type(x) is StringType: strings.append(x) text = string.join(strings) result = [text, float(length)] nextlinemark = ("nextLine", 0) if line and line[-1]==nextl...
text = string.join(strings)
text = ' '.join(strings)
def stringLine(line, length): "simple case: line with just strings and spacings which can be ignored" strings = [] from types import StringType for x in line: if type(x) is StringType: strings.append(x) text = string.join(strings) result = [text, float(length)] nextlinemark = ("nextLine", 0) if line and line[-1]==nextl...
from types import StringType
def simpleJustifyAlign(line, currentLength, maxLength): "simple justification with only strings" strings = [] from types import StringType for x in line[:-1]: if type(x) is StringType: strings.append(x) nspaces = len(strings)-1 slack = maxLength-currentLength text = string.join(strings) if nspaces>0 and slack>0: wordsp...
if type(x) is StringType:
if type(x) in (StringType, UnicodeType):
def simpleJustifyAlign(line, currentLength, maxLength): "simple justification with only strings" strings = [] from types import StringType for x in line[:-1]: if type(x) is StringType: strings.append(x) nspaces = len(strings)-1 slack = maxLength-currentLength text = string.join(strings) if nspaces>0 and slack>0: wordsp...
text = string.join(strings)
text = ' '.join(strings)
def simpleJustifyAlign(line, currentLength, maxLength): "simple justification with only strings" strings = [] from types import StringType for x in line[:-1]: if type(x) is StringType: strings.append(x) nspaces = len(strings)-1 slack = maxLength-currentLength text = string.join(strings) if nspaces>0 and slack>0: wordsp...
if string.upper(text) in ("Y", "YES", "TRUE", "1"):
if text.upper() in ("Y", "YES", "TRUE", "1"):
def readBool(text): if string.upper(text) in ("Y", "YES", "TRUE", "1"): return 1 elif string.upper(text) in ("N", "NO", "FALSE", "0"): return 0 else: raise RMLError, "true/false attribute has illegal value '%s'" % text
elif string.upper(text) in ("N", "NO", "FALSE", "0"):
elif text.upper() in ("N", "NO", "FALSE", "0"):
def readBool(text): if string.upper(text) in ("Y", "YES", "TRUE", "1"): return 1 elif string.upper(text) in ("N", "NO", "FALSE", "0"): return 0 else: raise RMLError, "true/false attribute has illegal value '%s'" % text
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY up = string.upper(text)
up = text.upper()
def readAlignment(text): from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY up = string.upper(text) if up == 'LEFT': return TA_LEFT elif up == 'RIGHT': return TA_RIGHT elif up in ['CENTER', 'CENTRE']: return TA_CENTER elif up == 'JUSTIFY': return TA_JUSTIFY
text = string.strip(text)
text = text.strip()
def readLength(text): """Read a dimension measurement: accept "3in", "5cm", "72 pt" and so on.""" text = string.strip(text) try: return float(text) except ValueError: text = string.lower(text) numberText, units = text[:-2],text[-2:] numberText = string.strip(numberText) try: number = float(numberText) except ValueError...
text = string.lower(text)
text = text.lower()
def readLength(text): """Read a dimension measurement: accept "3in", "5cm", "72 pt" and so on.""" text = string.strip(text) try: return float(text) except ValueError: text = string.lower(text) numberText, units = text[:-2],text[-2:] numberText = string.strip(numberText) try: number = float(numberText) except ValueError...
numberText = string.strip(numberText)
numberText = numberText.strip()
def readLength(text): """Read a dimension measurement: accept "3in", "5cm", "72 pt" and so on.""" text = string.strip(text) try: return float(text) except ValueError: text = string.lower(text) numberText, units = text[:-2],text[-2:] numberText = string.strip(numberText) try: number = float(numberText) except ValueError...
from string import split, strip s = strip(s)
s = s.strip()
def lengthSequence(s, converter=readLength): """from "(2, 1)" or "2,1" return [2,1], for example""" from string import split, strip s = strip(s) if s[:1]=="(" and s[-1:]==")": s = s[1:-1] sl = split(s, ",") sl = map(strip, sl) sl = map(converter, sl) return sl
sl = split(s, ",") sl = map(strip, sl) sl = map(converter, sl)
sl = s.split(',') sl = [s.strip() for s in sl] sl = [converter(s) for s in sl]
def lengthSequence(s, converter=readLength): """from "(2, 1)" or "2,1" return [2,1], for example""" from string import split, strip s = strip(s) if s[:1]=="(" and s[-1:]==")": s = s[1:-1] sl = split(s, ",") sl = map(strip, sl) sl = map(converter, sl) return sl
if text[0] in string.letters:
if text[0] in LETTERS:
def readColor(text): """Read color names or tuples, RGB or CMYK, and return a Color object.""" if not text: return None from reportlab.lib import colors if text[0] in string.letters: return colors.__dict__[text] tup = lengthSequence(text) msg = "Color tuple must have 3 (or 4) elements for RGB (or CMYC)." assert 3 <= l...
"li.defaultStyle": "Definition"
"ul.defaultStyle": "UnorderedList", "ol.defaultStyle": "OrderedList", "li.defaultStyle": "Definition",
def addAttributes(self, dictionary): for key in dictionary.keys(): value = dictionary[key] if value is not None: if hasattr(StyleAttributeConverters, key): converter = getattr(StyleAttributeConverters, key)[0] value = converter(value) setattr(self, key, value)
words = string.split(simpletext)
words = simpletext.split()
def wrap(self, availableWidth, availableHeight): simpletext = self.simpletext self.availableWidth = availableWidth style = self.style text = self.simpletext rightIndent = style.rightIndent leftIndent = style.leftIndent leading = style.leading font = style.fontName size = style.fontSize firstindent = style.firstLineInde...
lines.append( (string.join(currentline), currentlength, len(currentline)) )
lines.append( (' '.join(currentline), currentlength, len(currentline)) )
def wrap(self, availableWidth, availableHeight): simpletext = self.simpletext self.availableWidth = availableWidth style = self.style text = self.simpletext rightIndent = style.rightIndent leftIndent = style.leftIndent leading = style.leading font = style.fontName size = style.fontSize firstindent = style.firstLineInde...
remainder = self.remainder = string.join(words[cursor:])
remainder = self.remainder = ' '.join(words[cursor:])
def wrap(self, availableWidth, availableHeight): simpletext = self.simpletext self.availableWidth = availableWidth style = self.style text = self.simpletext rightIndent = style.rightIndent leftIndent = style.leftIndent leading = style.leading font = style.fontName size = style.fontSize firstindent = style.firstLineInde...
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY
def draw(self): from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT, TA_JUSTIFY style = self.style lines = self.lines rightIndent = style.rightIndent leftIndent = style.leftIndent leading = style.leading font = style.fontName size = style.fontSize alignment = style.alignment firstindent = style.firstLineIndent...
if context is None: context = defaultContext() self.context = context
self.context = buildContext(context)
def __init__(self, style, parsedText=None, bulletText=None, state=None, context=None, baseindent=0): #print id(self), "para", parsedText self.baseindent = baseindent if context is None: context = defaultContext() self.context = context self.parsedText = parsedText self.bulletText = bulletText self.style1 = style # make...
self.face = "times" self.size = 10
self.face = style.fontName self.size = style.fontSize
def __init__(self, style, parsedText=None, bulletText=None, state=None, context=None, baseindent=0): #print id(self), "para", parsedText self.baseindent = baseindent if context is None: context = defaultContext() self.context = context self.parsedText = parsedText self.bulletText = bulletText self.style1 = style # make...
(formattedProgram, remainder, laststate, heightused) = p.format(availableWidth, availableHeight, program, leading)
(formattedProgram, remainder, \ laststate, heightused) = p.format(availableWidth, availableHeight, program, leading)
def wrap(self, availableWidth, availableHeight): if debug: print "WRAPPING", id(self), availableWidth, availableHeight print " ", self.formattedProgram print " ", self.program self.availableHeight = availableHeight self.myengine = p = paragraphEngine() p.baseindent = self.baseindent # for shifting bullets as needed...
self.remainder = Para(self.style1, parsedText=None, bulletText=None, state=laststate)
self.remainder = Para(self.style1, parsedText=None, bulletText=None, \ state=laststate, context=self.context)
def wrap(self, availableWidth, availableHeight): if debug: print "WRAPPING", id(self), availableWidth, availableHeight print " ", self.formattedProgram print " ", self.program self.availableHeight = availableHeight self.myengine = p = paragraphEngine() p.baseindent = self.baseindent # for shifting bullets as needed...
from types import StringType, InstanceType
def compileProgram(self, parsedText, program=None): style = self.style1 # standard parameters #program = self.program if program is None: program = [] a = program.append fn = style.fontName # add style information if there was no initial state a( ("face", fn ) ) from reportlab.lib.fonts import ps2tt (self.face, self.bo...
if tx is StringType or tx is InstanceType:
if tx in (StringType, UnicodeType, InstanceType):
def compileProgram(self, parsedText, program=None): style = self.style1 # standard parameters #program = self.program if program is None: program = [] a = program.append fn = style.fontName # add style information if there was no initial state a( ("face", fn ) ) from reportlab.lib.fonts import ps2tt (self.face, self.bo...
if ttext is types.StringType:
if ttext in (StringType, UnicodeType):
def compileComponent(self, parsedText, program): import types ttext = type(parsedText) #program = self.program if ttext is types.StringType: # handle special characters here... # short cut if parsedText: stext = parsedText.strip() #string.strip(parsedText) if not stext: program.append(" ") # contract whitespace to sing...
elif ttext is types.ListType:
elif ttext is ListType:
def compileComponent(self, parsedText, program): import types ttext = type(parsedText) #program = self.program if ttext is types.StringType: # handle special characters here... # short cut if parsedText: stext = parsedText.strip() #string.strip(parsedText) if not stext: program.append(" ") # contract whitespace to sing...
elif ttext is types.TupleType:
elif ttext is TupleType:
def compileComponent(self, parsedText, program): import types ttext = type(parsedText) #program = self.program if ttext is types.StringType: # handle special characters here... # short cut if parsedText: stext = parsedText.strip() #string.strip(parsedText) if not stext: program.append(" ") # contract whitespace to sing...
t = string.join(L, "")
t = ''.join(L)
def compileComponent(self, parsedText, program): import types ttext = type(parsedText) #program = self.program if ttext is types.StringType: # handle special characters here... # short cut if parsedText: stext = parsedText.strip() #string.strip(parsedText) if not stext: program.append(" ") # contract whitespace to sing...
import types
def compile_ul(self, attdict, content, extra, program, tagname="ul"): # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker(tagname, atts, self.context) # now do each element as a separate paragraph import types for e in content: te = type(e) if te is types.StringType: i...
if te is types.StringType: if e.strip():
if te in (StringType, UnicodeType): if e.strip():
def compile_ul(self, attdict, content, extra, program, tagname="ul"): # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker(tagname, atts, self.context) # now do each element as a separate paragraph import types for e in content: te = type(e) if te is types.StringType: i...
elif te is types.TupleType:
elif te is TupleType:
def compile_ul(self, attdict, content, extra, program, tagname="ul"): # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker(tagname, atts, self.context) # now do each element as a separate paragraph import types for e in content: te = type(e) if te is types.StringType: i...
import types
def compile_dl(self, attdict, content, extra, program): # by transformation #print "compile", tagname, attdict atts = attdict.copy() # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker("dl", atts, self.context) # now do each element as a separate paragraph import types...
if te is types.StringType: if e.strip():
if te in (StringType, UnicodeType): if e.strip():
def compile_dl(self, attdict, content, extra, program): # by transformation #print "compile", tagname, attdict atts = attdict.copy() # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker("dl", atts, self.context) # now do each element as a separate paragraph import types...
elif te is types.TupleType:
elif te is TupleType:
def compile_dl(self, attdict, content, extra, program): # by transformation #print "compile", tagname, attdict atts = attdict.copy() # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker("dl", atts, self.context) # now do each element as a separate paragraph import types...
raise ValueError, "don't expect %s here inside list, expect 'dd' or 'dt'" % repr(tagname)
raise ValueError, "don't expect %s here inside list, expect 'dd' or 'dt'" % \ repr(tagname)
def compile_dl(self, attdict, content, extra, program): # by transformation #print "compile", tagname, attdict atts = attdict.copy() # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker("dl", atts, self.context) # now do each element as a separate paragraph import types...
if len(content1)!=1: raise ValueError, "only simple strings supported in dd content currently: "+repr(content1) bullet = content1[0] if type(bullet) is not types.StringType: raise ValueError, "only simple strings supported in dd content currently: "+repr(content1)
self.compile_para(attdict1, content1, extra, program)
def compile_dl(self, attdict, content, extra, program): # by transformation #print "compile", tagname, attdict atts = attdict.copy() # by transformation #print "compile", tagname, attdict atts = attdict.copy() bulletmaker = bulletMaker("dl", atts, self.context) # now do each element as a separate paragraph import types...
from types import StringType
def compile_bullet(self, attdict, content, extra, program): from types import StringType ### eventually should allow things like images and graphics in bullets too XXXX if len(content)!=1 or type(content[0]) is not StringType: raise ValueError, "content for bullet must be a single string" text = content[0] self.do_bull...
if len(content)!=1 or type(content[0]) is not StringType:
if len(content)!=1 or type(content[0]) not in (StringType, UnicodeType):
def compile_bullet(self, attdict, content, extra, program): from types import StringType ### eventually should allow things like images and graphics in bullets too XXXX if len(content)!=1 or type(content[0]) is not StringType: raise ValueError, "content for bullet must be a single string" text = content[0] self.do_bull...
if type(text) is types.StringType and "&" not in text:
if type(text) in (StringType, UnicodeType) and "&" not in text:
def translate(self, nodetuple, controller, context, overrides): (tagname, attdict, content, extra) = nodetuple stylename = tagname+".defaultStyle" stylename = attdict.get("style", stylename) style = context[stylename] mystyle = SimpleStyle(name="rml2pdf internal style", parent=style) mystyle.addAttributes(attdict) bull...
semi = string.find(fragment, ";")
semi = fragment.find(";")
def handleSpecialCharacters(engine, text, program=None, greeks=greeks): from string import whitespace # add space prefix if space here if text[0:1] in whitespace: program.append(" ") #print "handling", repr(text) # shortcut if 0 and "&" not in text: result = [] for x in text.split(): result.append(x+" ") if result: las...
if fragment and fragment[0] in string.whitespace:
if fragment and fragment[0] in WHITESPACE:
def handleSpecialCharacters(engine, text, program=None, greeks=greeks): from string import whitespace # add space prefix if space here if text[0:1] in whitespace: program.append(" ") #print "handling", repr(text) # shortcut if 0 and "&" not in text: result = [] for x in text.split(): result.append(x+" ") if result: las...
if fragment[-1] in string.whitespace:
if fragment[-1] in WHITESPACE:
def handleSpecialCharacters(engine, text, program=None, greeks=greeks): from string import whitespace # add space prefix if space here if text[0:1] in whitespace: program.append(" ") #print "handling", repr(text) # shortcut if 0 and "&" not in text: result = [] for x in text.split(): result.append(x+" ") if result: las...
def Paragraph(text, style, bulletText=None, frags=None):
def Paragraph(text, style, bulletText=None, frags=None, context=None):
def Paragraph(text, style, bulletText=None, frags=None): """ Paragraph(text, style, bulletText=None) intended to be like a platypus Paragraph but better. """ # if there is no & or < in text then use the fast paragraph if "&" not in text and "<" not in text: return FastPara(style, simpletext=text) else: # use the fully ...
return Para(style, parsedText=parsedpara, bulletText=bulletText, state=None)
return Para(style, parsedText=parsedpara, bulletText=bulletText, state=None, context=context)
def Paragraph(text, style, bulletText=None, frags=None): """ Paragraph(text, style, bulletText=None) intended to be like a platypus Paragraph but better. """ # if there is no & or < in text then use the fast paragraph if "&" not in text and "<" not in text: return FastPara(style, simpletext=text) else: # use the fully ...
stext = string.split(text)
stext = text.split()
def splitspace(text): # split on spacing but include spaces at element ends stext = string.split(text) result = [] for e in stext: result.append(e+" ") return result
def findT1File(fontName,ext='.pfb'):
def _searchT1Dirs(n):
def findT1File(fontName,ext='.pfb'): from reportlab.rl_config import T1SearchPath assert T1SearchPath!=[], "No Type-1 font search path" if sys.platform in ('linux2',) and ext=='.pfb': ext = '' n = _findFNR(fontName)+ext for d in T1SearchPath: f = os.path.join(d,n) if os.path.isfile(f): return f return None
if sys.platform in ('linux2',) and ext=='.pfb': ext = '' n = _findFNR(fontName)+ext
def findT1File(fontName,ext='.pfb'): from reportlab.rl_config import T1SearchPath assert T1SearchPath!=[], "No Type-1 font search path" if sys.platform in ('linux2',) and ext=='.pfb': ext = '' n = _findFNR(fontName)+ext for d in T1SearchPath: f = os.path.join(d,n) if os.path.isfile(f): return f return None
tx.moveCursor(offset + 0.5 * extraspace, 0)
m = offset + 0.5 * extraspace tx.moveCursor(m, 0)
def cleanBlockQuotedText(text): """This is an internal utility which takes triple- quoted text form within the document and returns (hopefully) the paragraph the user intended originally.""" stripped = string.strip(text) lines = string.split(stripped, '\n') trimmed_lines = map(string.lstrip, lines) return string.join(t...