§
    >²¸j4  ã                  óÜ   — d Z ddlmZ ddlmZ ddlmZ ddlZddl	mZ
 ddlmZmZ ddlmZ ddlmZmZ e
j        e         Zd	Zed&d„¦   «         Zed'd„¦   «         Zd(d„Zd)d„Zdedfd*d%„ZdS )+aë  Private Pillow-based text fallback for the OpenCV compatibility facade.

OpenCV renders text with built-in Hershey stroke fonts. The fallback instead
draws a proportional TrueType face (DejaVu Sans, shipped with Matplotlib, an
existing required dependency), so glyph shapes and text metrics differ from
OpenCV within the documented visual-divergence tier. ``getTextSize`` derives
its box from the same font ``putText`` renders with, so the reported rectangle
always encloses the drawn text.
é    )Úannotations)Úcache)ÚAnyN)ÚImageÚ	ImageDraw)Ú_paint)Ú_FONT_ITALICÚ_LINE_8é    ÚitalicÚboolÚreturnÚstrc                óŒ   — ddl m} | rdnd}|                     d|¬¦  «        }t          |                     |¦  «        ¦  «        S )zDLocate a bundled DejaVu Sans face through Matplotlib's font manager.r   )Úfont_managerr   ÚnormalzDejaVu Sans)ÚfamilyÚstyle)Ú
matplotlibr   ÚFontPropertiesr   Úfindfont)r   r   r   Ú
propertiess       úf/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/_cv2/_text.pyÚ
_font_pathr       sX   € ð (Ð'Ð'Ð'Ð'Ð'àÐ,ˆHˆH H€EØ×,Ò,°MÈÐ,ÑOÔO€JÝˆ|×$Ò$ ZÑ0Ô0Ñ1Ô1Ð1ó    Ú	font_faceÚintÚ
font_scaleÚfloatr   c                óÈ   — ddl m} t          dt          |t          z  ¦  «        ¦  «        }|                     t          t          | t          z  ¦  «        ¦  «        |¦  «        S )z;Return a cached Pillow font sized for an OpenCV font scale.r   )Ú	ImageFonté   )	ÚPILr!   ÚmaxÚroundÚ_PIXELS_PER_SCALEÚtruetyper   r   r	   )r   r   r!   Úsizes       r   Ú
_load_fontr)   *   s^   € ð ÐÐÐÐÐåˆq•%˜
Õ%6Ñ6Ñ7Ô7Ñ8Ô8€DØ×Ò�j­¨i½,Ñ.FÑ)GÔ)GÑHÔHÈ$ÑOÔOÐOr   Ú	thicknessc                ó(   — t          d| dz
  ¦  «        S )zJMap an OpenCV stroke thickness to the Pillow stroke_width it renders with.r   r"   )r$   )r*   s    r   Ú_stroke_widthr,   3   s   € åˆq�)˜a‘-Ñ Ô Ð r   ÚtextÚfontFaceÚ	fontScaleútuple[tuple[int, int], int]c                óÞ   — t          ||¦  «        }|                     ¦   «         \  }}t          |¦  «        }t          |                     | ¦  «        ¦  «        d|z  z   }||z   }	||z   }
||	f|
fS )aï  Return an OpenCV-shaped ``((width, height), baseline)`` for the face.

    Height is the font ascent and baseline the descent, both string-independent
    like OpenCV's contract, so consumers get stable row heights. Padding uses
    the same stroke_width _put_text renders with: Pillow's stroke dilates the
    glyph outline by stroke_width pixels on every side, so width grows by
    twice that (left and right) while height and baseline each grow by one
    stroke_width (top and bottom).
    é   )r)   Ú
getmetricsr,   r%   Ú	getlength)r-   r.   r/   r*   ÚfontÚascentÚdescentÚstroke_widthÚwidthÚheightÚbaselines              r   Ú_get_text_sizer<   8   sy   € õ �h 	Ñ*Ô*€DØ—o’oÑ'Ô'�O€FˆGÝ  Ñ+Ô+€LÝ�$—.’. Ñ&Ô&Ñ'Ô'¨!¨lÑ*:Ñ:€EØ�lÑ"€FØ˜Ñ%€HØ�6ˆ?˜HÐ$Ð$r   r"   FÚimgÚ_ImageArrayÚorgútuple[int, int]ÚcolorÚlineTypeÚbottomLeftOriginc	                óZ  — ~|rt          d¦  «        ‚|s| S t          ||¦  «        }	t          |¦  «        }
t          |d         ¦  «        t          |d         ¦  «        }}|	                     |d|
¬¦  «        \  }}}}||z
  ||z
  }}|dk    s|dk    r| S t          j        d||f¦  «        }t          j        |¦  «         	                    | | f|d|	d|
