
    Kwgo@                       d Z dZdgZdZddlZddlZddlmZ ddlm	Z	m
Z
mZmZ ddl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mZmZ ddlmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z& ddl'm(Z(  ejR                  d      Z*dZ+dZ,dde+fddde,fddde+fddde,fddde+fddde,fddde+fddde,fdiZ-d"dZ.d Z/d Z0d Z1 G d d      Z2d Z3 G d de      Z4e5d k(  r	 e6d!       yy)#z3.3.0zz
The Canvas object is the primary interface for creating PDF files. See
doc/reportlab-userguide.pdf for copious examples.
Canvas       N)digits)sincostanpi)	rl_config)pdfdoc)
pdfmetrics)
pathobject)PDFTextObject_PDFColorSetter)black_chooseEnforceColorSpaceColor	CMYKColortoColor)ImageReaderisSeqisStr	isUnicode	_digester	asUnicode)fp_str	escapePDF)aspectRatioFixz\dnSzf*fzB*Bc                     ddl m} |r0d| vr, ||j                  |j                  |j                  g      | d<   d| vr.|||xs dg}|r|j                   ||              ||      | d<   y y )Nr   )PDFArrayCBorder)reportlab.pdfbase.pdfdocr#   redgreenblueappend)Dcolor	thickness	dashArrayhradiusvradiusr#   borders           N/var/www/horilla/myenv/lib/python3.12/site-packages/reportlab/pdfgen/canvas.py
_annFormatr3   1   sn    1A599ekk5::>?#q').q1MM(9-.v&(	     c                    t        | t              r0| j                  dt        fd| j	                         D              fS t        | t
              rd| j                         fS t        | t        t        f      rt        |       }|dk(  rd| fS |dk(  r(d| fS t        | t              rt        t        |             S t        d| z        )N
DeviceCMYKc              3   (   K   | ]	  }|z    y wN ).0cds     r2   	<genexpr>z"_normalizeColor.<locals>.<genexpr>G   s     ">11Q3">s   	DeviceRGB      zUnknown color %r)
isinstancer   densitytuplecmykr   rgblistlenstr_normalizeColorr   
ValueError)aColorlr<   s     @r2   rI   rI   D   s    &)$NNU">">>>>	FE	"FJJL((	FUDM	*K6&&!V''	FC	 wv//
'&0
11r4   c                     d }g }| D ];  }t        |      \  }}|||k7  rt        d|d|      |}|j                  |       = ||fS )NzMismatch in color spaces: z and )rI   rJ   r*   )colorsspace	outcolorsrK   nspaceoutcolors         r2   _normalizeColorsrS   T   sf    EI #*62&eVTUU"# )r4   c                 `   ddl m}m} |"t        |      t        |       k7  rt	        d      t        |       dk(  r |d| d   | d         S t        |       dk(  r#||d   dk(  r|d   dk(  r |d| d   | d         S |3t        |       }t        |      D cg c]  }t        |      |dz
  z   }}nt        t        ||             }|j                  d        |d   d   dk7  r|j                  dd	|d   d   f       |d
   d   dk7  r|j                  d|d
   d   f       t        t        |       \  }} g }|dd
 D cg c]  }| }	}g }
| d   }| dd  D ]@  }|j                   |d||             |}|
j                  d	       |
j                  d       B  |||	|
d      S c c}w c c}w )Nr   )PDFExponentialFunctionPDFStitchingFunctionz4need to have the same number of colors and positionsr   )NC0C1   c                     | d   S )Nr   r9   )xs    r2   <lambda>z%_buildColorFunction.<locals>.<lambda>q   s
    QqT r4   )key              ?z	[0.0 1.0])Domain)r&   rU   rV   rG   rJ   rangefloatrF   zipsortinsertr*   )rN   	positionsrU   rV   ncr\   	poscolors	functionsposboundsencode	lastcolorr,   s                r2   _buildColorFunctionrp   _   s   UY3v;!>OPP
6{a%fQiF1IFF
6{a1!2y|q7H)A&)q	JJ[.3Bi8U1Xr!t_8	8 Y/0	>*Q<?aQil1o 67R=q c9R=#345 i1	6I&q_-cc-F-Fq	I /!	eLM	cc	
  	66+NN+ 9 .s   F& 	F+c                       e Zd Z edddddd      Z eh d      ZdhZed	        Zed
        Z	ed        Z
d Zd Zd Zd Zd Zy)	ExtGStater   Fr   Normal)CAcaOPopOPMBM>   Huer   Darkenrs   ScreenLightenOverlayMultiply	ColorBurn	Exclusion	HardLight	SoftLight
ColorDodge
Difference
Luminosity
Saturation)ry   ry   c                 4    t        |       j                         S r8   )rH   lowervs    r2   _boolTransformzExtGState._boolTransform   s    1v||~r4   c                     | S r8   r9   r   s    r2   _identityTransformzExtGState._identityTransform   s    r4   c                     d| z   S )N/r9   r   s    r2   _pdfNameTransformzExtGState._pdfNameTransform   s    1ur4   c                      i | _         i | _        y r8   )_d_cselfs    r2   __init__zExtGState.__init__   s    r4   c           	         | j                   |   }t        |t              rt        |      }| j                  }nY|| j                  v r?|| j
                  |   vr!t        d|d|d| j
                  |         | j                  }n| j                  }|| j                  j                  ||      k7  s|dk(  r| j                  d      |k7  r|| j                  |<   | ||      f}|| j                  v r| j                  |   }n0dt        t        | j                              z   }|| j                  |<   |j                  j!                  d|z         y y y )Nz
ExtGstate[z] = z not in allowed values rw   rv   gRLsz/%s gs)defaultsrA   boolr   pdfNameValuesallowedrJ   r   r   r   getgetValuer   rH   rG   _coder*   )r   canvar   r<   
vTransformtnames           r2   setzExtGState.set   s$   MM!a1gA,,J$$$$Q' aQ") * *//J00Jdggkk!A1d7t}}T/BA/EDGGAJ*Q-ADGG|wwqzc#dgg,//!
JJho. 0F7r4   c                 T    | j                   j                  || j                  |         S r8   )r   r   r   )r   r   s     r2   r   zExtGState.getValue   s     ww{{1T]]1-..r4   c                     i }| j                   j                         D ]'  \  }}t        j                  t	        |f            ||<   ) |xr t        j                  |      xs d S r8   )r   itemsr   PDFDictionarydict)r   r   r   r   s       r2   getStatezExtGState.getState   sY    ggmmo 	7FAd**4:6AdG	7,V))!,44r4   c                     | j                         }| j                  j                         |_        | j                  |_        |S )z=the states must be shared across push/pop, but the values not)	__class__r   copyr   )r   r\   s     r2   pushCopyzExtGState.pushCopy   s/    NNww||~wwr4   N)__name__
__module____qualname__r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r9   r4   r2   rr   rr      s    H G FM     /,/5r4   rr   c                     t        | t        t        f      r3t        |       dk7  rt	        d| z        d| D cg c]  }|rdnd
 c}z  S | rdS dS c c}w )NrZ   z wrong length for extend argumentz[%s %s]truefalsez[true true]z[false false])rA   rF   rC   rG   rJ   )extend_s     r2   _gradientExtendStrr      s\    &$u&v;>?&HIIfEaFW4EEE"=77 Fs   Ac                   *   e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zd Zd Zd	 Zd
j                         Z
 e e ee
                  Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+	 	 	 	 	 	 dd(Z,dd)Z-d* Z.d+ Z/d, Z0	 	 	 dd-Z1	 	 	 dd.Z2d/ Z3d0 Z4d1 Z5dd2Z6d3 Z7dd4Z8dd5Z9dd6Z:dd7Z;e;Z<dg d8dddfd9Z=dd:Z>e>Z?	 	 dd;Z@	 	 dd<ZAdd=ZBdd>ZCd? ZDd@ ZEdA ZFdB ZGdC ZHddDZIdE ZJdF ZKdG ZLdH ZMddIZNdJ ZOdK ZPdL ZQdM ZRdN ZSdO ZTdP ZUdQ ZVdR ZWdS ZXdT ZYddUZZdV Z[dW Z\ddXZ]ddYZ^ddZZ_dd[Z`dd\Zadd]Zbd^ Zcd_ Zddd`ZeddaZfddbZgddcZhdddZiejj                  ddddfdeZldf Zmdg ZnddhZoddiZpddjZqdk Zrdl Zsdm Ztdn Zug dfdoZvdp ZwddqZxddrZyddsZzddtZ{du Z|ddvZ}ddwZ~	 	 ddxZdy Zdz Zd{ Zd| Zd} Zd~ Zd ZddZed        Zed        Zy)r   a  This class is the programmer's interface to the PDF file format.  Methods
    are (or will be) provided here to do just about everything PDF can do.

    The underlying model to the canvas concept is that of a graphics state machine
    that at any given point in time has a current font, fill color (for figure
    interiors), stroke color (for figure borders), line width and geometric transform, among
    many other characteristics.

    Canvas methods generally either draw something (like canvas.line) using the
    current state of the canvas or change some component of the canvas
    state (like canvas.setFont).  The current state can be saved and restored
    using the saveState/restoreState methods.

    Objects are "painted" in the order they are drawn so if, for example
    two rectangles overlap the last draw will appear "on top".  PDF form
    objects (supported here) are used to draw complex drawings only once,
    for possible repeated use.

    There are other features of canvas which are not visible when printed,
    such as outlines and bookmarks which are used for navigating a document
    in a viewer.

    Here is a very silly example usage which generates a Hello World pdf document.

    Example:: 
    
       from reportlab.pdfgen import canvas
       c = canvas.Canvas("hello.pdf")
       from reportlab.lib.units import inch
       # move the origin up and to the left
       c.translate(inch,inch)
       # define a large font
       c.setFont("Helvetica", 80)
       # choose some colors
       c.setStrokeColorRGB(0.2,0.5,0.3)
       c.setFillColorRGB(1,0,1)
       # draw a rectangle
       c.rect(inch,inch,6*inch,9*inch, fill=1)
       # make text go straight up
       c.rotate(90)
       # change color
       c.setFillColorRGB(0,0,0.77)
       # say hello (note after rotate the y coord needs to be negative!)
       c.drawString(3*inch, -3*inch, "Hello World")
       c.showPage()
       c.save()

    Nr   r   c                 H   |t         j                  }|t         j                  }|r|nt         j                  | _        ||nd| _        ||n| j
                  dz  | _        || _        t        j                  ||||	xs t        j                  |      | _        t        |
      | _        || _        d| _        || _        || _        d| _        d| _        d| _        d| _        i | _        | j/                  |       d| _        g | _        | j5                          d| _        g | _        g | _        g | _        || _        t         j@                  | _!        || _"        || _#        || _$        || _%        | jM                          | jO                          g | _(        | jS                  |       y)a  Create a canvas of a given size. etc.

        You may pass a file-like object to filename as an alternative to
        a string.
        For more information about the encrypt parameter refer to the setEncrypt method.
        
        Most of the attributes are private - we will use set/get methods
        as the preferred interface.  Default page size is A4.
        cropMarks may be True/False or an object with parameters borderWidth, markColor, markWidth
        and markLength
    
        if enforceColorSpace is in ('cmyk', 'rgb', 'sep','sep_black','sep_cmyk') then one of
        the standard _PDFColorSetter callables will be used to enforce appropriate color settings.
        If it is a callable then that will be used.
        N   333333?)compression	invariantfilename
