
    Q?hhD                       S r SrSS/rSrSSKrSSKrSSKJr  SSKJ	r	J
r
JrJr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  SSKJr  SSKJrJrJr  SSKJrJrJrJrJ r   SSK!J"r"J#r#J$r$J%r%J&r&J'r'  SSK(J)r)  SSK*J+r+J,r,  SSK-J.r.  \R^                  " S5      r0Sr1Sr2SS\14SSS\24SSS\14SSS\24SSS\14SSS\24SSS\14SSS\24S0r3S&S jr4S r5S r6S r7 " S S 5      r8S! r9 " S" S5      r: " S# S\5      r;\<S$:X  a	  \=" S%5        gg)'z3.3.0zz
The Canvas object is the primary interface for creating PDF files. See
doc/reportlab-userguide.pdf for copious examples.
CanvasShowBoundaryValue       N)digits)sincostanpi)	rl_config)pdfdoc)
pdfmetrics)	ShapedStrshapeFragWord)
pathobject)PDFTextObject_PDFColorSetterbidiShapedText)black_chooseEnforceColorSpaceColor	CMYKColortoColor)ImageReaderisSeqisStr	isUnicode	_digester	asUnicode)ABag)fp_str	escapePDF)aspectRatioFixz\dnSzf*fzB*Bc                     SSK Jn  U(       a2  SU ;  a,  U" UR                  UR                  UR                  /5      U S'   SU ;  a7  XEU=(       d    S/nU(       a  UR                  U" U5      5        U" U5      U S'   g g )Nr   )PDFArrayCBorder)reportlab.pdfbase.pdfdocr(   redgreenblueappend)Dcolor	thickness	dashArrayhradiusvradiusr(   borders           I/var/www/html/env/lib/python3.13/site-packages/reportlab/pdfgen/canvas.py
_annFormatr8   6   sl    1A599ekk5::>?#q).q1MM(9-.v&(	     c                   ^ [        U [        5      (       a1  U R                  mS[        U4S jU R	                  5        5       5      4$ [        U [
        5      (       a  SU R                  5       4$ [        U [        [        45      (       a   [        U 5      nUS:X  a  SU 4$ US:X  a  SU 4$ O)[        U [        5      (       a  [        [        U 5      5      $ [        SU -  5      e)N
DeviceCMYKc              3   ,   >#    U  H	  oT-  v   M     g 7fN ).0cds     r7   	<genexpr>"_normalizeColor.<locals>.<genexpr>L   s     ">1Q3s   	DeviceRGB      zUnknown color %r)
isinstancer   densitytuplecmykr   rgblistlenstr_normalizeColorr   
ValueError)aColorlrA   s     @r7   rO   rO   I   s    &)$$NNU">">>>>	FE	"	"FJJL((	FUDM	*	*K6&&!V'' 	FC	 	 wv//
'&0
11r9   c                     S n/ nU  H>  n[        U5      u  pEUb  X:w  a  [        SU< SU< 35      eUnUR                  U5        M@     X4$ )NzMismatch in color spaces: z and )rO   rP   r/   )colorsspace	outcolorsrQ   nspaceoutcolors         r7   _normalizeColorsrY   Y   s[    EI*62eVTUU"  r9   c           	      \   SSK JnJn  Ub#  [        U5      [        U 5      :w  a  [	        S5      e[        U 5      S:X  a  U" SU S   U S   S9$ [        U 5      S:X  a#  Ub  US   S:X  a  US   S:X  a  U" SU S   U S   S9$ Uc6  [        U 5      n[        U5       Vs/ s H  n[        U5      US-
  -  PM     nnO[        [        X5      5      nUR                  S S9  US   S   S:w  a  UR                  SS	US   S   45        US
   S   S:w  a  UR                  SUS
   S   45        [        [        U6 5      u  p/ nUSS
  Vs/ s H  oPM     n	n/ n
U S   nU SS   H=  nUR                  U" SXS95        UnU
R                  S	5        U
R                  S5        M?     U" XyU
SS9$ s  snf s  snf )Nr   )PDFExponentialFunctionPDFStitchingFunctionz4need to have the same number of colors and positionsr   )NC0C1   c                     U S   $ Nr   r>   )xs    r7   <lambda>%_buildColorFunction.<locals>.<lambda>v   s    QqTr9   )key              ?z	[0.0 1.0])Domain)r+   r[   r\   rM   rP   rangefloatrL   zipsortinsertr/   )rT   	positionsr[   r\   ncrc   	poscolors	functionsposboundsencode	lastcolorr1   s                r7   _buildColorFunctionrx   d   s   UY3v;!>OPP
6{a%fQiF1IFF
6{a1!2y|q7H)A&)q	JJ[.3Bi8iU1Xr!t_i	8	 Y/0	>*Q<?aQil1o 67R=q c9R=#345 i1	I&q_-_cc_F-Fq	I/!	LM	cc	 
  	6+NN+ 9 .s   F$F)c            	           \ rS rSr\" SSSSSSS9r\" 1 SkS9rS	1r\S
 5       r	\S 5       r
\S 5       rS rS rS rS rS rSrg)	ExtGState   r   Fr   Normal)CAcaOPopOPMBM>   Huer   Darkenr|   ScreenLightenOverlayMultiply	ColorBurn	Exclusion	HardLight	SoftLight
ColorDodge
Difference
Luminosity
Saturation)r   r   c                 4    [        U 5      R                  5       $ r=   )rN   lowervs    r7   _boolTransformExtGState._boolTransform   s    1v||~r9   c                     U $ r=   r>   r   s    r7   _identityTransformExtGState._identityTransform   s    r9   c                     SU -   $ )N/r>   r   s    r7   _pdfNameTransformExtGState._pdfNameTransform   s    1ur9   c                      0 U l         0 U l        g r=   )_d_cselfs    r7   __init__ExtGState.__init__   s    r9   c           	         U R                   U   n[        U[        5      (       a  [        U5      nU R                  nO^X R                  ;   aC  X0R
                  U   ;  a$  [        SU< SU< SU R
                  U   < 35      eU R                  nOU R                  nX0R                  R                  X$5      :w  d  US:X  a  U R                  S5      U:w  a  X0R                  U'   X%" U5      4nX`R                  ;   a  U R                  U   nO/S[        [        U R                  5      5      -   nXpR                  U'   UR                  R!                  SU-  5        g g g )Nz
ExtGstate[z] = z not in allowed values r   r   gRLsz/%s gs)defaultsrG   boolr   pdfNameValuesallowedrP   r   r   r   getgetValuer   rN   rM   _coder/   )r   canvar   rA   
vTransformtnames           r7   setExtGState.set   s   MM!a1gA,,J$$$Q' aQ") * *//J00Jggkk!1d7t}}T/BA/EGGAJ*Q-AGG|wwqzc#dgg,//!
JJho. 0F7r9   c                 R    U R                   R                  XR                  U   5      $ r=   )r   r   r   )r   r   s     r7   r   ExtGState.getValue   s    ww{{1]]1-..r9   c                     0 nU R                   R                  5        H'  u  p#[        R                  " [	        U45      5      X'   M)     U=(       a    [        R                  " U5      =(       d    S $ r=   )r   itemsr   PDFDictionarydict)r   r$   r   r   s       r7   getStateExtGState.getState   sP    ggmmoFA**4:6AG &,V))!,44r9   c                     U R                  5       nU R                  R                  5       Ul        U R                  Ul        U$ )z=the states must be shared across push/pop, but the values not)	__class__r   copyr   )r   rc   s     r7   pushCopyExtGState.pushCopy   s/    NNww||~wwr9   )r   r   N)__name__
__module____qualname____firstlineno__r   r   r   r   staticmethodr   r   r   r   r   r   r   r   __static_attributes__r>   r9   r7   rz   rz      s    H G FM     /,/5r9   rz   c                     [        U [        [        45      (       a;  [        U 5      S:w  a  [	        SU -  5      eSU  Vs/ s H  o(       a  SOSPM     sn-  $ U (       a  S$ S$ s  snf )Nr`   z wrong length for extend argumentz[%s %s]truefalsez[true true]z[false false])rG   rL   rI   rM   rP   )extend_s     r7   _gradientExtendStrr      sc    &$u&&v;>?&HIIfEfaFW4fEEE"=77 Fs   A"c                   $    \ rS rSrSS jrS rSrg)r      Nc                 (    Xl         X l        X0l        g r=   )r1   widthr3   )r   r1   r   r3   s       r7   r   ShowBoundaryValue.__init__   s    

"r9   c                 J    U R                   S L=(       a    U R                  S:  $ rb   )r1   r   r   s    r7   __bool__ShowBoundaryValue.__bool__   s    zz%7$**a-7r9   )r1   r3   r   )r   r   r   g?N)r   r   r   r   r   r   r   r>   r9   r7   r   r      s    #
8r9   c                      \ rS rSrSr                 SS jrS rS rS	 rS
 r	SR                  5       r\" \" \" \5      5      5      rS rS rS rS rSS jrS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S  r$S! r%S" r&S# r'S$ r(S% r)S& r*S' r+S( r,      SS) jr-SS* jr.S+ r/S, r0S- r1   SS/ jr2   SS0 jr3S1 r4S2 r5S3 r6SS4 jr7S5 r8SS6 jr9SS7 jr:SS8 jr;SS9 jr<\<r=S/ S:QSSS4S; jr>SS< jr?\?r@  SS= jrA  SS> jrBSS? jrCSS@ jrDSA rESB rFSC rGSD rHSE rISSF jrJSG rKSH rLSI rMSJ rNSSK jrOSL rPSM rQSN rRSO rSSP rTSQ rUSR rVSS rWST rXSU rYSV rZSSW jr[SX r\SY r]SSZ jr^SS[ jr_SS\ jr`SS] jraSS^ jrbSS_ jrcS` rdSa reSSb jrfSSc jrgSSd jrhSSe jriSSf jrj\kR                  SSSSS.4Sg jrmSh rnSi roSSj jrpSSk jrqSSl jrrSm rsSn rtSo ruSp rv/ S4Sq jrwSr rxSSs jrySSt jrzSSu jr{SSv jr|Sw r}SSx jr~SSy jr  SSz jrS{ rS| rS} rS~ rS rS rS rSS jr\S 5       rS rSrg)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                 P   Uc  [         R                  nUc  [         R                  nU(       a  UO[         R                  U l        Ub  UOSU l        Ub  UOU R
                  S-  U l        Xl        [        R                  " UXQU	=(       d    [        R                  US9U l        [        U
5      U l        X`l        SU l        Xl        X l        SU l        SU l        SU l        SU l        0 U l        U R/                  U5        SU l        / U l        U R5                  5         SU l        / U l        / U l        / U l        X0l        [         R@                  U l!        Xl"        Xl#        UU l$        UU l%        U RM                  5         U RO                  5         / U l(        U RS                  U5        g)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   kwdss                       r7   r   Canvas.__init__  s   F 	(A(AX)*=*=i3B	HeHe3B3NTV1?1K~QUQfQfgjQj!&&?1:2<2Z@Z@Z,0)	 #;;L"M $ #!!%#!0!!# !%'"$&! !%99!  " r9   c                 r   U(       a  SSK Jn  [        U5      (       aD  [        U5      (       a  UR	                  S5      nUR                  U5      nUR                  S5        O([        XR
                  5      (       d  [        SU-  5      eXR                  l
        g U R                  ?
g! [         a     gf = f)a@  
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   rv   StandardEncryptionsetAllPermissionsrG   	TypeErrorr   r
  AttributeError)r   r
  r  s      r7   r  Canvas.setEncryptu  s     0W~~W%%%nnW5G$77@))!,)F)FGG  !M  PW  !W  X  X 'IIII%! s   B) )
B65B6c                    SU l         SU l        U R                  U l        U R                  U l        SU l        U R                  U l        SU l	        [        U l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        S U l        SU l        SU l        [0        R2                  =(       d    S=U l        U l        [9        5       U l        g )Nr   )ri   rg   rg   ri   rg   rg   d   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_strokeColorObjrz   
_extgstater   s    r7   r  Canvas.init_graphics_state  s    ....,,6&  
73 4=4N4N4YRYYT1#+r9   c                     0 nU R                   nU R                   H	  nX#   X'   M     U R                  R                  U5        U R                  R                  5       U l        g r=   )__dict__STATE_ATTRIBUTESr  r/   r9  r   )r   staterA   r   s       r7   push_state_stackCanvas.push_state_stack  sQ    MM))D'EK *&//224r9   c                 j    U R                   R                  U R                  R                  5       5        g r=   )r<  updater  popr   s    r7   pop_state_stackCanvas.pop_state_stack  s#    T--1134r9   a  _x _y _fontname _fontsize _textMode _leading _currentMatrix _fillMode
     _charSpace _wordSpace _horizScale _textRenderMode _rise _textLineMatrix
     _textMatrix _lineCap _lineJoin _lineDash _lineWidth _mitreLimit _fillColorObj
     _strokeColorObj _extgstatec                    / R                   nU R                  (       a	  U" S5        O!U" S[        U R                  S   5      -  5        U R                  n[        U5      nU R                  S:w  a  U R                  U R                  5        U R                  S:w  a  U R                  U R                  5        U" SR                  X#S  5      5        X#S 2	 [        R                  " U R                  5      nUR                  (       d[  UR                  R                   (       d  [#        U SS5      (       d.  U" SU R$                  R'                  U R                  5      -  5        SR                  UR(                  5      U l        g )	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   rM   r7  setFillColorr8  setStrokeColorjoinr   getFontr#  _dynamicFontfacebuiltIngetattrr   getInternalFontName__self__	_preamble)r   Pr)   r#   fonts        r7   r  Canvas._make_preamble  s   II== 6$..*;#<<=JJF(d0017* 4 45	#((1R5/bE!!$..1  yy  5Fu(M(M*TYY-J-J4>>-ZZ[!**-r9   c                     [        U5      $ r=   )r!   r   ss     r7   _escapeCanvas._escape  s    |r9   c                 :    U R                   R                  U5        g)zidentify 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     r7   r]  Canvas.setAuthor  s    
 			F#r9   c                 :    U R                   R                  U5        g)zHaccepts a func(yyyy,mm,dd,hh,m,s) used to create embedded formatted dateN)r   setDateFormatter)r   dateFormatters     r7   ra  Canvas.setDateFormatter  s    		""=1r9   c                 L    U R                   R                  R                  X#XS9  g)a2  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   titlerf   levelre  s        r7   rg  Canvas.addOutlineEntry  s"    h 			))#e)Kr9   c                 R    U R                   R                  R                  " U 4U-   6   g)a  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   rf  setNames)r   nametrees     r7   setOutlineNames0Canvas.setOutlineNames0  s#    " 			""dWX%57r9   c                 :    U R                   R                  U5        g)zXwrite a title into the PDF file that won't automatically display
in the document itself.N)r   setTitle)r   rh  s     r7   rq  Canvas.setTitle+  s     			5!r9   c                 :    U R                   R                  U5        g)zZwrite a subject into the PDF file that won't automatically display
in the document itself.N)r   
setSubject)r   subjects     r7   rt  Canvas.setSubject0  s     			W%r9   c                 :    U R                   R                  U5        g)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     r7   rx  Canvas.setCreator5  s     			W%r9   c                 :    U R                   R                  U5        g)z!change the default producer valueN)r   setProducer)r   producers     r7   r|  Canvas.setProducer;  s    		h'r9   c                     [        U[        [        45      (       a  SR                  U5      nU R                  R                  U5        g)z|write a list of keywords into the PDF file which shows in document properties.
Either submit a single string or a list/tuplez, N)rG   rL   rI   rK  r   setKeywords)r   keywordss     r7   r  Canvas.setKeywords?  s5     hU|,,yy*H		h'r9   c                 2    [        U R                  5      S:H  $ )zHInfo function - app can call it after showPage to see if it needs a saver   )rM   r   r   s    r7   pageHasDataCanvas.pageHasDataF  s    4::!##r9   c                 L    U R                   R                  R                  5         g)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    r7   r  Canvas.showOutlineJ  s     			&&(r9   c                 L    U R                   R                  R                  5         g)zSpecify that Acrobat Reader should start in full screen mode.
showFullScreen() and showOutline() conflict; the one called last
wins.N)r   r  showFullScreenr   s    r7   showFullScreen0Canvas.showFullScreen0P  s     			))+r9   c                 t    U R                   R                  S5        U R                  R                  U SU5        g)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).
transparencyr}   Nr   ensureMinPdfVersionr9  r   r   r   s     r7   _setStrokeAlphaCanvas._setStrokeAlphaV  ,     			%%n5Da(r9   c                 t    U R                   R                  S5        U R                  R                  U SU5        g)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  r~   Nr  r  s     r7   _setFillAlphaCanvas._setFillAlphaa  r  r9   c                 >    U R                   R                  U SU5        g )Nr   r9  r   r  s     r7   _setStrokeOverprintCanvas._setStrokeOverprintl      Da(r9   c                 >    U R                   R                  U SU5        g )Nr   r  r  s     r7   _setFillOverprintCanvas._setFillOverprinto  r  r9   c                 b    U R                   R                  U SU=(       a    S=(       d    S5        g )Nr   r   r   r  r  s     r7   _setOverprintMaskCanvas._setOverprintMaskr  s     DqwQ|!4r9   c                 >    U R                   R                  U SU5        g )Nr   r  r  s     r7   setBlendModeCanvas.setBlendModeu  r  r9   c                     U R                   nU(       a;  [        S[        USS5      5      n[        S[        USS5      5      nU(       a  X2-  nU$ g )Nr   
bleedWidthborderWidth$   )r   maxrP  )r   cMbleedWbws       r7   _getCmShiftCanvas._getCmShiftx  sL    __72l156FQwr-34BI r9   c                 8   U R                   S   nU R                   S   nU R                  nU R                  nU(       Ga  [        S[	        USS5      5      nU(       Ga  [	        USS5      n[        U[        S[	        USS5      5      5      n[	        USS	5      n[	        US
[        5      n	SU-  U-
  n
[        U5      nU(       a  U	(       a  U R                  5         U R                  U	5        U R                  U5        U R                  USXW4X-   SX-   U4XRU
-   XRSU-  -   4X-   X*-   X-   USU-  -   4SXWU4X-   XQSU-  -   U4SX%-   XrU-   4X-   X%-   USU-  -   X%-   4/5        U R                  5         U(       a  XKS nXKS2	 [        U5      n[        S[	        USS5      5      nU R                  5         U R                  X]-
  X]-
  5        U(       a$  U R                  SSU-  U-  -   SSU-  U-  -   5        XKS nXKS2	 XSS& U R                  5         U(       a  UR                  W5        SU-  U-   nSU-  U-   nUR!                  S5        ["        R$                  " 5       nXl        X/l        U R*                  Ul        U R.                  Ul        UR3                  U R4                  5        UR7                  U R8                  5        S HN  n[	        U SU-  S5      nU(       d  M  [;        UUR=                  5       S-   ["        R>                  " U5      5        MP     U R@                  b  U R@                  Ul!        U RD                  U RF                  /-   U-   U RH                  -   nURK                  U5        U RM                  U5        U RO                  U5        U RQ                  U5        U RS                  U5        U RU                  U5        U RV                  RY                  U5        U RZ                  (       a  U R[                  U R\                  5        U R_                  5         g)z8Close the current page and possibly start on a new page.r   r   r  r  markLast
markLength   	markWidth      ?	markColorr`   Nr  g       @rG  )cropartbleedtrim_%sBoxBox)0r   r   r   r  rP  minr   rM   	saveStaterJ  setLineWidthlinesrestoreState	translatescaler   r/   r   PDFPage	pagewidth
pageheightr   Rotate_currentPageHasImages	hasImagessetPageTransitionr   setCompression_pageCompressionsetattr
capitalizer(   r   Durr   rS  r   	setStream_setColorSpace_setExtGState_setXObjects_setShadingUsed_setAnnotationsr   addPager   r   
_startPage)r   	pageWidth
pageHeightr  coder  r  mlmwmcmgcx0Lr  r)   pageboxsizestrms                      r7   showPageCanvas.showPage  s    NN1%	^^A&
__zzQwr-34B"2j3C'"\""=>?RC0RE2rT"W$i"NN$''+%%b)JJAb"a	R8rM""_="jmILAbDQ2"b1R4;:=rM:"jmIadN:=Q	  	 %%' !J J!$iQwr,q9: ry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0C4T2DtS^^-e3FOOD4IJ 1 )))DH**dnn-==DtG`G``tD!4 $T"T"		$<<d&6&67r9   c                     U R                   (       a"  U R                  U R                   5        S U l         U =R                  S-  sl        U R                  5         U R	                  5         / U l        g Nr   )r   setPageSizer   r   r  r  r   s    r7   r  Canvas._startPage  sX    !!T334%)D"A!!#  "r9   c                     Xl         g)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     r7   setPageCallBackCanvas.setPageCallBack  s	    
 r9   c                 &    U R                   Ul        g r=   )_annotationrefsAnnotsr   r  s     r7   r  Canvas._setAnnotations  s    **r9   c                 &    U R                   Ul         g r=   )_colorsUsedr   objs     r7   r  Canvas._setColorSpace  s    **r9   c                 &    U R                   Ul         g r=   )_shadingUsedr  s     r7   r  Canvas._setShadingUsed  s     --r9   c                 |    U R                   nU(       a"  U R                  R                  U5      nX1l        gSUl        g)zKfor pages and forms, define the XObject dictionary for resources, if neededN)_formsinuser   xobjDictXObjects)r   thingformsxobjectsdicts       r7   r  Canvas._setXObjects  s0      99--e4L)N!ENr9   c                 h    U R                   n X!   $ !   [        R                  " U5      =o2U'    U$ = f)zDget a reference to a (possibly undefined, possibly unbound) bookmark)r   r   Destination)r   r   rA   results       r7   _bookmarkReferenceCanvas._bookmarkReference  s<    	87N	8%11$77FtWs    1c                    U R                  U5      nU R                  R                  5         U R                  R                  5       n	Uc  SnUc  SnUc  SnUc  SnUc  SnUS:X  a  UR	                  X4U5        OUS:X  a  UR                  5         OUS:X  a  UR                  U5        OUS:X  a  UR                  U5        OwUS:X  a  UR                  X5Xd5        O^US:X  a  UR                  5         OGUS:X  a  UR                  U5        O/US	:X  a  UR                  U5        O[        S
[        U5      -  5      eUR                  U	5        U$ )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fitbvrP   asciisetPage)
r   rf   r  lefttopbottomrightzoomdestpagerefs
             r7   bookmarkPageCanvas.bookmarkPage  s$   L &&s+		))'') <D;C>F=E<D%<HHTd#E\HHJF]IIcNF]IIdOF]IId%,F]IIKG^JJsOG^JJt2U3Z?@@Wr9   c                 $    U R                  XX#SS9$ )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   rf   r!  r   r  kws         r7   bookmarkHorizontalAbsolute!Canvas.bookmarkHorizontalAbsoluteO  s       3 JJr9   c                 T    U R                  X#5      u  pVU R                  " X4SU0UD6  g)z<w.r.t. the current transformation, bookmark this horizontal.r   N)absolutePositionr+  )r   rf   	relativeX	relativeYr*  r   r!  s          r7   bookmarkHorizontalCanvas.bookmarkHorizontalZ  s,    ++I@''BtBrBr9   c                     U R                   R                  SU R                  R                  U5      -  5        U R                  R                  U5        g)a!  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     r7   doFormCanvas.doFormg  s>     	

(TYY%=%=d%CCD%r9   c                 8    U R                   R                  U5      $ )z*Query whether form XObj really exists yet.)r   hasFormr6  s     r7   r:  Canvas.hasFormr  s    yy  &&r9   Fc           	          SU l         SSKJn  U" XX4U5      nUR                  U UXxU	U
S9  UR                  UR
                  4$ )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=  drawInlineImager   height)r   imagerc   yr   rE  r>  r?  r@  rA  rB  r=  img_objs                r7   rD  Canvas.drawInlineImage{  sR      &'"75Af5 3\# 	  	% w~~..r9   c                 X   SU l         [        U[        5      (       at  UR                  5       nUR                  nUS:X  a  U(       a  UR                  5       nO[        U5      n[        U5      (       a  UR                  S5      n[        X-   5      nO4U< U< 3n[        U5      (       a  UR                  S5      n[        U5      nU R                  R                  U5      nU R                  R                  R                  US5      nU(       Gd  [        R                  " XUS9nUUl        U R!                  U5        U R                  R#                  UU5        U R                  R%                  UU5        ['        USS5      nU(       a  U R                  R                  UR                  5      nU R                  R                  R                  US5      nU(       d3  U R!                  U5        U R                  R#                  UU5      Ul        O[        R*                  " U5      Ul        U?[/        XxX#XEUR0                  UR2                  U	5	      u  p#pEnU R5                  5         U R7                  X#5        U R9                  XE5        U R:                  R=                  SU-  5        U R?                  5         U
(       a  U RA                  XX4U5        U RB                  R=                  U5        U(       a'  URE                  5        H  n[G        5       U   UU'   M     UR0                  UR2                  4$ )	a	  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_smaskr4  )$r  rG   r   
getRGBData_dataArN   r   rv   r   r   r5  
idToObjectr   r   PDFImageXObjectr   r  	ReferenceaddFormrP  smaskPDFObjectReferencerN  r"   r   rE  r  r  r  r   r/   r  drawBoundaryr  keysvars)r   rF  rc   rG  r   rE  rM  r>  r?  r@  rA  rB  rawdatarU  mdatar   rY  regNameimgObjmRegNamemImgObjscaledks                          r7   	drawImageCanvas.drawImage  s   | &'" eK((&&(GLLEV|((*D	V,W]+D  &A||HHW%Q<D ))**40%%))'48++DdCFFKf%II0IIdF+F8D1E9933EJJ?))..228TB%%e,#'99#6#6uX#FFL#)#<#<X#FFLM #11DAPU]c]i]ijpjwjw  yC  #DE 	q

5!

(W,-lQV< 	% %%'!%A ( fmm,,r9   c                 &   U R                   (       aA  U R                   R                  S5      u  U l        U l        U l        U l        U l        U l        g / U l        / U l        / U l	        SU l
        / U l        / U l        S U l        0 U l        0 U l        g )Nrh   r   )r   rC  r   r  r  	_formDatar  r  r   r   r  r   s    r7   r   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r9   c                 $   U R                   U R                  U R                  U R                  U R                  U R
                  4nU R                  R                  U5        / U l         SU l        / U l        / U l        SU l        0 U l        0 U l        g)zVwhen you enter a form, save accumulator info not related to the form for page (if any)r   N)	r   r  r  re  r  r  r   r/   r  )r   saveds     r7   _pushAccumulatorsCanvas._pushAccumulators!  s~    T--t/C/CT^^UYUeUegkgxgxyu%
%&"!r9   c                 B    U R                   R                  5       Ul        g r=   )r9  r   rz   r  s     r7   r  Canvas._setExtGState-  s    002r9   c                     U R                  5         U R                  5         U R                  (       d  U R                  (       a  U R	                  5         XX4U4U l        U R
                  R                  5         g)aF  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   re  ri  r   inForm)r   r   lowerxloweryupperxupperys         r7   	beginFormCanvas.beginForm0  sU     	  "::""$ ?		r9   c                 <   U R                   u  p#pEn U R                  u  pxUc  UnUc  Un[        R                  " X4XVS9n	U R                  U	l        U	R                  U R                  /U R                  -   5        UR                  5        H  u  p[        XU5        M     U R                  U	5        U R                  U	5        U R                  U	5        U R                  U	5        U R                  R!                  X)5        U R#                  5         U R%                  5         g)zaemit the current collection of graphics operations as a Form
as declared previously in beginForm.N)ro  rp  rq  rr  )re  r   r   PDFFormXObjectr  r   setStreamListrS  r   r   r  r  r  r  r  r   rT  r   rD  )r   extra_attributesr   ro  rp  rq  rr  whformra  r   s               r7   endFormCanvas.endFormB  s     26.vv 	R>!6>!6$$F&`00DNN+djj89$**,DAD1 -D!4 $T"		$%!!#r9   c                 6   [        U5      (       a7  S[        R                  " UR                  S5      5      R	                  5       -   nO'S[        R                  " U5      R	                  5       -   nU R
                  R                  U5      nU R
                  R                  R                  US5      nU(       d`  [        R                  " US-   5      nU R                  U5        U R
                  R                  XT5        U R
                  R                  X55        US:X  a  U R                  R                  SU-  5        OCUS:X  a  U R                   R                  SU-  5        OU R"                  R                  SU-  5        U R$                  R                  U5        g)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   r4  r   )r   hashlibmd5rv   	hexdigestr   r5  rQ  r   r   PDFPostScriptXObjectr  rS  rT  r   r/   r   r   r  )r   commandpositionrawNamer\  psObjs         r7   addPostScriptCommandCanvas.addPostScriptCommand[  s4   $ WW[[)@AKKMMGW[[1;;==G))**73		$$(($7//$?Ee$II/IIg-q=&&--h.@Aq[JJh01%%,,X-?@(r9   c                    U(       d  U R                   u  p4SSX44nOU(       a  Uu  pVpxU R                  XV5      u  pU R                  Xx5      u  pU R                  XX5      u  pU R                  Xv5      u  nnXX4nXUU4n[        U5      [        U5      nn[        U5      [        U5      nnUUUU4nU R	                  5       nU(       a  US   U-   US   U-   US   U-   US   U-   4nU$ )Nr   r   r`   rE   )r   r.  r  r  r  )r   rectrelativery  rz  lxlyuxuyxllyllxuryurxulyulxlrylrxsysxminyminxmaxymaxr  s                           r7   _absRectCanvas._absRect  s    ..CAa9D!NBB++B2GC++B3GC++B3GC++B3GC3#B3#BR#b'$DR#b'$DtT)D72:d1gbjaDGBJ>Dr9   c                 v    U R                  X65      nU R                  [        R                  " X1U40 UD6XT5        g)z&DA is the default appearance string???N)r  _addAnnotationr   FreeTextAnnotation)r   contentsDARect	addtopager   r  r*  s           r7   freeTextAnnotationCanvas.freeTextAnnotation  s3    }}T+F55dbOBOQUar9   c                 t    U R                  X%5      nU R                  [        R                  " X!40 UD6XC5        g)z!Experimental, but works.
        N)r  r  r   TextAnnotation)r   r  r  r  r   r  r*  s          r7   textAnnotationCanvas.textAnnotation  s2     }}T+F11$GBGYr9   )g(\?g{Gz?gffffff?c                     U R                  X'5      nU(       d  [        R                  " U5      nU R                  [        R                  " X!X440 UD6Xe5        g)a  
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)r  r   rect_to_quadr  HighlightAnnotation)	r   r  r  
QuadPointsr   r  r   r  r*  s	            r7   highlightAnnotationCanvas.highlightAnnotation  sI     }}T,,,T2JF66tz_\^_aeqr9   c                     [         er=   )NotImplementedErrorr  rz  ry  r  r   InkAnnotation)r   r  InkListr  r  r   r  r*  s           r7   inkAnnotationCanvas.inkAnnotation  s    !!r9   c	                 4    U R                   " XX4U4SXgUS.U	D6$ )a  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   )r  r2   r1   r3   )linkRect)
r   r  destinationnamer  r  r   r2   r1   r3   r*  s
             r7   linkAbsoluteCanvas.linkAbsolute  s4      }}X MXY#IMIKM 	Mr9   c
                     U R                  U5      nU R                  X65      nX:S'   XS'   XS'   [        XXy5        U R                  [        R
                  " S0 U
D6XT5      $ )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  r>   )r  r  r8   r  r   LinkAnnotation)r   r  r  r  r  r   r  r2   r1   r3   r*  destinations               r7   r  Canvas.linkRect  sc    
 --o>}}T+6