¬¦  «         t          j        |t          ¬¦  «        }| j        d	d
…         \  }}t          d||z   ¦  «        t          d||z   ¦  «        }}t          |||z   ¦  «        t          |||z   ¦  «        }}||k    s||k    r| S |||z   z
  }|||z   z
  }|||||z
  z   …||||z
  z   …f         }t!          | ||…||…f         ||¦  «         | S )a  Render text with a Pillow face, anchored at OpenCV's baseline origin.

    Thickness maps to a Pillow stroke width to emulate OpenCV's bolder strokes.
    ``bottomLeftOrigin`` (an inverted-axis mode no Supervision caller uses) is
    rejected rather than silently ignored.
    z1bottomLeftOrigin is not supported by the fallbackr   r"   Úls)Úanchorr8   Ú1)Úfillr5   rF   r8   )ÚdtypeNr2   )Ú
ValueErrorr)   r,   r%   Úgetbboxr   Únewr   ÚDrawr-   ÚnpÚasarrayr   Úshaper$   Úminr   )r=   r-   r?   r.   r/   rA   r*   rB   rC   r5   r8   ÚxÚyÚleftÚtopÚrightÚbottomr9   r:   Ú
mask_imageÚmaskÚimage_heightÚimage_widthÚx_startÚy_startÚx_stopÚy_stopÚmask_xÚmask_yÚclipped_masks                                 r   Ú	_put_textrc   M   s  € ð" 	Øð NÝÐLÑMÔMÐMØð Øˆ
å�h 	Ñ*Ô*€DÝ  Ñ+Ô+€LÝ��Q”‰=Œ=�%  A¤™-œ-€q€AØ#Ÿ|š|Ø�T¨ð  ,ñ  ô  Ñ€Dˆ#ˆu�fð ˜D‘L &¨3¡,ˆ6€EØ�‚z€z�V˜q’[�[Øˆ
å”˜3 ¨ Ñ0Ô0€JÝ„N�:ÑÔ×#Ò#Ø
ˆ��ˆØØØØØ!ð $ñ ô ð õ Œ:�j­Ð-Ñ-Ô-€Dà #¤	¨"¨1¨"¤Ñ€L�+Ý˜1˜a $™hÑ'Ô'­¨Q°°C±©¬ˆW€GÝ˜ a¨%¡iÑ0Ô0µ#°lÀAÈÁJÑ2OÔ2OˆF€FØ�&ÒÐ˜G vÒ-Ð-Øˆ
Ø˜˜D™Ñ!€FØ˜˜C™Ñ €FØØ�˜6 GÑ+Ñ,Ð,Ø�˜6 GÑ+Ñ,Ð,ð	.ô€Lõ ˆ3ˆw�vˆ~˜w v˜~Ð-Ô.°¸eÑDÔDÐDØ€Jr   )r   r   r   r   )r   r   r   r   r   r   )r*   r   r   r   )
r-   r   r.   r   r/   r   r*   r   r   r0   )r=   r>   r-   r   r?   r@   r.   r   r/   r   rA   r   r*   r   rB   r   rC   r   r   r>   )Ú__doc__Ú
__future__r   Ú	functoolsr   Útypingr   ÚnumpyrN   Únumpy.typingÚnptr#   r   r   Úsupervision._cv2._drawingr   Úsupervision._cv2.constantsr	   r
   ÚNDArrayr>   r&   r   r)   r,   r<   rc   © r   r   ú<module>ro      sU  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <àŒk˜#Ô€ð Ð ð ð2ð 2ð 2ñ „ð2ð ðPð Pð Pñ „ðPð!ð !ð !ð !ð
%ð %ð %ð %ð8 ØØ"ð8ð 8ð 8ð 8ð 8ð 8ð 8r   