Ñò ŒÏáKc@s¯dZddkZddklZlZddklZlZdeƒ_dZ d„Z de fd „ƒYZ ddd „Zd „Zdddd „Zd e fd„ƒYZde fd„ƒYZde fd„ƒYZd„Zd„Zd„Zd„Zhed6ed6ed6Zd„Zd„Zd„Zdd„Zdd„Zddd„Zhd d!6d"d#6d$d%6d&d'6d(d)6d*d+6Zd,„Z d-e fd.„ƒYZ!dS(/s&fohelpers.py: XSL-FO helper functions For documentation, see: http://www.nmt.edu/tcc/projects/docbookindex/ Exports: subElement(parent, elt): [ parent and elt are et.Element instances -> parent := parent with elt added as its last child return elt ] class FlowTree: Represents a complete XSL-FO document FlowTree(): [ return a new, empty FlowTree ] .doc: [ the document as an et.ElementTree ] .root: [ the document root as an et.Element ] .masters: [ the layout-master-set as an et.Element ] .write(outFile): [ outFile is a writeable file-like object -> outFile +:= self as XML ] simpleMaster(masterName, dim, beforeName=None, afterName=None): [ (masterName is a valid XML name) and (dim is the page layout as a PageDim instance) and (beforeName is the master-name for region-before, defaulting to no name) and (afterName is the master-name for region-after, defaulting to no name) -> return a new simple-page-master et.Element with that master-name and that layout ] repeatMaster(masterName, cond1, cond2, ...): [ (masterName is the name of a new page-sequence-master) and (the remaining arguments are conditional-page-master-reference elements) -> return a new page-sequence-master named masterName containing a repeatable-page-master-alternatives child whose children are cond1, cond2, etc. ] conditionalMaster(masterRef, pagePos=None, oddEven=None, blankNon=None): [ (masterRef is the name of the referenced master) and (pagePos is "first", "rest", "last", defaulting to no page position test) and (oddEven is "odd" or "even", defaulting to no test) and (blankNon is "blank" or "non-blank", defaulting to no test) -> return a new conditional-page-master-reference element with those values ] class PageDim: Represents a page layout PageDim(pageBox, pageMargins=None, frameMargins=None, bodyMargins=None): [ (pageBox is the paper size as a Box instance) and (pageMargins represents the page margins as a MarginSet instance, defaulting to no margins) and (frameMargins represents the header and footer heights as a MarginSet instance, defaulting to zero) and (bodyMargins represents the margin above and below the body as a MarginSet instance, defaulting to zero) -> return a new PageDim instance representing that layout ] .pageBox: [ as passed to constructor ] .pageMargins: [ as passed to constructor ] .frameMargins: [ as passed to constructor ] .bodyMargins: [ as passed to constructor ] class Box: Represents a rectangle Box(wide, high): [ wide and high are positive XSL-FO dimensions as strings -> return a new Box representing those dimensions ] class MarginSet: Represents a set of four margin sizes MarginSet(top="0.0in", bot="0.0in", left="0.0in", right="0.0in"): [ arguments are valid XSL-FO dimensions -> return a new MarginSet instance representing top margin (top), bottom margin (bot), left margin (left), and right margin (right) ] .top, .bot, .left, .right: [ as passed to constructor ] .dict(): [ return a dict whose keys are "margin-top", etc., with corresponding values from self.top, etc. ] pageDimFactory(paperType): [ paperType is in ["letter", "legal", "3x5"] -> return a new PageDim instance for the corresponding paper size ] pageSequence(masterRef): [ masterRef is the name of a simple-master or page-sequence-master -> return a new page-sequence for masterRef ] staticContent(flowName): [ flowName is a flow name -> return a new static-content element for that flow name ] flow(): [ return a new flow element for xsl-region-body ] block(font=None): [ font is a dictionary of font properties or None -> return a new block, with those properties ] inline(font=None): [ font is a dictionary of font properties or None -> return a new inline, with those properties ] leader(length=None, pattern=None): [ (length is an FO dimension, defaulting to unspecified) and (pattern is a leader-pattern, defaulting to "space") -> return a new leader with that length and pattern ] font(fontFamily=None, fontSize=None, fontStyle=None, fontWeight=None, fontVariant=None, fontStretch=None): [ arguments are standard FO font properties -> return a dictionary of those font properties ] class FoDim: Represents an XSL-FO length property FoDim(n, units): [ (n is a number in a form acceptable to the Decimal() constructor) and (units is in ['in', 'mm', 'cm', 'pc', 'pt']) -> return a FoDim instance representing that length .__str__(self): [ return a string representing self as an XSL-FO length ] .__add__(self, other): [ other is a FoDim instance -> return a new FoDim representing self+other ] .__sub__(self, other): [ other is a FoDim instance -> return a new FoDim representing self-other ] .__mul__(self, other): [ other is a value acceptable to the Decimal() constructor -> return a new FoDim representing self*other ] .__neg__(self): [ return a new FoDim representing 0-self ] .convert(newUnits): [ newUnits is one of the units acceptable to FoDim() -> return a new FoDim representing self expressed in newUnits ] iÿÿÿÿN(tettE(tDecimalt getcontextis!http://www.w3.org/1999/XSL/FormatcCs|i|ƒ|S(s#Add elt as parent's next child (tappend(tparenttelt((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt subElements tFlowTreecBs eZdZd„Zd„ZRS(s#Represents an XSL-FO document. cCsItidtƒ|_ti|iƒ|_t|itdƒƒ|_dS(sConstructor txmlnsslayout-master-setN(Rtroott FO_NAMESPACERt ElementTreetdocRtmasters(tself((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt__init__šs cCs|ii|dtƒdS(sSerialize as XML. t pretty_printN(R twritetTrue(RtoutFile((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyRªs(t__name__t __module__t__doc__RR(((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyR•s c CsÁ|d john h|d6}|d john h|d6}tdh|d6|iid6|iid6|iiƒtd|iiƒƒtd|d|ii ƒtd |d|ii ƒƒS( s*Return a new simple-page-master tree. s region-namessimple-page-masters master-names page-widths page-heights region-bodys region-beforetextents region-afterN( tNoneRtpageBoxtwidethight pageMarginstdictt bodyMarginst frameMarginsttoptbot(t masterNametdimt beforeNamet afterNamet beforeDictt afterDict((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt simpleMaster°s         cGs tdh|d6td|ŒƒS(s.Set up a set of page master alternatives. spage-sequence-masters master-names#repeatable-page-master-alternatives(R(t masterReftcondList((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt repeatMasterÈs cCsbtdh|d6ƒ}|o||idR?RR@(R3R5R4RA(((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt legalPage#scCsåtdtddƒdtdtddƒdtddƒd td dƒd td dƒƒd tdtd dƒdtddƒd tddƒd tddƒƒdtdtddƒdtddƒd tddƒd tddƒƒƒS(NRt3int5inRR!s0.1R<R"R6s0.25R7R s1.5R>t1R?R(R3R5R4RA(((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt indexCardPage/stlettertlegalt3x5cCstdh|d6ƒS(s$Create a page-sequence element. s page-sequencesmaster-reference(R(R*((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt pageSequence?scCstdh|d6ƒS(s'Generate a static-content element. sstatic-contents flow-name(R(tflowName((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyt staticContentFscCstihdd6ƒS(s.Return a flow element for xsl-region-body sxsl-region-bodys flow-name(Rtflow(((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyROMscCs|ph}td|ƒS(sGenerate a block element. tblock(R(tfonttfontDict((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyRPSs cCs|ph}td|ƒS(Ntinline(R(RQRR((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyRSZs cCsL|djohn h|d6}ti|h|djodn|d6ƒS(sCreate a leader element. s leader-lengthtspacesleader-patternN(RRtleader(tlengthtpatternt lengthDict((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyRU_s   s font-familyt fontFamilys font-sizetfontSizes font-stylet fontStyles font-weightt fontWeights font-variantt fontVariants font-stretcht fontStretchcKs-h}x |D]}|||t|tptR<tcmtmmi is72.27s2.54i cCs·tii|ƒ}tii|ƒ}tdƒ}||jo/xst||ƒD]}|ti|9}qMWnH||jo:x7t|d|ddƒD]}|ti|:}q”Wn|S(sðFind any arbitrary conversion factor. [ fromUnits and toUnits are XSL-FO dimensional units -> return the factor that must be multiplied by a quantity using fromUnits to express it as toUnits ] iiÿÿÿÿ(RAtunitListtindexRtranget factorList(t fromUnitsttoUnitstfromPosttoPosRatpos((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyRnÄs    (spcRqsinRrRs(RRRRReRiRkRlRmRfRtRRwt staticmethodRn(((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyRA{s       ("Rtsyst etbuilderRRtdecimalRRtprecR RtobjectRRR)R,R2R3R5R4R:RBRDRHR8RLRNRORPRSRUR_RQRA(((s//u/www/docs/tcc/help/pubs/python25/fohelpers.pyts@