!:'=2I0""6#8#8#>2#>PPr9   c                 f   SSK Jn	Jn
JnJn  U	" US9nU
" S5      US'   U
" S5      US'   U" U R                  X#5      5      US'   U	" 5       nU
" S	5      US'   U" U5      nU
" U5      US
'   US:X  a  XS'   OUS:X  a
  XS'   SUS'   O[        SU-  5      eXS'   [        XXF5        U R                  U5        g)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 ]r0   zUnknown linkURI kind '%s'AN)	r+   r   r  r(   r  r  rP   r8   r  )r   urlr  r  r2   r1   r3   kindr*  r   r  r(   r  annr  uris                   r7   linkURLCanvas.linkURL  s     	YX $g&F It}}T;<F OH%&	n#;eH7]cF0AcF84?@@C3Y1C r9   c                     U R                   S-   =o@l         U(       d  S[        U5      -   nU R                  R                  X!5        U(       a  U R	                  U5        g g )Nr   NUMBER)r   reprr   addAnnotation_annotatePage)r   
annotationr   r  counts        r7   r  Canvas._addAnnotation  sP    (,(=(=a(??%(4;.T		1t$ r9   c                 p    U R                   R                  U5      nU R                  R                  U5        g r=   )r   refAnnotationr  r/   )r   r   refs      r7   r  Canvas._annotatePage  s*    ii%%d+##C(r9   c                     U R                   $ )z9get the page number for the current page being generated.)r   r   s    r7   getPageNumberCanvas.getPageNumber  s    r9   c                     [        U R                  5      (       a  U R                  5         U R                  R	                  U R
                  U 5        g)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)rM   r   r  r   
SaveToFiler   r   s    r7   saveCanvas.save  s1     tzz??DMMO		T^^T2r9   c                     [        U R                  5      (       a  U R                  5         U R                  R	                  U 5      n[        U5      (       a  UR                  S5      nU$ )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  )rM   r   r  r   
GetPDFDatar   rv   rX  s     r7   
getpdfdataCanvas.getpdfdata  sI     tzz??DMMOII  &Q<<!Ar9   c                 0    Xl         U R                  5         g)zHaccepts a 2-tuple in points for paper size for this
and subsequent pagesN)r   r  r   r  s     r7   r  Canvas.setPageSize!  s     r9   c                     UR                  5       nUR                  S5      (       a  USS nUS;  a  [        SU-  5      e[        U SU-  U5        g)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   endswithrP   r  )r   r  r   s      r7   
setCropBoxCanvas.setCropBox'  sP    zz|==Sb	443d:;;X_d+r9   c                 $    U R                  USS9  g )Nr  r   r  r  s     r7   
setTrimBoxCanvas.setTrimBox/  s    &)r9   c                 $    U R                  USS9  g )Nr  r  r  r  s     r7   	setArtBoxCanvas.setArtBox2  s    %(r9   c                 $    U R                  USS9  g )Nr  r  r  r  s     r7   setBleedBoxCanvas.setBleedBox5  s    '*r9   c                 0    US-  S:X  d   S5       eXl         g)z7Instruct display device that this page is to be rotatedg     V@rg   z)Rotation must be a multiple of 90 degreesN)r   )r   rots     r7   setPageRotationCanvas.setPageRotation8  s     TzS M"MM  r9   c                 ~    [        U5      nUS:X  a  U R                  U5      nU R                  R                  U5        g)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)rN   rZ  r   r/   )r   rY  escapeds      r7   
addLiteralCanvas.addLiteral=  s3     FA:QA

!r9   c                     U R                   u  pp4pVX-  X2-  -
  nXG-  nU* U-  n	X6-  XE-  -
  U-  n
X-  nU* U-  nXR-  Xa-  -
  U-  nU R                  XXX5        g)a  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                 r7   resetTransformsCanvas.resetTransformsJ  s~     6:5H5H2uUkEK')&*;,c1)&*;,c1w7Lr9   c                    [         (       aM  U R                  u  pxppXq-  X-  -   X-  X-  -   Xs-  X-  -   X-  X-  -   Xu-  X-  -   U-   X-  X-  -   U-   4U l        U R                  (       a  U R                  S   SS S:X  a  U R                  S   R                  5       n[	        [        [        USS 5      5      u  pxpp[        U5      S:  =(       a    [        U5      S-   =(       d    SnU[        Xq-  X-  -   X-  X-  -   Xs-  X-  -   X-  X-  -   Xu-  X-  -   U-   X-  X-  -   U-   5      -  U R                  S'   gU R                  R                  S[        XX4XV5      -  5        g)	zdadjoin a mathematical transform to the current graphics state matrix.
