+
    f0iCY                         Rt ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ]P&                  t]P(                  ! ]4      t ! R R ]
P.                  4      tR tRR	 lt ! R
 R4      tR# )PdfPagePdfColorSchemeN)PdfiumError)	PdfBitmap)PdfTextPage)	PdfObjectc                   >  a a ] tR t^t oRtV 3R lt]R 4       t]R 4       t	R t
R tR tR tR	 tR
 tR!R ltR tR!R ltR tR!R ltR tR!R ltR tR!R ltR tR tR tR tR tR tR"R lt] PB                  3R lt"^^ R#R]#PH                  RR3R lt%R t&Vt'V ;t(# )$r   a@  
Page helper class.

Attributes:
    raw (FPDF_PAGE):
        The underlying PDFium page handle.
    pdf (PdfDocument):
        Reference to the document this page belongs to.
    formenv (PdfFormEnv | None):
        Formenv handle, if the parent pdf had an active formenv at the time of page retrieval. None otherwise.
c                |   < Wn         W n        W0n        \        SV `  \
        P                  V P                  4       R # N)rawpdfformenvsuper__init__r   _close_impl)selfr   r   r   	__class__s   &&&&]/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/pypdfium2/_helpers/page.pyr   PdfPage.__init__"   s+    ,,dll;    c                n    V'       d   \         P                  ! W4       \         P                  ! V 4       R # r
   )pdfium_cFORM_OnBeforeClosePageFPDF_ClosePage)r   r   s   &&r   r   PdfPage._close_impl)   s!    ++C9$r   c                    V P                   # r
   )r   r   s   &r   parentPdfPage.parent0   s     xxr   c                .    \         P                  ! V 4      # )zH
Returns:
    float: Page width (horizontal size), in PDF canvas units.
)r   FPDF_GetPageWidthFr   s   &r   	get_widthPdfPage.get_width6   s    
 **400r   c                .    \         P                  ! V 4      # )zG
Returns:
    float: Page height (vertical size), in PDF canvas units.
)r   FPDF_GetPageHeightFr   s   &r   
get_heightPdfPage.get_height=   s    
 ++D11r   c                B    V P                  4       V P                  4       3# )zJ
Returns:
    (float, float): Page width and height, in PDF canvas units.
)r!   r%   r   s   &r   get_sizePdfPage.get_sizeD   s    
  $//"344r   c                X    \         P                  \        P                  ! V 4      ,          # )z7
Returns:
    int: Clockwise page rotation in degrees.
)pdfium_iRotationToDegreesr   FPDFPage_GetRotationr   s   &r   get_rotationPdfPage.get_rotationN   s     
 ))8+H+H+NPPr   c                ^    \         P                  ! V \        P                  V,          4       R# )zL
Define the absolute, clockwise page rotation (0, 90, 180, or 270 degrees).
N)r   FPDFPage_SetRotationr+   RotationToConst)r   rotations   &&r   set_rotationPdfPage.set_rotationU   s     	%%dH,D,DX,NOr   c                    \        4       \        4       \        4       \        4       3w  rErgV! WWVV4      pV'       g   V'       d   V! 4       # R # VP                  VP                  VP                  VP                  3# r
   )c_floatvalue)	r   box_funcfallback_funcfallback_okleftbottomrighttopoks	   &&&&     r   _get_boxPdfPage._get_box\   s\    #*9giGI#M ed&5'2MO==

FLL%++syyAAr   Tc                F    V P                  \        P                  R V4      # )a  
Returns:
    (float, float, float, float) | None:
    The page MediaBox in PDF canvas units, consisting of four coordinates (usually x0, y0, x1, y1).
    If MediaBox is not defined, returns ANSI A (0, 0, 612, 792) if ``fallback_ok=True``, None otherwise.

.. admonition:: Known issue

    Due to quirks in PDFium, all ``get_*box()`` functions except :meth:`.get_bbox` do not inherit from parent nodes in the page tree (as of PDFium 5418).
c                      R# )    )rE   rE   id  i   rF   r   r   <lambda>&PdfPage.get_mediabox.<locals>.<lambda>p   s    DTr   )rA   r   FPDFPage_GetMediaBoxr   r;   s   &&r   get_mediaboxPdfPage.get_mediaboxe   s     }}X::<TVabbr   c                6    \         P                  ! WW#V4       R# )z^
Set the page's MediaBox by passing four :class:`float` coordinates (usually x0, y0, x1, y1).
N)r   FPDFPage_SetMediaBoxr   lbrts   &&&&&r   set_mediaboxPdfPage.set_mediaboxr        	%%dqQ7r   c                X    V P                  \        P                  V P                  V4      # )zK
Returns:
    The page's CropBox (If not defined, falls back to MediaBox).
)rA   r   FPDFPage_GetCropBoxrK   rJ   s   &&r   get_cropboxPdfPage.get_cropboxx   s#    
 }}X994;L;LkZZr   c                6    \         P                  ! WW#V4       R# )z
Set the page's CropBox.
N)r   FPDFPage_SetCropBoxrO   s   &&&&&r   set_cropboxPdfPage.set_cropbox        	$$TaA6r   c                X    V P                  \        P                  V P                  V4      # )zK
Returns:
    The page's BleedBox (If not defined, falls back to CropBox).
)rA   r   FPDFPage_GetBleedBoxrY   rJ   s   &&r   get_bleedboxPdfPage.get_bleedbox   s#    
 }}X::D<L<LkZZr   c                6    \         P                  ! WW#V4       R# )z
Set the page's BleedBox.
N)r   FPDFPage_SetBleedBoxrO   s   &&&&&r   set_bleedboxPdfPage.set_bleedbox   rV   r   c                X    V P                  \        P                  V P                  V4      # )zJ
Returns:
    The page's TrimBox (If not defined, falls back to CropBox).
)rA   r   FPDFPage_GetTrimBoxrY   rJ   s   &&r   get_trimboxPdfPage.get_trimbox   s#    
 }}X994;K;K[YYr   c                6    \         P                  ! WW#V4       R# )z
Set the page's TrimBox.
N)r   FPDFPage_SetTrimBoxrO   s   &&&&&r   set_trimboxPdfPage.set_trimbox   r_   r   c                X    V P                  \        P                  V P                  V4      # )zI
Returns:
    The page's ArtBox (If not defined, falls back to CropBox).
)rA   r   FPDFPage_GetArtBoxrY   rJ   s   &&r   
get_artboxPdfPage.get_artbox   s#    
 }}X88$:J:JKXXr   c                6    \         P                  ! WW#V4       R# )z
Set the page's ArtBox.
N)r   FPDFPage_SetArtBoxrO   s   &&&&&r   
set_artboxPdfPage.set_artbox   s     	##DQ15r   c                    \         P                  ! 4       p\         P                  ! W4      pV'       g   \        R4      hVP                  VP
                  VP                  VP                  3# )zb
Returns:
    The bounding box of the page (the intersection between its media box and crop box).
z Failed to get page bounding box.)r   FS_RECTFFPDF_GetPageBoundingBoxr   r<   r=   r>   r?   )r   rectr@   s   &  r   get_bboxPdfPage.get_bbox   sP    
   "--d9@AA		4;;

DHH==r   c                    \         P                  ! V 4      pV'       g   \        R4      h\        W4      pV P	                  V4       V# )zA
Returns:
    PdfTextPage: A new text page handle for this page.
zFailed to load text page.)r   FPDFText_LoadPager   r   _add_kid)r   raw_textpagetextpages   &  r   get_textpagePdfPage.get_textpage   s>    
  11$79::|2hr   c                (   VP                   '       d   \        R4      hVP                  '       d&   VP                  V P                  Jd   \        R4      h\        P                  ! W4       VP                  4        Wn         V P                  Vn        R# )an  
Insert a pageobject into the page.

The pageobject must not belong to a page yet. If it belongs to a PDF, the target page must be part of that PDF.

Position and form are defined by the object's matrix.
If it is the identity matrix, the object will appear as-is on the bottom left corner of the page.

Parameters:
    pageobj (PdfObject): The pageobject to insert.
zAThe pageobject you attempted to insert already belongs to a page.zBThe pageobject you attempted to insert belongs to a different PDF.N)page
ValueErrorr   r   FPDFPage_InsertObject_detach_finalizer)r   pageobjs   &&r   
insert_objPdfPage.insert_obj   sg     <<<`aa;;;GKKtxx7abb&&t5!!#hhr   c                   VP                   V Jd   \        R4      hVP                  ^ 8  dB   VP                  f   Q h\        P
                  ! VP                  V4      p^ RuVn        Vn        M&VP                  e   Q h\        P                  ! W4      pV'       g   \        R4      hRVn         VP                  4        R# )a  
