
    }f<0                         d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ 	 ddlmZ n# e$ r d	ZY nw xY wd
ZdZdZdZ G d de
          Z G d de          Z G d de	          Z G d de          Zd	S )z
This module is in work-in-progress state.
Hint tables / hint streams have not been implemented yet,
and there are a few "TODO" comment remaining.
cf. https://github.com/py-pdf/fpdf2/issues/62
   )ContentWithoutIDOutputProducer	PDFHeader)sign_content)PDFArrayPDFContentStream	PDFObject)iobj_ref)buffer_subst    )signerNz0%1%2%3%4%5%6%7%8%9%a%b%c%dz1%2%3%4%5%6%z2%3%4%5%6%7%z3%4%5%6%7%8%c                        e Zd Z fdZ xZS )PDFLinearizationc                     t                                                       d| _        || _        t          | _        d | _        t          | _        t          | _
        t          | _        d S )N1)super__init__
linearizedn%HINT_STREAM_OFFSET_LENGTH_PLACEHOLDERho!FIRST_PAGE_END_OFFSET_PLACEHOLDERe&MAIN_XREF_1ST_ENTRY_OFFSET_PLACEHOLDERtFILE_LENGTH_PLACEHOLDERl)selfpages_count	__class__s     K/var/www/rtfcompare/venv/lib/python3.11/site-packages/fpdf/linearization.pyr   zPDFLinearization.__init__   sN    627(    __name__
__module____qualname__r   __classcell__r!   s   @r"   r   r      s8        
) 
) 
) 
) 
) 
) 
) 
) 
)r#   r   c                   L    e Zd ZdZd Zed             Zed             ZddZdS )PDFXrefAndTrailerz0%1*2+3-2/1^c                     || _         |j        dz   | _        d| _        d | _        d | _        d | _        d | _        d | _        d S )Nr   )	output_builderobj_idcountstart_obj_idcatalog_objinfo_obj
first_xref	main_xref	startxref)r   r-   s     r"   r   zPDFXrefAndTrailer.__init__*   sI    ,#*Q.
r#   c                 *    t          | j                  S N)boolr4   r   s    r"   is_first_xrefzPDFXrefAndTrailer.is_first_xref6   s    DN###r#   c                 *    t          | j                  S r7   )r8   r3   r9   s    r"   is_main_xrefzPDFXrefAndTrailer.is_main_xref:   s    DO$$$r#   Nc                 |   | j         }g }t          t          |j                            | _        | j        r9t          |j        | j        | j                            dd                    |_        |	                    d           |	                    | j
        dk    rdn| j
         d| j                    | j        s|	                    d           t          |j                  dk    s
J d            t          | j
        | j
        | j        z             D ]&}|	                    |j        |         dd	           '|	                    d
           |	                    d           | j        r,|	                    d| j        | j        j        z
              n| j        r@|	                    d| j        j                    |	                    d| j                    n|	                    d| j                    |	                    dt#          | j        j                              |	                    dt#          | j        j                              |j        }|                                }|dk    r|                    |j                  }|r|	                    d| d           |	                    d           |	                    d           | j        }| j        r| j        j        }| j        rd}|	                    |           |	                    d           d                    |          S )N    xrefr   r   z0000000000 65535 f z<TODO: how to know the offsets in the 1st xref at this stage?010z	 00000 n trailerz<<z/Size z/Prev z/Root z/Info z/ID []z>>r5   0z%%EOF
)r-   strlenbufferr5   r<   r    PREV_MAIN_XREF_START_PLACEHOLDERrjustappendr0   r/   r:   offsetsranger3   r4   pdf_refr1   idr2   fpdffile_id_default_file_idjoin)r   _security_handlerbuilderoutr.   rQ   rR   r5   s           r"   	serializezPDFXrefAndTrailer.serialize>   s1   %S0011 	)5$$R-- GN
 	

6

4,11aat7HWW4:WWXXX! 	.JJ,---  1$$$I %$$D-t/@4:/MNN 	B 	BFJJ'/&1@@@@AAAA

9

4 	/JJD
T_-B BDDEEEE! 2

:DN$8::;;;

KD$IKKLLLL