pdfVersionlangr   r   )*r
   defaultPageSizer   canvas_basefontname_initialFontName_initialFontSize_initialLeading	_filenamer   PDFDocumentPDF_VERSION_DEFAULT_docr   _enforceColorSpace
_verbosity_onPage
_cropMarks	_pagesize_hanging_pagesize_pageRotation_pageTransition_pageDuration_destinationssetPageCompression_pageNumber
_codeStack_restartAccumulators_annotationCount	_outlines_psCommandsBeforePage_psCommandsAfterPagebottomupdefaultImageCachingimageCaching_cropBox_artBox_trimBox	_bleedBoxinit_graphics_state_make_preamblestate_stack
setEncrypt)r   r   pagesizer   pageCompressionr   	verbosityencrypt	cropMarksr   enforceColorSpaceinitialFontNameinitialFontSizeinitialLeadingcropBoxartBoxtrimBoxbleedBoxr   s                      r2   r   zCanvas.__init__  s   D 	(A(AX)*=*=i3B	HeHe3B3NTV1?1K~QUQfQfgjQj!&&?1:X2<2Z@Z@Z,0)	 #;;L"M $ #!!%#!0!!# !%'"$&! !%99!  " r4   c                 L   |rddl m} t        |      r?t        |      r|j	                  d      }|j                  |      }|j                  d       n$t        ||j
                        st        d|z        || j                  _
        y	 | j                  `
y# t        $ r Y yw xY w)ah  
        Set the encryption used for the pdf generated by this canvas.
        If encrypt is a string object, it is used as the user password for the pdf.
        If encrypt is an instance of reportlab.lib.pdfencrypt.StandardEncryption, this object is
        used to encrypt the pdf. This allows more finegrained control over the encryption settings.
        r   )
pdfencryptutf-8r   zjExpected string or instance of reportlab.lib.pdfencrypt.StandardEncryption as encrypt parameter but got %rN)reportlab.libr   r   r   rn   StandardEncryptionsetAllPermissionsrA   	TypeErrorr   r   AttributeError)r   r   r   s      r2   r   zCanvas.setEncryptf  s     0W~W%%nnW5G$77@))!,)F)FG  !M  PW  !W  X  X 'DIIII%! s   
B 	B#"B#c                    d| _         d| _        | j                  | _        | j                  | _        d| _        | j                  | _        d| _	        t        | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d | _        d| _        d| _        t0        j2                  xs dx| _        | _        t9               | _        y )Nr   )ra   r_   r_   ra   r_   r_   d   r   r   r   r   )_x_yr   	_fontnamer   	_fontsize	_textModer   _leading_currentMatrixFILL_EVEN_ODD	_fillMode
_charSpace
_wordSpace_horizScale_textRenderMode_rise_textLineMatrix_textMatrix_lineCap	_lineJoin	_lineDash
_lineWidth_mitreLimitr
   canvas_baseColor_fillColorObj_strokeColorObjrr   
_extgstater   s    r2   r   zCanvas.init_graphics_state}  s    ....,,6&  
73 4=4N4N4YRYYT1#+r4   c                     i }| j                   }| j                  D ]
  }||   ||<    | j                  j                  |       | j                  j                         | _        y r8   )__dict__STATE_ATTRIBUTESr   r*   r  r   )r   stater<   r   s       r2   push_state_stackzCanvas.push_state_stack  sZ    MM)) 	"DD'E$K	"&//224r4   c                 j    | j                   j                  | j                  j                                y r8   )r  updater   popr   s    r2   pop_state_stackzCanvas.pop_state_stack  s#    T--1134r4   a  _x _y _fontname _fontsize _textMode _leading _currentMatrix _fillMode
     _charSpace _wordSpace _horizScale _textRenderMode _rise _textLineMatrix
     _textMatrix _lineCap _lineJoin _lineDash _lineWidth _mitreLimit _fillColorObj
     _strokeColorObj _extgstatec                    g j                   }| j                  r	 |d       n! |dt        | j                  d         z         | j                  }t        |      }| j                  dk7  r| j                  | j                         | j                  dk7  r| j                  | j                          |dj                  ||d               ||d = t        j                  | j                        }|j                  sQ|j                  j                   st#        | dd      s. |d| j$                  j'                  | j                        z         dj                  |j(                        | _        y )	Nz1 0 0 1 0 0 cmz1 0 0 -1 0 %s cmr   r   _drawTextAsPathFzBT %s 12 Tf 14.4 TL ET)r*   r   r   r   r   rG   r  setFillColorr  setStrokeColorjoinr   getFontr  _dynamicFontfacebuiltIngetattrr   getInternalFontName__self__	_preamble)r   Pr$   r   fonts        r2   r   zCanvas._make_preamble  s   II== 6$..*;#<<=JJF(d0017* 4 45	#((1QR5/abE!!$..1  yy  5Fu(M*TYY-J-J4>>-ZZ[!**-r4   c                     t        |      S r8   )r   r   ss     r2   _escapezCanvas._escape  s    |r4   c                 :    | j                   j                  |       y)a  identify the author for invisible embedding inside the PDF document.
           the author annotation will appear in the the text of the file but will
           not automatically be seen when the document is viewed, but is visible
           in document properties etc etc.N)r   	setAuthor)r   authors     r2   r9  zCanvas.setAuthor  s    
 			F#r4   c                 :    | j                   j                  |       y)zHaccepts a func(yyyy,mm,dd,hh,m,s) used to create embedded formatted dateN)r   setDateFormatter)r   dateFormatters     r2   r<  zCanvas.setDateFormatter  s    		""=1r4   c                 V    | j                   j                  j                  ||||       y)a  Adds a new entry to the outline at given level.  If LEVEL not specified,
        entry goes at the top level.  If level specified, it must be
        no more than 1 greater than the outline level in the last call.

        The key must be the (unique) name of a bookmark.
        the title is the (non-unique) name to be displayed for the entry.

        If closed is set then the entry should show no subsections by default
        when displayed.

        Example::
        
           c.addOutlineEntry("first section", "section1")
           c.addOutlineEntry("introduction", "s1s1", 1, closed=1)
           c.addOutlineEntry("body", "s1s2", 1)
           c.addOutlineEntry("detail1", "s1s2s1", 2)
           c.addOutlineEntry("detail2", "s1s2s2", 2)
           c.addOutlineEntry("conclusion", "s1s3", 1)
           c.addOutlineEntry("further reading", "s1s3s1", 2)
           c.addOutlineEntry("second section", "section1")
           c.addOutlineEntry("introduction", "s2s1", 1)
           c.addOutlineEntry("body", "s2s2", 1, closed=1)
           c.addOutlineEntry("detail1", "s2s2s1", 2)
           c.addOutlineEntry("detail2", "s2s2s2", 2)
           c.addOutlineEntry("conclusion", "s2s3", 1)
           c.addOutlineEntry("further reading", "s2s3s1", 2)

        generated outline looks like::
        
            - first section
            |- introduction
            |- body
            |  |- detail1
            |  |- detail2
            |- conclusion
            |  |- further reading
            - second section
            |- introduction
            |+ body
            |- conclusion
            |  |- further reading

        Note that the second "body" is closed.

        Note that you can jump from level 5 to level 3 but not
        from 3 to 5: instead you need to provide all intervening
        levels going down (4 in this case).  Note that titles can
        collide but keys cannot.
        )closedN)r   outlineaddOutlineEntry)r   titler^   levelr?  s        r2   rA  zCanvas.addOutlineEntry  s&    h 			))#ueF)Kr4   c                 R     | j                   j                  j                  | f|z     y)aF  nametree should can be a recursive tree like so::
            
               c.setOutlineNames(
                 "chapter1dest",
                 ("chapter2dest",
                  ["chapter2section1dest",
                   "chapter2section2dest",
                   "chapter2conclusiondest"]
                 ), # end of chapter2 description
                 "chapter3dest",
                 ("chapter4dest", ["c4s1", "c4s2"])
                 )
          
          each of the string names inside must be bound to a bookmark
          before the document is generated.
        N)r   r@  setNames)r   nametrees     r2   setOutlineNames0zCanvas.setOutlineNames0	  s%    " 	#		""dWX%57r4   c                 :    | j                   j                  |       y)zcwrite a title into the PDF file that won't automatically display
           in the document itself.N)r   setTitle)r   rB  s     r2   rI  zCanvas.setTitle  s     			5!r4   c                 :    | j                   j                  |       y)zewrite a subject into the PDF file that won't automatically display
           in the document itself.N)r   
setSubject)r   subjects     r2   rK  zCanvas.setSubject!  s     			W%r4   c                 :    | j                   j                  |       y)zwrite a creator into the PDF file that won't automatically display
           in the document itself. This should be used to name the original app
           which is passing data into ReportLab, if you wish to name it.N)r   
setCreator)r   creators     r2   rN  zCanvas.setCreator&  s     			W%r4   c                 :    | j                   j                  |       y)z!change the default producer valueN)r   setProducer)r   producers     r2   rQ  zCanvas.setProducer,  s    		h'r4   c                     t        |t        t        f      rdj                  |      }| j                  j                  |       y)zwrite a list of keywords into the PDF file which shows in document properties.
        Either submit a single string or a list/tuplez, N)rA   rF   rC   r)  r   setKeywords)r   keywordss     r2   rT  zCanvas.setKeywords0  s2     hU|,yy*H		h'r4   c                 2    t        | j                        dk(  S )zHInfo function - app can call it after showPage to see if it needs a saver   )rG   r   r   s    r2   pageHasDatazCanvas.pageHasData7  s    4::!##r4   c                 L    | j                   j                  j                          y)zSpecify that Acrobat Reader should start with the outline tree visible.
        showFullScreen() and showOutline() conflict; the one called last
        wins.N)r   _catalogshowOutliner   s    r2   rZ  zCanvas.showOutline;  s     			&&(r4   c                 L    | j                   j                  j                          y)zSpecify that Acrobat Reader should start in full screen mode.
        showFullScreen() and showOutline() conflict; the one called last
        wins.N)r   rY  showFullScreenr   s    r2   showFullScreen0zCanvas.showFullScreen0A  s     			))+r4   c                 t    | j                   j                  d       | j                  j                  | d|       y)z
        Define the transparency/opacity of strokes. 0 is fully
        transparent, 1 is fully opaque.

        Note that calling this function will cause a version 1.4 PDF
        to be generated (rather than 1.3).
        transparencyrt   Nr   ensureMinPdfVersionr  r   r   r   s     r2   _setStrokeAlphazCanvas._setStrokeAlphaG  ,     			%%n5Da(r4   c                 t    | j                   j                  d       | j                  j                  | d|       y)z
        Define the transparency/opacity of non-strokes. 0 is fully
        transparent, 1 is fully opaque.

        Note that calling this function will cause a version 1.4 PDF
        to be generated (rather than 1.3).
        r_  ru   Nr`  rb  s     r2   _setFillAlphazCanvas._setFillAlphaR  rd  r4   c                 >    | j                   j                  | d|       y )Nrv   r  r   rb  s     r2   _setStrokeOverprintzCanvas._setStrokeOverprint]      Da(r4   c                 >    | j                   j                  | d|       y )Nrw   rh  rb  s     r2   _setFillOverprintzCanvas._setFillOverprint`  rj  r4   c                 N    | j                   j                  | d|xr dxs d       y )Nrx   r   r   rh  rb  s     r2   _setOverprintMaskzCanvas._setOverprintMaskc  s     DqwQ|!4r4   c                 >    | j                   j                  | d|       y )Nry   rh  rb  s     r2   setBlendModezCanvas.setBlendModef  rj  r4   c                     | j                   }|r7t        dt        |dd            }t        dt        |dd            }|r||z  }|S y )Nr   
bleedWidthborderWidth$   )r   maxr.  )r   cMbleedWbws       r2   _getCmShiftzCanvas._getCmShifti  sN    __72l156FQwr-34BfI r4   c                    | j                   d   }| j                   d   }| j                  }| j                  }|rt        dt	        |dd            }|rt	        |dd      }t        |t        dt	        |dd                  }t	        |dd	      }t	        |d
t              }	d|z  |z
  }
t        |      }|r|	r| j                          | j                  |	       | j                  |       | j                  |d||f||z   d||z   |f|||
z   ||d|z  z   f||z   ||
z   ||z   |d|z  z   fd|||f||
z   ||d|z  z   |fd||z   |||z   f||
z   ||z   |d|z  z   ||z   fg       | j                          |r||d }||d= t        |      }t        dt	        |dd            }| j                          | j                  ||z
  ||z
         |r$| j                  dd|z  |z  z   dd|z  |z  z          ||d }||d= ||dd | j                          |r|j                         d|z  |z   }d|z  |z   }|j!                  d       t#        j$                         }||_        ||_        | j*                  |_        | j.                  |_        |j3                  | j4                         |j7                  | j8                         dD ]F  }t	        | d|z  d      }|st;        ||j=                         dz   t#        j>                  |             H | j@                  | j@                  |_!        | jD                  | jF                  gz   |z   | jH                  z   }|jK                  |       | jM                  |       | jO                  |       | jQ                  |       | jS                  |       | jU                  |       | jV                  jY                  |       | jZ                  r| j[                  | j\                         | j_                          y)z8Close the current page and possibly start on a new page.r   r   rs  rt  markLast
markLength   	markWidth      ?	markColorrZ   Nrr  g       @r%  )cropartbleedtrim_%sBoxBox)0r   r   r   ru  r.  minr   rG   	saveStater(  setLineWidthlinesrestoreState	translatescaler   r*   r   PDFPage	pagewidth
pageheightr   Rotate_currentPageHasImages	hasImagessetPageTransitionr   setCompression_pageCompressionsetattr
capitalizer#   r   Durr   r1  r   	setStream_setColorSpace_setExtGState_setXObjects_setShadingUsed_setAnnotationsr   addPager   r   
_startPage)r   	pageWidth
pageHeightrv  coderx  r{  mlmwmcmgcx0Lrw  r$   pageboxsizestrms                      r2   showPagezCanvas.showPager  s    NN1%	^^A&
__zzQwr-34B"2j3C'"\""=>?RC0RE2rT"W$i"NN$''+%%b)JJAb"2a	"R8JrM"Z"_="2jmIbLAbDQ2b"2b1R4;:b=JrM:"2jmIadN:b=Q	  	 %%' !J J!$iQwr,q9: r&yF3JJq#f*i!773v:z:Q8QR JJQq	!!#KKNbD9,	rTJ.
C~~"$((33t334D1120 	KC4T2DS^^-e3FOOD4IJ	K )))DH**dnn-==DtG`G``tD!4 $T"T"		$<<d&6&67r4   c                     | j                   r"| j                  | j                          d | _         | xj                  dz  c_        | j                          | j	                          g | _        y Nr   )r   setPageSizer   r   r   r   r   s    r2   r  zCanvas._startPage  sX    !!T334%)D"A!!#  "r4   c                     || _         y)zfunc(pageNum) will be called on each page end.

       This is mainly a hook for progress monitoring.
        Call setPageCallback(None) to clear a callback.N)r   )r   funcs     r2   setPageCallBackzCanvas.setPageCallBack  s    
 r4   c                 &    | j                   |_        y r8   )_annotationrefsAnnotsr   r  s     r2   r  zCanvas._setAnnotations  s    **r4   c                 &    | j                   |_         y r8   )_colorsUsedr   objs     r2   r  zCanvas._setColorSpace  s    **r4   c                 &    | j                   |_         y r8   )_shadingUsedr  s     r2   r  zCanvas._setShadingUsed  s     --r4   c                 t    | j                   }|r#| j                  j                  |      }||_        yd|_        y)zKfor pages and forms, define the XObject dictionary for resources, if neededN)_formsinuser   xobjDictXObjects)r   thingformsxobjectsdicts       r2   r  zCanvas._setXObjects  s2      99--e4L)EN!ENr4   c                 j    | j                   }	 ||   S #  t        j                  |      x}||<   Y |S xY w)zDget a reference to a (possibly undefined, possibly unbound) bookmark)r   r   Destination)r   r   r<   results       r2   _bookmarkReferencezCanvas._bookmarkReference  s@    	8T7N	8%11$77FQtWs    2c                 ~   | j                  |      }| j                  j                          | j                  j                         }	|d}|d}|d}|d}|d}|dk(  r|j	                  |||       n|dk(  r|j                          n|dk(  r|j                  |       n|dk(  r|j                  |       nu|dk(  r|j                  ||||       n[|dk(  r|j                          nE|dk(  r|j                  |       n.|d	k(  r|j                  |       nt        d