Remove a pageobject from the page.
As of PDFium 5692, detached pageobjects may be only re-inserted into existing pages of the same document.
If the pageobject is not re-inserted into a page, its ``close()`` method may be called.

Note:
    If the object's :attr:`~.PdfObject.type` is :data:`FPDF_PAGEOBJ_TEXT`, any :class:`.PdfTextPage` handles to the page should be closed before removing the object.

Parameters:
    pageobj (PdfObject): The pageobject to remove.
z@The pageobject you attempted to remove is not part of this page.NzFailed to remove pageobject.)	r   r   level	containerr   FPDFFormObj_RemoveObjectFPDFPage_RemoveObjectr   _attach_finalizer)r   r   r@   s   && r   
remove_objPdfPage.remove_obj   s     <<t#_``==1$$0002273D3DgNB/0$,GM7,$$,,,//>B<==!!#r   c                X    \         P                  ! V 4      pV'       g   \        R4      hR# )z
Generate page content to apply additions, removals or modifications of pageobjects.

If page content was changed, this function should be called once before saving the document or re-loading the page.
z Failed to generate page content.N)r   FPDFPage_GenerateContentr   )r   r@   s   & r   gen_contentPdfPage.gen_content  s(     ..t4@AA r   Nc           	   #  L  "   V'       d$   \         P                  p\         P                  pTpM"\         P                  p\         P                  pT pV! V4      pV^ 8  d   \        R4      h\        V4       F  p	V! Wy4      p
V
'       g   \        R4      h\        WV P                  W4R7      pV'       d   VP                  V9   d   Vx  VP                  \         P                  8X  g   Kt  WB^,
          8  g   K  V P                  VVVV^,           R7       Rj  xL
  K  	  R#  L
5i)a  
Iterate through the pageobjects on this page.

