ó
    �®žjÃ  ã                  óî  • % S r SSKJr  SSKrSSKJr  SSKJr  Sr\R                  " S5      r
\R                  " S5      r\R                  " S	5      r0 S
S_SS_SS_SS_SS_S\_S\_S\_S\_S\_SS_SS_SS_SS_SS_SS_S S!_S!S"S"S"S"S"S#.Er\" 1 S$k5      rSS%S&.SS%S&.S!SS"S'.S!SS"S'.S!SS&.S(.rS)S)S*S*S+S,S,S,S-S.S,\S4\S4\S4S/S0.rS1\S2'   \" S3S49 " S5 S65      5       rS;S7 jr\" S8S99S<S: j5       rg)=ab  Read weight and slant out of a PDF font name.

PDF font names are the only styling metadata Docling gets from the digital text layer:
``PdfTextCell.font_name`` carries the font dictionary's name (e.g. ``/Helvetica-Bold``,
``/NKDKGK+HelveticaNeueLTPro-Bd``, ``/KIDKQO+Times-Italic``). There is no standard for encoding
weight and slant in that string -- only foundry conventions -- so :func:`parse_font_style`
recognizes the common ones and reports everything else as *unknown* rather than guessing.

Two rules keep the parser conservative, because a false "bold" silently rewrites a heading level
while a miss only falls back to the previous behavior:

1. **Style words are matched as whole tokens**, after splitting the name on separators and
   camel-case boundaries. ``Avenir-Book`` is a regular weight, but the family ``Bookman`` is not.
2. **Abbreviations are only honored as a whole separator-delimited part.** ``-Bd`` is bold, but
   the ``TB`` in ``LinLibertineTB`` and the ``LT`` in ``HelveticaNeueLTPro`` are not read as
   styles -- foundry tags glued onto a family name look exactly like weight abbreviations.
é    )ÚannotationsN)Ú	dataclass)Ú	lru_cachei�  z^[A-Z]{6}\+z[-_,+ ]+z&[A-Z]+(?![a-z])|[A-Z][a-z]+|[a-z]+|\d+Úthinéd   ÚhairlineÚ
extralightéÈ   Ú
ultralightÚlighté,  ÚbookÚnormalÚplainÚregularÚromanÚmediuméô  ÚdemiéX  ÚdemiboldÚsemiÚsemiboldÚboldé¼  Ú	extraboldi   é„  )Ú	ultraboldÚblackÚfatÚheavyÚposterÚultra>   ÚitalÚitalicÚkursivÚobliqueÚslantedÚinclinedi^  )r   r   )r   r   r   )r   r   Úextrar#   Úx)r   N)r   T)r   N)NT)r   N)r   N)r   N)ÚbÚbdÚbiÚbditÚblkÚiÚitaÚitÚltÚmdÚoblÚregÚrgÚromÚsbz)dict[str, tuple[int | None, bool | None]]Ú_PART_ABBREVIATIONST)Úfrozenc                  óD   • \ rS rSr% Sr\rS\S'   SrS\S'   Sr	S\S'   S	r
g
)Ú
_FontStyleéc   z2Weight and slant read from a font name (internal).ÚintÚweightFÚboolr%   Úknown© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚREGULAR_WEIGHTrA   Ú__annotations__r%   rC   Ú__static_attributes__rD   ó    ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/docling/utils/font_style.pyr>   r>   c   s#   ‡ á<à €FˆCÓ Ø€FˆDÓØ€Eˆ4ÖrM   r>   c                ó    • U S:¼  a  gU S:¼  a  gg)a  Bucket a numeric weight into ``0`` (light/regular), ``1`` (medium/semibold), ``2`` (bold+).

