
    ,h(                         d dl mZmZmZ d dlmZmZmZ d dlm	Z	  G d de	      Z
 G d d      Z G d d	      Z G d
 d      Zd Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Zy)   )	MIME_TYPETIFF_FLDTIFF_TAG)
BIG_ENDIANLITTLE_ENDIANStreamReader)BaseImageHeaderc                   @    e Zd ZdZed        Zed        Zed        Zy)Tiffz`Image header parser for TIFF images.

    Handles both big and little endian byte ordering.
    c                 "    t         j                  S )z[Return the MIME type of this TIFF image, unconditionally the string
        ``image/tiff``.)r   TIFFselfs    Q/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/image/tiff.pycontent_typezTiff.content_type   s     ~~    c                      y)z:Default filename extension, always 'tiff' for TIFF images.tiff r   s    r   default_extzTiff.default_ext   s     r   c                     t         j                  |      }|j                  }|j                  }|j                  }|j
                  } | ||||      S )zYReturn a |Tiff| instance containing the properties of the TIFF image in
        `stream`.)_TiffParserparsepx_width	px_heighthorz_dpivert_dpi)clsstreamparserr   r   r   r   s          r   from_streamzTiff.from_stream   sK     ""6*??$$	????8Y(;;r   N)	__name__
__module____qualname____doc__propertyr   r   classmethodr!   r   r   r   r   r      sC    
  
   
< 
<r   r   c                        e Zd ZdZ fdZed        Zed        Zed        Z	ed        Z
ed        Zed        Zd	 Zed
        Z xZS )r   zkParses a TIFF image stream to extract the image properties found in its main
    image file directory (IFD)c                 8    t         t        |           || _        y N)superr   __init___ifd_entries)r   ifd_entries	__class__s     r   r,   z_TiffParser.__init__)   s    k4)+'r   c                     | j                  |      }|j                  d      }t        j                  ||      } | |      S )zmReturn an instance of |_TiffParser| containing the properties parsed from the
        TIFF image in `stream`.   )_make_stream_reader	read_long_IfdEntriesr!   )r   r   
stream_rdrifd0_offsetr.   s        r   r   z_TiffParser.parse-   sA     ,,V4
 **1-!--j+F;r   c                 @    | j                  t        j                        S )zThe horizontal dots per inch value calculated from the XResolution and
        ResolutionUnit tags of the IFD; defaults to 72 if those tags are not present.)_dpir   X_RESOLUTIONr   s    r   r   z_TiffParser.horz_dpi6        yy..//r   c                 @    | j                  t        j                        S )zThe vertical dots per inch value calculated from the XResolution and
        ResolutionUnit tags of the IFD; defaults to 72 if those tags are not present.)r8   r   Y_RESOLUTIONr   s    r   r   z_TiffParser.vert_dpi<   r:   r   c                 T    | j                   j                  t        j                        S )zThe number of stacked rows of pixels in the image, |None| if the IFD contains
        no ``ImageLength`` tag, the expected case when the TIFF is embeded in an Exif
        image.)r-   getr   IMAGE_LENGTHr   s    r   r   z_TiffParser.px_heightB   s!    
   $$X%:%:;;r   c                 T    | j                   j                  t        j                        S )zThe number of pixels in each row in the image, |None| if the IFD contains no
        ``ImageWidth`` tag, the expected case when the TIFF is embeded in an Exif
        image.)r-   r>   r   IMAGE_WIDTHr   s    r   r   z_TiffParser.px_widthI   s!    
   $$X%9%9::r   c                 h    |j                  d       |j                  d      }|dk(  rt        S t        S )zReturn either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian indicator
        found in the TIFF `stream` header, either 'MM' or 'II'.       s   MM)seekreadr   r   )r   r   
endian_strs      r   _detect_endianz_TiffParser._detect_endianP   s.     	A[[^
'50zCmCr   c                     | j                   }||vry|j                  t        j                  d      }|dk(  ry|dk(  rdnd}||   }t	        t        ||z              S )a!  Return the dpi value calculated for `resolution_tag`, which can be either
        TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION.

        The calculation is based on the values of both that tag and the
        TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries| instance.
        H   rD   r   gRQ@)r-   r>   r   RESOLUTION_UNITintround)r   resolution_tagr.   resolution_unitunits_per_inchdots_per_units         r   r8   z_TiffParser._dpiX   sj     '', &//(*B*BAFa-2#N357899r   c                 <    | j                  |      }t        ||      S )zReturn a |StreamReader| instance with wrapping `stream` and having "endian-
        ness" determined by the 'MM' or 'II' indicator in the TIFF stream header.)rH   r   )r   r   endians      r   r2   z_TiffParser._make_stream_readern   s!     ##F+FF++r   )r"   r#   r$   r%   r,   r'   r   r&   r   r   r   r   rH   r8   r2   __classcell__r/   s   @r   r   r   %   s    "(     0 0
 0 0
 < < ; ; D D:, , ,r   r   c                   F     e Zd ZdZ fdZd Zd Zed        ZddZ	 xZ
S )r4   z}Image File Directory for a TIFF image, having mapping (dict) semantics allowing
    "tag" values to be retrieved by tag code.c                 8    t         t        |           || _        y r*   )r+   r4   r,   _entries)r   entriesr/   s     r   r,   z_IfdEntries.__init__z   s    k4)+r   c                 8    | j                   j                  |      S )z5Provides ``in`` operator, e.g. ``tag in ifd_entries``)rX   __contains__r   keys     r   r[   z_IfdEntries.__contains__~   s    }}))#..r   c                 8    | j                   j                  |      S )zCProvides indexed access, e.g. ``tag_value = ifd_entries[tag_code]``)rX   __getitem__r\   s     r   r_   z_IfdEntries.__getitem__   s    }}((--r   c                     t        ||      }|j                         D ci c]  }|j                  |j                   }} | |      S c c}w )zVReturn a new |_IfdEntries| instance parsed from `stream` starting at
        `offset`.)
_IfdParseriter_entriestagvalue)r   r   offset
ifd_parsererY   s         r   r!   z_IfdEntries.from_stream   sH      /
+5+B+B+DEa155!''>EE7| Fs   Ac                 :    | j                   j                  ||      S )zhReturn value of IFD entry having tag matching `tag_code`, or `default` if no
        matching tag found.)rX   r>   )r   tag_codedefaults      r   r>   z_IfdEntries.get   s     }}  733r   r*   )r"   r#   r$   r%   r,   r[   r_   r'   r!   r>   rT   rU   s   @r   r4   r4   v   s0    1 /.  4r   r4   c                   8     e Zd ZdZ fdZd Zed        Z xZS )ra   zaService object that knows how to extract directory entries from an Image File
    Directory (IFD)c                 F    t         t        |           || _        || _        y r*   )r+   ra   r,   _stream_rdr_offset)r   r5   re   r/   s      r   r,   z_IfdParser.__init__   s    j$(*%r   c              #      K   t        | j                        D ]1  }| j                  dz   |dz  z   }t        | j                  |      }| 3 yw)zVGenerate an |_IfdEntry| instance corresponding to each entry in the
        directory.rD      N)range_entry_countrn   _IfdEntryFactoryrm   )r   idxdir_entry_offset	ifd_entrys       r   rb   z_IfdParser.iter_entries   sR      **+ 	C#||a/38<()9)9;KLIO	s   AAc                 L    | j                   j                  | j                        S )zDThe count of directory entries, read from the top of the IFD header.)rm   
read_shortrn   r   s    r   rr   z_IfdParser._entry_count   s     **4<<88r   )	r"   r#   r$   r%   r,   rb   r&   rr   rT   rU   s   @r   ra   ra      s&    
 9 9r   ra   c                    t         j                  t        t         j                  t        t         j
                  t        t         j                  t        i}| j                  |d      }|j                  |t              }|j                  | |      S )ztReturn an |_IfdEntry| subclass instance containing the value of the directory
    entry at `offset` in `stream_rdr`.rD   )r   ASCII_AsciiIfdEntrySHORT_ShortIfdEntryLONG_LongIfdEntryRATIONAL_RationalIfdEntryrx   r>   	_IfdEntryr!   )r5   re   ifd_entry_classes
field_typeEntryClss        r   rs   rs      sl     	},	 &&vq1J $$Z;H
F33r   c                   b     e Zd ZdZ fdZed        Zed        Zed        Z	ed        Z
 xZS )r   zsBase class for IFD entry classes.

    Subclasses are differentiated by value type, e.g. ASCII, long int, etc.
    c                 F    t         t        |           || _        || _        y r*   )r+   r   r,   	_tag_code_value)r   ri   rd   r/   s      r   r,   z_IfdEntry.__init__   s    i')!r   c                     |j                  |d      }|j                  |d      }|j                  |d      }| j                  ||||      } | ||      S )a!  Return an |_IfdEntry| subclass instance containing the tag and value of the
        tag parsed from `stream_rdr` at `offset`.

        Note this method is common to all subclasses. Override the ``_parse_value()``
        method to provide distinctive behavior based on field type.
        rC   r1      )rx   r3   _parse_value)r   r5   re   ri   value_countvalue_offsetrd   s          r   r!   z_IfdEntry.from_stream   s]     ((3 **615!++FA6  V[,O8U##r   c                      y)zReturn the value of this field parsed from `stream_rdr` at `offset`.

        Intended to be overridden by subclasses.
        zUNIMPLEMENTED FIELD TYPEr   r   r5   re   r   r   s        r   r   z_IfdEntry._parse_value   s     *r   c                     | j                   S )z.Short int code that identifies this IFD entry.)r   r   s    r   rc   z_IfdEntry.tag   s     ~~r   c                     | j                   S )z7Value of this tag, its type being dependent on the tag.)r   r   s    r   rd   z_IfdEntry.value   s     {{r   )r"   r#   r$   r%   r,   r'   r!   r   r&   rc   rd   rT   rU   s   @r   r   r      s]    

 $ $ * *    r   r   c                        e Zd ZdZed        Zy)r{   z<IFD entry having the form of a NULL-terminated ASCII string.c                 ,    |j                  |dz
  |      S )zReturn the ASCII string parsed from `stream_rdr` at `value_offset`.

        The length of the string, including a terminating ' ' (NUL) character, is in
        `value_count`.
        r   )read_strr   s        r   r   z_AsciiIfdEntry._parse_value   s     "";?LAAr   Nr"   r#   r$   r%   r'   r   r   r   r   r{   r{      s    FB Br   r{   c                        e Zd ZdZed        Zy)r}   z0IFD entry expressed as a short (2-byte) integer.c                 2    |dk(  r|j                  |d      S y)zReturn the short int value contained in the `value_offset` field of this
        entry.

        Only supports single values at present.
        r   r   z)Multi-value short integer NOT IMPLEMENTED)rx   r   s        r   r   z_ShortIfdEntry._parse_value   s"     !((33>r   Nr   r   r   r   r}   r}      s    :	? 	?r   r}   c                        e Zd ZdZed        Zy)r   z/IFD entry expressed as a long (4-byte) integer.c                 2    |dk(  r|j                  |d      S y)zReturn the long int value contained in the `value_offset` field of this
        entry.

        Only supports single values at present.
        r   r   z(Multi-value long integer NOT IMPLEMENTEDr3   r   s        r   r   z_LongIfdEntry._parse_value  s"     !''22=r   Nr   r   r   r   r   r     s    9	> 	>r   r   c                        e Zd ZdZed        Zy)r   z5IFD entry expressed as a numerator, denominator pair.c                 ^    |dk(  r(|j                  |      }|j                  |d      }||z  S y)zReturn the rational (numerator / denominator) value at `value_offset` in
        `stream_rdr` as a floating-point number.

        Only supports single values at present.
        r   r1   z$Multi-value Rational NOT IMPLEMENTEDr   )r   r5   re   r   r   	numeratordenominators          r   r   z_RationalIfdEntry._parse_value  s<     !",,\:I$..|Q?K{**9r   Nr   r   r   r   r   r     s    ?: :r   r   N)	constantsr   r   r   helpersr   r   r   imager	   r   r   r4   ra   rs   r   r{   r}   r   r   r   r   r   <module>r      s    4 4 < < "<? <>N, N,b4 4<9 9.4) )X
BY 
B?Y ? >I > :	 :r   