t        |      z        |j                  |	       |S )a]  
        This creates a bookmark to the current page which can
        be referred to with the given key elsewhere.

        PDF offers very fine grained control over how Acrobat
        reader is zoomed when people link to this. The default
        is to keep the user's current zoom settings. the last
        arguments may or may not be needed depending on the
        choice of 'fitType'.

        Fit types and the other arguments they use are:
        
        - XYZ left top zoom - fine grained control.  null
          or zero for any of the parameters means 'leave
          as is', so "0,0,0" will keep the reader's settings.
          NB. Adobe Reader appears to prefer "null" to 0's.

        - Fit - entire page fits in window

        - FitH top - top coord at top of window, width scaled
          to fit.

        - FitV left - left coord at left of window, height
          scaled to fit

        - FitR left bottom right top - scale window to fit
          the specified rectangle

        (question: do we support /FitB, FitBH and /FitBV
        which are hangovers from version 1.1 / Acrobat 3.0?)nullXYZFitFitHFitVFitRFitBFitBHFitBVzUnknown Fit type %s)r  r   inPagethisPageRefxyzfitfithfitvfitrfitbfitbhfitbvrJ   asciisetPage)
r   r^   r  lefttopbottomrightzoomdestpagerefs
             r2   bookmarkPagezCanvas.bookmarkPage  s*   L &&s+		))'') <D;C>F=E<D%<HHT#d#E\HHJF]IIcNF]IIdOF]IId6%,F]IIKG^JJsOG^JJt2U3Z?@@Wr4   c                 .    | j                  ||||d      S )a   Bind a bookmark (destination) to the current page at a horizontal position.
           Note that the yhorizontal of the book mark is with respect to the default
           user space (where the origin is at the lower left corner of the page)
           and completely ignores any transform (translation, scale, skew, rotation,
           etcetera) in effect for the current graphics state.  The programmer is
           responsible for making sure the bookmark matches an appropriate item on
           the page.r   )r  r  r  r  )r  )r   r^   r  r  r  kws         r2   bookmarkHorizontalAbsolutez!Canvas.bookmarkHorizontalAbsolute@  s        #3T JJr4   c                 Z    | j                  ||      \  }} | j                  ||fd|i| y)z<w.r.t. the current transformation, bookmark this horizontal.r  N)absolutePositionr  )r   r^   	relativeX	relativeYr  r  r  s          r2   bookmarkHorizontalzCanvas.bookmarkHorizontalK  s4    ++Ii@s'''SBtBrBr4   c                     | j                   j                  d| j                  j                  |      z         | j                  j                  |       y)aI  use a form XObj in current operation stream.

        The form should either have been defined previously using
        beginForm ... endForm, or may be defined later.  If it is not
        defined at save time, an exception will be raised. The form
        will be drawn within the context of the current graphics
        state./%s DoN)r   r*   r   getXObjectNamer  r   r   s     r2   doFormzCanvas.doFormX  s>     	