Not recommended for beginners.rh   r  Nz cmi   z %s cmz%s cm)ENABLE_TRACKINGr'  r   splitrL   maprl   rM   rK  r    r/   )r   r   br@   rA   er%   a0b0c0d0e0f0r  rY  s                  r7   r
  Canvas.transform^  sf    ? $ 3 3B"#%49bd#%49bd#%49R<bd2#?D ::$**R.-u4

2$$&A%)#eAbH*=%>"BBBAq.T!Wh.9'ART	"$rt)BDIbd24iPRPTUWUYPYZ\P\]_]abdbf]fgi]i!jjDJJrNJJgq1q(;;<r9   c                     [         (       d  [        S5      eU R                  u  p4pVpxX1-  XR-  -   U-   n	XA-  Xb-  -   U-   n
X4$ )zKreturn the absolute position of x,y in user space w.r.t. default user spacez0tracking not enabled! (canvas.ENABLE_TRACKING=0))r  rP   r'  )r   rc   rG  r   r  r@   rA   r   r%   xpyps              r7   r.  Canvas.absolutePositiono  sM    OPP++QS13Y]S13Y]xr9   c                 .    U R                  SSSSX5        g)zomove 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      r7   r  Canvas.translatex  s     	q1Qr%r9   c                 0    U R                  USSUSS5        g)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   rc   rG  s      r7   r  Canvas.scale}  s     	q1Qq#r9   c                     [        U[        -  S-  5      n[        U[        -  S-  5      nU R                  X#U* USS5        g)zHCanvas.rotate(theta)