0DJ00111JJ>(8(; < <>>???JJ;(8 9 9;;<<<<DllnnG"}}//?? /

-7---...

4

;N	 	21I 	I

9

7yy~~r#   r7   )	r%   r&   r'   rJ   r   propertyr:   r<   rX    r#   r"   r+   r+   '   ss        '5$
 
 
 $ $ X$ % % X%. . . . . .r#   r+   c                         e Zd Zd fd	Z xZS )PDFHintStreamFc                     t                                          ||           d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d S )N)contentscompress)r   r   sr   r   ar   vicr   rb)r   r^   r_   r!   s      r"   r   zPDFHintStream.__init__p   sq    (X>>>r#   )Fr$   r)   s   @r"   r\   r\   o   s=                 r#   r\   c                       e Zd Zd ZdS )LinearizedOutputProducerc           	      d   | j         }| j                            t          |j                             t          |j                  }|                     |           t          |           }| j                            |           | 	                                }t          d          }| j                            |           |                     t          dd                    }| j        dz   |_        t          | j                  }d| _        |                    |                     t          dd                                |                                 }|                                 }	|                                 }
|                                 }|                                 }|                     |
||          }|j        D ]}|                     |d           |                                 }|                                 \  }}|                                 }|                                 }t          |           }| j                            |           | j        dz   |_        |D ]7}t;          |t<                    s ||ur| xj        dz  c_        | j        |_        8| xj        dz  c_        | j        |_        |d         j        |_         tC          |          |_"        | #                    |||d         |	|||           g }|D ]}||_$        ||_%        |j&        D ]^}|j'        r|                    |j'                   |j(        r4tS          |j(        d          r|                    |j(        j'                   _|j&        sd |_&        |D ]}|                    |j'                   |D ])}tU          ||j+        dz
           j                  |_,        *|j-        j.        j/        D ]$}||+                                dz
           |_0        %||_1        ||_2        ||fD ]}||_3        ||_4        | j5        rJ d| j5                     | j6        rJ dto          | j6                               | j        D ]}t;          |t<                    rd }n@to          | j5                  | j6        |j        <   | j8        9                    |j                  }|rU| :                    |          5  | ;                    |<                                           d d d            n# 1 swxY w Y   | ;                    |<                                           | =                                 | j6        |j                 }to          |<                                          }t}          | j5        t~          d	|d
d|d
d          | _5        t}          | j5        t          | j6        |d         j        dz            d
          | _5        t}          | j5        t          | j6        |j                 d
          | _5        t}          | j5        t          to          | j5                  d
          | _5        |jC        r=t          t          | j5        |jC        |jF        |jG        |jH        |jI                  | _5        | j5        S )N r   r   embedded_files)pages_root_objfirst_page_objsig_annotation_objxmp_metadata_objstruct_tree_root_objoutline_dict_objdestz@Nothing should have been appended to the .buffer at this stage: z.No offset should have been set at this stage: [z 12dr?   rD   )JrQ   pdf_objsrL   r   pdf_versionr   r    _add_pdf_objr+   _add_catalogr\   
_add_pagesslicer.   r/   listextend_add_pages_root_add_annotations_as_objects
_add_fonts_add_images_add_gfxstates_add_resources_dictrk   _add_structure_tree_add_document_outline_add_xmp_metadata	_add_infor0   
isinstancer   rP   r   r   kids_finalize_catalogparent	resourcesannotsrr   ra   hasattrrO   page_numberpage_refstruct_builderdoc_struct_elemkpgr3   r4   r1   r2   rI   rM   rH   trace_labels_per_obj_idget_trace_size_outrX   _log_final_sections_sizesr   r   r   r   r   	_sign_keyr   r   
_sign_cert_sign_extra_certs_sign_hashalgo
_sign_time) r   rQ   linearization_objr3   r1   hint_stream_obj	page_objsfirst_xref_pdf_objsrl   rn   font_objs_per_indeximg_objs_per_indexgfxstate_objs_per_nameresources_dict_objembedded_filerp   rq   outline_itemsro   r2   r4   pdf_objdestspage_objannotoutline_itemrr   struct_elemr@   trace_label
hs1_offset
hs1_lengths                                    r"   	bufferizez"LinearizedOutputProducer.bufferize   s   y 	Yt'788999,T-=>>+,,,&t,,
Z(((''))'++_---OOE!QKK00	  ;?
"4=11 	q$88999 --//!==??"oo//!--//!%!4!4!6!6!55!35K
 
 "0 	? 	?Mm-=>>>>#7799*.*D*D*F*F'-1133>>##%d++	Y''' #'+/
* 	- 	-Gw(899-?22q !%q![ (lo&y11)$Q<1-!5- 	 	
 	
 	
 ! 
	' 
	'H,HO!3H! / /: -LL,,,7 /wuw77 /LL...? '"&) 	, 	,LLL*++++ 	H 	HD#Id.>.B$C$FGGDMM.>@ 	F 	FK&{'>'>'@'@1'DEKNN)	(

+ 	% 	%D*D$DMM 	\ 	\[dk[[	\ 	\ 	\ 	P 	POC<M<MOO	P 	P 	P } 	/ 	/G'#344 K"+.t{+;+;WZ(":>>wzJJ /%%k22 3 3IIg//112223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 		'++--....&&((( \/"45
224455
"K14
444*4444
 

 #K-|IaLOa/077
 

 #K2|I23::
 

 #K#4;&&
 
 > 		&&# DK {s   .(T""T&	)T&	N)r%   r&   r'   r   rZ   r#   r"   rh   rh      s(        b b b b br#   rh   )__doc__outputr   r   r   signr   syntaxr   r   r	   r
   rO   utilr   endesiver   ImportErrorr   r   r   r   r   r+   r\   rh   rZ   r#   r"   <module>r      s    @ ? ? ? ? ? ? ? ? ?       9 9 9 9 9 9 9 9 9 9 ' ' ' ' ' '         FFF )F %$2 !)7 &( ) ) ) ) )y ) ) )E E E E E( E E EP    $    c c c c c~ c c c c cs   1 ;;