rL ihJdZddlZddlmZddlmZddlmZddlmZddlm Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlZdd lmZmZmZmZmZdd l m!Z!dd l"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)dd l*m+Z+ddl,m-Z-m.Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9m:Z:ddl;mZ>ddlm?Z?ddl@mAZAe jeCZDduO A PDF Matplotlib backend. Author: Jouni K Seppänen and others. N)timezone)datetime)Enum)total_ordering)BytesIO)Image)_api _text_helpers _type1fontcbookdviread)Gcf)_BackendFigureCanvasBaseFigureManagerBaseGraphicsContextBase RendererBase)MixedModeRenderer)Figure)get_font fontManager)AFM)FT2Font FaceFlagsKerning LoadFlags StyleFlags)Affine2DBboxBase)Path)UTC)_path)_backend_pdf_psc"d}d}g}t|D]H\}}t|}||z|kr ||dzz }"|jdj||||}|}J|jdj||ddj|S)z Make one string from sequence of strings, with whitespace in between. The whitespace is chosen to form lines of at most *linelen* characters, if possible. rr# N ) enumeratelenappendjoin)stringslinelencurrposlastiresultislengths e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/backends/backend_pdf.py_fillr5_sG E F'"1Q V g % vz !G MM$))GE!$45 6EG MM$))GEFO,- ::f c tjd}|rDtjt |t j }|jt}ntj}dtjdd|dtj|d|}|jDcic] \}}| || }}}d}d |_ d }d |_ d } d | _ ||||||||| d } |D]j}|| vr&tjd|dt!| d-| |||r.is_string_likes!S!!r6zan instance of strc"t|tSr>)r?rrAs r4is_datez&_create_pdf_info_dict..is_dates!X&&r6z an instance of datetime.datetimecFt|tr|jdvS|dvS)N)sTruesFalsesUnknown)TrueFalseUnknownr?NamenamerAs r4 check_trappedz,_create_pdf_info_dict..check_trappeds( a 66<< <44 4r6z#one of {"True", "False", "Unknown"}) TitleAuthorSubjectKeywordsr:r;r<ModDateTrappedzUnknown infodict keyword: z. Must be one of .zBad value for infodict keyword z. Got z which is not rS)osgetenvr fromtimestampintrutcreplacer!todaympl __version__itemstext_for_warningr warn_externalsetrK) backendmetadatasource_date_epoch source_dateinfokvrCrErMkeywordss r4_create_pdf_info_dictrjus@ "56,,S1B-CX\\R !)))5 nn& "#//!22JK!'*S__4EF#    D $zz| =Vaq}AqD =D ="&:N#'AG5 &KM"  !"!"  HC H    !;A5A114X0A D E!T!W%   !@D&&*1g["*1+">">!?q B C CDtI/Y KO >s 1 E4<E4c2|jd}|j}| |j}n1tjrtj }ntj }|dk(r|dz }|S|dkr|d| dz| dzfzz }|S|d|dz|dzfzz }|S)zX Convert a datetime to a PDF string representing it. Used for PDF and PGF. zD:%Y%m%d%H%M%SrZz +%02d'%02d'iz -%02d'%02d')strftime utcoffsetsecondstimedaylightaltzoner)drzs r4_datetime_to_pdfrvs #$A A} II == A AAv S H Q ]rdlaR4K8 88 H ]a4iT2 22 Hr6ctj| }tj|}tj|}|||zz}|||zz}|||zz||zz} |||zz ||zz} |||zz} |||zz } ||f| | f| | f||ffS)zR Calculate the coordinates of rectangle when rotated by angle around x, y )mathradianssincos) rBywidthheightangle sin_angle cos_angleabcrsefs r4!_calculate_quad_point_coordinatesrs LL% EII FY A FY A EI  22A EI  22A EI A EI A FQFQFQF ++r6c6t|||||}|dzrdnd}td|D|z }td|D|z }td|D|z} td|D|z} ttj j |||| | ffS)zg Get the coordinates of rotated rectangle and rectangle that covers the rotated rectangle. Zgh㈵>rc3&K|] }|d ywrN.0rhs r4 z,_get_coordinates_of_block..'!'c3&K|] }|d ywr#Nrrs r4rz,_get_coordinates_of_block..rrc3&K|] }|d ywrrrs r4rz,_get_coordinates_of_block..rrc3&K|] }|d ywrrrs r4rz,_get_coordinates_of_block..rr)rminmaxtuple itertoolschain from_iterable) rBr|r}r~rverticespadmin_xmin_ymax_xmax_ys r4_get_coordinates_of_blockrs 1Au17@HRZ'QC 'h' '# -E 'h' '# -E 'h' '# -E 'h' '# -E )////9 : E5% ( **r6ct|||||\}}tdtd|gdtd|jdd}|dzr||d<|S) z= Create a link annotation object for embedding URLs. AnnotLinkrrrURI)Sr)TypeSubtypeRectBorderAr QuadPoints)rrKget_url) gcrBr|r}r~r quadpointsrectlink_annotations r4_get_link_annotationr sd1AufeLJW <e::< O rz(2 % r6z\\z\(z\)z\nz\r)\()  c ,t|dr|jSt|ttj frEt j |s tdd|z}|jdjdSt|trddg|St|ttjfrd|zSt|trPt|jr|jd Stj |jd zSt|t"r9d |j%d j't(jd zd zSt|t*rWt-dg|j/Dcgc]-\}}t1|jdzt|z/c}}dSt|t2t4fr't-dg|Dcgc] }t|c}dS|yt|t6rtt9|St|t:r,t-|j<Dcgc] }t|c}St?dtA|dcc}}wcc}wcc}w)z!Map Python objects to PDF syntax.pdfReprz%Can only output finite numbers in PDFs%.10f0.sfalsestrues%dasciizUTF-16BE(zlatin-1)s<>[]snullz$Don't know a PDF representation for z objects)!hasattrrr?floatnpfloatingisfinite ValueErrorrstripboolrXintegerr@isasciiencodecodecs BOM_UTF16_BEbytesdecode translate _str_escapesdictr5r^rKlistrrrvrbounds TypeErrortype)objrtrgrhvals r4rr+sWsI{{} C%- .{{3DE E sNxx~$$T** C '"3'' C#rzz* +s{ C ckkmszz'*J J"//#**Z2HHJ J C   JJy ! + +L 9 @ @ K L   C   @C L1d1goo$&3 L      C$ 'dAc:sgcl:ADABB  C "',-- C "cjj9sgcl9::>tCykJ""# #+M ;:s2J /J Jc>|dk(r|dkS|dk(r|dkSt)a  Returns True if the font is able to provide codepoint *glyph* in a PDF. For a Type 3 font, this method returns True only for single-byte characters. For Type 42 fonts this method return True if the character is from the Basic Multilingual Plane. *)NotImplementedError)fonttypeglyphs r4_font_supports_glyphrts/1}|2~~  r6c(eZdZdZdZdZdZdZy) ReferencezV PDF reference object. Use PdfFile.reserveObject() to create References. c||_yr>idselfrs r4__init__zReference.__init__s r6c d|jzS)Nzrrs r4__repr__zReference.__repr__s$''))r6c d|jzS)Ns%d 0 Rrrs r4rzReference.pdfReprs477""r6cx|j}|d|jz|t||dy)N %d 0 obj s endobj )writerr)rcontentsfilers r4rzReference.writes1  mdgg%& gh  mr6N)__name__ __module__ __qualname____doc__rrrrrr6r4rrs *#r6rceZdZdZdZhedheededdzz Dcic]}|d|z c}}ZdZd Z d Z d Z d Z d Z dZycc}}w)rKzPDF name object.rL!~r#z#%02xct|tr|j|_yt|tr|j d}|j |j jd|_y)Nr)r?rKrLrrr_hexifyr)rrLs r4rz Name.__init__sN dD ! DI$&{{7+t||4;;GDDIr6c d|jzS)Nz rrs r4rz Name.__repr__sTYY&&r6c>d|jjdzS)N/r)rLrrs r4__str__z Name.__str__sTYY%%g...r6cXt|txr|j|jk(Sr>rJrothers r4__eq__z Name.__eq__s!%&B499 +BBr6cXt|txr|j|jkSr>rJrs r4__lt__z Name.__lt__s!%&A499uzz+AAr6c,t|jSr>)hashrLrs r4__hash__z Name.__hash__sDIIr6c d|jzS)N/rrs r4rz Name.pdfReprsdiir6N)rrrr __slots__rangeordrrrrrr r rrrs00r4rKrKs~I%%* (H%C#c(Q,*G(HHJ'A+~JGE'/CB 5Js ArKceZdZdZdZdZy)VerbatimzEStore verbatim PDF command content for later inclusion in the stream.c||_yr>_x)rrBs r4rzVerbatim.__init__s r6c|jSr>rrs r4rzVerbatim.pdfReprs wwr6N)rrrrrrrr6r4rrsOr6rceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)e*d(Z+y))*Opz'PDF operators (not an exhaustive list).bBfhsSnsBTsETcsrelmscmsDoGgsRGsrgsCSscssSCNsscndjJsgsqQsTdsTfsTmsTjsTJwWsshc|jSr>)valuers r4rz Op.pdfReprs zzr6cn|r|r |jS|jS|r |jS|jS)z Return the PDF operator to paint a path. Parameters ---------- fill : bool Fill the path with the fill color. stroke : bool Stroke the outline of the path with the line color. ) fill_strokestrokefillendpath)clsr3r2s r4 paint_pathz Op.paint_paths4 &zz!xx{{"r6N),rrrrclose_fill_stroker1r3 closepath close_stroker2r4 begin_textend_textcurveto rectanglelinetomoveto concat_matrix use_xobjectsetgray_strokesetgray_nonstroke setrgb_strokesetrgb_nonstrokesetcolorspace_strokesetcolorspace_nonstrokesetcolor_strokesetcolor_nonstrokesetdash setlinejoin setlinecap setgstategsavegrestoretextpos selectfont textmatrixshowshowkern setlinewidthclipshadingr classmethodr6rr6r4rrs1K DIL FGJHGI F FMKNM #OGKJI EHGJJ DHL DG##r6rc4eZdZdZdZd dZdZdZdZdZ y) Streamz PDF stream object. This has no pdfRepr method. Instead, call begin(), then output the contents of the stream by calling write(), and finally call end(). )rr)pdfFiler compressobjextraposNc^||_||_||_|j|_d|_|t |_n|j|_|'|jjtd|d|jj|jtjdr-|s+tj tjd|_|jt|_y|j!|jj#|_y)a@ Parameters ---------- id : int Object id of the stream. len : Reference or None An unused Reference object for the length of the stream; None means to use a memory buffer so the length can be inlined. file : PdfFile The underlying object to write the stream to. extra : dict from Name to anything, or None Extra key-value pairs to include in the stream header. png : dict or None If the data is already png encoded, the decode parameters. N FlateDecode)Filter DecodeParmspdf.compression)rr)r[fhrr\rr]copyupdaterK recordXrefr\rcParamszlibr _writeHeadertellr^)rrr)rr]pngs r4rzStream.__init__s  GG  =DJDJ ? JJ  d=.A.13 4 ( <<) *3#// ./ 1D  88  DI    yy~~'DHr6c|jj}|d|jz|j}|j|d<t j drtd|d<|t||dy)NrLengthrcr`ras stream ) rrrr]r)r\rhrKr)rrrs r4rjzStream._writeHeader9se  mdgg%&zzX <<) *!-0DN gdm mr6c$|j|j|jj}t||_|jj |_|j |jj||jjdy|jj|jz }|jjd|jj|j|y)zFinalize stream.Ns endstream endobj ) _flushr)rgetvaluer[rdrjrrkr^ writeObject)rrr3s r4endz Stream.endDs 88 yy))+H8}DH DI     IIOOH % IIOO4 5YY^^%0F IIOO4 5 LL $ $TXXv 6r6c|j|jj|y|jj|}|jj|y)zWrite some data on the stream.N)r\rrcompress)rdata compresseds r4rz Stream.writeTsF    # IIOOD !))2248J IIOOJ 'r6c|j=|jj}|jj|d|_yy)zFlush the compression object.N)r\flushrr)rrws r4rpz Stream._flush]sA    '))//1J IIOOJ '#D  (r6NN) rrrrrrrjrsrrprr6r4rZrZ s) PI%(N 7 ($r6rZc Nt|d}d|jz }i}|D]}|j|tj}t j |jdg|j|zdzjt}|j\}} |dzjt}t j| dk(\} | ddd} t j th| h| dz zh| dzzt} | || || dz || dzzdz jtk(jd } |j|fd vr|dddfxxdzcc<||zdzjt}|| dz || dzzdz jt|| <d j!t#t$|j'd d zt)j*t-|| dddddgddzdz||j/|<|S)Nr#)hinting_factorrg?@raxis))DejaVuSerif-ItalicM)r rs d1 F)r$r#r6r"rTr)r units_per_EM load_glyphrNO_SCALErarray horiAdvancebboxastyperXget_pathnonzerosortedallpostscript_namer+mapr@rr"convert_to_stringr get_glyph_name) font_path glyph_idsfontconvprocsglyph_idgd1rhrquadsquads_on quads_mid_onimplicits r4_get_pdf_charprocsrfs4 Ia 0D $## #D E& OOHi&8&8 9hh q216623d:R? G G L}}1 VOOC AF#A;xx ;X;EAI/.UQY.@ A3H  |_L1$%,*:(;;q@HHMN SaS[  ( +0   adGqLG X] " "3 ' x!|_qA .! 3VVC[ (  HHSb\ " ) )' 2X =%%Q D$tR-t5 5    d!!(+,A&N Lr6ceZdZdZd5fd ZdZgdfdZdZdZd Z d Z d Z d6d Z d Z dddZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZej>de d Z!d!Z"d"Z#d#Z$d$Z%d%Z&d&Z'd5d'Z(d(Z)d)Z*d*Z+d+Z,d,Z-e.d7d-Z/d8d.Z0d9d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6xZ7S):PdfFilezPDF file object.Nct |tjd|_gdg|_d|_d|_d|_tj|dd\}}|s |j|_|}d|_||_d|_|j!d |j!d |j#d |_|j#d |_g|_|j#d |_|j#d|_|j#d|_|j#d|_|j#d|_|j#d|_t7d|j&d}|j9|j$|t;d|xsi|_i|_dtjdD|_ i|_!i|_"tGjH|_%i|_&dtjdD|_'i|_(dtjdD|_)g|_*i|_+dtjdD|_,g|_-i|_.dtjdD|_/i|_0i|_1g|_2g|_3g|_4djkDcgc] }t7|}}|j*|j2|j,|j.|j0|d}|j9|j4|y#t$rt}||_YwxYwcc}w)a Parameters ---------- filename : str or path-like or file-like Output target; if a string, a file will be opened for writing. metadata : dict from strings to strings and dates Information dictionary object (see PDF reference section 10.2.1 'Document Information Dictionary'), e.g.: ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``. The standard keys are 'Title', 'Author', 'Subject', 'Keywords', 'Creator', 'Producer', 'CreationDate', 'ModDate', and 'Trapped'. Values have been predefined for 'Creator', 'Producer' and 'CreationDate'. They can be removed by setting them to `None`. r#)rrthe zero objectFNrwbT) return_openeds %PDF-1.4 s% rootpagesfontszextended graphics statesztiling patternszGouraud triangleszexternal objects resourcesCatalog)rPagespdfc38K|]}td|yw)FNrKrr1s r4rz#PdfFile.__init__.."MQ4!A3="Mc38K|]}td|yw)rNrrs r4rz#PdfFile.__init__..s K1!g Krc38K|]}td|yw)SMNrrs r4rz#PdfFile.__init__..sJ!tbH~Jrc38K|]}td|yw)HNrrs r4rz#PdfFile.__init__..rrc38K|]}td|yw)INrrs r4rz#PdfFile.__init__..sEQ4!A3=ErPDF Text ImageB ImageC ImageI)FontXObject ExtGStatePatternShadingProcSet)6superrrcount _object_seq xrefTablepassed_in_file_objectoriginal_file_like tell_baser to_filehandlerkOSErrorrrd currentstreamr reserveObject rootObject pagesObjectpageList fontObject_extGStateObject hatchObject gouraudObject XObjectObjectresourceObjectrKrrrjinfoDict fontNames_internal_font_seq dviFontInfotype1Descriptorsr$CharacterTracker_character_tracker alphaStates_alpha_state_seq_soft_mask_states_soft_mask_seq_soft_mask_groups_hatch_patterns_hatch_pattern_seqgouraudTriangles_images _image_seqmarkersmulti_byte_charprocspaths _annotationspageAnnotationssplit) rfilenamercrdopenedrrBprocsetsr __class__s r4rzPdfFile.__init__s " $??1-78%*""&((4tL F 2!) -1*!  (),,V4--g6 ,,W5 $ 2 23M N--.?@!//0CD!//0BC"00=Y))+ $/-eX^D "M)//!:L"M ""1"B"B"D K 8J K!#Jyq7IJ!#!"M)//!:L"M " E)//!2DE $&!  "&E%J%J%LMDGMM "__ $ 2 2"&"7"7 $ 0 0 $ 2 2 ( * ,,i8W 3Y*2' 3@Ns'M'M4M10M1c|j||c|_|_|jd}|jd}t d|j |j ddd|zd|zg||d}|jd}|j|||jj||jj||jf|j|j|jd|jt d tj |jt d tj"|jt$j&d tj(g|_ y) Nz page contents annotationsPagerH)rParent ResourcesMediaBoxContentsAnnotspagezlength of content stream DeviceRGBround) endStreamr}r~rrKrrrrrr*rr beginStreamroutputrrFrGGraphicsContextPdf joinstylesrK)rr}r~ contentObject annotsObjectthePage pageObjects r4newPagezPdfFile.newPagesK "' DK**?; ))-8 <!-- $ 3 3 !1b5j"v+>,) ''/  W- Z(   ,0D0D!EF ))++,FG I D%r'>'>? D%r'A'AB &11':BNNK "r6r rrcltdtd||d}|jj|y)NrText)rrrr)rKrr*)rtext positionRecttheNotes r4 newTextnotezPdfFile.newTextnotes3="6l#' ##G,r6cfdtt|jtjdzdzz}|d}|dddz|zS)Ncz||krtj|S||z|tj||zzSr>)stringascii_uppercase)nbasetoStrs r4rz,PdfFile._get_subsetted_psname..toStr'sD4x--a00!t)T*V-C-CAH-MMr6r#r+)r  frozensetkeyssysmaxsize)rps_namecharmaphashedprefixrs @r4_get_subsetted_psnamezPdfFile._get_subsetted_psname&sU i /0S[[1_4IJvr"bqzC'))r6c |j|j|j|j|j |j |j |jjDcic] \}}}|| }}}}|jjD] }|d||d<|jjD] \}}|||< |jD]\ }}}}} } } } } |||<|j|j||j|j!|j#|j|j$t'd|j(t+|j(d|j-|j/|j1ycc}}}w)z>Write out the various deferred objects and the pdf end matter.r#rr)rKidsCountN)r_write_annotations writeFontswriteExtGSTates_write_soft_mask_groups writeHatcheswriteGouraudTrianglesrvaluesrrr^rrrr writeImages writeMarkerswritePathCollectionTemplatesrrKrr) writeInfoDict writeXref writeTrailer)rimagerLobxobjectstupr/pathtransr+cappaddingfilledstrokeds r4finalizezPdfFile.finalize6s  !   $$&  ""$,0LL,?,?,ACC(bD"HCC<<&&( &C"1vHSV  &44::< #KD%"HTN #:: FD$r4gvwHTN  ++X6   ))+ ))"&w-"&--#&t}}#57 8   +CsGc$|j|jr|jjy|j3|jj |jj |jjy)z)Flush all buffers and free all resources.N)rrrdryrrrqclosers r4r@z PdfFile.closeWs^   % % GGMMO&&2''--dgg.>.>.@A GGMMOr6c|j|jj|y|jj|yr>)rrdr)rrvs r4rz PdfFile.writebs2    % GGMM$     $ $T *r6c |jt|Dcgc] }t|c}|jdycc}w)Nr')rr5r)rrvrBs r4rzPdfFile.outpuths3 5d3'!*345 54sA cH|jJt||||||_yr>)rrZ)rrr)r]rls r4rzPdfFile.beginStreamls)!!)))#BT5#>r6c`|j"|jjd|_yyr>)rrsrs r4rzPdfFile.endStreamps-    )    " " $!%D  *r6r]c|j|jd||jj||j yr>)rrrrr)rrefrvr]s r4 outputStreamzPdfFile.outputStreamus6 u-   & r6cP|jD]\}}|j||yr>)rrr)rrrs r4r'zPdfFile._write_annotationszs,)-):): 8 %L+   \; 7 8r6ct|tr|g}nOtjdr't j |dt j}nt j |}d}|D]d}|jj|}|s|}|%t|j}||j|<tjd|||rc|}f|S)z Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename of the font. pdf.use14corefontsafm)fontext directoryNzAssigning font %s = %r)r?r@r\rh _fontManager_find_fonts_by_props RendererPdf _afm_font_dirrgetnextr_logdebug)rfontprop filenamesfirst_FxfnameFxs r4fontNamezPdfFile.fontName~s h $! I \\. /$99%;3L3LI%99(CI "E##E*Bz$112(*u% 3R?!H "r6cp|jj|j}| |jSt j t j d}||j}|j/tdj|j|jt|j}tjd||jtj |||j|j|j"|j$|j|j<|S)z Given a dvi font object, return a name suitable for Op.selectfont. This registers the font information in ``self.dviFontInfo`` if not yet registered. z pdftex.mapzNNo usable font file found for {} (TeX: {}); the font may lack a Type-1 versionzAssigning font %s = %s (dvi))dvifontpdfnamefontfilebasefont encodingfileeffects)rrStexnamer_r PsfontsMap find_tex_filerrformatpsnamerTrrUrVtypesSimpleNamespaceencodingrc)rr^dvi_info tex_font_mappsfontr_s r4 dviFontNamezPdfFile.dviFontNames##''8  ## #))'*?*? *MN goo. ?? "5 w79 9 t../ 17GOOL,1,A,A__]]NN -$)r6ci}t|jjD];\}}|j}tj d||j |||<=t|jD]}|j|}tj d||jdr*tj d|j|||<ctj d|jjj|}|s|j||||<|j|j|y)Nz"Embedding Type-1 font %s from dvi.zEmbedding font %s.z.afmzWriting AFM font.zWriting TrueType font.)rrr^r_rUrV _embedTeXFontrendswith_write_afm_fontrusedrSembedTTFrrr)rrdvinamerfr[rcharss r4r(zPdfFile.writeFontss#D$4$4$:$:$<= 1MGTB JJ;W E**40E"I 1t~~. ?H)B JJ+X 6  ( ./ 00:b  34//4488B $ h >E"I ? %0r6ct|d5}t|}dddj}tdtdt|tdd}|j d}|j |||S#1swYixYw)NrbrType1WinAnsiEncoding)rrBaseFontEncodingfont dictionary)openr get_fontnamerKrrr)rrrdrfontnamefontdictfontdictObjects r4rszPdfFile._write_afm_fonts (D ! Rr7D $$& L#G} $X $%6 79++,=> 2  s BB ctjd|jj|j|j d}|j ||jj|j d}tdtddt|jjdz |d}|j?td dgtttj|jd |d <|jLtjd |j t|j |d <|j |||St#j$|j}|j&r|j)|j&}t|j*d |d <|j&j-dd|j&j-ddf}|j.j-|j|f}|7|j1||j}||j.|j|f<||d<|j |||S)Nz#Embedding TeX font %s - fontinfo=%s font widthsr~rrzrr#)rr FirstCharLastCharWidthsr}r DifferenceszBecause of TeX configuration (pdftex.map, see updmap option pdftexDownloadBase14) the font %s is not embedded. This is deprecated as of PDF 1.5 and it may cause the consumer application to show something that was not intended.r|FontNameslantextend?FontDescriptor)rUrVr^rd__dict__rrrwidthsrKr)rbrr _parse_encr`warningrar Type1Fontrc transformproprSrcreateType1Descriptor)rfontinfo widthsObjectrrt1fontrcfontdescs r4rqzPdfFile._embedTeXFontsA 8##++X->-> @))-8  x'7'7'>'>?++,=>fgX--4459%   ,Z( ND'"4"4X5J5J"KL N$HZ     $ LLG!!  # $((9(9#:HZ   ^X 6! !%%h&7&78   %%h&6&67F#FKK $;< ##''5##''#68((,,h.?.?-IJ  11&(:K:KLHBJD ! !8#4#4g"> ?%-!" 2r6c f|jd}|jd}|jd}|jd}d}|r|dz} |dz}|r|d z} t|}td t|jd ||j||j |j d d ||jddd } |j|| |j|dj|jddt|jdt|jddd|S)Nfont descriptorz font file ItalicAngle isFixedPitchrr#rr~rrr}i FamilyName2) rrFlagsFontBBoxrAscentDescent CapHeightXHeightFontFile FontFamilyStemVr6)Length1Length2Length3rE) rrrrKrascender descenderrrrHr+partsr)) rrr`fontdescObjectfontfileObject italic_angle fixed_pitchflagsft2font descriptors r4rzPdfFile.createType1DescriptorsQ++,=>++K8{{=1 kk.1   VOE  VOE  VOE   8$ 01 J 78 "<<'"++",,)!;;|4 " 4 .#((6<<3C*D,/ Q,@,/ Q,@,-!/  0 r6c|j|}dj|jjtj j tj j|d|gS)N-r)r\r+rLrrUr8splitextbasename)rr glyph_namer[s r4_get_xobject_glyph_namezPdfFile._get_xobject_glyph_nameUs] ]]8 $xx GGNN  GG  RWW--h7 8 ;  r6sO/CIDInit /ProcSet findresource begin 12 dict begin begincmap /CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def /CMapName /Adobe-Identity-UCS def /CMapType 2 def 1 begincodespacerange <0000> endcodespacerange %d beginbfrange %s endbfrange endcmap CMapName currentdict /CMap defineresource pop end endc \t}tjd|jdfdfd}fd}j |j |j jddt|jdxsd d d }|jd xsd d i}|j}|j} d } d} tj|vr| dz} | r| dz} n| dz} tj| vr| dz} td| |j D cgc] } | dc} |j"d|j$d|dd|d|d dd d } dk(r |||| Sdk(r |||| Sycc} w)z9Embed the TTF font from the named file into the document. pdf.fonttypeTc||z dz}|r t|S|dkrtj|Stj|S)z2Convert font coordinates to PDF glyph coordinates.r}r)rrxfloorceil)r3upenearestr/s r4cvtzPdfFile.embedTTF..cvtwsBSL4'EU|#qyzz%((yy''r6c #jd}#jd}#jd}#jd}g}d\}} jD cgc] }  | d} } td"|| |td |d | gd |td |d |d } ddlm fd} t j 5t jdt|| dzDcgc] }| | }}dddt|d<g}g}t}|D]a}|}j|}|j|j|}|dkr|j||fQ|j|c|jd}|D]:\}}||dzk7r|j||jt||}<t!!|}i}t#|D]}||}i}||vr/tdtd| d}||j%ddzd}#jd}#j'|||||vr"#j)!|}|#j*|<|||<#j-|| #j-||#j-||#j-|||Scc} wcc}w#1swYxYw)z5The Type 3-specific part of embedding a Truetype fontrrr~zcharacter procs)rrFrrType3r)MbP?rrrrrr}r) rr|rrrrrKr FontMatrix CharProcsr}rr)cp1252ctj|}j|tjtj zj }|S)Nr)rdecoding_table load_charrr NO_HINTINGr)charcoder2r}rrrs r4get_char_widthz?PdfFile.embedTTF..embedTTFType3..get_char_widthsT--h78Y//)2F2FF'HHS 5z!r6ignorer#NMaxWidthrrFormrrBBoxd1rcharProcrE)rrrK encodingsrwarningscatch_warningsfilterwarningsrrraget_char_indexr*raddsortrrfindrHrrrr)$r charactersrrrrcharprocsObjectdifferencesArray firstcharlastcharrBrrrrrr differencesmulti_byte_charsrccodegindrlast_crL rawcharprocs charprocscharnamestream charprocDictcharprocObjectrrrrrs$` @r4 embedTTFType3z'PdfFile.embedTTF..embedTTFType3s9--m@H  H Hs$K'K*K 9K KKc -jd}-jd}-jd}-jd}-jd}-jd}-jd} djd |D} tjd *| t j *| 5} t j | } d d d tjd *tj*j jj|} t| }td td,dddd|||d}td td,td|g| d}||d<-j|| jd| jjidgdz}g}d}|D]}|}|j!|}|j#|t$j&t$j(z}|j+|)|j,f|dkrt/|||<t1||}|j3|d |dz}d}g}d}g}|D]n\}}||dzk7r7|j+||j+|g|j+||gn|dj+|||dd<t1||}|}pg}|D]Q\}}|d kDr t5d |}|j+d!||d"jd#t7||dzDfzS-j8t;|d$j|fz}g} |D]1}t=+|r| j!|}| j+|3| j>D!cgc] }!)|!d%&}"}!tA*| }#tC|#D]|}$|#|$}%td'td(|"d)}&|%|%jEd*d+zd }%-jd,}'-j|'|%|&-jG*|$}(|'-jH|(<~dj|jKd-}-j||-j| |||d.<-jM||-jM||-jM||-jM|||S#1swYxYwcc}!w)/z6The Type 42-specific part of embedding a Truetype fontrzCID font dictionaryzType 0 font dictionaryzCIDToGIDMap streamzfont file streamz Type 0 widthsz ToUnicode mapc32K|]}t|ywr>)chrrs r4rz;PdfFile.embedTTF..embedTTFType42..s %dr CIDFontType2AdobeIdentityr)RegistryOrdering Supplement)rrr| CIDSystemInforW CIDToGIDMapType0z Identity-H)rrr|r}DescendantFonts ToUnicode FontFile2rrEirr#rrrs<%04x> <%04x> [%s]r&c3&K|] }d|z yw)s<%04x>Nr)rrBs r4rz;PdfFile.embedTTF..embedTTFType42..MsJy1}Jrr'Frrrrrrrutf-16ber)'rr+rUrVr$get_glyphs_subset font_as_filerUstatst_size getbuffernbytesrrKrHrqrrrrrr*rrrrrr_identityToUnicodeCMapr)rrrrrrrrrr).rrrrcidFontDictObjecttype0FontDictObjectcidToGidMapObjectrwObjecttoUnicodeMapObject subset_strsubsetfontdata full_font cidFontDict type0FontDictcid_to_gid_mapr max_ccoderrrr last_ccodew max_widthunicode_groupsr}unicode_bfrangestartrs unicode_cmaprrBrrrrrrrLrrrrrs. r4embedTTFType42z(PdfFile.embedTTF..embedTTFType42sL!//0ABN $ 2 23H I "&"4"45M"N  $ 2 23G H !//0BCN((9G!%!3!3O!D  < <>BaC5)BDB-h BL"<0 A%h/(,Y+/<(, .   E 2Q 6 78!%!3!3J!?!!.& !M33HhG2@))$/! A& WW^4;;JGN   / @   0, ?%.Jz "   . <   0- @   ^Z 8   Wa (& &G @ @@Cs>S*.S7*S4rrZpcltr) capHeightxHeightpost italicAnglerrFr#r r~rrr(r)) rrrrrrrrrrrrN)rr\rhrr#r get_charmaprrKget_sfnt_table face_flags style_flagsr FIXED_WIDTHrITALICrrr)rrrrrr&r'r*ffsfrsymbolicrBrrrrs`` @@@r4ruzPdfFile.embedTTFqs!<</ --t (h "TO 'O 'f,,      ..)4w-""6*LA!.L""6*E}f.E __     B & VOE  VOE VOE    " VOE )*8< B1Q.B$--74>>59T+.>4 ?+ .q1   q= z:> > ^!$ J? ?Cs0F) c|jj|d}||dSt|j}|t d|d|ddf|j|<|S)z?Return name of an ExtGState that sets alpha to the given value.Nrrr#)rCAca)rrSrTrrK)ralphastaterLs r4 alphaStatezPdfFile.alphaStatess  $$UD1  8OD))* D-(%(4 5  r6c |jj|d}||dSt|j}|j d}|t ddt dt ddg|d d f|j|<|j j|t d t d dt d t ddgddd|iigddt dtjgf|S)aA Return an ExtGState that sets the soft mask to the given shading. Parameters ---------- smask : Reference Reference to a shading in DeviceGray color space, whose luminosity is to be used as the alpha channel. Returns ------- Name Nrz transparency group for soft maskrFMask Luminosityr#)rrBCG)rAISSMaskrr Transparency DeviceGray)rCS)r#rrr#rrrr)rrr#r#)rrFormTypeGroupMatrixrr) rrSrTrrrKrr*rrW)rsmaskr;rLgroupObs r4_soft_mask_statezPdfFile._soft_mask_states&&**5$7  8OD''($$%GH [) Ll+#   ) u% %% Y<n-|,-'#u6$ #Y #'   r6c|j|jtg|jj |j j yr>)rrrrrr-rrs r4r)zPdfFile.writeExtGSTatessT   ! ! !!((*''..0  r6c|jD]B\}}}|j|jd||j||j Dyr>)rrrrr)rr5 attributescontents r4r*zPdfFile._write_soft_mask_groupssL'+'='=  #B G   RUUD* 5 DKK ! NN  r6c|\}}}}| t|}| t|}||||f}|jj|d}||St|j}||j|<|Sr>)rrrSrTr)r hatch_styleedgefacehatchlwpatternrLs r4 hatchPatternzPdfFile.hatchPatterns +dE2  ;D  ;DT5"- &&**;=  ND++,,0[) r63.10c |jjDcic]\}\}}}}||||fc}}}}}Scc}}}}}wr>)rr^)rrgrrhls r4zPdfFile.sJ,0,@,@,F,F,HCC(LQ1aAq!9 CCs= ct}d}|jjD]\}}|jd}|||<ddj Dcgc] }t |c}i}|j |jdt dddddd||g|||ddddd|jdzgd |\}} } } |j|d|d|d tj| M|j| d| d| d tjdd||tjtj |j| tj|j|j!t#j$| t'j)|d |jtj*|j-|j/|j0|ycc}w) NR@z hatch patternProcsetsrrr#rr) r PatternType PaintType TilingTyperXStepYSteprrIrFsimplify)rrr^rrrKrrr~rrrDrEr=r3rUpathOperationsr rUrscaler1rrrr) r hatchDictsidelenrRrLr5rBres stroke_rgbfill_rgbrUrVs r4r+zPdfFile.writeHatchessF !%!5!5!;!;!=  K##O4B IdO%D%J%J%LMDGMOC   ti !Q1!G!q!Q4;;+;< > ?/: +J% KK 1 z!}jm(( *# HQK!hqk//q'7BLLGG% KKBOO , DKK,, 5!   )-  ! KK ' NN A B ))95;NsG/ctdt|jz}|jd|}|jj ||||f||fS)a Add a Gouraud triangle shading. Parameters ---------- points : np.ndarray Triangle vertices, shape (n, 3, 2) where n = number of triangles, 3 = vertices, 2 = x, y. colors : np.ndarray Vertex colors, shape (n, 3, 1) or (n, 3, 4) as with points, but last dimension is either (gray,) or (r, g, b, alpha). Returns ------- Name, Reference zGT%dzGouraud triangle )rKr)rrr*)rpointscolorsrLr5s r4addGouraudTriangleszPdfFile.addGouraudTriangles:s\$FS!6!6778   "3D6 : ; $$dB%?@Rxr6cLt}|jD]n\}}}}|||<|j}|j|d|dzdf}|jd}|dvsJ|j|d|dz|f} |dk(rd}t j |ddz } t j |ddz} d | | z z } |j|jddd d d t|dk(rd nd d| d| d| d| dgddg|zzdt j|d|dzfdddd|ffg} d| d<|| z | z| d<| ddd|fdz| d<|j| j|jq|j|j|y)Nrr#rr#rrrrrlr-rrEF) ShadingTypeBitsPerCoordinateBitsPerComponent BitsPerFlag ColorSpace AntiAliasDecode)ru1)rpz>u4)rrqr}dtyperrpgo@)rrshapereshaperrrrrrKemptyrtobytesrrrr)r gouraudDictrLr5rprqr flat_pointscolordim flat_colors points_min points_maxfactor streamarrs r4r,zPdfFile.writeGouraudTrianglesQsf (,(=(='  $D"ff "K LLE ..%(U1X*=q)ABK||AHv% %% ..%(U1X*=x)HIK1} !4?J !4?J: #:;F   t !&(%& !#$,M[| $']JqM']JqM; !fx/0  qE!H$&&. $ 467I "#Ig #.#;v"EIh "-a(l";e"CIh  JJy((* + NN O' P ++[9r6c|jjt|d}||dSt|j}|j d|}|||f|jt|<|S)z=Return name of an image XObject representing the given image.Nr#zimage )rrSrrTrr)rr4entryrLr5s r4 imageObjectzPdfFile.imageObject}so   ED1  8ODOO$   & 0#($"3 RY r6cB|ddd}|jdk(r|dfS|ddddddf}tj|d}|jddk(rH|dddddfd}tj|d k(rd}||fStj|d}||fSd}||fS) z Unpack image array *im* into ``(data, alpha)``, which have shape ``(height, width, 3)`` (RGB) or ``(height, width, 1)`` (grayscale or alpha), except that alpha is None if the image is fully opaque. NrrrC)orderr).Nr)ndimrrrr)rimrgbr:s r4_unpackzPdfFile._unpacks "X 77a<t8OQ2A2X,C((3c*Cxx{a1a7 I.66%3,' E : HHU#6E: : r6ct}|j|d|jdd}dx}} tjd|j d\}}|dvrQ|j |}t ||k7r td|d k(rt|d}n+|d k(r|}n#|d k(r||z }n|d k(rn%|j|d |jdd |||fS)zn Write the image *img* into the pdf file using png predictors with Flate compression. rl)rgrur6Ns!L4s)IHDRPLTEIDATztruncated datarrrsIENDr#r) rsaveseekstructunpackreadr) RuntimeErrorrX) rimgbufferpng_data bit_depthpaletter3rrvs r4 _writePngzPdfFile._writePngs  & A"" G!==&++a.ALFD22{{6*t9&&'7887? #DG IW_"GW_$H FA& KK1 !"G++r6c f|j\}}}tdtd||tddd|dd}|r||d<tjd rX|jd d k(r|j d }d ||d}t j |} | jd} |dk(r| t| } tj| D cgc]\} } | D]}|c}} } tj}|dddjtjdz|d ddjtjdzz|dddz}|dddddfjtjdz|ddddd fjtjdzz|dddddfz}tj|jtj}|tj|||}t j |j!d} | j#||j%| \}}}|| t'd|d| dz}tdtd| d z |g|d<||d<d |d<||d<n|j%| \}} } nd}|j)||j+d|||r|j,j/n)|j,j/|j1|j3ycc}} } w) a Write the image *data*, of shape ``(height, width, 1)`` (grayscale) or ``(height, width, 3)`` (RGB), as pdf object *id* and with the soft mask (alpha channel) *smask*, which should be either None or a ``(height, width, 1)`` array. rrrErr#rru)rrWidthHeightrzrxrCrcrr#r ) PredictorColorsColumnsr) maxcolorsrNr~rr)sorterPzinvalid PNG headerIndexedrzrxrzlength of image stream)rl)rrKr\rhsqueezer fromarray getcolorsr)rruint8ruint32argsort searchsortedconvert putpaletterrrrrrrr)rrvrrJr~r}color_channelsrrlr img_colors num_colors_colorcompr palette24rgb24indicesrgb8rrs r4 _writeImgzPdfFile._writeImgs)- %~Iw-!l{"CN"ST#$ &  CL <<) *zz"~"|||, "nOC//$'C5J"z'=!_ ((#V#VXQPU#VD#VD#V)+3%addm22299=C%addm22299=BD$QTT]+ q!Qw-..ryy9R?q!Qw-..ryy9Q>@aAg'**Y/66rxx@ry%PQood+33C8w'/3~~c/B,)W$&';<<!/:>2%))_d;6G%/!^W%>L!*3&' !H *3&'!%!4!QC     7 8        $ $X .    $ $T\\^ 4 G$WsL, c|jjD]i\}}}|j|\}}|.|jd}|j ||j nd}|j ||j |ky)NrJ)rr-rrrr)rrrLr5rvadata smaskObjects r4r.zPdfFile.writeImagessw!\\002 5MCr,,s+KD% "009 uknn5" NN4 4 5r6c|j||d}t|t|t|||f} |jj | } | nt dt |jz} |jdt |jz} |j|} | | | |g|j| <| S| d|kr|| d<| d} | S)zDLL 112D##K#dll2C$CDB##E*D!%r4 4DLL   bzBr !9D r6c b|jjD]\\}}}}}\}}}} |j| dz}|j|jdt dt dt |jd|jtj|tj|jtj|tj|j||jtj|||j!y)Nrrr)rr^paddedrrrKrextentsrrrrrK capstylesrLr6r) rrr3r2rrrLr5rrVs r4r/zPdfFile.writeMarkers#s&*ll&8&8&:  # 9gtVY !dBb;;rAv&D   tiT&\dll+- . KK*55i@ ( KK*44X> N DKK ! KK dF3 4 NN ' r6c tdt|jz}|jdt|jz}|jj |||||j |j |||f |S)NzP%dzpath %d)rKr)rrr* get_joinstyle get_capstyle) rrr8r9r;r<r=rLr5s r4pathCollectionObjectzPdfFile.pathCollectionObject9sxEC O+,    C O ; <  4B$4$4$68I fg ' ( r6c |jD]h\ }}}}}}}}} |j||d} |j|} tjtj | j sgd} n&| j|} t| j } |j|jdtdtd| d|jtj|tj |jtj"|tj$|j| |jtj'|| |j)ky)NFrfrrrrrrr)rrhrrrrrrrrrrKrrrrrKrrLr6r) rrLr8r9r5rrr;r<r=rrrs r4r0z$PdfFile.writePathCollectionTemplatesAs(  T4Ix& ))$)FG##E*D66"++dll34&{{7+t||,   tiT&\ " # KK*55i@ ( KK*44X> N DKK ! KK fg6 7 NN % r6cttj|||||dtjj tj j dtjj tjj gdgS)Nrr6T) rr"rrr?r/r>r<r8)r8rrVrgsketchs r4rhzPdfFile.pathOperationsVsg00 )T8V YY__biioosBJJ4D4D \\   !   r6c|r-dd|jdz|jdzf}|j}nd}d}|j|||||}|j|y)NrrF)rgr)r}r~should_simplifyrhr)rr8rrVrrgcmdss r4 writePathzPdfFile.writePath_sg djj2ot{{R/?@D++HDH""4D8*0#2 Tr6c~t|j}|jjdd|gt |S)z Reserve an ID for an indirect object. The name is used for debugging in case we forget to print out the object with writeObject. Nr)rTrrr*r)rrLrs r4rzPdfFile.reserveObjectjs6$"" # tQo.}r6cr|jj|jz |j|d<yNr)rdrkrrrs r4rgzPdfFile.recordXrefus( $  ?r1r6c^|j|j|j||yr>)rgrr)robjectrs r4rrzPdfFile.writeObjectxs   " Xt$r6cT|jj|jz |_|j dt |j zt|j D]=\}\}}}|td||fz|dk(rdnd}d|||fz}|j |?y)zWrite out the xref table.s xref 0 %d NzNo offset for object %d (%s)rrr!s%010d %05d %b ) rdrkr startxrefrr)rr(AssertionError)rr1offset generationrLrr s r4r2zPdfFile.writeXref|s$..8 ?S%889-6t~~-F ! )A) D~$2aY>@@#&77dT*fj#-FF 4  !r6c||jd|_|j|j|jy)z8Write out the info dictionary, checking it for good formrfN)r infoObjectrrrrs r4r1zPdfFile.writeInfoDicts.,,V4 $--8r6c|jd|jtt|j|j|j d|jd|j zy)zWrite out the PDF trailer.strailer )SizeRootInfos startxref %d %%%%EOF N)rrr)rrrrrs r4r3zPdfFile.writeTrailersZ <  7(____ &' ( 04>>ABr6r>rz)NNNFN)r)8rrrrrrrr#r>r@rrrrrHr'r\ror(rsrqrrrrur<rLr)r*rXr deprecatedproperty hatchPatternsr+rrr,rrrrr.rr/rr0 staticmethodrhrrrgrrr2r1r3 __classcell__rs@r4rrs<g9R":.@-* B + ?& 04 8><1* 8t=~*|@| 2h  ",ODOOF+H6-M$6L.*:X .,:=~5:,*  @% !9 Cr6rceZdZejdZdZfdZdZddZ dZ ddZ dd Z d Z dd Zd Zdd ZdZdddZdZddZdZdZxZS)rQzfonts/pdfcorefontsrKclt|||||_|j|_||_yr>)rrrnew_gcr image_dpi)rrrr~r}rs r4rzRendererPdf.__init__s- ' ++-"r6cf|jj|jjyr>)rrrr>rs r4r>zRendererPdf.finalizes# $''**,-r6Nct|dd}||_t|dd}|j|jdd|jr|j |j f|_n@|t|dkr|jd d f|_n|jd |d f|_|jj|}|r|jj|||_||_y) N _fillcolorrrr_effective_alphasrrrT)isRGBArrr) getattrrget_rgbset_foreground _forced_alpha_alpharr)_rgbrdeltarr)rr fillcolor orig_fill orig_alphasr s r4check_gczRendererPdf.check_gcsB l; ! b"5zB ::<    l4  8  $&IIryy#9B  #i.1"4$&GGAJ#4B $&GGAJ ! #=B  b!  DII  e $" *r6c |jdz S)Nr_)rrs r4get_image_magnificationz#RendererPdf.get_image_magnifications~~d""r6c|jdd\}}|dk(s|dk(ry||jd|j|d|z|jz }d|z|jz }|jj |}|^|jj tj|dd|||tj|tjtj y|jj\} } } } } }|jj tjdddd||tj| | | | | |tj|tjtjy)Nrrrr_r#)r set_alpharrrrrrrNr@rArOfrozen to_values)rrrBr|rrr[r imobtr1tr2tr3tr4tr5tr6s r4 draw_imagezRendererPdf.draw_images8xx|1 6Q!V    LL  b 1Ht~~ % 1Ht~~ %yy$$R(   II  RXX1aAr/?/?!2>>2;; @,5+;+;+=+G+G+I (Cc3S II  RXX1aAr/?/? #sCc2;K;K!2>>2;; @r6c|j|||jj|||duxr|jdu|j |jj |j jyr>)rrrget_hatch_pathget_sketch_paramsrrpaint)rrr8rrgbFaces r4 draw_pathzRendererPdf.draw_pathsk b'"  ) tO ; 1 1 3t ;  " $ )r6cd}tj|}tj|}t|sd}|j }n-tj|dddf|dk(r |ddk7}nd}t|sd}n[tjtj| dk(rd}n-tj|dddf|dk(r |ddk7}nd}t|dkDrt|dj nd}|j |||||}||zdz||zk}|r|s"tj|||||||||| | | | | Stj| }g}t|j|||D]9\}\}}|jj||||}|j|;|jj}||j j#d\}}|j%||||||| | | | | D]T\}}}} }!|j'| |!||z ||z }#}"|d ddd |"|#t(j*|t(j, ||}}V||j j/y) NTFr)rrrrrr,r#)rasarrayr) get_hatchrr_iter_collection_uses_per_pathrdraw_path_collectionrr(_iter_collection_raw_pathsrrr*rrpush_iter_collectionrrr@rApop)$rrmaster_transformrall_transformsoffsets offset_trans facecolors edgecolors linewidths linestyles antialiasedsurlsoffset_positioncan_do_optimizationr<r=len_path uses_per_pathshould_do_optimizationr; path_codesr1r8rrLrlastxlastyxoyopath_idgc0r!dxdys$ r4r'z RendererPdf.draw_path_collections#ZZ + ZZ + :F&(lln"4 vvjA&*T*::;#D)S0&+#:Gvvbjj,34 1a4(Jt,<<=$T*c1&+# .1Z!^3uQx(();; >7J D  } $q (8m+C C $-C44b*E>z:J d ! ! &&$ $-d.M.M %/9%: $ A i9911D)Wfg?D   d #  $ !!  u-1-B-BJJ JdO.5 " )BGS' MM#w '%ZeB 1aAr2r'7'7>> #r5E "  r6c t|}t|}||z||zdzkrtj|||||||y|j|||j |} |j } |j j} |j j||| | |jj|j|j} | tjd\} }|j|dd|j j dz|j j"dzfdD]\}}t|s|dd\}}d|cxkr|j j dzkr'nn$d|cxkr|j j"dzksnd|| z ||z }}| dddd||tj$| tj& ||}} | tj(y) Nrr,rrF)rVrgrr#)r)r draw_markersrr3r2rrrr _linewidthrrrrN iter_segmentsr}r~r@rArO)rr marker_path marker_transr8r9r!len_marker_pathusesr3r2rmarkerr<r=rcoderBr|rBrCs r4rEzRendererPdf.draw_markers4s k*4y T !Od$:Q$> >  % %dB \&*E7 <  b'"www!!'' tVTWW5G5G     13 rxx u"00DIIOOB. 0@0@0CD1 $NHd8}}1Q6$))//B"66;dii&6&6&;;UAIBq!Q2r2+;+;r~~/ !u $ r{{r6ct|t|k(sJt|dk(ry|jdk(sJ|jddk(sJ|jddk(sJ|jdk(sJ|jddk(sJ|jddvsJ|j}|j|d|dzdf}|j |}|j|}|j j ||\}}|j j} |jddk(r:|jd|j|| |tjy|d} tj| |dddddfr:|j| |j|| |tjy|dddddfdddddf} |j j || \}} |j j| } | tj| tj |tjtj"y)Nrrr#rrtr)rrr)r)rrrrrrrrrrrrWrallcloserLrNrMrO) rrrprqr9rtpointsrLrrr:smask_obgstates r4draw_gouraud_trianglesz"RendererPdf.draw_gouraud_trianglesZs6{c&k))) v;!  {{a||A!###||A!###{{a||A!###||A&((( qE!H!4a 89//&)//%())//@a!! <<?a  LL  MM"  4 $ w ;;ufQ1Wo . LL  MM"  4 $1a7OAq$J/E))77GKAxYY//9F 288VR\\;; r6c ||cxk(rdk(r5nn2|jj||z ||z tjyt j |}|jjt j |t j|t j| t j |||tj|jjddtjyr) rrrrPrxryr{rzrR)rrBr|roldxoldyoldangles r4_setup_textposzRendererPdf._setup_textposs H ! ! II  QXq4x <LL'E II  TXXe_dhhuo"hhuo-txx2== 2 II  Q2:: .r6c |jjj|d|\}}} } } |j9|jj ddj t||||||tjd} tj|} |jjtj|jjtj| tj | tj |  tj| ||tj"|j%||j&d}d\}}g}|jjtj(| D] \}}}}}|jj*j-|||j.}t1| |s|j |||||f_|j3||d||||}}||f|k7rH|jj|jj5||tj6||f}|jj|j9t;|| tj< |jjtj>|D],\}}}}}|jA|||jC|||.| D]a\}}}}|jjtj||||tjDtjFtjHc|jjtjHy)Nrrr#rrzr,r)% _text2pathmathtext_parserparserrrr*rr\rhrxryrrrNr{rzr@rr r:r track_glyphrZrrXr\rQ encode_stringrrSr;_draw_xobject_glyphrr=r3rO)rrrBr|r2rrr}r~descentglyphsrectsrr prev_fontrUrVunsupported_charsrfontsizenumoxoyrs r4 draw_mathtextzRendererPdf.draw_mathtexts OO + + 1 1!R > .vw ::< # II " "2 &q ) 0 01EAq%20 1<</ LL  " !dhhqk((1+txx{Ar// 1 b"''"  d '+1 * 'D(CR II ( ( 4 4T3 ?zzH'#6"(($"b#)FG##BAtT:dh'94II$$TYY%7%7%A8%']]4 (( 2I   !3!3CHh!G!#* * %+< B 'D(BC  $ $h 3 3C 8"b B B &+ A !BE6 II  RXXr2uf\\277BKK A A %r6)mtextc |j}|j} |j|| } tj| d5} | \} ddd|j M|j jddjt||| j| j|dg}}  jD]V\}}}}}|| k7r0|j j|}|d||jggz }|} |d||t|gg||zggz }Xd\}}} |t!|dz kr|||dz\}}|ddk(r|d} n|d|dcxk(rdk(r~nn{|d|dk(rp|d |dz }t#|d kr-|d dxx|d dz cc<|d xx|d |dz z cc<n#|d xx|d z| z |d dgz cc<|d |d <||dz=|dz }|t!|dz krt%j'|j)||}|j+||j,|j j/t0j2d \}}}}|D]}|ddk(r2|j j/|d|dt0j4=|ddk(r|j7|d|df\}}|j9|||||||}}t!|d dk(r1|j j/|d dt0j:|j j/|d t0j<J|j j/t0j>|jA}|jC||jEdtFjHtFjJtFjJtFjJtFjLg}| jND]L\}}} }!tG||g||!z|g||!z|| zg||| zgddgg|}"|jQ||"||j,Ny#1swYxYw)Nrrr#rr )rrNrrrg?rg@@r))get_texmanagerget_size_in_pointsmake_dvir Dvirrrr*rr}r~r rosizerr)absr rotate_degrrr rrr:rQrrXrSrTr;rcopy_properties set_linewidthr MOVETOLINETO CLOSEPOLYboxesr")#rrrBr|r2rrrj texmanagerredvifiledviroldfontseqx1y1r^rr}r_r1curxeltnxtrmytranscuryrUrVboxgcrr[r r8s# r4draw_texzRendererPdf.draw_texsS((* **,%%a2 [[" % ED  ::< # II " "2 &q ) 0 01EAq$**dkk52: ;R-1YY B )BGUE'!))//8',,788! VReUGn%5r%x@A AC  B'4#c(1*n1QqSzHC1vq6Q3q6+V+A#a&0@Q#a&v;$F2J#a&)+JFc!fSVm+FFvf}X5s1vayAAF VCF!H FA#c(1*n"*''.88A> b"''" '!+dD$ C1v   QQ?Q6!$..AA/?@ d##D$tTB!4ds1v;!#II$$SVAY8II$$SVR[[9u  %  b! A;; T[[$++>># JJ :LBAq"bBqD":1bd|b"Q$ZQ!")+D NN5$ 9 :S  s QQ$cR|dvr|jddS|jddS)NrrrZr )r)rr2rs r4r^zRendererPdf.encode_string s, v 88Hi0 0xx I..r6c  |j||j|r|j||||||S|j} tj dr|j |} d} nJ|j|} |jjj| |tj d} |jc| j|| j\} } |jjddjt!|||| dz | dz || dvr|jj#t$j&|jj)|| t$j*|j-||||jj#|j/|| t$j0t$j2yg}g}d}| }t5j6|| t8j:D]}t=| t?|j@r|s|jB|k7r4|j|jB|jDgf|jB}|jFr!|dd j|jF|dd j|j@d }|j|jB|jD|jHfd}|jj#t$jJtMjN|}|jj#tMjP|tMjR|tMjR| tMjP|||t$jT|jj#t$j&d }|D]\}}}|jj)|jV}|jj#|| t$j*|j-|d d |d d |jj#tYjZ|t\Dcgc]@\}}|t^k(rd ta|z| z n |j/d jc|| Bc}}t$jd|}|jj#t$j2|D]\}}}|jg|| ||d |jj#t$jhycc}}w)NrKr#rrr~)rrT) kern_moderFrir)5rr rirmr\rh _get_font_afm _get_font_ttfrrtrackrset_textget_width_heightrr*rrrr:r\rQrXr^rSr;r layoutrUNFITTEDrrchar ft_objectrB prev_kern glyph_idxrNrxryr{rzr@rZrgroupbyrrrTr+rTr_rO)rrrBr|r2rrismathrjrerrr}r~singlebyte_chunksmultibyte_glyphsprev_was_multibytercitemr prev_start_xrstart_xkerns_or_charsft_nametpgrouprs r4 draw_textzRendererPdf.draw_text sB b"''" %%b!Q4? ?**, <<, -%%d+DH%%d+D II ( ( . .tQ 7||N3H ::< # MM!  113ME6 II " "2 &q ) 0 01EAq%"*frk52: ; 7 " II  R]]!YY//5x P   1e , II  T//8<WWbkk 3$!# ! !% I%,,Q@P@PQ .'#dii.A)T^^y-H)00$..$&&"1MN$(NN ~~)"-a077G%b)!,33DII>).&$++T^^TVVT^^,TU)-& . II  RXX & U#A II  TXXa[$((1+"hhqk\488A;2#3#3 5 II  R]] +L6G '2 7N)),,Y__=   (BMMB##GQ<AF   '0&7&7&MO"U8:U{UT%[(83,,RWWU^XFGOKK ! '  ' II  R[[ )1A - 7I((xGQ  II  R[[ )Os?AU c J|j|}|jj|j|}|jj t j d|zddd|z||t jt|t jt j y)z)rrrs r4rzRendererPdf.new_gc s!$)),,r6r>rr)rrrr _get_data_pathrR_use_afm_rc_namerr>rrrr"r'rErSrXrirr^rr_rrrs@r4rQrQs(E(()=>M+# .+6#@<*DN"$L& P/4&l;?Q:f/ _*B  -r6rQc eZdZfdZdZdZdZdZdddd Zdddd Z d Z d Z d Z dZ dZdZdZdZdZdZdZdefdefde fdefde fde fde fdefdeff ZdZfd Zd!ZxZS)"rcZt|d|_d|_||_d|_y)Nrr)rrrrrparent)rrrs r4rzGraphicsContextPdf.__init__ s+ )!+  r6cNt|j}|d=|d=t|S)Nrr)rrrepr)rrss r4rzGraphicsContextPdf.__repr__ s'   fI hKAwr6c|jdkDxr=|jdkDxr,t|jdkxs|jddk7S)z Predicate: does the path need to be stroked (its outline drawn)? This tests for the various conditions that disable stroking the path, in which case it would presumably be filled. rrr)rFrr)r rs r4r2zGraphicsContextPdf.stroke sK!#= a=TYY1$; ! (; >r6ct|r|d}n |j}|jxs|duxrt|dkxs|ddk7S)z Predicate: does the path need to be filled? An optional argument can be used to specify an alternative _fillcolor, as needed by RendererPdf.draw_markers. rNrr)r)r_hatch)rargsrs r4r3zGraphicsContextPdf.fill sX t9aJJ A4'@j/Q&>*Q-3*> Br6cftj|j|jS)zo Return the appropriate pdf operator to cause the path to be stroked, filled, or both. )rr6r3r2rs r4r zGraphicsContextPdf.paint s! }}TYY[$++-88r6rr#r)buttr projecting)miterrbevelc@|j|tjgSr>)rrrLrstyles r4 capstyle_cmdzGraphicsContextPdf.capstyle_cmd su%r}}55r6c@|j|tjgSr>)rrrKrs r4 joinstyle_cmdz GraphicsContextPdf.joinstyle_cmd s&77r6c&|tjgSr>)rrU)rr}s r4 linewidth_cmdz GraphicsContextPdf.linewidth_cmd sr''r6cP|\}}|g}d}t||tjgSr)rrrJ)rdashesrdashs r4dash_cmdzGraphicsContextPdf.dash_cmd s/  <DFT FBJJ//r6c\|jj|}|tjgSr>)rr<rrM)rr:forcedeffective_alphasrLs r4 alpha_cmdzGraphicsContextPdf.alpha_cmd s&yy##$45bll##r6c6|sB|j|j|jStdtjgS||j||f}|j j |}tdtj|tjgS)Nrr)r fillcolor_cmdrKrrGrrXrI)rrU hatch_colorhatch_linewidthrRrLs r4 hatch_cmdzGraphicsContextPdf.hatch_cmd s*))$//::[)2+E+EFF&PK99))+6DOR%?%?"//1 1r6ctjdrgS|d|dcxk(r|dk(rnn|dtjgSg|ddtjSNzpdf.inheritcolorrr#rr)r\rhrrBrDrrs r4rgb_cmdzGraphicsContextPdf.rgb_cmd s^ <<* +I q6SV %s1v %FB--. ./S!W/b../ /r6c|tjdrgS|d|dcxk(r|dk(rnn|dtjgSg|ddtjSr)r\rhrrCrErs r4rz GraphicsContextPdf.fillcolor_cmd sb ;#,,'9:I Vs1v 'Q 'FB001 12S!W2b112 2r6ct|j}|j||j|_||_tj gSr>)rrrsrrrN)rrs r4r)zGraphicsContextPdf.push s<#DII.t$   zr6c|jJ|j|j|jj|_tjgSr>)rrsrrOrs r4r+zGraphicsContextPdf.pop sA{{&&& T[[)kk((  }r6cg}|j|jf||fk7rU|jI|j|j |j|jf||fk7r |jI|j|jf||fk7s |j|j|j |j|k7r?|j|t jt jt jg|j|k7r[|j\}}|jtj||dt jt jgz|S)z1Set clip rectangle. Calls `.pop()` and `.push()`.Frf) _cliprect _clippathrrr+r)rr=rVr4get_transformed_path_and_affinerrh)rcliprectclippathrr8affines r4clip_cmdzGraphicsContextPdf.clip_cmd s#/Hh3GGKK+ KK #/Hh3GGKK+^^T^^ ,80D D # KK $~~) Xr||RWWbjjIJ~~)'GGI f **4%*HWWbjj)*+ r6)rr)rrr) _capstyle)r) _joinstyle)rF)_dashes)r )r _hatch_color_hatch_linewidthc ~g}d}|jD]\}}d}|D]6}t||}t||} || || u}nt|| k7}|s6n|jdk(r|rd}|sY|jdk(rd}|Dcgc]}t||} }|j||g| |D]}t||t|||S#t$r`t j |}t j | } |j | j k7xst j|| k7}YwxYwcc}w)z} Copy properties of other into self and return PDF commands needed to transform *self* into *other*. FrTr) commandsrrrrr$ranyrrsetattr) rrrfill_performedparamscmd differentpourstheirss r4r zGraphicsContextPdf.delta s\ == 8KFCI tQ' * 9|v~$($6 $($8  "||{*~ <zGraphicsContextPdf.finalizeN s6kk% KK #kk% r6)rrrrrr2r3r rrrrrrrrrrr)r+rrr rsr>rrs@r4rr s > B9Qa8Iq15J68(0$ 103 , $X. 99E & -( -( -( x G 7C H$L 2r6rceZdZdZej dddddZdZd Zd Z d Z d Z dd Z dZ gdfdZy)PdfPagesa= A multi-page PDF file. Examples -------- >>> import matplotlib.pyplot as plt >>> # Initialize: >>> with PdfPages('foo.pdf') as pdf: ... # As many times as you like, create a figure fig and save it: ... fig = plt.figure() ... pdf.savefig(fig) ... # When no figure is specified the current figure is saved ... pdf.savefig() Notes ----- In reality `PdfPages` is a thin wrapper around `PdfFile`, in order to avoid confusion when using `~.pyplot.savefig` and forgetting the format argument. rY keep_emptyzThis parameter does nothing.)addendumNc.||_||_d|_y)a Create a new PdfPages object. Parameters ---------- filename : str or path-like or file-like Plots using `PdfPages.savefig` will be written to a file at this location. The file is opened when a figure is saved for the first time (overwriting any older file with the same name). metadata : dict, optional Information dictionary object (see PDF reference section 10.2.1 'Document Information Dictionary'), e.g.: ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``. The standard keys are 'Title', 'Author', 'Subject', 'Keywords', 'Creator', 'Producer', 'CreationDate', 'ModDate', and 'Trapped'. Values have been predefined for 'Creator', 'Producer' and 'CreationDate'. They can be removed by setting them to `None`. N) _filename _metadata_file)rrrrcs r4rzPdfPages.__init__m s."! r6c|Sr>rrs r4 __enter__zPdfPages.__enter__ s r6c$|jyr>)r@)rexc_typeexc_valexc_tbs r4__exit__zPdfPages.__exit__ s  r6c~|j&t|j|j|_|jS)Nrc)rrrrrs r4 _ensure_filezPdfPages._ensure_file s, ::  $..IDJzzr6c|j<|jj|jjd|_yy)z_ Finalize this object, making the underlying file a complete PDF file. N)rr>r@rs r4r@zPdfPages.close s: :: ! JJ   ! JJ   DJ "r6c6|jjS)z Return a modifiable information dictionary object (see PDF reference section 10.2.1 'Document Information Dictionary'). )rrrs r4infodictzPdfPages.infodict s   "+++r6c t|tsR|tj}ntj|}|t d||j j}|j|fddd|y)a5 Save a `.Figure` to this file as a new page. Any other keyword arguments are passed to `~.Figure.savefig`. Parameters ---------- figure : `.Figure` or int, default: the active figure The figure, or index of the figure, that is saved to the file. Nz No figure r)rgrb) r?rr get_activeget_fig_managerrcanvasfiguresavefig)rrkwargsmanagers r4rzPdfPages.savefig so&&)~..*--f5 :fX!677^^**FtCE5CFCr6cHt|jjS)z=Return the current number of pages in the multipage pdf file.)r)rrrs r4 get_pagecountzPdfPages.get_pagecount s4$$&//00r6r cD|jj||y)z Add a new text note to the page to be saved next. The optional positionRect specifies the position of the new note on the page. It is outside the page per default to make sure it is invisible on printouts. N)rr)rr rs r4 attach_notezPdfPages.attach_note s ''l;r6rzr>)rrrrr delete_parameterrrrrr@rrrr rr6r4rrX s`(T6<$BDD2 ,D,1.@eZdZdZddiZdZddddZfdZxZS) FigureCanvasPdfrrzPortable Document Formatcy)Nrrrs r4get_default_filetypez$FigureCanvasPdf.get_default_filetype sr6N)bbox_inches_restorercc |jj}d|j_|jj\}}t|tr|j }n t ||} |j||t|j|||t|||||}|jj||jt|ts|jt|tr|jy|jy#t|tr|jw|jwxYw)Nrr)r)rdpiget_size_inchesr?rrrrrrQdrawr>rr@) rrrrcrr}r~rrenderers r4 print_pdfzFigureCanvasPdf.print_pdf skkoo  335 v h )((*D8h7D  LL '( UFCD#vu5$79H KK  X &    h1 (H-  (H-  s 4BD**3EcT|jjt| Sr>)rdraw_without_renderingrr)rrs r4rzFigureCanvasPdf.draw s **,w|~r6) rrr fixed_dpi filetypesrrrrrs@r4r r  s0I23I'+T4r6r ceZdZeZy) _BackendPdfN)rrrr  FigureCanvasrr6r4rr s"Lr6r)K)r)_rrrrenumr functoolsriorrloggingrxrUrrrrprirrinumpyrPILr matplotlibr\r r r r r matplotlib._pylab_helpersrmatplotlib.backend_basesrrrrr!matplotlib.backends.backend_mixedrmatplotlib.figurermatplotlib.font_managerrrrOmatplotlib._afmrmatplotlib.ft2fontrrrrrmatplotlib.transformsrrmatplotlib.pathr matplotlib.datesr!r"rr$ getLoggerrrUr5rjrvrrrr@ maketransrrrrrKrrrZrrRendererPDFPSBaserQrrr FigureManagerPdfexportrrr6r4r5s $  FF)@$IQQ4 w"d,Tn 0,"*04}} u5UDE F#R  .   BA#A#HZ$Z$z+\DCDCN(m-/33m-`J,JZn<n