Rotate the canvas by the angle theta (in degrees).   r   N)r   r
   r   r
  )r   thetar@   rY  s       r7   rotateCanvas.rotate  s@     
S !
S !qaRAq)r9   c                     [        U[        -  S-  5      n[        U[        -  S-  5      nU R                  SX4SSS5        g )Nr4  r   r   )r	   r
   r
  )r   alphabetatanAlphatanBetas        r7   skewCanvas.skew  s<    urzC'(trzC'(q(Q15r9   c                 Z    U R                  5         U R                  R                  S5        g)a!  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    r7   r  Canvas.saveState  s"     	

#r9   c                 Z    U R                   R                  S5        U R                  5         g)zGrestore the graphics state to the matching saved state (see saveState).QN)r   r/   rD  r   s    r7   r  Canvas.restoreState  s     

#r9   c           	      p    U R                   R                  S[        X5      < S[        X45      < S35        g)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        r7   lineCanvas.line  s#     	

VB^VB^LMr9   c           	          U R                   R                  S5        U H;  u  p#pEU R                   R                  [        X#5      < S[        XE5      < S35        M=     U R                   R                  S5        g)zLike 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#   rG  z lr$   NrH  )r   linelistrI  rJ  rK  rL  s         r7   r  Canvas.lines  sU     	

#%MR2JJVB^VB^LM &

#r9   c	                    US-  nUS-  nXU-
  XU-
  4XU-   XU-   4X-
  X!U-
  U4X-   X!U-   U4/n	U R                  5         U(       a)  U R                  U5        U(       a  U R                  U5        U(       a  U R                  U5        U R	                  U	5        U(       a(  Ub  U R                  U5        U R                  X-
  X%5        U R                  5         g )Nr  )r  rJ  rI  r  r  setFontSizedrawRightStringr  )
r   rc   rG  r  gaptextstrokeColorstrokeWidthfontSize
crosshairss
             r7   crossCanvas.cross  s    s
4C%(!cE!dF);afQuQ=OQRQVWX[_Y_`aPbc
,!!+.k*

:#T%5%5h%?  1r9   c                    [        U5      S:  d   S5       e[        U5      S:  d   S5       e/ nUS   US   pTUS   US   pvU H  nUR                  XX45        M     U H  n	UR                  XiXy45        M     U R                  U5        g)zHLays 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   rh   N)rM   r/   r  )
r   xlistylistr  y0rJ  x0rI  rc   rG  s
             r7   gridCanvas.grid  s     5zA~EEE~5zA~EEE~q59Bq59BALL!q% ALL"r% 

5r9   c	                 t    U R                   R                  S[        X5      < S[        X4XVXx5      < S35        g)z/Bezier curve with the four given control pointsrF  rG  z c SNrH  )	r   rI  rJ  rK  rL  x3y3x4y4s	            r7   bezierCanvas.bezier  s,    

!">6"""+IK 	r9   c                     [         R                  " U R                  S9R                  XX4XV5        U R	                  SS5        g)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   rI  rJ  rK  rL  startAngextents          r7   rn  
Canvas.arc  s5    
 	  djj155bB(RAa r9   c           	          U R                   R                  S[        XX45      -  [        XVU R                  4   -   5        g)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   rc   rG  r   rE  strokefills          r7   r  Canvas.rect   s:    

*vaE'BB$V4>>%ABC 	Dr9   c                     [         R                  " U R                  S9R                  XX1-
  XB-
  5        U R	                  XV5        g)zDraw an ellipse defined by an enclosing rectangle.

Note that (x1,y1) and (x2,y2) are the corner points of
the enclosing rectangle.
rl  N)r   rm  r   ellipsero  )r   rI  rJ  rK  rL  ru  rv  s          r7   ry  Canvas.ellipse  s7     	  djj199""%OF)r9   c	                     [         R                  " U R                  S9n	U	R                  SX-   -  SX$-   -  5        U	R	                  XX4XV5        U	R                  5         U R                  Xx5        g)z[Like arc, but connects to the centre of the ellipse.
Most useful for pie charts and PacMan!rl  r  N)r   rm  r   moveToarcToclosero  )
r   rI  rJ  rK  rL  rp  rq  ru  rv  ps
             r7   wedgeCanvas.wedge  sY     $$$**5	beS"%[)	bH,		F(r9   c                 J    X-
  nX-   nX#-
  nX#-   n	U R                  XhXyXE5        g)zNdraw a cirle centered at (x_cen,y_cen) with radius r (special case of ellipse)N)ry  )
r   x_ceny_cenrru  rv  rI  rK  rJ  rL  s
             r7   circleCanvas.circle  s0     YYYYRRV2r9   c                     [         R                  " U R                  S9R                  XX4U5        U R	                  Xg5        g)ztDraws a rectangle with rounded corners.  The corners are
approximately quadrants of a circle, with the given radius.rl  N)r   rm  r   	roundRectro  )r   rc   rG  r   rE  radiusru  rv  s           r7   r  Canvas.roundRect   s4     	  djj1;;A%QWXF(r9   c                 X    U R                   R                  U5      nX R                  U'   U$ r=   )r   
addShadingr  r   shadingr   s      r7   _addShadingCanvas._addShading'  s)    yy##G,"&$r9   c                 b    U R                  U5      nU R                  R                  SU-  5        g )Nz/%s sh)r  r   r/   r  s      r7   shadeCanvas.shade,  s(    (

(T/*r9   c                     SSK Jn  [        U5      u  p[        X5      nU" XX4UU	[	        U5      S9nU R                  U5        g )Nr   )PDFAxialShadingFunction
ColorSpaceExtend)r+   r  rY   rx   r   r  )r   ra  r`  rI  rJ  rT   rp   r   r  
colorSpacencolorsfcnr  s                r7   linearGradientCanvas.linearGradient0  sD    <.v6
!'5!""3%.@.HJ

7r9   c                     SSK Jn  [        U5      u  p[        X5      n
U" XSXX:U[	        U5      S9	nU R                  U5        g )Nr   )PDFRadialShadingrg   r  )r+   r  rY   rx   r   r  )r   rc   rG  r  rT   rp   r   r  r  r  r  r  s               r7   radialGradientCanvas.radialGradient9  sF    =.v6
!'5"1aF%.@.HJ

7r9   c	                    [        X6U R                  U R                  US9u  p9U R                  XUS9n
Ub  U
R	                  U5        U(       a  U
R                  U5        U(       a  U
R                  U5        U
R                  U5        U(       a  U
R                  S5        U(       a  U
R                  S5        Ub  U
R	                  S5        U R                  U
5        g)z*Draws a string in the current text styles.fontNamerY  shaping	directionNr   )	r   r#  r$  	beginTextsetTextRenderModesetCharSpacesetWordSpacetextLinedrawTextr   rc   rG  rV  mode	charSpacer  	wordSpacer  r   r   s              r7   
drawStringCanvas.drawStringL  s    $TT^^UYUcUcmtuNN19N5Q006annY/annY/	

4annQ'annQ'Q003ar9   c	                 ^   [        X6U R                  U R                  US9u  p9U(       a  U	[        U5      S-
  U-  -  n	U(       a+  XR	                  S5      UR	                  S5      -   S-
  U-  -  n	U R                  X-
  U5      n
Ub  U
R                  U5        U(       a  U
R                  U5        U(       a  U
R                  U5        U
R                  U5        U(       a  U
R                  S5        U(       a  U
R                  S5        Ub  U
R                  S5        U R                  U
5        g)z2Draws a string right-aligned with the x coordinater  r   rG      Nr   r   r#  r$  rM   r  r  r  r  r  r  r  r  s              r7   rT  Canvas.drawRightStringZ  s    $TT^^UYUcUcmtueD	!Y66ee

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

4annQ'annQ'Q003ar9   c	                 f   [        X6U R                  U R                  US9u  p9U(       a  U	[        U5      S-
  U-  -  n	U(       a+  XR	                  S5      UR	                  S5      -   S-
  U-  -  n	U R                  USU	-  -
  U5      n
Ub  U
R                  U5        U(       a  U
R                  U5        U(       a  U
R                  U5        U
R                  U5        U(       a  U
R                  S5        U(       a  U
R                  S5        Ub  U
R                  S5        U R                  U
5        g)z_Draws a string centred on the x coordinate. 

We're British, dammit, and proud of our spelling!r  r   rG  r  r  Nr   r  r  s              r7   drawCentredStringCanvas.drawCentredStringi  s     %TT^^UYUcUcmtueD	!Y66ee

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

4annQ'annQ'Q003ar9   c
                 L   UR                  US5      n
U R                  X@R                  U R                  5      n[	        U
5      S:X  a  [
        R                  U5      by  US   [        ;  al  U
S   SS nU
S   S   nUS   [        ;  a  US   U-   nUSS nUS   [        ;  a  M  U R                  USU-  -
  X,XVXxU	S9  U R                  USU-  -
  X-XVXxU	S9  gU
S   nU R                  USU-  -
  X,XVXxU	S9  [	        U
5      S:  a!  XJS   -   nU R                  USU-  -
  X-XVXxU	S9  gg)aT  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   Nrh   r   r  )r  r  r  r  r  )
r  stringWidthr#  r$  rM   digitPatsearchr   rT  r  )r   rc   rG  rV  	pivotCharr  r  r  r  r  partspivWleftText	rightTexts                 r7   drawAlignedStringCanvas.drawAlignedStringz  se   8 

9Q'	>>4>>Ju:?xt4@T"XU[E[ Qx"~HaI2,f,$RL94	#Ab> 2,f,   3t8Qt'g ! OOOAc$hJ4'g  O
 QxH  3t8Qt'g ! O5zA~%a0	#d(
At"+'   S r9   c                 :    U R                   R                  5       nU$ )zsReturns the list of PostScript font names available.

Standard set now, but may grow in future with font embedding.)r   getAvailableFonts)r   	fontnamess     r7   r  Canvas.getAvailableFonts  s     II//1	r9   c                 t    [        [        R                  R                  5       5      nUR	                  5         U$ )z-Convenience function to list all loaded fonts)rL   r   widthsrX  rn   )r   namess     r7   listLoadedFonts0Canvas.listLoadedFonts0  s)    Z&&++-.

r9   c           
         Xl         X l        Uc  US-  nX0l        [        R                  " U R                   5      nUR
                  (       d  UR                  R                  (       d  [        U SS5      (       dV  U R                  R                  U5      nU R                  R                  SU< S[        U5      < S[        U5      < S35        ggg)	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   rH  FzBT rG  z Tf z TL ET)r#  r$  r&  r   rL  rM  rN  rO  rP  r   rQ  r   r/   r    )r   
psfontnamer  leadingrU  pdffontnames         r7   setFontCanvas.setFont  s    
 $?SjG!!$..1  yy  5Fu(M(M"ii;;JG

!!KPTW]^eWf"gh )N !r9   c                 x    Uc  U R                   nUc  U R                  nU R                  U R                  X5        g)z7Sets font size or leading without knowing the font faceN)r$  r&  r  r#  )r   r  r  s      r7   rS  Canvas.setFontSize  s.    <?dmmGT^^T3r9   c                 v    [         R                  " X=(       d    U R                  X0R                  4USL    5      $ )z1gets width of a string in the given font and sizeN)r   r  r#  r$  )r   rV  r  rY  s       r7   r  Canvas.stringWidth  s6    %%d,F%-nn$=h$>N$OQ 	Qr9   c                 ^    Xl         U R                  R                  S[        U5      -  5        g )Nz%s w)r4  r   r/   r    )r   r   s     r7   r  Canvas.setLineWidth  s"    

&6%=01r9   c                 f    US;   d   S5       eXl         U R                  R                  SU-  5        g)z0=butt,1=round,2=squarer   r   r`   z*Line caps allowed: 0=butt,1=round,2=squarez%d JN)r1  r   r/   r   r  s     r7   
setLineCapCanvas.setLineCap  s/    wL LL

&4-(r9   c                 f    US;   d   S5       eXl         U R                  R                  SU-  5        g)z0=mitre, 1=round, 2=bevelr  z-Line Joins allowed: 0=mitre, 1=round, 2=bevelz%d jN)r2  r   r/   r  s     r7   setLineJoinCanvas.setLineJoin  s/    wO OO

&4-(r9   c                 ^    Xl         U R                  R                  S[        U5      -  5        g )Nz%s M)_miterLimitr   r/   r    )r   limits     r7   setMiterLimitCanvas.setMiterLimit  s#     

&6%=01r9   c                    Sn[        U[        [        45      (       a  X4nSnO[        U5      (       d  SnU Vs/ s H(  n[        U[        [        45      (       a  US:  d  M&  UPM*     nnU(       d!  [        U[        [        45      (       a  US:  a  SnOU(       a  [	        U5      S::  a  SnU(       a  [        SU< SU< SU< 35      eU R                  R                  S	[        U5      < S
U< S35        gs  snf )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=r  [z] z dN)	rG   intrl   r   sumrP   r   r/   r    )r   arrayphasereasonr   bads         r7   setDashCanvas.setDash  s    eSK((NEEuHFJ%Qz!SK'@'@AEq%JjE{33uQwCFs5z1}<FvVWW

>? Ks   %C:#C:c                 ,    [         R                  " 5       $ )zReturns a fresh path object.  Paths are used to draw
complex figures.  The object returned follows the protocol
for a pathobject.PDFPathObject instance)r   rm  r   s    r7   	beginPathCanvas.beginPath  s     ''))r9   c                     Uc  [        USU R                  5      nU R                  R                  [	        UR                  5       5      5        U R                  X#U5        g)z*Draw the path object in the mode indicatedNr)  )rP  r)  r   r/   rN   getCodero  )r   aPathru  rv  fillModes        r7   drawPathCanvas.drawPath	  sG    u[@H

#emmo./F1r9   c                 j    U R                   R                  [        XUb  UOU R                  4   5        g r=   )r   r/   rt  r)  )r   ru  rv  r  s       r7   ro  Canvas._strokeAndFill  s,    

(6X=QW[WeWe#efgr9   c                     Uc  [        USU R                  5      nUR                  5       n[        X#U4   nU[        :H  =(       a    S=(       d    SnU< U< U< 3nU R
                  R                  U5        g)zclip as well as drawingNr)  z W* z W )rP  r)  r  rt  r(  r   r/   )	r   r  ru  rv  r  gcpathopsclipitems	            r7   clipPathCanvas.clipPath  se    u[@H]]_x1G(HgM)4f=tW-

$r9   c                     [        XX#S9$ )zdReturns a fresh text object.  Text objects are used
to add large amounts of text.  See PDFTextObjectr  )r   )r   rc   rG  r  s       r7   r  Canvas.beginText  s     Ta==r9   c                 h    U R                   R                  [        UR                  5       5      5        g)zDraws a text objectN)r   r/   rN   r  )r   aTextObjects     r7   r  Canvas.drawText$  s"    

#k11345r9   c                     Uc  [         R                  nXl        U R                  R	                  U R                  5        g)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     r7   r   Canvas.setPageCompression(  s2     "i6O6OO /		  !6!67r9   c                     Xl         g)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     r7   setPageDurationCanvas.setPageDuration3  s
     &r9   c                    0 U l         U(       d  gUS;   a  SSU-  4nO[        R                  " S5      eUS;   a  SSU-   4nO[        R                  " S	5      eUS
;   a  SSU-   4nO[        R                  " S5      eXh/U/U/U// U/S.n	 X   n
0 nSUS'   SU-  US'   SU-   US'   U
 H	  u  pXU'   M     Xl         g! [         a    [        R                  " SU-  5      ef = f)a  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   r4  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/Transr  z%dr0   r$   )r   r   PDFErrorKeyError)r   
effectnamer  r  	dimensionmotiondirection_argdimension_arg
motion_argPageTransitionEffectsargs	transDictrf   values                 r7   r  Canvas.setPageTransition?  s)   <  " &!59#45M//"HII
"!3?3M//"HIIYsV|,J//"EFF $0$o<#_$o!	K(4D
 	$	&	#z)	# LS"cN !(  	K//"<z"IJJ	Ks   B< <$C c                 8    SR                  U R                  5      $ )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 diskr  )rK  r   r   s    r7   getCurrentPageContentCanvas.getCurrentPageContent  s    
 yy$$r9   c                 ~    U R                   R                  n[        USS5      nUc  SSKJn  U" 5       =oCl        X$U'   g)zCset one of the allowed enbtries in the documents viewer preferencesViewerPreferencesNr   )ViewerPreferencesPDFDictionary)r   CatalogrP  r+   r2  r1  )r   prefr+  catalogVPr2  s         r7   setViewerPreferenceCanvas.setViewerPreference  s=    ))##W06:O-K-MMB*4r9   c                 H    U R                   R                  R                  U   $ ).you'll get an error here if none have been setr   r3  r1  r   r4  s     r7   getViewerPreferenceCanvas.getViewerPreference  s    yy  22488r9   c                 F    U R                   R                  R                  U	 g)r:  Nr;  r<  s     r7   delViewerPreferenceCanvas.delViewerPreference  s    II//5r9   c                    SSK JnJnJn  [	        U5      (       a	  U" U5      nOA[        U[        [        45      (       a	  U" U5      nO[        U[        5      (       a  U" U5      n[        U R                  R                  X5        g )Nr   )r   r(   r  )r+   r   r(   r  r   rG   rL   rI   r   r  r   r3  )r   rf   r+  r   r(   r  s         r7   setCatalogEntryCanvas.setCatalogEntry  s`    OO<<e$EtEl++UOEd##!%(E		!!#,r9   c                 B    [        U R                  R                  U5      $ r=   )rP  r   r3  r   rf   s     r7   getCatalogEntryCanvas.getCatalogEntry  s    tyy((--r9   c                 D    [        U R                  R                  U5        g)z-you'll get an error here if it's not been setN)delattrr   r3  rF  s     r7   delCatalogEntryCanvas.delCatalogEntry  s    		!!#&r9   c                     U R                   R                  n[        USS5      nUc  SSKJn  U" 5       =oel        SSKJn  UR                  X" X#U5      5        g)zadd a PDFPageLabel for pageNum
PageLabelsNr   )PDFPageLabels)PDFPageLabel)r   r3  rP  r+   rO  rN  rP  addPageLabel)	r   pageNumstylestartprefixr5  PLrO  rP  s	            r7   rQ  Canvas.addPageLabel  sL    ))##W\$/:>&3o5B#9
U @Ar9   c                      U R                   $ ! [         a=    SSKJ n  U" U 5      =U R                  R                  l         U l         U R                   s $ f = f)z/get form from canvas, create the form if neededr   )AcroForm)rY  r  reportlab.pdfbase.acroformr   r  )r   rY  s     r7   acroFormCanvas.acroForm  sJ    	!==  	!;:B4.HDII'$-== 	!s    AAAc                 P   [        U[        [        [        45      =(       d    [        U[        5      nSnSnU(       a  [        US5      n	U	S:g  nOV[        U[        5      (       aA  U(       a:  [        UR                  S5      n	U	S:g  nU(       a  UR                  nUR                  nU(       aP  U R                  5         U R                  W	5        US:  a  U R                  U5        U(       a  U R                  U5        U R                  X#XE5        U(       a  U R                  5         gg)z9draw a boundary as a rectangle (primarily for debugging).rh   Nr   )rG   rN   rI   rL   r   r   r   r1   r   r3   r  rJ  r  r  r  r  )
r   sbrI  rJ  r   rE  ssry  dar@   s
             r7   rW  Canvas.drawBoundary  s    Cd+,D
2e0D2AbB,--"$AbBHH\\NN"!tT&&q)4<<#		"%t  "2r9   )>rY  r   r  r   r  r*  r   r   r  r   r   r'  r  r   r   r   r9  r   r7  r)  r#  r$  re  r  r   r,  r   r   r   r&  r1  r3  r2  r4  r  r5  r   r   r  r   r   r   r   r   rS  r   r   r.  r  r8  r/  r0  r%  r-  r  r   r+  r!  r"  r   r   r  )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   NNNrE   )r   r  )r   r   )NT)Nr   NNFr=   )NN)r   r   N)r   r   N)Nr   r   r  r  )NNN)r   r   r   r   __doc__r   r  r  r?  rD  r  r=  rL   rk   rM   STATE_RANGEr  rZ  r]  ra  rg  rn  rq  rt  rx  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r+  r1  r7  r:  rD  rb  r   ri  r  rs  r|  r  r  r  r  textAnnotation0r  r  inkAnnotation0r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r.  r  r  r6  r=  r  r  rM  r  r[  rb  ri  rn  r  ry  r  r  r  r  r  r  r  r  rT  r  r   decimalSymbolr  r  r  r  rS  r  r  r  r  r  r  r  r  ro  r  r  r  r   r  r  r.  r7  r=  r@  rC  rG  rK  rQ  propertyr[  rW  r   r>   r9   r7   r   r      s   /d !%! #'!%!% $#_!B.&>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  PU 6Spi 4Q2))2 a @&*2h >
6	8
& ;<9<H)T%96-.'	B ! !#r9   __main__zFor test scripts, look in tests)r   r   )>__version__rc  __all__r  rer  stringr   mathr   r   r	   r
   	reportlabr   reportlab.pdfbaser   r   reportlab.pdfbase.ttfontsr   r   reportlab.pdfgenr   reportlab.pdfgen.textobjectr   r   r   reportlab.lib.colorsr   r   r   r   r   reportlab.lib.utilsr   r   r   r   r   r   reportlab.lib.abagr   reportlab.lib.rl_accelr    r!   reportlab.lib.boxstuffr"   compiler  r(  FILL_NON_ZEROrt  r8   rO   rY   rx   rz   r   r   r   r   printr>   r9   r7   <module>r|     s>   	 	
  	   " "  $ ( > ( V V [ [ Z Z # 4 1::e  =!C=!C=!C=!C=!D=!C=!D=!C'&2 	#OJG GR88 8y#_ y#v7 z	
+, r9   