Parameters:
    filter (list[int] | None):
        An optional list of pageobject types to filter (:attr:`FPDF_PAGEOBJ_*`).
        Any objects whose type is not contained will be skipped.
        If None or empty, all objects will be provided, regardless of their type.
    max_depth (int):
        Maximum recursion depth to consider when descending into Form XObjects.

Yields:
    :class:`.PdfObject`: A pageobject.
z$Failed to get number of pageobjects.zFailed to get pageobject.)r   r   r   r   )filter	max_depthformr   N)r   FPDFFormObj_CountObjectsFPDFFormObj_GetObjectFPDFPage_CountObjectsFPDFPage_GetObjectr   ranger   r   typeFPDF_PAGEOBJ_FORMget_objects)r   r   r   r   r   count_objects
get_objectr   	n_objectsiraw_obj
helper_objs   &&&&&       r   r   PdfPage.get_objects  s       $==M!77JF$::M!44JF!&)	q=DEEy!A +G!"=>> #7488taJZ__6  ("<"<<STAT++# )%!AI	 ,    "s   C"D$)
D$8D$D"D$c                    V P                   '       g   \        R4      h\        P                  ! W4      pV\        P                  8X  d   \        R4      hV# )a+  
Flatten form fields and annotations into page contents.

Attention:
    * :meth:`~.PdfDocument.init_forms` must have been called on the parent pdf, before the page was retrieved, for this method to work. In other words, :attr:`.PdfPage.formenv` must be non-null.
    * Flattening may invalidate existing handles to the page, so you'll want to re-initialize these afterwards.