(TYY%=%=d%CCD%r4   c                 8    | j                   j                  |      S )z*Query whether form XObj really exists yet.)r   hasFormr  s     r2   r  zCanvas.hasFormc  s    yy  &&r4   c                     d| _         ddlm}  ||||||      }|j                  | ||||	|
       |j                  |j
                  fS )a  See drawImage, which should normally be used instead... 
        
        drawInlineImage behaves like drawImage, but stores the image content
        within the graphics stream for the page.  This means that the mask
        parameter for transparency is not available.  It also means that there 
        is no saving in file size or time if the same image is reused.  
        
        In theory it allows images to be displayed slightly faster; however, 
        we doubt if the difference is noticeable to any human user these days.
        Only use this if you have studied the PDF specification and know the
        implications.
        r   r   )PDFImage)preserveAspectRatioanchor
anchorAtXYshowBoundaryextraReturn)r  reportlab.pdfgen.pdfimagesr  drawInlineImagewidthheight)r   imager\   yr  r  r  r  r  r  r  r  img_objs                r2   r   zCanvas.drawInlineImagel  sX      &'"75!Auf5 3Z\# 	  	% w~~..r4   c                    d| _         t        |t              rj|j                         }|j                  }|dk(  r|r|j                         }nt        |      }t        |      r|j                  d      }t        ||z         }n-||}t        |      r|j                  d      }t        |      }| j                  j                  |      }| j                  j                  j                  |d      }|st        j                  |||      }||_        | j!                  |       | j                  j#                  ||       | j                  j%                  ||       t'        |dd      }|r| j                  j                  |j                        }| j                  j                  j                  |d      }|s3| j!                  |       | j                  j#                  ||      |_        nt        j*                  |      |_        |`t/        |||||||j0                  |j2                  |		      \  }}}}}| j5                          | j7                  ||       | j9                  ||       | j:                  j=                  d|z         | j?                          |
r| jA                  |
||||       | jB                  j=                  |       |r%|jE                         D ]  }tG               |   ||<    |j0                  |j2                  fS )	aX  Draws the image (ImageReader object or filename) as specified.

        "image" may be an image filename or an ImageReader object. 
 
        x and y define the lower left corner of the image you wish to
        draw (or of its bounding box, if using preserveAspectRation below).
         
        If width and height are not given, the width and height of the
        image in pixels is used at a scale of 1 point to 1 pixel.  
       
        If width and height are given, the image will be stretched to fill 
        the given rectangle bounded by (x, y, x+width, y-height).  
        
        If you supply negative widths and/or heights, it inverts them and adjusts
        x and y accordingly.

        The method returns the width and height of the underlying image, since
        this is often useful for layout algorithms and saves you work if you have
        not specified them yourself.

        The mask parameter supports transparent backgrounds. It takes 6 numbers
        and defines the range of RGB values which will be masked out or treated
        as transparent.  For example with [0,2,40,42,136,139], it will mask out
        any pixels with a Red value from 0-2, Green from 40-42 and
        Blue from 136-139  (on a scale of 0-255).

        New post version 2.0:  drawImage can center an image in a box you
        provide, while preserving its aspect ratio.  For example, you might
        have a fixed square box in your design, and a collection of photos
        which might be landscape or portrait that you want to appear within 
        the box.  If preserveAspectRatio is true, your image will appear within
        the box specified.

        
        If preserveAspectRatio is True, the anchor property can be used to
        specify how images should fit into the given box.  It should 
        be set to one of the following values, taken from the points of
        the compass (plus 'c' for 'centre'):

                nw   n   ne
                w    c    e
                sw   s   se

        The default value is 'c' for 'centre'.  Thus, if you want your
        bitmaps to always be centred and appear at the top of the given box,
        set anchor='n'.      There are good examples of this in the output
        of test_pdfgen_general.py

        Unlike drawInlineImage, this creates 'external images' which
        are only stored once in the PDF file but can be drawn many times.
        If you give it the same filename twice, even at different locations
        and sizes, it will reuse the first occurrence, resulting in a saving
        in file size and generation time.  If you use ImageReader objects,
        it tests whether the image content has changed before deciding
        whether to reuse it.

        In general you should use drawImage in preference to drawInlineImage
        unless you have read the PDF Spec and understand the tradeoffs.r   autoutf8r   N)mask_smaskr  )$r  rA   r   
getRGBData_dataArH   r   rn   r   r   r  
idToObjectr   r   PDFImageXObjectr   r  	ReferenceaddFormr.  smaskPDFObjectReferencer
  r   r  r  r  r  r  r   r*   r  drawBoundaryr  keysvars)r   r  r\   r  r  r  r	  r  r  r  r  r  rawdatar  mdatar   r6  regNameimgObjmRegNamemImgObjscaledks                          r2   	drawImagezCanvas.drawImage  s   | &'" eK(&&(GLLEV|((*D	V,WU]+D  &A|HHW%Q<D ))**40%%))'48++D%dCFFKf%II0IIdF+F8D1E9933EJJ?))..228TB%%e,#'99#6#6uX#FFL#)#<#<X#FFLM #11DVAaPUV\]c]i]ijpjwjw  yC  #D!E& 	q!

5&!

