Ë
    £eh.  ã                   óø   — d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZmZ d	d
gZdZdZ ej&                  e«      ZeZd„ Z G d„ de«      Zd„ Zd„ Zdd„Zdd„Z	 dd„Z	 	 	 	 	 	 	 dd„Zd„ Zd„ Z y)a—  Converts cubic bezier curves to quadratic splines.

Conversion is performed such that the quadratic splines keep the same end-curve
tangents as the original cubics. The approach is iterative, increasing the
number of segments for a spline until the error gets below a bound.

Respective curves from multiple fonts will be converted at once to ensure that
the resulting splines are interpolation-compatible.
é    N)ÚAbstractPen)ÚPointToSegmentPen)ÚReverseContourPené   )Úcurves_to_quadratic)ÚUnequalZipLengthsErrorÚIncompatibleSegmentNumberErrorÚIncompatibleSegmentTypesErrorÚIncompatibleGlyphsErrorÚIncompatibleFontsErrorÚfonts_to_quadraticÚfont_to_quadraticgü©ñÒMbP?z&com.github.googlei18n.cu2qu.curve_typec                  óp   — t        t        d„ | D «       «      «      dk7  rt        | Ž ‚t        t	        | Ž «      S )zyEnsure each argument to zip has the same length. Also make sure a list is
    returned for python 2/3 compatibility.
    c              3   ó2   K  — | ]  }t        |«      –— Œ y ­w©N©Úlen)Ú.0Úas     úQ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/fontTools/cu2qu/ufo.pyú	<genexpr>zzip.<locals>.<genexpr><   s   è ø€ Ò$˜!Œs�1�vÑ$ùs   ‚r   )r   Úsetr   ÚlistÚ_zip)Úargss    r   Úzipr   7   s6   € ô
 Œ3Ñ$˜tÔ$Ó$Ó%¨Ò*Ü$ dÐ+Ð+Ü”�d�ÓÐó    c                   óF   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zy)ÚGetSegmentsPenz®Pen to collect segments into lists of points for conversion.

    Curves always include their initial on-curve point, so some points are
    duplicated between segments.
    c                 ó    — d | _         g | _        y r   )Ú_last_ptÚsegments©Úselfs    r   Ú__init__zGetSegmentsPen.__init__H   s   € ØˆŒØˆ�r   c                 óZ   — |dv r
