<s> import os <EOL> import sys <EOL> import re <EOL> from copy import copy <EOL> from types import * <EOL> from os . path import abspath , dirname , expanduser , join <EOL> import docutils . nodes <EOL> import reportlab <EOL> from reportlab . platypus import * <EOL> import reportlab . lib . colors as colors <EOL> import reportlab . lib . units as units <EOL> from reportlab . pdfbase . ttfonts import TTFont <EOL> from reportlab . lib . fonts import addMapping <EOL> from reportlab . lib . styles import * <EOL> from reportlab . lib . enums import * <EOL> from reportlab . pdfbase import pdfmetrics <EOL> import reportlab . lib . pagesizes as pagesizes <EOL> import reportlab . rl_config <EOL> from rst2pdf . rson import loads as rson_loads <EOL> import findfonts <EOL> from log import log <EOL> from opt_imports import ParagraphStyle , wordaxe , wordaxe_version <EOL> HAS_WORDAXE = wordaxe is not None <EOL> unit_separator = re . compile ( '<STR_LIT>' ) <EOL> class StyleSheet ( object ) : <EOL> '''<STR_LIT>''' <EOL> @ staticmethod <EOL> def stylepairs ( data ) : <EOL> '''<STR_LIT>''' <EOL> styles = data . get ( '<STR_LIT>' , { } ) <EOL> try : <EOL> stylenames = styles . keys ( ) <EOL> except AttributeError : <EOL> for style in styles : <EOL> yield style <EOL> return <EOL> while stylenames : <EOL> name = stylenames . pop ( ) <EOL> parent = styles [ name ] . get ( '<STR_LIT>' ) <EOL> if parent not in stylenames : <EOL> yield name , styles [ name ] <EOL> continue <EOL> names = [ name ] <EOL> while parent in stylenames : <EOL> stylenames . remove ( parent ) <EOL> names . append ( parent ) <EOL> parent = styles [ names [ - <NUM_LIT:1> ] ] . get ( '<STR_LIT>' ) <EOL> while names : <EOL> name = names . pop ( ) <EOL> yield name , styles [ name ] <EOL> def __init__ ( self , flist , font_path = None , style_path = None , def_dpi = <NUM_LIT> ) : <EOL> log . info ( '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( flist ) ) <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> self . PATH = abspath ( dirname ( sys . executable ) ) <EOL> else : <EOL> self . PATH = abspath ( dirname ( __file__ ) ) <EOL> flist = [ join ( self . PATH , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> join ( self . PATH , '<STR_LIT>' , '<STR_LIT>' ) ] + flist <EOL> self . def_dpi = def_dpi <EOL> if font_path is None : <EOL> font_path = [ ] <EOL> font_path += [ '<STR_LIT:.>' , os . path . join ( self . PATH , '<STR_LIT>' ) ] <EOL> self . FontSearchPath = map ( os . path . expanduser , font_path ) <EOL> if style_path is None : <EOL> style_path = [ ] <EOL> style_path += [ '<STR_LIT:.>' , os . path . join ( self . PATH , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ] <EOL> self . StyleSearchPath = map ( os . path . expanduser , style_path ) <EOL> self . FontSearchPath = list ( set ( self . FontSearchPath ) ) <EOL> self . StyleSearchPath = list ( set ( self . StyleSearchPath ) ) <EOL> log . info ( '<STR_LIT>' % self . FontSearchPath ) <EOL> log . info ( '<STR_LIT>' % self . StyleSearchPath ) <EOL> findfonts . flist = self . FontSearchPath <EOL> self . pw = <NUM_LIT:0> <EOL> self . ph = <NUM_LIT:0> <EOL> self . ps = None <EOL> self . tm = <NUM_LIT:0> <EOL> self . bm = <NUM_LIT:0> <EOL> self . lm = <NUM_LIT:0> <EOL> self . rm = <NUM_LIT:0> <EOL> self . gm = <NUM_LIT:0> <EOL> self . tw = <NUM_LIT:0> <EOL> self . emsize = <NUM_LIT:10> <EOL> self . languages = [ ] <EOL> ssdata = self . readSheets ( flist ) <EOL> self . ps = pagesizes . A4 <EOL> self . page = { } <EOL> for data , ssname in ssdata : <EOL> page = data . get ( '<STR_LIT>' , { } ) <EOL> if page : <EOL> self . page . update ( page ) <EOL> pgs = page . get ( '<STR_LIT:size>' , None ) <EOL> if pgs : <EOL> pgs = pgs . upper ( ) <EOL> if pgs in pagesizes . __dict__ : <EOL> self . ps = list ( pagesizes . __dict__ [ pgs ] ) <EOL> self . psname = pgs <EOL> if '<STR_LIT:width>' in self . page : del ( self . page [ '<STR_LIT:width>' ] ) <EOL> if '<STR_LIT>' in self . page : del ( self . page [ '<STR_LIT>' ] ) <EOL> elif pgs . endswith ( '<STR_LIT>' ) : <EOL> self . psname = pgs . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] <EOL> self . ps = list ( pagesizes . landscape ( pagesizes . __dict__ [ self . psname ] ) ) <EOL> if '<STR_LIT:width>' in self . page : del ( self . page [ '<STR_LIT:width>' ] ) <EOL> if '<STR_LIT>' in self . page : del ( self . page [ '<STR_LIT>' ] ) <EOL> else : <EOL> log . critical ( '<STR_LIT>' % ( page [ '<STR_LIT:size>' ] , ssname ) ) <EOL> continue <EOL> else : <EOL> if '<STR_LIT:size>' in self . page : <EOL> del ( self . page [ '<STR_LIT:size>' ] ) <EOL> if '<STR_LIT:width>' in page : <EOL> self . ps [ <NUM_LIT:0> ] = self . adjustUnits ( page [ '<STR_LIT:width>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . ps [ <NUM_LIT:1> ] = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> self . pw , self . ph = self . ps <EOL> if '<STR_LIT>' in page : <EOL> self . lm = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . rm = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . tm = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . bm = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . gm = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . ts = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . bs = self . adjustUnits ( page [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in page : <EOL> self . firstTemplate = page [ '<STR_LIT>' ] <EOL> self . tw = self . pw - self . lm - self . rm - self . gm <EOL> self . pageTemplates = { } <EOL> for data , ssname in ssdata : <EOL> templates = data . get ( '<STR_LIT>' , { } ) <EOL> for key in templates : <EOL> template = templates [ key ] <EOL> if key in self . pageTemplates : <EOL> self . pageTemplates [ key ] . update ( template ) <EOL> else : <EOL> self . pageTemplates [ key ] = template <EOL> self . fontsAlias = { } <EOL> for data , ssname in ssdata : <EOL> self . fontsAlias . update ( data . get ( '<STR_LIT>' , { } ) ) <EOL> embedded_fontnames = [ ] <EOL> self . embedded = [ ] <EOL> for data , ssname in ssdata : <EOL> embedded = data . get ( '<STR_LIT>' , [ ] ) <EOL> for font in embedded : <EOL> try : <EOL> if isinstance ( font , unicode ) : <EOL> fname , pos = findfonts . guessFont ( font ) <EOL> if font in embedded_fontnames : <EOL> pass <EOL> else : <EOL> fontList = findfonts . autoEmbed ( font ) <EOL> if fontList : <EOL> embedded_fontnames . append ( font ) <EOL> if not fontList : <EOL> if ( fname , pos ) in embedded_fontnames : <EOL> fontList = None <EOL> else : <EOL> fontList = findfonts . autoEmbed ( fname ) <EOL> if fontList is not None : <EOL> self . embedded += fontList <EOL> suff = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if not fontList [ <NUM_LIT:0> ] . startswith ( font ) : <EOL> for fname , aliasname in zip ( <EOL> fontList , <EOL> [ font + suffix for suffix in suff ] ) : <EOL> self . fontsAlias [ aliasname ] = fname <EOL> continue <EOL> if font [ <NUM_LIT:0> ] . lower ( ) . endswith ( '<STR_LIT>' ) : <EOL> for variant in font : <EOL> location = self . findFont ( variant ) <EOL> pdfmetrics . registerFont ( <EOL> TTFont ( str ( variant . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) , <EOL> location ) ) <EOL> log . info ( '<STR_LIT>' % ( str ( variant . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) , location ) ) <EOL> self . embedded . append ( str ( variant . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) ) <EOL> regular , bold , italic , bolditalic = [ <EOL> variant . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] for variant in font ] <EOL> addMapping ( regular , <NUM_LIT:0> , <NUM_LIT:0> , regular ) <EOL> addMapping ( regular , <NUM_LIT:0> , <NUM_LIT:1> , italic ) <EOL> addMapping ( regular , <NUM_LIT:1> , <NUM_LIT:0> , bold ) <EOL> addMapping ( regular , <NUM_LIT:1> , <NUM_LIT:1> , bolditalic ) <EOL> else : <EOL> faceName = font [ <NUM_LIT:0> ] <EOL> regular = pdfmetrics . EmbeddedType1Face ( * font [ <NUM_LIT:1> ] ) <EOL> italic = pdfmetrics . EmbeddedType1Face ( * font [ <NUM_LIT:2> ] ) <EOL> bold = pdfmetrics . EmbeddedType1Face ( * font [ <NUM_LIT:3> ] ) <EOL> bolditalic = pdfmetrics . EmbeddedType1Face ( * font [ <NUM_LIT:4> ] ) <EOL> except Exception , e : <EOL> try : <EOL> if isinstance ( font , list ) : <EOL> fname = font [ <NUM_LIT:0> ] <EOL> else : <EOL> fname = font <EOL> log . error ( "<STR_LIT>" , <EOL> os . path . splitext ( fname ) [ <NUM_LIT:0> ] , str ( e ) ) <EOL> log . error ( "<STR_LIT>" , fname ) <EOL> self . fontsAlias [ fname ] = '<STR_LIT>' <EOL> except Exception , e : <EOL> log . critical ( "<STR_LIT>" , <EOL> fname , str ( e ) ) <EOL> continue <EOL> for data , ssname in ssdata : <EOL> for [ skey , style ] in self . stylepairs ( data ) : <EOL> for key in style : <EOL> if key == '<STR_LIT>' or key . endswith ( '<STR_LIT>' ) : <EOL> if style [ key ] in self . fontsAlias : <EOL> style [ key ] = self . fontsAlias [ style [ key ] ] <EOL> if style [ key ] in self . embedded : <EOL> continue <EOL> if style [ key ] in ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) : <EOL> continue <EOL> fname , pos = findfonts . guessFont ( style [ key ] ) <EOL> if style [ key ] in embedded_fontnames : <EOL> pass <EOL> else : <EOL> fontList = findfonts . autoEmbed ( style [ key ] ) <EOL> if fontList : <EOL> embedded_fontnames . append ( style [ key ] ) <EOL> if not fontList : <EOL> if ( fname , pos ) in embedded_fontnames : <EOL> fontList = None <EOL> else : <EOL> fontList = findfonts . autoEmbed ( fname ) <EOL> if fontList : <EOL> embedded_fontnames . append ( ( fname , pos ) ) <EOL> if fontList : <EOL> self . embedded += fontList <EOL> suff = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if not fontList [ <NUM_LIT:0> ] . startswith ( style [ key ] ) : <EOL> basefname = style [ key ] . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] <EOL> for fname , aliasname in zip ( <EOL> fontList , <EOL> [ basefname + suffix for <EOL> suffix in suff ] ) : <EOL> self . fontsAlias [ aliasname ] = fname <EOL> style [ key ] = self . fontsAlias [ basefname + suff [ pos ] ] <EOL> else : <EOL> log . error ( "<STR_LIT>" <EOL> "<STR_LIT>" , style [ key ] ) <EOL> style [ key ] = "<STR_LIT>" <EOL> self . stylesheet = { } <EOL> self . styles = [ ] <EOL> self . linkColor = '<STR_LIT>' <EOL> self . tocColor = None <EOL> for data , ssname in ssdata : <EOL> self . linkColor = data . get ( '<STR_LIT>' ) or self . linkColor <EOL> self . tocColor = data . get ( '<STR_LIT>' ) or self . tocColor <EOL> for [ skey , style ] in self . stylepairs ( data ) : <EOL> sdict = { } <EOL> for key in style : <EOL> if key == '<STR_LIT>' or key . endswith ( '<STR_LIT>' ) and style [ key ] : <EOL> style [ key ] = formatColor ( style [ key ] ) <EOL> elif key == '<STR_LIT>' : <EOL> style [ key ] = validateCommands ( style [ key ] ) <EOL> elif key == '<STR_LIT>' : <EOL> style [ key ] = dict ( TA_LEFT = <NUM_LIT:0> , <EOL> LEFT = <NUM_LIT:0> , <EOL> TA_CENTER = <NUM_LIT:1> , <EOL> CENTER = <NUM_LIT:1> , <EOL> TA_CENTRE = <NUM_LIT:1> , <EOL> CENTRE = <NUM_LIT:1> , <EOL> TA_RIGHT = <NUM_LIT:2> , <EOL> RIGHT = <NUM_LIT:2> , <EOL> TA_JUSTIFY = <NUM_LIT:4> , <EOL> JUSTIFY = <NUM_LIT:4> , <EOL> DECIMAL = <NUM_LIT:8> , ) [ style [ key ] . upper ( ) ] <EOL> elif key == '<STR_LIT>' : <EOL> if not style [ key ] in self . languages : <EOL> self . languages . append ( style [ key ] ) <EOL> sdict [ str ( key ) ] = style [ key ] <EOL> sdict [ '<STR_LIT:name>' ] = skey <EOL> if skey in self . stylesheet : <EOL> self . stylesheet [ skey ] . update ( sdict ) <EOL> else : <EOL> self . stylesheet [ skey ] = sdict <EOL> self . styles . append ( sdict ) <EOL> styles2 = [ ] <EOL> for s in self . styles : <EOL> if not re . match ( "<STR_LIT>" , s [ '<STR_LIT:name>' ] ) : <EOL> s2 = copy ( s ) <EOL> s2 [ '<STR_LIT:name>' ] = docutils . nodes . make_id ( s [ '<STR_LIT:name>' ] ) <EOL> log . warning ( '<STR_LIT>' % ( s [ '<STR_LIT:name>' ] , s2 [ '<STR_LIT:name>' ] ) ) <EOL> styles2 . append ( s2 ) <EOL> self . styles . extend ( styles2 ) <EOL> self . StyleSheet = StyleSheet1 ( ) <EOL> if not hasattr ( self . StyleSheet , '<STR_LIT>' ) : <EOL> self . StyleSheet . __class__ . has_key = lambda s , k : k in s <EOL> for s in self . styles : <EOL> if '<STR_LIT>' in s : <EOL> if s [ '<STR_LIT>' ] is None : <EOL> if s [ '<STR_LIT:name>' ] != '<STR_LIT>' : <EOL> s [ '<STR_LIT>' ] = self . StyleSheet [ '<STR_LIT>' ] <EOL> else : <EOL> del ( s [ '<STR_LIT>' ] ) <EOL> else : <EOL> s [ '<STR_LIT>' ] = self . StyleSheet [ s [ '<STR_LIT>' ] ] <EOL> else : <EOL> if s [ '<STR_LIT:name>' ] != '<STR_LIT>' : <EOL> s [ '<STR_LIT>' ] = self . StyleSheet [ '<STR_LIT>' ] <EOL> if ( '<STR_LIT>' not in s ) and ( '<STR_LIT>' in s ) : <EOL> s [ '<STR_LIT>' ] = s [ '<STR_LIT>' ] <EOL> hasFS = True <EOL> if '<STR_LIT>' not in s : <EOL> s [ '<STR_LIT>' ] = s [ '<STR_LIT>' ] . fontSize <EOL> s [ '<STR_LIT>' ] = None <EOL> hasFS = False <EOL> elif '<STR_LIT>' in s : <EOL> s [ '<STR_LIT>' ] = self . adjustUnits ( s [ '<STR_LIT>' ] , <EOL> s [ '<STR_LIT>' ] . fontSize ) <EOL> s [ '<STR_LIT>' ] = s [ '<STR_LIT>' ] <EOL> else : <EOL> s [ '<STR_LIT>' ] = self . adjustUnits ( s [ '<STR_LIT>' ] , <NUM_LIT:10> ) <EOL> if '<STR_LIT>' not in s and hasFS : <EOL> s [ '<STR_LIT>' ] = <NUM_LIT> * s [ '<STR_LIT>' ] <EOL> if ( '<STR_LIT>' not in s ) and ( '<STR_LIT>' in s ) : <EOL> s [ '<STR_LIT>' ] = s [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in s and ( ( HAS_WORDAXE and wordaxe_version <= '<STR_LIT>' ) or <EOL> reportlab . Version < "<STR_LIT>" ) and isinstance ( s [ '<STR_LIT>' ] , list ) : <EOL> log . warning ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % s [ '<STR_LIT:name>' ] ) <EOL> s [ '<STR_LIT>' ] = s [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . StyleSheet . add ( ParagraphStyle ( ** s ) ) <EOL> self . emsize = self [ '<STR_LIT>' ] . fontSize <EOL> reportlab . rl_config . canvas_basefontname = self [ '<STR_LIT>' ] . fontName <EOL> reportlab . platypus . tables . CellStyle . fontname = self [ '<STR_LIT>' ] . fontName <EOL> def __getitem__ ( self , key ) : <EOL> if not re . match ( "<STR_LIT>" , key ) : <EOL> key = docutils . nodes . make_id ( key ) <EOL> if self . StyleSheet . has_key ( key ) : <EOL> return self . StyleSheet [ key ] <EOL> else : <EOL> if key . startswith ( '<STR_LIT>' ) : <EOL> log . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % key ) <EOL> newst = copy ( self . StyleSheet [ '<STR_LIT:code>' ] ) <EOL> else : <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % key ) <EOL> newst = copy ( self . StyleSheet [ '<STR_LIT>' ] ) <EOL> newst . name = key <EOL> self . StyleSheet . add ( newst ) <EOL> return newst <EOL> def readSheets ( self , flist ) : <EOL> '''<STR_LIT>''' <EOL> flist . reverse ( ) <EOL> sheetdict = { } <EOL> result = [ ] <EOL> while flist : <EOL> ssname = flist . pop ( ) <EOL> data = sheetdict . get ( ssname ) <EOL> if data is None : <EOL> data = self . readStyle ( ssname ) <EOL> if data is None : <EOL> continue <EOL> sheetdict [ ssname ] = data <EOL> if '<STR_LIT>' in data and '<STR_LIT>' in data [ '<STR_LIT>' ] : <EOL> flist . append ( ssname ) <EOL> newsheets = list ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> newsheets . reverse ( ) <EOL> flist . extend ( newsheets ) <EOL> continue <EOL> result . append ( ( data , ssname ) ) <EOL> return result <EOL> def readStyle ( self , ssname ) : <EOL> if callable ( ssname ) : <EOL> return ssname ( ) <EOL> fname = self . findStyle ( ssname ) <EOL> if fname : <EOL> try : <EOL> return rson_loads ( open ( fname ) . read ( ) ) <EOL> except ValueError , e : <EOL> log . critical ( '<STR_LIT>' % ( fname , str ( e ) ) ) <EOL> except IOError , e : <EOL> log . critical ( '<STR_LIT>' % ( fname , str ( e ) ) ) <EOL> def findStyle ( self , fn ) : <EOL> """<STR_LIT>""" <EOL> def innerFind ( path , fn ) : <EOL> if os . path . isabs ( fn ) : <EOL> if os . path . isfile ( fn ) : <EOL> return fn <EOL> else : <EOL> for D in path : <EOL> tfn = os . path . join ( D , fn ) <EOL> if os . path . isfile ( tfn ) : <EOL> return tfn <EOL> return None <EOL> for ext in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> result = innerFind ( self . StyleSearchPath , fn + ext ) <EOL> if result : <EOL> break <EOL> if result is None : <EOL> log . warning ( "<STR_LIT>" % fn ) <EOL> return result <EOL> def findFont ( self , fn ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . isabs ( fn ) : <EOL> for D in self . FontSearchPath : <EOL> tfn = os . path . join ( D , fn ) <EOL> if os . path . isfile ( tfn ) : <EOL> return str ( tfn ) <EOL> return str ( fn ) <EOL> def styleForNode ( self , node ) : <EOL> """<STR_LIT>""" <EOL> n = docutils . nodes <EOL> styles = { n . sidebar : '<STR_LIT>' , <EOL> n . figure : '<STR_LIT>' , <EOL> n . tgroup : '<STR_LIT>' , <EOL> n . table : '<STR_LIT>' , <EOL> n . Admonition : '<STR_LIT>' <EOL> } <EOL> return self [ styles . get ( node . __class__ , '<STR_LIT>' ) ] <EOL> def tstyleHead ( self , rows = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> alignment = { <NUM_LIT:0> : '<STR_LIT>' , <NUM_LIT:1> : '<STR_LIT>' , <NUM_LIT:1> : '<STR_LIT>' , <NUM_LIT:2> : '<STR_LIT>' , <EOL> <NUM_LIT:4> : '<STR_LIT>' , <NUM_LIT:8> : '<STR_LIT>' } [ self [ '<STR_LIT>' ] . alignment ] <EOL> return [ <EOL> ( '<STR_LIT>' , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( - <NUM_LIT:1> , rows - <NUM_LIT:1> ) , <EOL> self [ '<STR_LIT>' ] . backColor ) , <EOL> ( '<STR_LIT>' , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( - <NUM_LIT:1> , rows - <NUM_LIT:1> ) , <EOL> alignment ) , <EOL> ( '<STR_LIT>' , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( - <NUM_LIT:1> , rows - <NUM_LIT:1> ) , <EOL> self [ '<STR_LIT>' ] . textColor ) , <EOL> ( '<STR_LIT>' , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( - <NUM_LIT:1> , rows - <NUM_LIT:1> ) , <EOL> self [ '<STR_LIT>' ] . fontName , <EOL> self [ '<STR_LIT>' ] . fontSize , <EOL> self [ '<STR_LIT>' ] . leading ) , <EOL> ( '<STR_LIT>' , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ( - <NUM_LIT:1> , rows - <NUM_LIT:1> ) , <EOL> self [ '<STR_LIT>' ] . valign ) ] <EOL> def adjustFieldStyle ( self ) : <EOL> """<STR_LIT>""" <EOL> tstyle = self . tstyles [ '<STR_LIT>' ] <EOL> extras = self . pStyleToTStyle ( self [ '<STR_LIT>' ] , <NUM_LIT:0> , <NUM_LIT:0> ) + self . pStyleToTStyle ( self [ '<STR_LIT>' ] , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> for e in extras : <EOL> tstyle . add ( * e ) <EOL> return tstyle <EOL> def pStyleToTStyle ( self , style , x , y ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> if style . backColor : <EOL> results . append ( ( '<STR_LIT>' , ( x , y ) , ( x , y ) , style . backColor ) ) <EOL> if style . borderWidth : <EOL> bw = style . borderWidth <EOL> del style . __dict__ [ '<STR_LIT>' ] <EOL> if style . borderColor : <EOL> bc = style . borderColor <EOL> del style . __dict__ [ '<STR_LIT>' ] <EOL> else : <EOL> bc = colors . black <EOL> bc = str ( bc ) <EOL> results . append ( ( '<STR_LIT>' , ( x , y ) , ( x , y ) , bw , bc ) ) <EOL> if style . borderPadding : <EOL> if isinstance ( style . borderPadding , list ) : <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding [ <NUM_LIT:0> ] ) ) <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding [ <NUM_LIT:1> ] ) ) <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding [ <NUM_LIT:2> ] ) ) <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding [ <NUM_LIT:3> ] ) ) <EOL> else : <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding ) ) <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding ) ) <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding ) ) <EOL> results . append ( ( '<STR_LIT>' , <EOL> ( x , y ) , <EOL> ( x , y ) , <EOL> style . borderPadding ) ) <EOL> return results <EOL> def adjustUnits ( self , v , total = None , default_unit = '<STR_LIT>' ) : <EOL> if total is None : <EOL> total = self . tw <EOL> return adjustUnits ( v , total , <EOL> self . def_dpi , <EOL> default_unit , <EOL> emsize = self . emsize ) <EOL> def combinedStyle ( self , styles ) : <EOL> '''<STR_LIT>''' <EOL> validst = [ x for x in styles if self . StyleSheet . has_key ( x ) ] <EOL> newname = '<STR_LIT:_>' . join ( [ '<STR_LIT>' ] + validst ) <EOL> validst = [ self [ x ] for x in validst ] <EOL> newst = copy ( validst [ <NUM_LIT:0> ] ) <EOL> for st in validst [ <NUM_LIT:1> : ] : <EOL> newst . __dict__ . update ( st . __dict__ ) <EOL> newst . name = newname <EOL> return newst <EOL> def adjustUnits ( v , total = None , dpi = <NUM_LIT> , default_unit = '<STR_LIT>' , emsize = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> if v is None or v == "<STR_LIT>" : <EOL> return None <EOL> v = str ( v ) <EOL> l = re . split ( '<STR_LIT>' , v ) <EOL> n = l [ <NUM_LIT:1> ] <EOL> u = default_unit <EOL> if len ( l ) == <NUM_LIT:3> and l [ <NUM_LIT:2> ] : <EOL> u = l [ <NUM_LIT:2> ] <EOL> if u in units . __dict__ : <EOL> return float ( n ) * units . __dict__ [ u ] <EOL> else : <EOL> if u == '<STR_LIT:%>' : <EOL> return float ( n ) * total / <NUM_LIT:100> <EOL> elif u == '<STR_LIT>' : <EOL> return float ( n ) * units . inch / dpi <EOL> elif u == '<STR_LIT>' : <EOL> return float ( n ) <EOL> elif u == '<STR_LIT>' : <EOL> return float ( n ) * units . inch <EOL> elif u == '<STR_LIT>' : <EOL> return float ( n ) * emsize <EOL> elif u == '<STR_LIT>' : <EOL> return float ( n ) * emsize / <NUM_LIT:2> <EOL> elif u == '<STR_LIT>' : <EOL> return float ( n ) * <NUM_LIT:12> <EOL> log . error ( '<STR_LIT>' % u ) <EOL> return float ( n ) <EOL> def formatColor ( value , numeric = True ) : <EOL> """<STR_LIT>""" <EOL> if value in colors . __dict__ : <EOL> return colors . __dict__ [ value ] <EOL> else : <EOL> c = value . strip ( ) <EOL> if c [ <NUM_LIT:0> ] == '<STR_LIT:#>' : <EOL> c = c [ <NUM_LIT:1> : ] <EOL> while len ( c ) < <NUM_LIT:6> : <EOL> c = '<STR_LIT:0>' + c <EOL> if numeric : <EOL> r = int ( c [ : <NUM_LIT:2> ] , <NUM_LIT:16> ) / <NUM_LIT> <EOL> g = int ( c [ <NUM_LIT:2> : <NUM_LIT:4> ] , <NUM_LIT:16> ) / <NUM_LIT> <EOL> b = int ( c [ <NUM_LIT:4> : <NUM_LIT:6> ] , <NUM_LIT:16> ) / <NUM_LIT> <EOL> if len ( c ) >= <NUM_LIT:8> : <EOL> alpha = int ( c [ <NUM_LIT:6> : <NUM_LIT:8> ] , <NUM_LIT:16> ) / <NUM_LIT> <EOL> return colors . Color ( r , g , b , alpha = alpha ) <EOL> return colors . Color ( r , g , b ) <EOL> else : <EOL> return str ( "<STR_LIT:#>" + c ) <EOL> validCommands = { <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:3> , "<STR_LIT:string>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:string>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:string>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:string>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:string>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:string>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> } <EOL> def validateCommands ( commands ) : <EOL> '''<STR_LIT>''' <EOL> fixed = [ ] <EOL> for command in commands : <EOL> command [ <NUM_LIT:0> ] = command [ <NUM_LIT:0> ] . upper ( ) <EOL> flag = False <EOL> if command [ <NUM_LIT:0> ] not in validCommands : <EOL> log . error ( '<STR_LIT>' , command [ <NUM_LIT:0> ] ) <EOL> continue <EOL> if type ( command [ <NUM_LIT:1> ] ) not in ( ListType , TupleType ) : <EOL> log . error ( '<STR_LIT>' , type ( command [ <NUM_LIT:1> ] ) , command [ <NUM_LIT:1> ] ) <EOL> flag = True <EOL> if type ( command [ <NUM_LIT:2> ] ) not in ( ListType , TupleType ) : <EOL> log . error ( '<STR_LIT>' , type ( command [ <NUM_LIT:1> ] ) , command [ <NUM_LIT:1> ] ) <EOL> flag = True <EOL> l = len ( command ) - <NUM_LIT:3> <EOL> if l > validCommands [ command [ <NUM_LIT:0> ] ] [ <NUM_LIT:1> ] : <EOL> log . error ( '<STR_LIT>' , command ) <EOL> flag = True <EOL> if l < validCommands [ command [ <NUM_LIT:0> ] ] [ <NUM_LIT:0> ] : <EOL> log . error ( '<STR_LIT>' , command ) <EOL> flag = True <EOL> for pos , arg in enumerate ( command [ <NUM_LIT:3> : ] ) : <EOL> typ = validCommands [ command [ <NUM_LIT:0> ] ] [ pos + <NUM_LIT:2> ] <EOL> if typ == "<STR_LIT>" : <EOL> command [ <NUM_LIT:3> + pos ] = formatColor ( arg ) <EOL> elif typ == "<STR_LIT>" : <EOL> command [ <NUM_LIT:3> + pos ] = [ formatColor ( c ) for c in arg ] <EOL> elif typ == "<STR_LIT>" : <EOL> pass <EOL> elif typ == "<STR_LIT:string>" : <EOL> command [ <NUM_LIT:3> + pos ] = str ( arg ) <EOL> else : <EOL> log . error ( "<STR_LIT>" , typ ) <EOL> if not flag : <EOL> fixed . append ( command ) <EOL> return fixed <EOL> class CallableStyleSheet ( str ) : <EOL> '''<STR_LIT>''' <EOL> def __new__ ( cls , name , value = '<STR_LIT>' ) : <EOL> self = str . __new__ ( cls , name ) <EOL> self . value = value <EOL> return self <EOL> def __call__ ( self ) : <EOL> return rson_loads ( self . value ) </s>