(W,-l1QuV< 	% %%' +!%A+ fmm,,r4   c                    | j                   rA| j                   j                  d      \  | _        | _        | _        | _        | _        | _        y g | _        g | _        g | _	        d| _
        g | _        g | _        d | _        i | _        i | _        y )Nr`   r   )r   r"  r   r  r  	_formDatar  r  r   r   r  r   s    r2   r   zCanvas._restartAccumulators  s    ??uy  vE  vE  vI  vI  JL  vMrDJ($*>tO_aearDJ(*D%)+D&)*D&!D#%D !DN!D "Dr4   c                 $   | j                   | j                  | j                  | j                  | j                  | j
                  f}| j                  j                  |       g | _         d| _        g | _        g | _        d| _        i | _        i | _        y)zVwhen you enter a form, save accumulator info not related to the form for page (if any)r   N)	r   r  r  r   r  r  r   r*   r  )r   saveds     r2   _pushAccumulatorszCanvas._pushAccumulators  s~    T--t/C/CT^^UYUeUegkgxgxyu%
%&"!r4   c                 B    | j                   j                         |_        y r8   )r  r   rr   r  s     r2   r  zCanvas._setExtGState  s    002r4   c                     | j                          | j                          | j                  s| j                  r| j	                          |||||f| _        | j
                  j                          y)a}  declare the current graphics stream to be a named form.
           A graphics stream can either be a page or a form, not both.
           Some operations (like bookmarking) are permitted for pages
           but not forms.  The form will not automatically be shown in the
           document but must be explicitly referenced using doForm in pages
           that require the form.N)r  r   r   r   r#  r   inForm)r   r   lowerxloweryupperxupperys         r2   	beginFormzCanvas.beginForm!  sY     	  "::""$ ?		r4   c                 H   | j                   \  }}}}}	 | j                  \  }}||}||}t        j                  ||||      }	| j                  |	_        |	j                  | j                  g| j                  z          |j                         D ]  \  }
}t        |	|
|        | j                  |	       | j                  |	       | j                  |	       | j                  |	       | j                  j!                  ||	       | j#                          | j%                          y)zlemit the current collection of graphics operations as a Form
           as declared previously in beginForm.N)r'  r(  r)  r*  )r   r   r   PDFFormXObjectr  r   setStreamListr1  r   r   r  r  r  r  r  r   r  r   r#  )r   extra_attributesr   r'  r(  r)  r*  whformr  r   s               r2   endFormzCanvas.endForm3  s    26.vvvv 	R1>!6>!6$$F6&Y_`00DNN+djj89$**, 	DAqD1	D!4 $T"		$%!!#r4   c                    t        |      r6dt        j                  |j                  d            j	                         z   }n&dt        j                  |      j	                         z   }| j
                  j                  |      }| j
                  j                  j                  |d      }|sat        j                  |dz         }| j                  |       | j
                  j                  ||       | j
                  j                  ||       |dk(  r| j                  j                  d|z         nB|dk(  r| j                   j                  d|z         n| j"                  j                  d|z         | j$                  j                  |       y)a  Embed literal Postscript in the document.

        With position=0, it goes at very beginning of page stream;
        with position=1, at current point; and
        with position=2, at very end of page stream.  What that does
        to the resulting Postscript depends on Adobe's header :-)

        Use with extreme caution, but sometimes needed for printer tray commands.
        Acrobat 4.0 will export Postscript to a printer or file containing
        the given commands.  Adobe Reader 6.0 no longer does as this feature is
        deprecated.  5.0, I don't know about (please let us know!). This was
        funded by Bob Marshall of Vector.co.uk and tested on a Lexmark 750.
        See test_pdfbase_postscript.py for 2 test cases - one will work on
        any Postscript device, the other uses a 'setpapertray' command which
        will error in Distiller but work on printers supporting it.
        PSr   N
r   r  r   )r   hashlibmd5rn   	hexdigestr   r  r  r   r   PDFPostScriptXObjectr  r  r  r   r*   r   r   r  )r   commandpositionrawNamer  psObjs         r2   addPostScriptCommandzCanvas.addPostScriptCommandL  s5   $ WW[[)@AKKMMGW[[1;;==G))**73		$$(($7//$?Ee$IIw/IIgu-q=&&--h.@Aq[JJh01%%,,X-?@(r4   c                    |s| j                   \  }}dd||f}n|r|\  }}}}| j                  ||      \  }	}
| j                  ||      \  }}| j                  ||      \  }}| j                  ||      \  }}|	|||f}|
|||f}t        |      t        |      }}t        |      t        |      }}||||f}| j	                         }|r|d   |z   |d   |z   |d   |z   |d   |z   f}|S )Nr   r   rZ   r?   )r   r  r  ru  ry  )r   rectrelativer0  r1  lxlyuxuyxllyllxuryurxulyulxlrylrxsysxminyminxmaxymaxrx  s                           r2   _absRectzCanvas._absRects  s   ..CAaa!9D!NBB++Br2GC++B3GC++B3GC++B3GCc3#Bc3#BR#b'$DR#b'$DtT)D72:d1gbjaDGBJ>Dr4   c                 z    | j                  ||      }| j                  t        j                  |||fi |||       y)z&DA is the default appearance string???N)rU  _addAnnotationr   FreeTextAnnotation)r   contentsDARect	addtopager   rB  r  s           r2   freeTextAnnotationzCanvas.freeTextAnnotation  s:    }}T(+F55dHbOBOQUW`ar4   c                 x    | j                  ||      }| j                  t        j                  ||fi |||       y)z!Experimental, but works.
        N)rU  rW  r   TextAnnotation)r   rY  r[  r\  r   rB  r  s          r2   textAnnotationzCanvas.textAnnotation  s8     }}T(+F11$GBGyYr4   )g(\?g{Gz?gffffff?c                     | j                  ||      }|st        j                  |      }| j                  t        j                  ||||fi |||       y)a1  
        Allows adding of a highlighted annotation.

        Rect: Mouseover area to show contents of annotation
        QuadPoints: List of four x/y points [TOP-LEFT, TOP-RIGHT, BOTTOM-LEFT, BOTTOM-RIGHT]
          These points outline the areas to highlight.
          You can have multiple groups of four to allow multiple highlighted areas.
          Is in the format [x1, y1, x2, y2, x3, y3, x4, y4, x1, y1, x2, y2, x3, y3, x4, y4] etc
          QuadPoints defaults to be area inside of passed in Rect
        Color: The color of the highlighting.
        N)rU  r   rect_to_quadrW  HighlightAnnotation)	r   rY  r[  
QuadPointsr   r\  r   rB  r  s	            r2   highlightAnnotationzCanvas.highlightAnnotation  sS     }}T8,,,T2JF66tXzSX_\^_aegpqr4   c                     t         r8   )NotImplementedErrorrU  r1  r0  rW  r   InkAnnotation)r   rY  InkListr[  r\  r   rB  r  s           r2   inkAnnotationzCanvas.inkAnnotation  s    !!r4   c	                 :     | j                   |||||fd|||d|	S )a9  rectangular link annotation positioned wrt the default user space.
           The identified rectangle on the page becomes a "hot link" which
           when clicked will send the viewer to the page and position identified
           by the destination.

           Rect identifies (lowerx, lowery, upperx, uppery) for lower left
           and upperright points of the rectangle.  Translations and other transforms
           are IGNORED (the rectangular position is given with respect
           to the default user space.
           destinationname should be the name of a bookmark (which may be defined later
           but must be defined before the document is generated).

           You may want to use the keyword argument Border='[0 0 0]' to
           suppress the visible rectangle around the during viewing link.r   )rB  r-   r,   r.   )linkRect)
r   rY  destinationnamer[  r\  r   r-   r,   r.   r  s
             r2   linkAbsolutezCanvas.linkAbsolute  s<      t}}Xi MXY#5IMIKM 	Mr4   c
                     | j                  |      }| j                  ||      }||
d<   ||
d<   ||
d<   t        |
|||	       | j                  t	        j
                  di |
||      S )zrectangular link annotation w.r.t the current user transform.
           if the transform is skewed/rotated the absolute rectangle will use the max/min x/y
        r[  Contentsr  r9   )r  rU  r3   rW  r   LinkAnnotation)r   rY  rm  r[  r\  r   rB  r-   r,   r.   r  destinations               r2   rl  zCanvas.linkRect  sq    
 --o>}}T(+6
!:'=2eIi0""6#8#8#>2#>iPPr4   c                 t   ddl m}	m}
m}m}  |	|      } |
d      |d<    |
d      |d<    || j                  ||            |d<    |	       } |
d	      |d<    ||      } |
|      |d
<   |dk(  r||d<   n|dk(  r||d<   d|d<   nt        d|z        ||d<   t        ||||       | j                  |       y)a  Create a rectangular URL 'hotspot' in the given rectangle.

        if relative=1, this is in the current coord system, otherwise
        in absolute page space.
        The remaining options affect the border appearance; the border is
        drawn by Acrobat, not us.  Set thickness to zero to hide it.
        Any border drawn this way is NOT part of the page stream and
        will not show when printed to a Postscript printer or distilled;
        it is safest to draw your own.r   )r   PDFNamer#   	PDFString)r   AnnotTypeLinkSubtyper[  Actionr   URIGoToRFz[ 0 /XYZ null null null ]r+   zUnknown linkURI kind '%s'AN)	r&   r   rt  r#   ru  rU  rJ   r3   rW  )r   urlrA  rB  r-   r,   r.   kindr  r   rt  r#   ru  annr~  uris                   r2   linkURLzCanvas.linkURL  s     	YX $g&F It}}T(;<F OH%&	n#;AeH7]AcF0AcF84?@@C3uYy1C r4   c                     | j                   dz   x}| _         |sdt        |      z   }| j                  j                  ||       |r| j	                  |       y y )Nr   NUMBER)r   reprr   addAnnotation_annotatePage)r   
annotationr   r\  counts        r2   rW  zCanvas._addAnnotation  sT    (,(=(=a(??%(4;.T		j1t$ r4   c                 p    | j                   j                  |      }| j                  j                  |       y r8   )r   refAnnotationr  r*   )r   r   refs      r2   r  zCanvas._annotatePage  s*    ii%%d+##C(r4   c                     | j                   S )z9get the page number for the current page being generated.)r   r   s    r2   getPageNumberzCanvas.getPageNumber  s    r4   c                     t        | j                        r| j                          | j                  j	                  | j
                  |        y)zSaves and close the PDF document in the file.
           If there is current data a ShowPage is executed automatically.
           After this operation the canvas must not be used further.N)rG   r   r  r   
SaveToFiler   r   s    r2   savezCanvas.save  s/     tzz?DMMO		T^^T2r4   c                     t        | j                        r| j                          | j                  j	                  |       }t        |      r|j                  d      }|S )zReturns the PDF data that would normally be written to a file.
        If there is current data a ShowPage is executed automatically.
        After this operation the canvas must not be used further.r   )rG   r   r  r   
GetPDFDatar   rn   r5  s     r2   
getpdfdatazCanvas.getpdfdata  sE     tzz?DMMOII  &Q<!Ar4   c                 2    || _         | j                          y)zPaccepts a 2-tuple in points for paper size for this
        and subsequent pagesN)r   r   r   r  s     r2   r  zCanvas.setPageSize  s     r4   c                     |j                         }|j                  d      r|dd }|dvrt        d|z        t        | d|z  |       y)zMaccepts a 2-tuple in points for name+'Box' size for this and subsequent pagesr  N)r  r  r  r  zunknown box name: %rr  )r   endswithrJ   r  )r   r  r   s      r2   
setCropBoxzCanvas.setCropBox  sM    zz|==Sb	443d:;;X_d+r4   c                 *    | j                  |d       y )Nr  r   r  r  s     r2   
setTrimBoxzCanvas.setTrimBox   s    &)r4   c                 *    | j                  |d       y )Nr  r  r  r  s     r2   	setArtBoxzCanvas.setArtBox#  s    %(r4   c                 *    | j                  |d       y )Nr  r  r  r  s     r2   setBleedBoxzCanvas.setBleedBox&  s    '*r4   c                 0    |dz  dk(  sJ d       || _         y)z7Instruct display device that this page is to be rotatedg     V@r_   z)Rotation must be a multiple of 90 degreesN)r   )r   rots     r2   setPageRotationzCanvas.setPageRotation)  s"    TzS M"MM  r4   c                 |    t        |      }|dk(  r| j                  |      }| j                  j                  |       y)zintroduce the literal text of PDF operations s into the current stream.
           Only use this if you are an expert in the PDF file format.r   N)rH   r7  r   r*   )r   r6  escapeds      r2   