Coarse on purpose: heading levels are derived from the distinct classes present in a document,
so a finer scale would split near-identical styles into separate levels.
r   é   r   é   r   rD   )rA   s    rN   Úweight_classrR   l   s   € ð �ƒ}ØØ�ƒ}ØØrM   i   )Úmaxsizec                óB  • [         R                  SU =(       d    SR                  S5      SS9nU(       d
  [        5       $ SnSn[        R                  U5       GH  nU(       d  M  [        R                  UR                  5       5      nUb  Uu  pgUb  UOUnUb  UOUnMG  [        R                  U5       Vs/ s H  oˆR                  5       PM     n	nSn
U
[        U	5      :  d  MŒ  Xš   n[        R                  U5      nUb4  U
S-   [        U	5      :  a"  UR                  XšS-      5      nUb	  UnU
S-  n
Ma  U[        ;   a
  [        U   nOU[        ;   a  SnU
S-  n
U
[        U	5      :  a  M†  GM     Uc  Uc
  [        5       $ [        Ub  UO[        [!        U5      SS	9$ s  snf )
a]  Read weight and slant from a PDF font name.

Returns a regular, upright style with ``known=False`` when the name carries no recognizable
styling -- an unstyled family, a foundry-tagged name, or a bare resource key such as ``/F1``
(docling-parse falls back to the key, or to the literal ``"null"``, when the font dictionary
has no descriptive name).
Ú Ú/rQ   )ÚcountNr   rP   T)rA   r%   rC   )Ú_SUBSET_PREFIXÚsubÚlstripr>   Ú_SEPARATORSÚsplitr;   ÚgetÚlowerÚ_TOKENSÚfindallÚlenÚ_WEIGHT_MODIFIERSÚ_WEIGHT_TOKENSÚ_ITALIC_TOKENSrJ   rB   )Ú	font_nameÚnamerA   r%   ÚpartÚabbreviationÚpart_weightÚpart_italicÚtokenÚtokensÚindexÚmodifierÚcombineds                rN   Úparse_font_stylerp   y   s˜  € ô ×Ñ˜b 9§?°×":Ñ":¸3Ó"?ÀqÐÐI€DÞÜ‹|Ðà€FØ€Fä×!Ñ! $×'ˆÞÙÜ*×.Ñ.¨t¯z©z«|Ó<ˆØÑ#Ø'3Ñ$ˆKØ$/Ñ$;‘[ÀˆFØ$/Ñ$;‘[ÀˆFÙä-4¯_©_¸TÔ-BÓCÒ-B E—+‘+–-Ñ-BˆÐCØˆØ”c˜&“kÕ!Ø‘MˆEÜ(×,Ñ,¨UÓ3ˆHØÑ#¨°©	´C¸³KÓ(?Ø#Ÿ<™<¨°q©yÑ(9Ó:�ØÑ'Ø%�FØ˜Q‘J�EÙØœÓ&Ü'¨Ñ.‘Øœ.Ó(Ø�Ø�Q‰JˆEð ”c˜&“k×!Ð!ñ (ð6 �~˜&™.Ü‹|ÐÜØÑ+‰v´Ü�F‹|Øñð ùò' Ds   Â6F)rA   r@   Úreturnr@   )re   Ústrrq   r>   )rI   Ú
__future__r   ÚreÚdataclassesr   Ú	functoolsr   rJ   ÚcompilerX   r[   r_   rc   Ú	frozensetrd   rb   r;   rK   r>   rR   rp   rD   rM   rN   Ú<module>ry      s  ðòõ$ #ã 	Ý !Ý ð €ð —’˜NÓ+€Ø�jŠj˜Ó%€à
�*Š*Ð>Ó
?€ðØ
ˆCðà�ðð �#ðð �#ð	ð
 ˆSðð ˆNðð ˆnðð ˆ^ðð ˆ~ðð ˆ^ðð ˆcðð ˆCðð �ðð ˆCðð �ðð  ˆCð!ð" �ð#ð$ ØØØØØò/€ñ4 ÚBó€ð  3Ñ'Ø 3Ñ'Ø C°#Ñ6Ø C°#Ñ6Ø Ñ	$ñÐ ð 
Ø
Ø
ØØØ	ØØ
Ø
Ø
ØØ˜DÐ!Ø˜4Ð
 Ø˜DÐ!Ø
ñBÐ Ð>ó ñ& �$Ñ÷ð ó ðô
ñ �4Ñó0ó ñ0rM   