ó
    uÕgj   ã                  ó‚   • S r SSKJr  SSKJr  SSKJrJr  SSKr\(       a  SSK	J
r
  \\\\\4   rS
S jrSS jrSS	 jrg)aü  Page-level operations on a source PDF.

`slice_page` writes one page out as its own one-page PDF. `render_page`
rasterizes one page to a PNG. `render_region` rasterizes one rectangle of a page.
All three address pages 1-based, the numbering the document artifacts and the CLI
use.

Single-page work has two callers that pay per page: an ADE submission bills by
the page submitted, so a one-page slice bills one page's credits instead of the
whole document's, and a vision agent looking at one page needs that page and no
other.

A region is rendered when an element's picture has to be re-cut because its
boundary moved: the document model stores a bitmap of each detected picture, and
a bitmap of the old boundary would depict something the element no longer is.
é    )Úannotations)ÚPath)ÚTYPE_CHECKINGÚTupleN©ÚImagec           
     ó¼  • [         R                  " [        U 5      5       nSUs=::  a  UR                  ::  d+  O  [	        SU SU R
                   SUR                   S35      e[         R                  " 5        nUR                  X1S-
  US-
  S9  UR                  [        U5      5        SSS5        SSS5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)zAWrite the single 1-based `page` of `pdf` to `dest` and return it.é   úpage ú out of range: ú has ú pages)Ú	from_pageÚto_pageN)ÚfitzÚopenÚstrÚ
page_countÚ
ValueErrorÚnameÚ
insert_pdfÚsave)ÚpdfÚpageÚdestÚsrcÚsliceds        Ú-/home/mande/repo/quber/src/quber/files/pdf.pyÚ
slice_pager   !   s®   € ä	�Š”3�s“8Ô	 Ø�DÕ*˜CŸN™NÕ*Ü˜u T F¨/¸#¿(¹(¸À5ÈÏÉÐHXÐX^Ð_Ó`Ð`Ü�YŠYŒ[˜FØ×Ñ˜c°A©X¸tÀa¹xÐÑHØ�K‰Kœ˜D›	Ô"÷ ÷ 
ð €K÷ �[ú÷ 
Ô	ð €Kús$    ACÁ81B;Â)CÂ;
C		ÃCÃ
Cc           
     ó´  • [         R                  " [        U 5      5       nSUs=::  a  UR                  ::  d+  O  [	        SU SU R
                   SUR                   S35      eXAS-
     nUR                  R                  UR                  R                  pvUR                  US9R                  [        U5      5        SSS5        UWW4$ ! , (       d  f       N= f)zÇRasterize the 1-based `page` of `pdf` to `dest`; return it with the page size.

The size is the page's width and height in PDF points, so a caller can map a
normalized box back onto the source page.
r
   r   r   r   r   )ÚdpiN)r   r   r   r   r   r   ÚrectÚwidthÚheightÚ
get_pixmapr   )r   r   r!   r   ÚdocÚpgr#   r$   s           r   Úrender_pager(   ,   s­   € ô 
�Š”3�s“8Ô	 Ø�DÕ*˜CŸN™NÕ*Ü˜u T F¨/¸#¿(¹(¸À5ÈÏÉÐHXÐX^Ð_Ó`Ð`Ø˜‘‰]ˆØŸ™Ÿ™ r§w¡w§~¡~ˆvØ
�‰˜#ˆÐ×#Ñ#¤C¨£IÔ.÷ 
ð �˜ÐÐ÷ 
Õ	ús    BC	Ã	
Cc                ó  • SSK Jn  [        R                  " [	        U 5      5       nSUs=::  a  UR
                  ::  d+  O  [        SU SU R                   SUR
                   S35      eXQS-
     nUR                  nUu  p‰p«[        R                  " UR                  [        XŠ5      UR                  -  -   UR                  [        X›5      UR                  -  -   UR                  [        XŠ5      UR                  -  -   UR                  [        X›5      UR                  -  -   5      nUR!                  XÃS9nUR#                  S	UR                  UR                  4UR$                  5      sS
S
S
5        $ ! , (       d  f       g
= f)zàRasterize the rectangle `box` of the 1-based `page` of `pdf` at `dpi`.

The box is normalized against the page's own rectangle rather than assumed to
start at the origin, so a page whose media box is offset crops correctly.
r   r   r
   r   r   r   r   )Úclipr!   ÚRGBN)ÚPILr   r   r   r   r   r   r   r"   ÚRectÚx0Úminr#   Úy0r$   Úmaxr%   Ú	frombytesÚsamples)r   r   Úboxr!   ÚPILImager&   r'   r"   ÚleftÚtopÚrightÚbottomr*   Úpixs                 r   Úrender_regionr;   ;   s)  € õ &ä	�Š”3�s“8Ô	 Ø�DÕ*˜CŸN™NÕ*Ü˜u T F¨/¸#¿(¹(¸À5ÈÏÉÐHXÐX^Ð_Ó`Ð`Ø˜‘‰]ˆØ�w‰wˆØ#&Ñ ˆ�5Ü�yŠyØ�G‰G”c˜$Ó&¨¯©Ñ3Ñ3Ø�G‰G”c˜#Ó&¨¯©Ñ4Ñ4Ø�G‰G”c˜$Ó&¨¯©Ñ3Ñ3Ø�G‰G”c˜#Ó&¨¯©Ñ4Ñ4ó	
ˆð �m‰m ˆmÐ/ˆØ×!Ñ! %¨#¯)©)°S·Z±ZÐ)@À#Ç+Á+ÓN÷ 
×	×	ús   ¦EE1Å1
E?)r   r   r   Úintr   r   Úreturnr   )
r   r   r   r<   r!   r<   r   r   r=   zTuple[Path, float, float])
r   r   r   r<   r4   ÚNormBoxr!   r<   r=   z'Image')Ú__doc__Ú
__future__r   Úpathlibr   Útypingr   r   r   Ú	PIL.Imager   Úfloatr>   r   r(   r;   © ó    r   Ú<module>rG      sC   ðñõ" #å ß 'ã æÝð ��u˜e UÐ*Ñ
+€ôôõOrF   