addLiteralzCanvas.addLiteral.  s3     FA:QA

!r4   c                     | j                   \  }}}}}}||z  ||z  z
  }||z  }| |z  }	||z  ||z  z
  |z  }
||z  }| |z  }||z  ||z  z
  |z  }| j                  |||	||
|       y)aX  I want to draw something (eg, string underlines) w.r.t. the default user space.
           Reset the matrix! This should be used usually as follows::
           
              canv.saveState()
              canv.resetTransforms()
              #...draw some stuff in default space coords...
              canv.restoreState() # go back!
        N)r  	transform)r   selfaselfbselfcselfdselfeselffdetresultaresultcresulteresultdresultbresultfs                 r2   resetTransformszCanvas.resetTransforms;  s     6:5H5H2ueUEEkE%K')&*;u,c1)&*;u,c1w'7GLr4   c                    t         r\| j                  \  }}}	}
}}||z  |	|z  z   ||z  |
|z  z   ||z  |	|z  z   ||z  |
|z  z   ||z  |	|z  z   |z   ||z  |
|z  z   |z   f| _        | j                  r| j                  d   dd dk(  r| j                  d   j                         }t	        t        t        |dd             \  }}}	}
}}t        |      dkD  xr t        |      dz   xs d}|t        ||z  |	|z  z   ||z  |
|z  z   ||z  |	|z  z   ||z  |
|z  z   ||z  |	|z  z   |z   ||z  |
|z  z   |z         z  | j                  d<   y| j                  j                  dt        ||||||      z         y)	zoadjoin a mathematical transform to the current graphics state matrix.
           Not recommended for beginners.r`   r  Nz cmi   z %s cmz%s cm)ENABLE_TRACKINGr  r   splitrF   maprd   rG   r)  r   r*   )r   r   br;   r<   er    a0b0c0d0e0f0r  r6  s                  r2   r  zCanvas.transformO  s     $ 3 3Br"R2#%a419Abd#%a419Abd#%a419R<Abd2#?D ::$**R.-u4

2$$&A%)#eAbH*=%>"BBBAq.T!Wh.9'A1RT	"Q$r!t)BqDAIbd2a4iPRSTPTUWXYUYPYZ\P\]_`a]abdefbf]fgi]i!jjDJJrNJJgq1Qq(;;<r4   c                     t         st        d      | j                  \  }}}}}}||z  ||z  z   |z   }	||z  ||z  z   |z   }
|	|
fS )zKreturn the absolute position of x,y in user space w.r.t. default user spacez0tracking not enabled! (canvas.ENABLE_TRACKING=0))r  rJ   r  )r   r\   r  r   r  r;   r<   r  r    xpyps              r2   r  zCanvas.absolutePosition`  s[    OPP++1Qq1qS1Q3Y]qS1Q3Y]Bxr4   c                 0    | j                  dddd||       y)zzmove the origin from the current (0,0) point to the (dx,dy) point
           (with respect to the current graphics state).r   r   Nr  )r   dxdys      r2   r  zCanvas.translatei  s     	q1Qr"%r4   c                 0    | j                  |dd|dd       y)zScale the horizontal dimension by x and the vertical by y
           (with respect to the current graphics state).
           For example canvas.scale(2.0, 0.5) will make everything short and fat.r   Nr  )r   r\   r  s      r2   r  zCanvas.scalen  s     	q1Qq#r4   c                     t        |t        z  dz        }t        |t        z  dz        }| j                  ||| |dd       y)zPCanvas.rotate(theta)

        Rotate the canvas by the angle theta (in degrees).   r   N)r   r	   r   r  )r   thetar;   r6  s       r2   rotatezCanvas.rotatet  sB     
S !
S !q!aRAq)r4   c                     t        |t        z  dz        }t        |t        z  dz        }| j                  d||ddd       y )Nr  r   r   )r   r	   r  )r   alphabetatanAlphatanBetas        r2   skewzCanvas.skew|  s>    urzC'(trzC'(q(GQ15r4   c                 Z    | j                          | j                  j                  d       y)ai  Save the current graphics state to be restored later by restoreState.

        For example:
            canvas.setFont("Helvetica", 20)
            canvas.saveState()
            ...
            canvas.setFont("Courier", 9)
            ...
            canvas.restoreState()
            # if the save/restore pairs match then font is Helvetica 20 again.
        qN)r  r   r*   r   s    r2   r  zCanvas.saveState  s"     	

#r4   c                 Z    | j                   j                  d       | j                          y)zGrestore the graphics state to the matching saved state (see saveState).QN)r   r*   r#  r   s    r2   r  zCanvas.restoreState  s     

#r4   c           	      p    | j                   j                  dt        ||      dt        ||      d       y)zdraw a line segment from (x1,y1) to (x2,y2) (with color, thickness and
        other attributes determined by the current graphics state).n  m z l SNr   r*   r   )r   x1y1x2y2s        r2   linezCanvas.line  s'     	

VB^VB^LMr4   c           	          | j                   j                  d       |D ]<  \  }}}}| j                   j                  t        ||      dt        ||      d       > | j                   j                  d       y)a&  Like line(), permits many lines to be drawn in one call.
           for example for the figure::
           
               |
             -- --
               |

             crosshairs = [(20,0,20,10), (20,30,20,40), (0,20,10,20), (30,20,40,20)]
             canvas.lines(crosshairs)
        r   r  z lr   Nr  )r   linelistr  r  r  r  s         r2   r  zCanvas.lines  sd     	

#% 	NMR2bJJVB^VB^LM	N

#r4   c	                    |dz  }|dz  }|||z
  |||z
  f|||z   |||z   f||z
  |||z
  |f||z   |||z   |fg}	| j                          |r$| j                  |       |r| j                  |       |r| j                  |       | j	                  |	       |r)|| j                  |       | j                  ||z
  ||       | j                          y )Nr  )r  r(  r'  r  r  setFontSizedrawRightStringr  )
r   r\   r  r  gaptextstrokeColorstrokeWidthfontSize
crosshairss
             r2   crosszCanvas.cross  s    s
4!C%(!AcE!AdF);afQquQ=OQRSVQVWXYZ[_Y_`aPbc
,!!+.k*