Parameters:
    flag (int): PDFium flattening target (:attr:`FLAT_*`)
Returns:
    int: PDFium flattening status (:attr:`FLATTEN_*`). :attr:`FLATTEN_FAIL` is handled internally.
zHpage.flatten() requires previous pdf.init_forms() before page retrieval.z,Failed to flatten annotations / form fields.)r   RuntimeErrorr   FPDFPage_FlattenFLATTEN_FAILr   )r   flagrcs   && r   flattenPdfPage.flatten>  sH     |||ijj&&t2&&&LMM	r   Fc                *   \         P                  ! V P                  4       V,          4      p	\         P                  ! V P                  4       V,          4      p
VR	9   d   YrV Uu. uF  p\         P                  ! W,          4      NK!  	  ppW^ ,          ,
          V^,          ,
          pW^,          ,
          V^,          ,
          p\        ;QJ d    R W3 4       F  '       g   K   RM	  RM! R W3 4       4      '       d   \        R4      h\        V 3/ VB w  rppVe    V'       d   V\        P                  ,          pV! WWR7      pVP                  V^ ^ W4       V^ ,          ) V^,          ) W\        P                  V,          3pVV .VOVN5pVf   \        P                  ! V!   M\        P                  ! ^R7      p\        P                  ! VRR 4       VP                  V4      p\        P                   ! . VOVNVN5!  pV\        P"                  8X  g   Q h\        P$                  ! V 4       V'       d5   V P&                  '       d#   \        P(                  ! V P&                  .VO5!   \*        P,                  ! V 4      .VO5Vn        V# u upi )
a   
Rasterize the page to a :class:`.PdfBitmap`.