|d   | _         | j                  j                  ||f«       y )N)ÚmoveÚlineÚqcurveÚcurveéÿÿÿÿ)r!   r"   Úappend)r$   Útagr   s      r   Ú_add_segmentzGetSegmentsPen._add_segmentL   s,   € ØÐ5Ñ5Ø  ™HˆDŒMØ�‰×Ñ˜c 4˜[Õ)r   c                 ó(   — | j                  d|«       y )Nr'   ©r.   ©r$   Úpts     r   ÚmoveTozGetSegmentsPen.moveToQ   ó   € Ø×Ñ˜& "Õ%r   c                 ó(   — | j                  d|«       y )Nr(   r0   r1   s     r   ÚlineTozGetSegmentsPen.lineToT   r4   r   c                 ó@   —  | j                   d| j                  g|¢­Ž  y )Nr)   ©r.   r!   ©r$   Úpointss     r   ÚqCurveTozGetSegmentsPen.qCurveToW   s   € Øˆ×Ñ˜( D§M¡MÐ;°FÔ;r   c                 ó@   —  | j                   d| j                  g|¢­Ž  y )Nr*   r8   r9   s     r   ÚcurveTozGetSegmentsPen.curveToZ   s   € Øˆ×Ñ˜' 4§=¡=Ð:°6Ô:r   c                 ó&   — | j                  d«       y )NÚcloser0   r#   s    r   Ú	closePathzGetSegmentsPen.closePath]   s   € Ø×Ñ˜'Õ"r   c                 ó&   — | j                  d«       y )NÚendr0   r#   s    r   ÚendPathzGetSegmentsPen.endPath`   s   € Ø×Ñ˜%Õ r   c                  ó   — y r   © )r$   Ú	glyphNameÚtransformations      r   ÚaddComponentzGetSegmentsPen.addComponentc   s   € Ør   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r.   r3   r6   r;   r=   r@   rC   rH   rE   r   r   r   r   A   s4   „ ñòò*ò
&ò&ò<ò;ò#ò!ór   r   c                 ój   — t        «       }t        |d¬«      }| j                  |«       |j                  S )z6Get a glyph's segments as extracted by GetSegmentsPen.T)ÚoutputImpliedClosingLine)r   r   Ú
drawPointsr"   )ÚglyphÚpenÚpointPens      r   Ú_get_segmentsrS   g   s2   € ô Ó
€Cô ! ¸tÔD€HØ	×Ñ�XÔØ�<‰<Ðr   c                 ó˜  — | j                  «        | j                  «       }|rt        |«      }|D ]˜  \  }}|dk(  r |j                  |Ž  Œ|dk(  r |j                  |Ž  Œ0|dk(  r |j
                  |dd Ž  ŒH|dk(  r |j                  |dd Ž  Œ`|dk(  r|j                  «        Œv|dk(  r|j                  «        ŒŒt        d	|z  «      ‚ y)
z=Draw segments as extracted by GetSegmentsPen back to a glyph.r'   r(   r*   r   Nr)   r?   rB   zUnhandled segment type "%s")
ÚclearContoursÚgetPenr   r3   r6   r=   r;   r@   rC   ÚAssertionError)rP   r"   Úreverse_directionrQ   r-   r   s         r   Ú_set_segmentsrY   z   sÎ   € ð 
×ÑÔØ
�,‰,‹.€CÙÜ Ó$ˆØò F‰	ˆˆTØ�&Š=ØˆC�J‰J˜ÒØ�FŠ]ØˆC�J‰J˜ÒØ�GŠ^ØˆC�K‰K˜˜a˜b˜Ò"Ø�HŠ_ØˆC�L‰L˜$˜q˜r˜(Ò#Ø�GŠ^Ø�M‰M�OØ�EŠ\Ø�K‰K�Mä Ð!>ÀÑ!DÓEÐEñFr   c                 óŠ  ‡— t        d„ | D «       «      sJ d«       ‚t        | D �cg c]  }|d   ‘Œ	 c}||«      }t        |d   «      Št        ˆfd„|dd D «       «      sJ d«       ‚t        ‰dz
  «      }|j	                  |d«      dz   ||<   |s‰d	k(  r|D �cg c]  }d
|f‘Œ c}S |D �cg c]  }d|f‘Œ c}S c c}w c c}w c c}w )z2Return quadratic approximations of cubic segments.c              3   ó,   K  — | ]  }|d    dk(  –— Œ y­w)r   r*   NrE   )r   Úss     r   r   z)_segments_to_quadratic.<locals>.<genexpr>•   s   è ø€ Ò1 1ˆq�‰t�w�Ñ1ùs   ‚zNon-cubic given to convertr   r   c              3   ó:   •K  — | ]  }t        |«      ‰k(  –— Œ y ­wr   r   )r   r\   Úns     €r   r   z)_segments_to_quadratic.<locals>.<genexpr>™   s   øè ø€ Ò3˜qŒs�1‹v˜�{Ñ3ùs   ƒNzConverted incompatiblyé   é   r)   r*   )Úallr   r   ÚstrÚget)	r"   Úmax_errÚstatsÚall_quadraticr\   Ú
new_pointsÚspline_lengthÚpr^   s	           @r   Ú_segments_to_quadraticrj   ’   sÑ   ø€ ô Ñ1¨Ô1Ô1ÐOÐ3OÓOÐ1ä$°HÖ%=¨q a¨£dÒ%=¸wÈÓV€JÜˆJ�q‰MÓ€AÜÓ3 J¨q¨r NÔ3Ô3ÐMÐ5MÓMÐ3ä˜˜A™“J€MØ Ÿ9™9 ]°AÓ6¸Ñ:€Eˆ-Ñá˜˜QšØ'1Ö2 !�˜1’Ò2Ð2à&0Ö1 �˜!’Ò1Ð1ùò &>ùò 3ùâ1s   ¤B6ÂB;Â(C c                 ó  ‡— 	 t        | D �cg c]  }t        |«      ‘Œ c}Ž }t	        |«      sy|}g }i }	t        |«      D ]j  \  }
}|d   d   Št        ˆfd„|dd D «       «      s|D �cg c]  }|d   ‘Œ	 c}|	|
<   n‰dk(  rt        ||||«      }|s||k7  rd}|}|j                  |«       Œl |r)t        |Ž }t        | |«      D ]  \  }}t        |||«       Œ |	rt        | |	¬«      ‚|S c c}w # t        $ r t        | «      ‚w xY wc c}w )	z£Do the actual conversion of a set of compatible glyphs, after arguments
    have been set up.

    Return True if the glyphs were modified, else return False.
    Fr   c              3   ó.   •K  — | ]  }|d    ‰k(  –— Œ y­w)r   NrE   )r   r\   r-   s     €r   r   z'_glyphs_to_quadratic.<locals>.<genexpr>¹   s   øè ø€ Ò5 1�1�Q‘4˜3•;Ñ5ùs   ƒr   Nr*   T)r"   )r   rS   r   r	   ÚanyÚ	enumeratera   rj   r,   rY   r
   )Úglyphsrd   rX   re   rf   ÚgÚsegments_by_locationÚglyphs_modifiedÚnew_segments_by_locationÚincompatibleÚir"   r\   Únew_segmentsÚnew_segments_by_glyphrP   r-   s                   @r   Ú_glyphs_to_quadraticrx   ¤   sK  ø€ ð5Ü"¸vÖ$F¸!¤]°1Õ%5Ò$FÐGÐô Ð#Ô$Øð (€Oà!ÐØ€LÜ Ð!5Ó6ò 2‰ˆˆ8Ø�q‰k˜!‰nˆÜÓ5¨°°¨Ô5Ô5Ø-5Ö6¨˜q ›tÒ6ˆL˜ŠOØ�GŠ^Ü1Ø˜' 5¨-óˆLñ  °Ò 8Ø"&�Ø#ˆHØ ×'Ñ'¨Õ1ð2ñ Ü #Ð%=Ð >ÐÜ#& vÐ/DÓ#Eò 	BÑˆE�<Ü˜% Ð/@ÕAð	Bñ Ü+¨F¸\ÔJÐJØÐùò? %GøÜ!ò 5Ü,¨VÓ4Ð4ð5üò 7s!   ƒ	C- ŒC(žC- Á(DÃ(C- Ã-Dc                 óÀ   — |€i }|s	t         dz  }t        |t        t        f«      r|}n|gt	        | «      z  }t	        |«      t	        | «      k(  sJ ‚t        | ||||«      S )a²  Convert the curves of a set of compatible of glyphs to quadratic.

    All curves will be converted to quadratic at once, ensuring interpolation
    compatibility. If this is not required, calling glyphs_to_quadratic with one
    glyph at a time may yield slightly more optimized results.

    Return True if glyphs were modified, else return False.

    Raises IncompatibleGlyphsError if glyphs have non-interpolatable outlines.
    iè  )ÚDEFAULT_MAX_ERRÚ
isinstancer   Útupler   rx   )ro   rd   rX   re   rf   Ú
max_errorss         r   Úglyphs_to_quadraticr~   Î   sm   € ð €}Øˆáä! DÑ(ˆä�'œD¤%˜=Ô)Ø‰
à�Y¤ V£Ñ,ˆ
Üˆz‹?œc &›kÒ)Ð)Ð)äØ�
Ð-¨u°móð r   c                 ó
  ‡— |r�| D �ch c]"  }|j                   j                  t        d«      ’Œ$ }	}t        |	«      dk(  r?t	        t        |	«      «      }
|
dv rt        j                  d«       y|
dk(  rn.t        |
«      ‚t        |	«      dkD  rt        j                  d«       ‰€i Š|r|rt        d«      ‚|s|st        }t        |t        t        f«      rt        |«      t        | «      k(  sJ ‚|}n|r|gt        | «      z  }t        |t        t        f«      rOt        | «      t        |«      k(  sJ ‚t        | |«      D ��cg c]  \  }}|j                  j                   |z  ‘Œ  }}}n(|r&| D �cg c]  }|j                  j                   |z  ‘Œ }}t#        «       }i } t#        «       j$                  d	„ | D «       Ž D ]e  }g }g }t        | «      D ]/  \  }}||v sŒ|j'                  ||   «       |j'                  |«       Œ1 	 t)        |||‰|«      r|j+                  |«       Œg |rt1        |«      ‚|rK|rIt3        ‰j5                  «       «      }t        j                  d
dj7                  ˆfd„|D «       «      z  «       |rF| D ]A  }|j                   j                  t        d«      }
|rdnd}|
|k7  sŒ/||j                   t        <   ŒC |S c c}w c c}}w c c}w # t,        $ r%}t        j/                  |«       |||<   Y d}~�ŒEd}~ww xY w)a  Convert the curves of a collection of fonts to quadratic.

    All curves will be converted to quadratic at once, ensuring interpolation
    compatibility. If this is not required, calling fonts_to_quadratic with one
    font at a time may yield slightly more optimized results.

    Return the set of modified glyph names if any, else return an empty set.

    By default, cu2qu stores the curve type in the fonts' lib, under a private
    key "com.github.googlei18n.cu2qu.curve_type", and will not try to convert
    them again if the curve type is already set to "quadratic".
    Setting 'remember_curve_type' to False disables this optimization.

    Raises IncompatibleFontsError if same-named glyphs from different fonts
    have non-interpolatable outlines.
    Úcubicr   )Ú	quadraticÚmixedz%Curves already converted to quadraticFz'fonts may contain different curve typesNz4Only one of max_err and max_err_em can be specified.c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­wr   )Úkeys)r   Úfs     r   r   z%fonts_to_quadratic.<locals>.<genexpr>-  s   è ø€ Ò6¨1˜aŸf™fŸhÑ6ùs   ‚zNew spline lengths: %sz, c              3   ó2   •K  — | ]  }d |‰|   fz  –— Œ y­w)z%s: %dNrE   )r   Úlre   s     €r   r   z%fonts_to_quadratic.<locals>.<genexpr>D  s   øè ø€ ÒJ°a˜ Q¨¨a© MÕ1ÑJùs   ƒr�   r‚   )Úlibrc   ÚCURVE_TYPE_LIB_KEYr   ÚnextÚiterÚloggerÚinfoÚNotImplementedErrorÚwarningÚ	TypeErrorrz   r{   r   r|   r   Ú
unitsPerEmr   Úunionr,   rx   Úaddr   Úerrorr   Úsortedr„   Újoin)ÚfontsÚ
max_err_emrd   rX   re   Ú
dump_statsÚremember_curve_typerf   r…   Úcurve_typesÚ
curve_typer}   ÚeÚmodifiedÚglyph_errorsÚnamero   Úcur_max_errorsÚfontr”   ÚexcÚspline_lengthsÚnew_curve_types       `                  r   r   r   í   sÚ  ø€ ñ6 ØGLÖMÀ!�q—u‘u—y‘yÔ!3°WÕ=ÐMˆÐMÜˆ{Ó˜qÒ Üœd ;Ó/Ó0ˆJØÐ3Ñ3Ü—‘ÐCÔDØØ˜wÒ&Øä)¨*Ó5Ð5Ü�Ó Ò!ä�N‰NÐDÔEà€}Øˆá‘gÜÐNÓOÐOÙ™'Ü$ˆ
ä�'œD¤%˜=Ô)Ü�7‹|œs 5›zÒ)Ð)Ð)Ø‰
Ù	Ø�Y¤ U£Ñ+ˆ
ä�*œt¤U˜mÔ,Ü�5‹zœS ›_Ò,Ð,Ð,Ü8;¸EÀ:Ó8N×O±°°1�a—f‘f×'Ñ'¨!Ó+ÐOˆ
ÒOÙ	Ø>CÖD¸�a—f‘f×'Ñ'¨*Ó4ÐDˆ
ÐDä‹u€HØ€LØ”“—‘Ñ6°Ô6Ð7ò %ˆØˆØˆÜ˜u jÓ1ò 	-‰KˆD�%Ø�tŠ|Ø—‘˜d 4™jÔ)Ø×%Ñ% eÕ,ð	-ð	%Ü#Ø˜Ð(9¸5À-ôð —‘˜TÔ"øð%ñ  Ü$ \Ó2Ð2á‘JÜ §
¡
£Ó-ˆÜ�‰Ø$Ø�y‰yÓJ¸>ÔJÓJñLô	
ñ
 Øò 	>ˆDØŸ™Ÿ™Ô&8¸'ÓBˆJÙ,9™[¸wˆNØ˜^Ó+Ø/=�—‘Ô+Ò,ð		>ð
 €OùòI Nùó< PùâDøô  'ò 	%Ü�L‰L˜ÔØ!$ˆL˜×ûð	%ús)   ˆ'KÄ?#K	Å, KÇ> KË	LËK=Ë=Lc                 ó   — t        | gfi |¤ŽS )z†Convenience wrapper around glyphs_to_quadratic, for just one glyph.
    Return True if the glyph was modified, else return False.
    )r~   )rP   Úkwargss     r   Úglyph_to_quadraticr¨   P  s   € ô
  ˜wÑ1¨&Ñ1Ð1r   c                 ó   — t        | gfi |¤ŽS )z�Convenience wrapper around fonts_to_quadratic, for just one font.
    Return the set of modified glyph names if any, else return empty set.
    )r   )r¢   r§   s     r   r   r   X  s   € ô
 ˜t˜fÑ/¨Ñ/Ð/r   )T)NFNT)NNFNFTT)!rL   ÚloggingÚfontTools.pens.basePenr   ÚfontTools.pens.pointPenr   Ú fontTools.pens.reverseContourPenr   Ú r   Úerrorsr   r	   r
   r   r   Ú__all__rz   r‰   Ú	getLoggerrI   rŒ   r   r   r   rS   rY   rj   rx   r~   r   r¨   r   rE   r   r   ú<module>r²      sµ   ðñ ó Ý .Ý 5Ý >å !÷õ ð  Ð!4Ð
5€ð
 €Ø=Ð à	ˆ×	Ñ	˜8Ó	$€ð €òô#�[ô #òLò&Fó02ó$'ðV NRóðB ØØØ
ØØØó`òF2ó0r   