
,Sc           @   s  d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z m Z d  d l m Z m Z m Z d  d	 l m Z m Z m Z m Z m Z m Z d  d
 l m Z d  d l m Z m Z m  Z  m! Z! m" Z" d  d l# Z# d  d l$ Z$ d  d l% Z% d  d l& Z& d  d l' Z' d  d l( Z( d  d l) Z) d  d l* Z+ d  d l, Z+ d e' j- _. e$ j/ d  Z0 d Z1 d Z2 d Z3 d Z4 d   Z5 e5 e _5 d   Z6 d   Z7 d e j8 f d     YZ9 d e j: f d     YZ; d e< f d     YZ= d S(   i(   t   TA_LEFT(   t
   addMapping(   t	   landscapet   A4(   t   ParagraphStyle(   t
   pdfmetrics(   t   TTFont(   t   Framet   ShowBoundaryValue(   t   ParaFragt   ps2ttt   tt2ps(   t   getSizet	   getCoordst   getFilet   pisaFileObjectt   getFrameDimensionst   getColor(   t   css(   t   PmlPageTemplatet   PmlTableOfContentst   PmlParagrapht   PmlParagraphAndImaget   PmlPageCountNi    t	   xhtml2pdfi   g?u    c         K   sQ   t  |  j   } | rD | j } | j |  d | k rD | d =qD n  d  | _ | S(   Nt   cbDefn(   R	   t   __dict__t   updatet   Nonet
   bulletText(   t   selft   kwargst   nt   d(    (    s   /xhtml2pdf/context.pyt   clone2   s    		c         C   st  t    } d | _ d | _ d | _ d | _ d | _ d | _ d  | _ d | _	 d | _
 t |  j
  \ | _
 | _ | _ |  j | _ |  j | _ d | _ d | _ d | _ d | _ d  | _ d | _ d | _ d | _ d | _ d | _ t | _ t | _ d  | _ d | _ d  | _  d | _! d  | _" | j | _# | j" | _$ | j  | _% | j | _& | j" | _' | j  | _( | j | _) | j" | _* | j  | _+ | j | _, | j" | _- | j  | _. d | _/ d | _0 d | _1 d | _2 d  | _3 d  | _4 d | _5 d  | _6 t | _7 t | _8 d  | _9 d  | _: d | _; d  | _< d | _= d | _> t | _? d | _@ t | _A d | _B | S(	   Ni    t    s   Times-Romant   normals   150%i   t	   Helveticag      ?(C   R	   t   subt   supert   riset	   underlinet   striket   greekR   t   linkt   textt   fontNameR
   t   boldt   italict   fontSizet	   textColort   leadingt   letterSpacingt   leadingSourcet   leadingSpacet	   backColort   spaceBeforet
   spaceAftert
   leftIndentt   rightIndentt   firstLineIndentt   Falset   keepWithNextR    t	   alignmentt   vAlignt   borderWidtht   borderStylet   borderPaddingt   borderColort   borderLeftWidtht   borderLeftColort   borderLeftStylet   borderRightWidtht   borderRightColort   borderRightStylet   borderTopWidtht   borderTopColort   borderTopStylet   borderBottomWidtht   borderBottomColort   borderBottomStylet   paddingLeftt   paddingRightt
   paddingTopt   paddingBottomt   listStyleTypet   listStyleImaget
   whiteSpacet   wordWrapt
   pageNumbert	   pageCountt   heightt   widtht   bulletIndentR   t   bulletFontNamet   zoomt   outlinet   outlineLevelt   outlineOpent   insideStaticFrame(   t   stylet   frag(    (    s   /xhtml2pdf/context.pyt   getParaFragA   s~    										!																																					c         C   s<   t  j  |   } | j r |  St j j t j j |    Sd  S(   N(   t   urlparset   schemet   ost   patht   dirnamet   abspath(   Rj   t   parts(    (    s   /xhtml2pdf/context.pyt
   getDirName   s    	t   pisaCSSBuilderc           B   sD   e  Z d    Z e d d d  Z d d d  Z d   Z d   Z RS(   c   	      C   s   |  j  |  j d  g |  } | d j   d } d | k rH i  i  f S| d } t | j d d   j   } | d k } | r | d k r t j |  j j	 d |   n  t | j d d   j   d k } |  j j
 | d d |  j j j } |  j j | | d | d | i  i  f S(   s   
        Embed fonts
        t   *i    t   srcs   font-familys   font-weightR$   R/   t   boldert   500t   600t   700t   800t   900s)   @fontface, unknown value font-weight '%s's
   font-styleR#   R0   t   obliquet   relative(   R/   Rr   Rs   Rt   Ru   Rv   Rw   (   R0   Rx   (   t   rulesett   selectort   valuest   strt   gett   lowert   logt   warnt   ct   warningR   t	   cssParsert   rootPatht   loadFont(	   R   t   declarationst   resultt   datat   namest   fweightR/   R0   Rq   (    (    s   /xhtml2pdf/context.pyt
   atFontFace   s"    

$%	i    c         C   s   |  j  } | s" d | j   } n  | j d t  rK | d | d f } n  t | | d | d  \ } } }	 }
 | r | d  | j d |  | | |	 |
 | f S| | j d d   | j d |  | | |	 |
 | f S(   Ns   -pdf-frame-%dt   is_landscapei   i    s   -pdf-frame-borders   -pdf-frame-content(   R   t   UIDR~   R=   R   R   (   R   t   nameR   t   firstt   bordert   sizeR   t   xt   yt   wt   h(    (    s   /xhtml2pdf/context.pyt   _pisaAddFrame   s    	&(c         C   s{   | s d   } n  t  |  t t f k rY xJ | D]! } | | k rQ | | |  S| SWn | | k rs | | |  S| Sd  S(   Nc         S   s   |  S(   N(    (   R   (    (    s   /xhtml2pdf/context.pyt   <lambda>   R#   (   t   typet   listt   tuple(   R   R   t   attrt   defaultt   funct   a(    (    s   /xhtml2pdf/context.pyt   _getFromData   s    c   (      C   s  |  j  } i  } | p d } d  } | rw |  j |  j d  g |  } | rw | d j   d } | j d d   } qw n  | | j k r t j |  j  j	 d |   n  d | k r t
 j j j t | d  j   | j  | _ n  t } d | k r| d }	 t |	  t j k	 r|	 g }	 n  g  }
 x |	 D] } t |  j   } t |  t j k ro|
 j t |   q,| d k rt } q,| t
 j j k rt
 j j | | _ q,t j | j	 d	   q,Wt |
  d
 k rt |
  | _ n  | rt | j  | _ qn  |  j | d d t  } |  j | d d t  } |  j | d d t  } |  j | d d t  } |  j | d2 d  t  } |  j | d3 d t  } xO d4 D]G } | | k r| j j |  j | | d! t d" | d | j  PqqWg  } g  } x| j D]\ } } } } } } } } |  j | d | t  } |  j | d | t  } |  j | d | t  }  |  j | d | t  }! |  j | d5 | t  }" |  j | d6 | t  }# | s| rt   }$ n t d# |" d |#  }$ | rt  | | j d | j d$  \ } } } } n  t! | | | | | j  \ } } } } | d k sO| d k rkt j |  j  j	 d%   n  t" | | | | d& | d' | d( |  d) |! d* | d+ |$ }% | rg  |% _# |% g | j$ j | g   | j$ | <| j |%  q | j |%  q W| j d, d   }& |& r3|  j  j% |& d- |  j  j& j' }& n  | sVt j | j	 d.   |  j | | d! t d" | d | j \ } } } } } } } } t! | | | | | j  \ } } } } | d k s| d k rt j | j	 d/   n  | s| rt   }$ n t d# | d |  }$ | j t" | | | | d& | d' | d( | d) | d* | d+ |$  n  t( d& | d0 | d1 | j  }' | |' _) |& |' _* | j+ |' _+ | r|' j, |' _- n  |' | j | <d  | _. g  | _ g  | _/ i  i  f S(7   Nt   bodyRp   i    s   -pdf-frame-borders&   template '%s' has already been defineds   -pdf-page-sizeR   R   s   Unknown size value for @pagei   s   padding-tops   padding-lefts   padding-rights   padding-bottoms   border-top-colors   border-bottom-colors   border-left-colors   border-right-colors   border-top-widths   border-bottom-widths   border-left-widths   border-right-widths
   margin-tops   margin-lefts   margin-rights   margin-bottomt   topt   leftt   rightt   bottomR\   R[   R   R   t   colori   s<   Negative width or height of frame. Check @frame definitions.t   idt   leftPaddingt   rightPaddingt   bottomPaddingt
   topPaddingt   showBoundarys   background-imageRy   sC   missing explicit frame definition for content or just static framess;   Negative width or height of frame. Check @page definitions.t   framest   pagesize(   s   border-top-colors   border-bottom-colors   border-left-colors   border-right-color(   s   border-top-widths   border-bottom-widths   border-left-widths   border-right-width(
   s
   margin-tops   margin-lefts   margin-rights   margin-bottomR   R   R   R   R\   R[   (   s   border-top-colors   border-bottom-colors   border-left-colors   border-right-color(   s   border-top-widths   border-bottom-widths   border-left-widths   border-right-width(0   R   R   Rz   R{   R|   R~   t   templateListR   R   R   R   R   t   PML_PAGESIZESR}   R   t   pageSizeR=   R   t   typest   ListTypet	   TupleTypet   appendR   t   Truet   lenR   R   R   R   t	   frameListR   R   R   R   R   t   pisaStaticStoryt   frameStaticR   R   R   R   t   pisaStaticListt   pisaBackgroundt   pisaBackgroundListt	   LANDSCAPEt   pageorientationt   templatet   frameStaticList((   R   R   t
   pseudopageR   R   R   t
   pageBorderR   t   isLandscapeR   t   sizeListt   valuet   valueStrt   padding_topt   padding_leftt   padding_rightt   padding_bottomt   border_colort   border_widtht   propR   t
   staticListt   fnamet   staticR   R   R   R   R   t   fdatat   fpadding_topt   fpadding_leftt   fpadding_rightt   fpadding_bottomt   fborder_colort   fborder_widtht   frame_bordert   framet
   backgroundt   pt(    (    s   /xhtml2pdf/context.pyt   atPage   s    	1
			
1(		/'		#$$'						c         C   s   | ru |  j  |  j d  g |  } | d } | ru | j   d } |  j j j |  j | | d |  j j  qu n  i  i  f S(   NRp   i    R   (   Rz   R{   R|   R   R   R   R   R   (   R   R   R   R   R   (    (    s   /xhtml2pdf/context.pyt   atFrameb  s    
%N(   i    i    (	   t   __name__t
   __module__R   R=   R   R   R   R   R   (    (    (    s   /xhtml2pdf/context.pyRo      s
   		t   pisaCSSParserc           B   s   e  Z d    Z RS(   c         C   s   |  j  } |  j j | d |  j  } | s. d  S|  j  rg t j |  j   j rg t j |  j  |  |  _  n t | j  |  _  |  j	 | j
    } | |  _  | S(   NRy   (   R   R   R   R   Rg   Rh   t   urljoinRn   t   urit   parset   getData(   R   t   cssResourceNamet   oldRootPatht   cssFileR   (    (    s   /xhtml2pdf/context.pyt   parseExternalq  s    		(   R   R   R   (    (    (    s   /xhtml2pdf/context.pyR   p  s   t   pisaContextc           B   s:  e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z g  d	  Z	 d
   Z
 d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z d d$ d  Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d$ d  Z d d   Z g  d!  Z  d" d d d#  Z! RS(%   sZ   
    Helper class for creation of reportlab story and container for
    various data.
    i    ic         C   s  t  j  t j j  |  _ g  |  _ | |  _ d  |  _ t	   |  _
 g  |  _ d  |  _ g  |  _ g  |  _ d |  _ d |  _ d |  _ d |  _ t |  _ t |  _ d  |  _ i  |  _ g  |  _ i  |  _ g  |  _ g  |  _ d  |  _ t d  |  _ g  |  _ g  |  _  d  |  _! t" t# d |  j$     |  _% |  _& g  |  _' g  |  _( g  |  _) t* |  _+ d |  _, d |  _- d |  _. d  |  _/ i  |  _0 t |  _1 d  |  _2 | pd |  _3 t4 j4 |  j3  } | j5 st6 j j7 |  j3  |  _3 n  t8 |  j3  |  _9 t: d d d d d	 d d
 d d t  |  _; d  S(   Ni    u    t   12pts	   default%dR#   t	   __dummy__t   authort   titlet   subjectt   keywordsR   (<   t   copyR   R   t   DEFAULT_FONTt   fontListRj   t   capacityR   t   nodeR   t   toct   storyt   indexing_storyR-   R   t   errR   t   uidctrR=   t
   multiBuildR   R   R   R   R   R   R   R   t   keepInFrameIndexR   t   baseFontSizet
   anchorFragt
   anchorNamet	   tableDataRf   R   R   Re   t	   fragBlockt   fragListt
   fragAnchort	   fragStackR   t	   fragStript   listCountert   cssTextt   cssDefaultTextt   imaget	   imageDatat   forcet   pathCallbackt   pathDocumentRg   Rh   Ri   Rl   Rn   t   pathDirectoryt   dictt   meta(   R   Rj   t   debugR   Rm   (    (    s   /xhtml2pdf/context.pyt   __init__  sb    																							&												c         C   s   |  j  d 7_  |  j  S(   Ni   (   R   (   R   (    (    s   /xhtml2pdf/context.pyR     s    c         C   sg   | j    } | j d  r+ | d d !} n  | j d  rJ | d d !} n  |  j | j    d 7_ d  S(   Ns	   <![CDATA[i	   is   <!--i   s   
(   t   stript
   startswithR  (   R   R   (    (    s   /xhtml2pdf/context.pyt   addCSS  s    c         C   sg   | j    } | j d  r+ | d d !} n  | j d  rJ | d d !} n  |  j | j    d 7_ d  S(   Ns	   <![CDATA[i	   is   <!--i   s   
(   R  R  R  (   R   R   (    (    s   /xhtml2pdf/context.pyt   addDefaultCSS  s    c         C   s   d d  l  } t d d d d g  |  _ | j |   |  j _ t d    t _ t |  j  |  _ |  j	 |  j _
 | j |   |  j _ t d    t _ |  j j |  j  |  _ |  j j |  j  |  _ t j d |  j d	 |  j  |  _ |  j |  j _ d  S(
   Nit	   mediumSett   allt   printt   pdfc         S   s
   |  j    S(   N(   t   _c(   R   (    (    s   /xhtml2pdf/context.pyR     R#   c         S   s
   |  j    S(   N(   R  (   R   (    (    s   /xhtml2pdf/context.pyR     R#   t	   userAgentt   user(   t   weakrefRo   t
   cssBuildert   refR  t   propertyR   R   R   R  R   R   R  R   R  t
   cssDefaultt   CSSCascadeStrategyt
   cssCascadet   parser(   R   R  (    (    s   /xhtml2pdf/context.pyt   parseCSS  s    !c         C   s   |  j  j |  d  S(   N(   R   R   (   R   R   (    (    s   /xhtml2pdf/context.pyt   addStory  s    c         C   s)   t  j  |  t  j  |  j  |  _ } | S(   N(   R   R   (   R   R   (    (    s   /xhtml2pdf/context.pyt	   swapStory  s    %c         C   s  t  d |  j   d | j } | j | _ | j | _ | j | _ t | j | j | j d  | _ | j	 | _	 | j
 | _
 | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j p | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j | _ | j  | _  | j d  k r| j r| j | _ n  | j d  k r| j r| j | _ n  | j d  k r| j r| j | _ n  | j  d  k r+| j r+| j | _  n  | j" | _" | j# | _# | j$ | _$ | j% | _% | j& | _& t' | j | j( | j)  | _ | S(   Ns	   default%dR>   g      ?(*   R   R   R>   R.   R1   R4   t   maxR3   R6   R7   R8   R9   R:   R;   R<   R2   R?   R^   t   bulletFontSizeR]   RX   RM   RK   RL   RP   RN   RO   RG   RE   RF   RJ   RH   RI   R   RC   RS   RT   RQ   RR   R   R/   R0   (   R   R   Rd   (    (    s   /xhtml2pdf/context.pyt   toParagraphStyle  sX    #c         C   s   g  } x t  d  D] } d | |  j j d <t j j |  j |   |  _ t j j |  i d d 6d d 6d d 6d d 6t  |  j	 |  j
  } | j |  q W| |  j _ |  j |  j  d  |  _ d  S(	   Ni   s   pdftoclevel%dt   classi    s
   margin-tops   margin-bottoms   margin-lefts   margin-right(   t   xrangeR   t
   attributesR   R%  t
   CSSCollectt   cssAttrt   CSS2FragR   R+  Re   R   R   t   levelStylesR'  R   R   (   R   t   stylest   it   pstyle(    (    s   /xhtml2pdf/context.pyt   addTOC8  s    c         C   s%   |  j  s! t   |  _ t |  _  n  d  S(   N(   R   R   R   R   (   R   (    (    s   /xhtml2pdf/context.pyt   addPageCountJ  s    	c         C   s   d  S(   N(    (   R   t   fragsRd   (    (    s   /xhtml2pdf/context.pyt   dumpParaO  s    c         C   s  | p |  j  } t |  _  y t |  j  } Wn# t j |  j  } | j   n Xd } xR |  j D]G } t | j | j  | j	 } t
 | | j | j	 |  } | | _ qa W| s |  j j   r|  j r|  j } |  j |  } | j	 r | | _ n t | j | j  | j	 | _ t j | j  } d  | _ | sSt |  j |  j  d k rq|  j r|  j j |  j d j d d   n1 |  j j   }	 d |	 _ d |	 _ |  j j |	  |  j |  j |  j |  t |  j | d |  j |  j d | }
 | j |
 _ | j |
 _ | j |
 _ | j |
 _ d |
 _ |  j rat  |
 |  j d	 |  j! j" d
 d  }
 n  |  j# |
  n  g  |  _ d  | _ n  d  |  _ i  |  _! |  j$   d  S(   Ni    iR-   R#   R%   R8  R   R)  t   sidet   alignR   (%   R  R=   t   reversedR  R   t   reverseR   R5   R1   R6   R)  R3   R-   R  R  R+  R   R   R   R  R   R"   Re   R.   R9  R   R`   Ra   Rb   R>   t   autoLeadingR	  R   R
  R~   R'  t	   clearFrag(   R   R  t	   rfragListt
   maxLeadingRe   R3   R   Rd   R   t   blankt   para(    (    s   /xhtml2pdf/context.pyt   addParaR  sb    				"	&									c         C   s   g  |  _  t |  _ d |  _ d  S(   Nu    (   R  R   R  R-   (   R   (    (    s   /xhtml2pdf/context.pyR?    s    		c         K   s   |  j  j |   S(   N(   Re   R"   (   R   t   kw(    (    s   /xhtml2pdf/context.pyt   copyFrag  s    c         K   s   |  j  j |   |  _  |  j  S(   N(   Re   R"   (   R   RE  (    (    s   /xhtml2pdf/context.pyt   newFrag  s    c         C   sO   | j  r; | j  j d  r; |  j j | | j  d f  n  |  j j |  d  S(   Nt   #i   (   R,   R  R   R   R  (   R   Re   (    (    s   /xhtml2pdf/context.pyt   _appendFrag  s     R#   c         C   s  |  j  j   } } | j d k rF | j d k rF d | _ d | _ n  | j r| | j t | _ t | j t d  | _ n5 | j r | j t	 | _ t | j t d  | _ n  t
 | j | j | j  | _ | _ | j d d  j d t  j d t  } | j d k rxt j d	 |  D] } |  j | 7_ d
 | k sOd | k r}| j   } d | _ d | _ |  j |  q"| j d d  } xQ t j d |  D]= } | j   } | d k rt } n  | | _ |  j |  qWq"Wn x t j d t d |  D] } | j   } | t k rTt |  _ t | _ |  j | 7_ |  j |  qd j d | d j    d d !| _ |  j r| j j   | _ | j rt |  _ qn  |  j | j 7_ |  j |  qWd  S(   Ni   i    i   u   ­u    u   Â u    t   pres   (\r\n|\n|\r)s   
s   R#   u   	i   u    s   (\ )t    u   (u   )R   iu           (   Re   R"   R&   R'   R1   t   subFractionR(   R)  t	   sizeDeltat   superFractionR   R.   R/   R0   R^   t   replacet   NBSPRW   t   ret   splitR-   t	   lineBreakRI  R   R  t   joinR  t   lstripR=   (   R   R-   Re   t   baseFrag(    (    s   /xhtml2pdf/context.pyt   addFrag  sX    			%				!		'		c         C   s!   |  j  j |  j  |  j   d  S(   N(   R  R   Re   RG  (   R   (    (    s   /xhtml2pdf/context.pyt   pushFrag  s    c         C   s   |  j  j   |  _ d  S(   N(   R  t   popRe   (   R   (    (    s   /xhtml2pdf/context.pyt   pullFrag  s    i   c         C   s9   y* t  d j |  j j   j   |    SWn d SXd  S(   NRK  R#   (   t   reprRT  R   t   toxmlRR  (   R   t   l(    (    s   /xhtml2pdf/context.pyt   _getFragment  s    *c         C   s   d S(   Ni    (    (   R   (    (    s   /xhtml2pdf/context.pyt   _getLineNumber  s    c         C   s   d t  |  |  j d  f S(   Ns   %s
%si2   (   R}   R^  (   R   t   msg(    (    s   /xhtml2pdf/context.pyt   context  s    	c         G   ss   |  j  d 7_  |  j j t j j |  j   t |  |  j d  f  y |  j	 | |  SWn |  j	 |  SXd  S(   Ni   i2   (
   R   R   R   R   R   t   PML_WARNINGR_  R}   R^  Ra  (   R   R`  t   args(    (    s   /xhtml2pdf/context.pyR     s    7c         G   ss   |  j  d 7_  |  j j t j j |  j   t |  |  j d  f  y |  j	 | |  SWn |  j	 |  SXd  S(   Ni   i2   (
   R   R   R   R   R   t	   PML_ERRORR_  R}   R^  Ra  (   R   R`  Rc  (    (    s   /xhtml2pdf/context.pyt   error  s    7c         C   s  y | p |  j  } | j d  r% | S|  j d  k	 rI |  j | |  } nj | d  k rq t j d  t j   } n  t j j	 t j j
 | |   } | o t j j |  s d  } n  | d  k r t j |  j d |   n  | SWn, t j |  j d | | |  d d n Xd  S(   Ns   data:s;   Could not find main directory for getting filename. Use CWDs   File '%s' does not exists   getFile %r %r %rt   exc_infoi   (   R  R  R  R   R   R   Ri   t   getcwdRj   t   normpathRT  t   isfileR   (   R   R   Ry   Rj   t   nv(    (    s   /xhtml2pdf/context.pyt   _getFileDeprecated  s"    !	c         C   s;   |  j  d k	 r% t |  j | |   St | | p7 |  j  S(   s-   
        Returns a file name or None
        N(   R  R   R   Rk  R  (   R   R   Ry   (    (    s   /xhtml2pdf/context.pyR   1  s    t	   helveticac         C   s   t  |  t j k	 rQ t  |  t j k r9 t |  } n  | j   j d  } n  xc | D][ } t  |  t j k r t |  } n  |  j j | j   j	   d  } | d k	 rX | SqX W|  j j | d  S(   s    
        Name of a font
        t   ,N(   R   R   R   t   StringTypesR}   R  RR  R   R~   R   R   (   R   R   R   R   t   font(    (    s   /xhtml2pdf/context.pyt   getFontName9  s    !c         C   sk   t  |  |  j t  |  j   <xE | D]= } t |  t j k rP t  |  } n  | |  j t  |  <q& Wd  S(   N(   R}   R   R   R   R   Rn  (   R   t   fontnamet   aliasR   (    (    s   /xhtml2pdf/context.pyt   registerFontJ  s
    t   WinAnsiEncodingc         C   s  | r| r| } | j  } t j d |  t |  t j k rI | } n d   | j d  D } g  | D] } t |  ^ qi } | d }	 | j d  }
 d j |
 d   |
 d } } | j	   } | d k rd	 |	 | | f } | |  j
 k rt j |  j d
 |   q| j   } t j t | |   xQ d D]I } x@ d D]8 } d	 |	 | | f |  j
 k rDt |	 | | |  qDqDWq7W|  j |	 | | g  q| d k r| d k r| j   } t | d  } | j   } n( | j   } t | d  } | j   } d	 |	 | | f } | |  j
 k rGt j |  j d |	   qt j | |  } | j } t j |  t j | | |  } t j |  xQ d D]I } x@ d D]8 } d	 |	 | | f |  j
 k rt |	 | | |  qqWqW|  j |	 | | | g  qt j |  j d   n  d  S(   Ns   Load font %rc         s   s'   |  ] } | r | j    j   Vq d  S(   N(   R   R  (   t   .0R   (    (    s   /xhtml2pdf/context.pys	   <genexpr>^  s    Rm  i    t   .it   ttct   ttfs   %s_%d%ds+   Repeated font embed for %s, skip new embed i   t   afmt   pfbs   .pfbs   .afms*   Repeated font embed for %s, skip new embeds   wrong attributes for <pdf:font>(   Rw  Rx  (   i    i   (   i    i   (   Ry  Rz  (   i    i   (   i    i   (   R   R   R  R   R   R   RR  R}   RT  R   R   R   R   t   getNamedFileR   Rs  R   R   R   t   EmbeddedType1FaceR   t   registerTypeFacet   Font(   R   R   Rq   t   encodingR/   R0   t   filet	   fontAliasR   R.   Rm   t   baseNamet   suffixt   fullFontNamet   filenameRy  t   tfileRz  t   facet   fontNameOriginalt   justFont(    (    s   /xhtml2pdf/context.pyR   Q  sZ    		
	N("   R   R   t   __doc__R  R   R  R  R&  R'  R(  R+  R6  R7  R9  R=   RD  R?  RF  RG  RI  R   RW  RX  RZ  R^  R_  Ra  R   Re  Rk  R   Rp  Rs  R   (    (    (    s   /xhtml2pdf/context.pyR     s<   C							9			P				B								(>   t   reportlab.lib.enumsR    t   reportlab.lib.fontsR   t   reportlab.lib.pagesizesR   R   t   reportlab.lib.stylesR   t   reportlab.pdfbaseR   t   reportlab.pdfbase.ttfontsR   t   reportlab.platypus.framesR   R   t   reportlab.platypus.paraparserR	   R
   R   t   xhtml2pdf.utilR   R   R   R   R   R   t   xhtml2pdf.w3cR   t   xhtml2pdf.xhtml2pdf_reportlabR   R   R   R   R   R   t   loggingRi   RQ  t	   reportlabR   Rg   t   xhtml2pdf.defaultR   t   xhtml2pdf.parsert	   rl_configt   warnOnMissingFontGlyphst	   getLoggerR   RM  RL  RN  RP  R"   Rf   Rn   t
   CSSBuilderRo   t	   CSSParserR   t   objectR   (    (    (    s   /xhtml2pdf/context.pyt   <module>   s@   .(			O	