Parameters:
    
    scale (float):
        A factor scaling the number of pixels per PDF canvas unit. This defines the resolution of the image.
        To convert a DPI value to a scale factor, multiply it by the size of 1 canvas unit in inches (usually 1/72in). [#user_unit]_
    
    rotation (int):
        Additional rotation in degrees (0, 90, 180, or 270).
    
    crop (tuple[float, float, float, float]):
        Amount in PDF canvas units to cut off from page borders (left, bottom, right, top). Crop is applied after rotation.
    
    may_draw_forms (bool):
        If True, render form fields (provided the document has forms and :meth:`~.PdfDocument.init_forms` was called).
    
    bitmap_maker (typing.Callable):
        Callback function used to create the :class:`.PdfBitmap`.
    
    fill_color (tuple[int, int, int, int]):
        Color the bitmap will be filled with before rendering. This uses RGBA syntax regardless of the pixel format used, with values from 0 to 255.
        If the fill color is not opaque (i.e. has transparency), ``{BGR,RGB}A`` will be used.
    
    grayscale (bool):
        If True, render in grayscale mode.
    
    optimize_mode (None | str):
        Page rendering optimization mode (None, "lcd", "print").
    
    draw_annots (bool):
        If True, render page annotations.
    
    no_smoothtext (bool):
        If True, disable text anti-aliasing. Overrides ``optimize_mode="lcd"``.
    
    no_smoothimage (bool):
        If True, disable image anti-aliasing.
    
    no_smoothpath (bool):
        If True, disable path anti-aliasing.
    
    force_halftone (bool):
        If True, always use halftone for image stretching.
    
    limit_image_cache (bool):
        If True, limit image cache size.
    
    rev_byteorder (bool):
        If True, render with reverse byte order, leading to ``RGB{A/x}`` output rather than ``BGR{A/x}``.
        Other pixel formats are not affected.
    
    prefer_bgrx (bool):
        If True, use 4-byte ``{BGR/RGB}x`` rather than 3-byte ``{BGR/RGB}`` (i.e. add an unused byte).
        Other pixel formats are not affected.
    
    maybe_alpha (bool):
        If True, use a pixel format with alpha channel (i.e. ``{BGR/RGB}A``) if page content has transparency.
        This is recommended for performance in these cases, but as page-dependent format selection can be unexpected, it is not enabled by default.
    
    force_bitmap_format (int | None):
        If given, override automatic pixel format selection and enforce use of the given format (one of the :attr:`FPDFBitmap_*` constants). In this case, you should not pass any other format selection options, except potentially *rev_byteorder*.
    
    extra_flags (int):
        Additional PDFium rendering flags. May be combined with bitwise OR (``|`` operator).
    
    color_scheme (PdfColorScheme | None):
        A custom pdfium color scheme. Note that this may flatten different colors into one, so the usability of this is limited.
    
    fill_to_stroke (bool):
        If a *color_scheme* is given, whether to only draw borders around fill areas using the `path_stroke` color, instead of filling with the `path_fill` color.

Returns:
    PdfBitmap: Bitmap of the rendered page.

.. admonition:: Format selection
    
    This is the format selection hierarchy used by :meth:`.render`, from lowest to highest priority:
    
    * default: ``BGR``
    * ``prefer_bgrx=True``: ``BGRx``
    * ``grayscale=True``: ``L``
    * ``maybe_alpha=True``: ``BGRA`` if the page has transparency, else the format selected otherwise
    * ``fill_color[3] < 255``: ``BGRA`` (background color with transparency)
    * ``force_bitmap_format=...`` -> any supported by pdfium
    
    Additionally, ``rev_byteorder=True`` will swap ``BGR{A/x}`` to ``RGB{A/x}`` if applicable.

.. [#user_unit] Since PDF 1.6, pages may define an additional user unit factor. In this case, 1 canvas unit is equivalent to ``user_unit * (1/72)`` inches. PDFium does not currently provide an API to get the user unit, so this is not taken into account.
c              3   *   "   T F	  q^8  x  K  	  R# 5i)   NrF   ).0ds   & r   	<genexpr>!PdfPage.render.<locals>.<genexpr>  s     .o1uos   TFzCrop exceeds page dimensions)formatrev_byteorder)versionNeedToPauseNowc                     R # )FrF   )_s   &r   rG    PdfPage.render.<locals>.<lambda>  s    Ur   )Z   i  )mathceilr!   r%   anyr   _parse_renderoptsr   FPDF_CONVERT_FILL_TO_STROKE	fill_rectr+   r2   FPDF_RenderPageBitmapIFSDK_PAUSEset_callbackconvert*FPDF_RenderPageBitmapWithColorScheme_StartFPDF_RENDER_DONEFPDF_RenderPage_Closer   FPDF_FFLDrawweakrefref	_pos_args)r   scaler3   cropmay_draw_formsbitmap_makercolor_schemefill_to_strokekwargs	src_width
src_heightcwidthheight	cl_formatr   
fill_colorflagsbitmappos_argsrender_argspausefpdf_csstatuss   &&&&&&&&,               r   renderPdfPage.renderX  s   N YYt~~/589	YYt0589
y $.z,01Dq		!'"D11g%Q/1g%Q/3.uo.333.uo...;<<6G6WPV6W3	*e$.X999EeI[Q59!WHtAwh	x?W?WX`?abt6h66**K8((3E!!%)9?K"**=9GHHf+fW^f`efFX66666**40dlll!!$,,==#KK-99= 2s   $%J)r   r   r   )T)N   NrE   )rE   rE   rE   rE   ))__name__
__module____qualname____firstlineno____doc__r   staticmethodr   propertyr   r!   r%   r(   r.   r4   rA   rK   rT   rY   r]   rb   rf   rj   rn   rr   rv   r|   r   r   r   r   r   r   FLAT_NORMALDISPLAYr   r   
new_nativer   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r   r      s     
< % %  
125QPBc8[7[8Z7Y6	>
0$BB.b $66 8 !$//"J Jr   c                    V^,          ^8  g%   V'       d-   \         P                  ! V 4      '       d   \         P                  # V'       d   \         P                  # V'       d   \         P                  # \         P
                  # )   )r   FPDFPage_HasTransparencyFPDFBitmap_BGRAFPDFBitmap_GrayFPDFBitmap_BGRxFPDFBitmap_BGR)r   r   	grayscaleprefer_bgrxmaybe_alphas   &&&&&r   _auto_bitmap_formatr    sY     !}s{x/P/PQU/V/V'''	'''	'''&&&r   c                    Vf   \        WW+V4      pMTpV\        P                  8X  d   Rp
TpV'       d   V\        P                  ,          pV'       d   V\        P                  ,          pV'       d   V\        P
                  ,          pV'       d   V\        P                  ,          pV'       d   V\        P                  ,          pV'       d   V\        P                  ,          pV	'       d   V\        P                  ,          pV
'       d   V\        P                  ,          pV'       d]   VP                  4       pVR8X  d   V\        P                  ,          pM-VR8X  d   V\        P                  ,          pM\        RV 24      hWVV3# )NFlcdprintzInvalid optimize_mode )r  r   r   FPDF_GRAYSCALE
FPDF_ANNOTFPDF_RENDER_NO_SMOOTHTEXTFPDF_RENDER_NO_SMOOTHIMAGEFPDF_RENDER_NO_SMOOTHPATHFPDF_RENDER_FORCEHALFTONEFPDF_RENDER_LIMITEDIMAGECACHEFPDF_REVERSE_BYTE_ORDERlowerFPDF_LCD_TEXTFPDF_PRINTINGr   )r   r   r   optimize_modedraw_annotsno_smoothtextno_smoothimageno_smoothpathforce_halftonelimit_image_cacher   r  r  force_bitmap_formatextra_flagsr   r   s   &&&&&&&&&&&&&&&  r   r   r     s1   $ "')R]^	'	H,,,E((($$$333444333333777111%++-E!X+++Eg%X+++E5m_EFF Z66r   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )r   i+  z
Rendering color scheme.
Each color shall be provided as a list of values for red, green, blue and alpha, ranging from 0 to 255.
c                *    \        WW4R 7      V n        R# ))path_fill_colorpath_stroke_colortext_fill_colortext_stroke_colorN)dictcolors)r   	path_fillpath_stroke	text_filltext_strokes   &&&&&r   r   PdfColorScheme.__init__1  s    %%
r   c                L    \        V 4      P                   R V P                   R2# )z(**))r   r   r"  r   s   &r   __repr__PdfColorScheme.__repr__7  s$    t*%%&c$++a88r   c           	         \         P                  ! 4       pV P                  P                  4        F%  w  r4\	        W#\
        P                  ! WA4      4       K'  	  V# )zD
Returns:
    The color scheme as :class:`FPDF_COLORSCHEME` object.
)r   FPDF_COLORSCHEMEr"  itemssetattrr+   color_tohex)r   r   r   keyr8   s   &&   r   r   PdfColorScheme.convert:  sE    
 ++-++++-JCG("6"6u"LM .r   )r"  N)
r   r   r   r   r   r   r*  r   r   r   )r   s   @r   r   r   +  s     

9 r   )r   r   ))   r3  r3  r3  FNTFFFFFFFFNrE   )__all__r   ctypesloggingr   pypdfium2.rawr   r   pypdfium2.internalinternalr+   pypdfium2._helpers.miscr   pypdfium2._helpers.bitmapr   pypdfium2._helpers.textpager   pypdfium2._helpers.pageobjectsr   r7   	getLoggerr   loggerAutoCloseabler   r  r   r   rF   r   r   <module>rA     sm    (       % / / 3 4
..			8	$Mx%% M`
'67r r   