� J�g���dZddlmZddlmZmZddlmZmZm Z Gd�de��Z Gd�d e��Z Gd �d e��Z Gd �d ��Z dS)u� Quoting the PDF spec: > PDF’s logical _structure facilities_ provide a mechanism for incorporating > structural information about a document’s content into a PDF file. > The logical structure of a document is described by a hierarchy of objects called > the _structure hierarchy_ or _structure tree_. > At the root of the hierarchy is a dictionary object called the _structure tree root_, > located by means of the **StructTreeRoot** entry in the document catalog. The contents of this module are internal to fpdf2, and not part of the public API. They may change at any time without prior warning or any deprecation period, in non-backward-compatible ways. �)� defaultdict)�List�Union�)� PDFObject� PDFString�PDFArrayc�2��eZdZdZdZ�fd�Zd�fd� Z�xZS)� NumberTreeu�A number tree is similar to a name tree, except that its keys are integers instead of strings and are sorted in ascending numerical order. A name tree serves a similar purpose to a dictionary—associating keys and values—but by different means. The values associated with the keys may be objects of any type. Stream objects are required to be specified by indirect object references. It is recommended, though not required, that dictionary, array, and string objects be specified by indirect object references, and other PDF objects (nulls, numbers, booleans, and names) be specified as direct objects )�_id�numsc�z��t�����tt��|_dS�N)�super�__init__r�listr ��self� __class__s ��c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fpdf/structure_tree.pyrzNumberTree.__init__&s,��� ����������%�%�� � � �Nc�����d�d��fd�|j���D����}t���dd|�d�i��S)N� c3�h�K�|],\}}|�d��d�|D�����d�V��-dS)z [c3�$K�|] }|jV�� dSr)�ref)�.0� struct_elems r� <genexpr>z1NumberTree.serialize.<locals>.<genexpr>.<genexpr>-s$����/`�/`�K� ��/`�/`�/`�/`�/`�/`r�]N)�join)r�struct_parent_id� struct_elems�newlines �rrz'NumberTree.serialize.<locals>.<genexpr>,si�����$ �$ �.� �,� � c� c�7�<�<�/`�/`�S_�/`�/`�/`�#`�#`� c� c� c�$ �$ �$ �$ �$ �$ rz/Nums�[r )r!r �itemsr� serialize)r�obj_dict�_security_handler�serialized_numsr$rs @�rr'zNumberTree.serialize*sy�������)�)�$ �$ �$ �$ �26�)�/�/�2C�2C�$ �$ �$ � � ���w�w� � �'�+A��+A�+A�+A�!B�C�C�Cr)NN)�__name__� __module__� __qualname__�__doc__� __slots__rr'� __classcell__�rs@rr r sq������� � � �I�&�&�&�&�&�D�D�D�D�D�D�D�D�D�Drr c�"��eZdZdZ�fd�Z�xZS)�StructTreeRoot)r �type� parent_tree�kc���t�����d|_t��|_t ��|_dS)Nz/StructTreeRoot)rrr4r r5r r6rs �rrzStructTreeRoot.__init__6s;��� ��������%�� �%�<�<���������r)r+r,r-r/rr0r1s@rr3r33s=�������3�I���������rr3c �r��eZdZdZ d dededeeeedfdededef �fd � Z d �Z �xZ S) � StructElem) r r4�s�pr6�t�alt�pg� _page_numberN� struct_type�parent�kids� page_number�titler=c���t�����d|_||_||_t |��|_|�dnt|��|_|�dnt|��|_ d|_ ||_ dS)Nz /StructElem) rrr4r:r;r r6rr<r=r>r?)rr@rArBrCrDr=rs �rrzStructElem.__init__Ls~��� ��������!�� ��������$���������I�e�,<�,<����;�4�4�I�c�N�N������'����rc��|jSr)r?�rs rrCzStructElem.page_numberbs ��� � r�NNN) r+r,r-r/�strrrr�intrrCr0r1s@rr9r9?s�������� �I�" ���(�(��(��(��D��I�t�L�1�1�2� (� � (� � (��(�(�(�(�(�(�,!�!�!�!�!�!�!rr9c �J�eZdZd�Z d dededededef d�Zd �Zd �Zd �Z dS) �StructureTreeBuilderc��t��|_td|jg���|_|jj�|j��i|_dS)Nz /Document)r@rArB)r3�struct_tree_rootr9�doc_struct_elemr6�append�spid_per_page_numberrGs rrzStructureTreeBuilder.__init__gs^�� .� 0� 0���)�#�D�,A�� � � ��� ���&�&�t�';�<�<�<�$&��!�!�!rNrCr@�mcidrD�alt_textc�N�|j�|��}|�t|j��}||j|<t||j|�gn|g|||���}|jj�|��|jjj |�|��||fS)N)r@rArBrCrDr=) rQ�get�lenr9rOr6rPrNr5r )rrCr@rRrDrS�struct_parents_idrs r�add_marked_contentz'StructureTreeBuilder.add_marked_contentos���!�5�9�9�+�F�F�� � $� #�D�$=� >� >� �5F�D� %�k� 2� �#��'��|���$��#���  � � � � ���%�%�k�2�2�2� ��)�.�/@�A�H�H��U�U�U��-�-�-rc�N��t�fd�|jjD����S)Nc3�Z�K�|]%}|����k�|j�!dV��&dS)rN)rCr6)rrrCs �rrz:StructureTreeBuilder.next_mcid_for_page.<locals>.<genexpr>�sP����� � ���&�&�(�(�K�7�7�� �8� �7�7�7�7� � r)�sumrOr6)rrCs `r�next_mcid_for_pagez'StructureTreeBuilder.next_mcid_for_page�sA���� � � � �#�3�5� � � � � � rc��|jj Sr)rOr6rGs r�emptyzStructureTreeBuilder.empty�s���'�)�)�)rc#�nK�|jV�|jV�|jjV�|jjEd{V��dS)z@Iterate all PDF objects in the tree, starting with the tree rootN)rNrOr5r6rGs r�__iter__zStructureTreeBuilder.__iter__�sZ�����#�#�#�#��"�"�"�"��#�/�/�/�/��'�)�)�)�)�)�)�)�)�)�)rrH) r+r,r-rrJrIrXr\r^r`�rrrLrLfs�������'�'�'���� .�.��.��.�� .� � .� � .�.�.�.�0 � � �*�*�*�*�*�*�*�*rrLN)r.� collectionsr�typingrr�syntaxrrr r r3r9rLrarr�<module>res�� � �$�#�#�#�#�#���������2�2�2�2�2�2�2�2�2�2�D�D�D�D�D��D�D�D�: � � � � �Y� � � �$!�$!�$!�$!�$!��$!�$!�$!�N1*�1*�1*�1*�1*�1*�1*�1*�1*�1*r
Memory