:#T%5%5h%?  4D1r4   c                    t        |      dkD  sJ d       t        |      dkD  sJ d       g }|d   |d   }}|d   |d   }}|D ]  }|j                  ||||f        |D ]  }	|j                  ||	||	f        | j                  |       y)zPLays out a grid in current line style.  Supply list of
        x an y positions.r   z$x coordinate list must have 2+ itemsz$y coordinate list must have 2+ itemsr   r`   N)rG   r*   r  )
r   xlistylistr  y0r  x0r  r\   r  s
             r2   gridzCanvas.grid  s     5zA~EEE~5zA~EEE~q59Bq59B 	&ALL!Bq%	& 	&ALL"Qr!%	&

5r4   c	                 x    | j                   j                  dt        ||      dt        ||||||      d       y)z/Bezier curve with the four given control pointsr  r  z c SNr  )	r   r  r  r  r  x3y3x4y4s	            r2   bezierzCanvas.bezier  s4    

!"b>6"b"b"b+IK 	r4   c                     t        j                  | j                        j                  ||||||       | j	                  dd       y)zDraw a partial ellipse inscribed within the rectangle x1,y1,x2,y2,
        starting at startAng degrees and covering extent degrees.   Angles
        start with 0 to the right (+x) and increase counter-clockwise.
        These should have x1<x2 and y1<y2.r  r   r   N)r   PDFPathObjectr   arc_strokeAndFill)r   r  r  r  r  startAngextents          r2   r  z
Canvas.arc  s;    
 	  djj155bBr(6RAa r4   c           	          | j                   j                  dt        ||||      z  t        ||| j                  f   z          y)zPdraws a rectangle with lower left corner at (x,y) and width and height as given.zn %s re N)r   r*   r   PATH_OPSr
  )r   r\   r  r  r  strokefills          r2   rA  zCanvas.rect  s@    

*vaE6'BB$VT4>>%ABC 	Dr4   c                     t        j                  | j                        j                  ||||z
  ||z
         | j	                  ||       y)zDraw an ellipse defined by an enclosing rectangle.

        Note that (x1,y1) and (x2,y2) are the corner points of
        the enclosing rectangle.
        r  N)r   r   r   ellipser  )r   r  r  r  r  r  r  s          r2   r
  zCanvas.ellipse  s?     	  djj199"b"R%BOFD)r4   c	                     t        j                  | j                        }	|	j                  d||z   z  d||z   z         |	j	                  ||||||       |	j                          | j                  ||       y)zcLike arc, but connects to the centre of the ellipse.
        Most useful for pie charts and PacMan!r  r  N)r   r   r   moveToarcTocloser  )
r   r  r  r  r  r  r  r  r  ps
             r2   wedgezCanvas.wedge  se     $$$**5	beS"R%[)	2bHV,		F4(r4   c                 X    ||z
  }||z   }||z
  }||z   }	| j                  ||||	||       y)zNdraw a cirle centered at (x_cen,y_cen) with radius r (special case of ellipse)N)r
  )
r   x_ceny_cenrr  r  r  r  r  r  s
             r2   circlezCanvas.circle  s>     QYQYQYQYRRVT2r4   c                     t        j                  | j                        j                  |||||       | j	                  ||       y)z|Draws a rectangle with rounded corners.  The corners are
        approximately quadrants of a circle, with the given radius.r  N)r   r   r   	roundRectr  )r   r\   r  r  r  radiusr  r  s           r2   r  zCanvas.roundRect  s:     	  djj1;;Aq%QWXF4(r4   c                 Z    | j                   j                  |      }|| j                  |<   |S r8   )r   
addShadingr  r   shadingr   s      r2   _addShadingzCanvas._addShading  s+    yy##G,"&$r4   c                 b    | j                  |      }| j                  j                  d|z         y )Nz/%s sh)r  r   r*   r  s      r2   shadezCanvas.shade  s(    (

(T/*r4   c                     ddl m} t        |      \  }	}
t        |
|      } |||||||	t	        |            }| j                  |       y )Nr   )PDFAxialShadingFunction
ColorSpaceExtend)r&   r!  rS   rp   r   r  )r   r  r  r  r  rN   rh   r   r!  
colorSpacencolorsfcnr  s                r2   linearGradientzCanvas.linearGradient!  sL    <.v6
G!'95!"b"b3%.@.HJ

7r4   c                     ddl m} t        |      \  }}	t        |	|      }
 |||d||||
|t	        |      	      }| j                  |       y )Nr   )PDFRadialShadingr_   r"  )r&   r+  rS   rp   r   r  )r   r\   r  r  rN   rh   r   r+  r&  r'  r(  r  s               r2   radialGradientzCanvas.radialGradient*  sP    =.v6
G!'95"1aaFS%.@.HJ

7r4   c                 j   t        |      }| j                  |||      }||j                  |       |r|j                  |       |r|j	                  |       |j                  |       |r|j                  d       |r|j	                  d       ||j                  d       | j                  |       y)z*Draws a string in the current text styles.	directionNr   )r   	beginTextsetTextRenderModesetCharSpacesetWordSpacetextLinedrawText)	r   r\   r  r  mode	charSpacer/  	wordSpacer   s	            r2   
drawStringzCanvas.drawString=  s    NN1a9N5Q006annY/annY/	

4annQ'annQ'Q003ar4   c                 r   t        |t              s|j                  d      }| j                  || j                  | j
                        }|r|t        |      dz
  |z  z  }|r,||j                  d      |j                  d      z   dz
  |z  z  }| j                  ||z
  ||      }	||	j                  |       |r|	j                  |       |r|	j                  |       |	j                  |       |r|	j                  d       |r|	j                  d       ||	j                  d       | j                  |	       y)z2Draws a string right-aligned with the x coordinater   r   r%      r.  Nr   rA   rH   decodestringWidthr  r  rG   r  r0  r1  r2  r3  r4  r5  
r   r\   r  r  r6  r7  r/  r8  r  r   s
             r2   r  zCanvas.drawRightStringK  s
   $$;;w'D  t~~t~~FeD	!Y66ee

4 0G1D DQ F	QQeNN1u9a9N=Q006annY/annY/	

4annQ'annQ'Q003ar4   c                 x   t        |t              s|j                  d      }| j                  || j                  | j
                        }|r|t        |      dz
  |z  z  }|r,||j                  d      |j                  d      z   dz
  |z  z  }| j                  |d|z  z
  ||      }	||	j                  |       |r|	j                  |       |r|	j                  |       |	j                  |       |r|	j                  d       |r|	j                  d       ||	j                  d       | j                  |	       y)	zoDraws a string centred on the x coordinate. 
        
        We're British, dammit, and proud of our spelling!r   r   r%  r;  r  r.  Nr   r<  r?  s
             r2   drawCentredStringzCanvas.drawCentredString\  s    $$;;w'D  t~~t~~FeD	!Y66ee

4 0G1D DQ F	QQeNN1s5y=!yNAQ006annY/annY/	

4annQ'annQ'Q003ar4   c	           	      d   |j                  |d      }	| j                  || j                  | j                        }
t	        |	      dk(  rt
        j                  |      ||d   t        vrq|	d   dd }|	d   d   }|d   t        vr|d   |z   }|dd }|d   t        vr| j                  |d|
z  z
  ||||||       | j                  |d|
z  z
  ||||||       y|	d   }| j                  |d|
z  z
  ||||||       t	        |	      dkD  r'||	d   z   }| j                  |d|
z  z
  ||||||       yy)a  Draws a string aligned on the first '.' (or other pivot character).

        The centre position of the pivot character will be used as x.
        So, you could draw a straight line down through all the decimals in a
        column of numbers, and anything without a decimal should be
        optically aligned with those that have.

        There is one special rule to help with accounting formatting.  Here's
        how normal numbers should be aligned on the 'dot'. Look at the
        LAST two::
        
           12,345,67
              987.15
               42
           -1,234.56
             (456.78)
             (456)
               27 inches
               13cm
        
        Since the last three do not contain a dot, a crude dot-finding
        rule would place them wrong. So we test for the special case
        where no pivot is found, digits are present, but the last character
        is not a digit.  We then work back from the end of the string
        This case is a tad slower but hopefully rare.
        
        r   Nr`   r   r  )r6  r7  r/  r8  )
r  r>  r  r  rG   digitPatsearchr   r  r9  )r   r\   r  r  	pivotCharr6  r7  r/  r8  partspivWleftText	rightTexts                r2   drawAlignedStringzCanvas.drawAlignedStringo  sv   8 

9Q'	4>>4>>Ju:?xt4@T"XU[E[ Qx"~HaI2,f,$RL94	#Ab> 2,f,   3t8Qty'9 ! >OOAc$hJ949'9  >
 QxH  3t8Qty'9 ! >5zA~%a0	#d(
Ayty"+y   B r4   c                 :    | j                   j                         }|S )z{Returns the list of PostScript font names available.

        Standard set now, but may grow in future with font embedding.)r   getAvailableFonts)r   	fontnamess     r2   rL  zCanvas.getAvailableFonts  s     II//1	r4   c                 t    t        t        j                  j                               }|j	                          |S )z-Convenience function to list all loaded fonts)rF   r   widthsr  rf   )r   namess     r2   listLoadedFonts0zCanvas.listLoadedFonts0  s)    Z&&++-.

r4   c           
         || _         || _        ||dz  }|| _        t        j                  | j                         }|j
                  sw|j                  j                  st        | dd      sS| j                  j                  |      }| j                  j                  d|dt        |      dt        |      d       yyy)	zSets the font.  If leading not specified, defaults to 1.2 x
        font size. Raises a readable exception if an illegal font
        is supplied.  Font names are case-sensitive! Keeps track
        of font name and size for metrics.Nr   r&  FzBT r%  z Tf z TL ET)r  r  r  r   r*  r+  r,  r-  r.  r   r/  r   r*   r   )r   
psfontnamer  leadingr3  pdffontnames         r2   setFontzCanvas.setFont  s    
 $?SjG!!$..1  yy  5Fu(M"ii;;JG

!!KPTW]^eWf"gh )N !r4   c                 v    || j                   }|| j                  }| j                  | j                  ||       y)z7Sets font size or leading without knowing the font faceN)r  r  rV  r  )r   r  rT  s      r2   r  zCanvas.setFontSize  s0    <?dmmGT^^T73r4   c                 n    t        j                  ||xs | j                  || j                  f|du          S )z1gets width of a string in the given font and sizeN)r   r>  r  r  )r   r  fontNamer  s       r2   r>  zCanvas.stringWidth  s:    %%dH,F%-dnn$=h$>N$OQ 	Qr4   c                 `    || _         | j                  j                  dt        |      z         y )Nz%s w)r  r   r*   r   )r   r  s     r2   r  zCanvas.setLineWidth  s$    

&6%=01r4   c                 d    |dv sJ d       || _         | j                  j                  d|z         y)z0=butt,1=round,2=squarer   r   rZ   z*Line caps allowed: 0=butt,1=round,2=squarez%d JN)r  r   r*   r   r6  s     r2   
setLineCapzCanvas.setLineCap  s1    wL LL

&4-(r4   c                 d    |dv sJ d       || _         | j                  j                  d|z         y)z0=mitre, 1=round, 2=bevelr\  z-Line Joins allowed: 0=mitre, 1=round, 2=bevelz%d jN)r  r   r*   r]  s     r2   setLineJoinzCanvas.setLineJoin  s1    wO OO

&4-(r4   c                 `    || _         | j                  j                  dt        |      z         y )Nz%s M)_miterLimitr   r*   r   )r   limits     r2   setMiterLimitzCanvas.setMiterLimit  s%     

&6%=01r4   c                    d}t        |t        t        f      r||f}d}nt        |      sd}|D cg c]   }t        |t        t        f      r|dk  s|" }}|st        |t        t        f      r|dk  rd}n|rt	        |      dk  rd}|rt        d|d|d|      | j                  j                  d	t        |      d
|d       yc c}w )z7Two notations.  pass two numbers, or an array and phase r   z1array should be a sequence of numbers or a numberz,array & phase should be non-negative numbersz%dash cycle should be larger than zerozsetDash: array=z phase=r6  [z] z dN)	rA   intrd   r   sumrJ   r   r*   r   )r   arrayphasereasonr   bads         r2   setDashzCanvas.setDash  s    eSK(ENEEuHFJQz!SK'@AEqJJjE{3uQwCFs5z1}<FvVWW

>? Ks    CCc                 *    t        j                         S )zReturns a fresh path object.  Paths are used to draw
        complex figures.  The object returned follows the protocol
        for a pathobject.PDFPathObject instance)r   r   r   s    r2   	beginPathzCanvas.beginPath  s     ''))r4   c                     |t        |d| j                        }| j                  j                  t	        |j                                      | j                  |||       y)z*Draw the path object in the mode indicatedNr
  )r.  r
  r   r*   rH   getCoder  )r   aPathr  r  fillModes        r2   drawPathzCanvas.drawPath  sI    u[@H

#emmo./F41r4   c                 j    | j                   j                  t        ||||n| j                  f          y r8   )r   r*   r  r
  )r   r  r  rt  s       r2   r  zCanvas._strokeAndFill  s.    

(64X=QW[WeWe#efgr4   c                     |t        |d| j                        }|j                         }t        |||f   }|t        k(  xr dxs d}|||}| j
                  j                  |       y)zclip as well as drawingNr
  z W* z W )r.  r
  rr  r  r	  r   r*   )	r   rs  r  r  rt  gcpathopsclipitems	            r2   clipPathzCanvas.clipPath  sg    u[@H]]_x1G(HgM)4f=tW-

$r4   c                      t        | |||      S )zoReturns a fresh text object.  Text objects are used
           to add large amounts of text.  See PDFTextObjectr.  )r   )r   r\   r  r/  s       r2   r0  zCanvas.beginText  s     T1a9==r4   c                 h    | j                   j                  t        |j                                      y)zDraws a text objectN)r   r*   rH   rr  )r   aTextObjects     r2   r5  zCanvas.drawText  s"    

#k11345r4   c                     |t         j                  }|| _        | j                  j	                  | j                         y)a>  Possible values None, 1 or 0
        If None the value from rl_config will be used.
        If on, the page data will be compressed, leading to much
        smaller files, but takes a little longer to create the files.
        This applies to all subsequent pages, or until setPageCompression()
        is next called.N)r
   r   r  r   r  )r   r   s     r2   r   zCanvas.setPageCompression  s4     "i6O6OO /		  !6!67r4   c                     || _         y)a  Allows hands-off animation of presentations :-)

        If this is set to a number, in full screen mode, Acrobat Reader
        will advance to the next page after this many seconds. The
        duration of the transition itself (fade/flicker etc.) is controlled
        by the 'duration' argument to setPageTransition; this controls
        the time spent looking at the page.  This is effective for all
        subsequent pages.N)r   )r   durations     r2   setPageDurationzCanvas.setPageDuration(  s     &r4   c                    i | _         |sy|dv rdd|z  f}nt        j                  d      |dv rdd|z   f}nt        j                  d	      |d
v rdd|z   f}nt        j                  d      ||g|g|g|gg |gd}		 |	|   }
i }d|d<   d|z  |d<   d|z   |d<   |
D ]
  \  }}|||<    || _         y# t        $ r t        j                  d|z        w xY w)as  PDF allows page transition effects for use when giving
        presentations.  There are six possible effects.  You can
        just guive the effect name, or supply more advanced options
        to refine the way it works.  There are three types of extra
        argument permitted, and here are the allowed values::
        
            direction_arg = [0,90,180,270]
            dimension_arg = ['H', 'V']
            motion_arg = ['I','O'] (start at inside or outside)
        
        This table says which ones take which arguments::

            PageTransitionEffects = {
                'Split': [direction_arg, motion_arg],
                'Blinds': [dimension_arg],
                'Box': [motion_arg],
                'Wipe' : [direction_arg],
                'Dissolve' : [],
                'Glitter':[direction_arg]
                }
        
        Have fun!
        N)r   Z   r  i  Diz/%dz$ directions allowed are 0,90,180,270)HVDmr   z$dimension values allowed are H and V)IOMz!motion values allowed are I and O)SplitBlindsr  WipeDissolveGlitterzUnknown Effect Name "%s"z/Transrw  z%dr+   r   )r   r   PDFErrorKeyError)r   
effectnamer  r/  	dimensionmotiondirection_argdimension_arg
motion_argPageTransitionEffectsargs	transDictr^   values                 r2   r  zCanvas.setPageTransition4  s8   <  " &!59#45M//"HII
"!3?3M//"HIIYsV|,J//"EFF $Z0$o<#_$o!	K(4D
 	$	&	#z)	#  	#LS%"IcN	#(  	K//"<z"IJJ	Ks   >B1 1"Cc                 8    dj                  | j                        S )zReturn uncompressed contents of current page buffer.

        This is useful in creating test cases and assertions of what
        got drawn, without necessarily saving pages to diskr6  )r)  r   r   s    r2   getCurrentPageContentzCanvas.getCurrentPageContent~  s    
 yy$$r4   c                     | j                   j                  }t        |dd      }|ddlm}  |       x}|_        |||<   y)zCset one of the allowed enbtries in the documents viewer preferencesViewerPreferencesNr   )ViewerPreferencesPDFDictionary)r   Catalogr.  r&   r  r  )r   prefr  catalogVPr  s         r2   setViewerPreferencezCanvas.setViewerPreference  sA    ))##W06:O-K-MMB*4r4   c                 H    | j                   j                  j                  |   S ).you'll get an error here if none have been setr   r  r  r   r  s     r2   getViewerPreferencezCanvas.getViewerPreference  s    yy  22488r4   c                 F    | j                   j                  j                  |= y)r  Nr  r  s     r2   delViewerPreferencezCanvas.delViewerPreference  s    II//5r4   c                     ddl m}m}m} t	        |      r	 ||      }n7t        |t        t        f      r	 ||      }nt        |t              r ||      }t        | j                  j                  ||       y )Nr   )r   r#   ru  )r&   r   r#   ru  r   rA   rF   rC   r   r  r   r  )r   r^   r  r   r#   ru  s         r2   setCatalogEntryzCanvas.setCatalogEntry  sZ    OO<e$EtEl+UOEd#!%(E		!!#e,r4   c                 B    t        | j                  j                  |      S r8   )r.  r   r  r   r^   s     r2   getCatalogEntryzCanvas.getCatalogEntry  s    tyy((--r4   c                 D    t        | j                  j                  |       y)z-you'll get an error here if it's not been setN)delattrr   r  r  s     r2   delCatalogEntryzCanvas.delCatalogEntry  s    		!!#&r4   c                     | j                   j                  }t        |dd      }|ddlm}  |       x}|_        ddlm} |j                  | ||||             y)zadd a PDFPageLabel for pageNum
PageLabelsNr   )PDFPageLabels)PDFPageLabel)r   r  r.  r&   r  r  r  addPageLabel)	r   pageNumstylestartprefixr  PLr  r  s	            r2   r  zCanvas.addPageLabel  sP    ))##W\$/:>&3o5B#9
U5 @Ar4   c                     	 | j                   S # t        $ r= ddlm }  ||       x| j                  j                  _         | _         | j                   cY S w xY w)z/get form from canvas, create the form if neededr   )AcroForm)r  r   reportlab.pdfbase.acroformr   rY  )r   r  s     r2   acroFormzCanvas.acroForm  sJ    	!==  	!;:B4.HDII'$-== 	!s    AAAc                 X     t         d      sddlm  fd _         j                  S )N_drawBoundaryr   )Framec                 0    j                  | ||||      S r8   )r  )sbr\   r  r0  r1  r  r   s        r2   r]   z%Canvas.drawBoundary.<locals>.<lambda>  s     E4G4GRPQRSTUVW4X r4   )hasattrreportlab.platypusr  r  )r   r  s   `@r2   r  zCanvas.drawBoundary  s$    tO,0!XD!!!r4   )Nr   NNr   NNNNNNNNNNNN)r   N)r  NNNNN)r   r  )NNFr;   FFN)NNNFr;   FFN)r   r   NN)r   )r   )Nr   Nr   )NNr   Nr   )Nr   Nr   NN)Nr   Nr   r   NN)r   r   NNr{  r  )r  )   r   NNNr?   )r   r  )r   r   )NT)Nr   NNr8   )NN)r   r   N)r   r   N)Nr   r   r  r  )NNN)r   r   r   __doc__r   r   r   r  r#  r  r  rF   rc   rG   STATE_RANGEr   r7  r9  r<  rA  rG  rI  rK  rN  rQ  rT  rW  rZ  r]  rc  rf  ri  rl  rn  rp  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r   r#  r  r+  r3  r?  rU  r]  r`  textAnnotation0re  rj  inkAnnotation0rn  rl  r  rW  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rA  r
  r  r  r  r  r  r)  r,  r9  r  rA  r
   decimalSymbolrJ  rL  rQ  rV  r  r>  r  r^  r`  rd  rn  rp  ru  r  r|  r0  r5  r   r  r  r  r  r  r  r  r  r  r  propertyr  r  r9   r4   r2   r   r      s   /d !%! #'!%!% $#^!@.&>55# $)57  uS!1234K.*$24Ll8&"
&
&(($),	)	)))5)Sj++."  ! KZ	KC	&' =AQV/2 DHRW|-|#
3$2%)N(b
Z
 %O=AI[gh!%r$b #NSW/3M& _`/3Q"!H%) 3,*)+!
M(="&
$*62N
 "
!D
*)3)
+&"& 7@6M6MTXdequ  BF 6Bpi 4Q2))2 a @&*2h >
6	8
& ;<9<H)T%96-.'	B ! ! " "r4   __main__zFor test scripts, look in tests)r   r   )7__version__r  __all__r  rer7  stringr   mathr   r   r   r	   	reportlabr
   reportlab.pdfbaser   r   reportlab.pdfgenr   reportlab.pdfgen.textobjectr   r   reportlab.lib.colorsr   r   r   r   r   reportlab.lib.utilsr   r   r   r   r   r   reportlab.lib.rl_accelr   r   reportlab.lib.boxstuffr   compilerC  r	  FILL_NON_ZEROr  r3   rI   rS   rp   rr   r   r   r   printr9   r4   r2   <module>r     s%   	
 * 	   " "  $ ( ( F [ [ Z Z 4 12::e  =!C=!C=!C=!C=!D=!C=!D=!C'&2 	#OJG GR8m"_ m"^7 z	
+, r4   