� ��gW��&�dZddlZddlmZmZmZmZddlmZddl m Z m Z m Z ddl mZmZgd�ZGd�d ��ZGd �d e��ZGd �d e��ZGd�de ��ZGd�de��ZGd�de��ZGd�dee��ZdS)a� ========= PointPens ========= Where **SegmentPens** have an intuitive approach to drawing (if you're familiar with postscript anyway), the **PointPen** is geared towards accessing all the data in the contours of the glyph. A PointPen has a very simple interface, it just steps through all the points in a call from glyph.drawPoints(). This allows the caller to provide more data for each point. For instance, whether or not a point is smooth, and its name. �N)�Any�Optional�Tuple�Dict)�LogMixin)� AbstractPen�MissingComponentError�PenError)�DecomposedTransform�Identity)�AbstractPointPen�BasePointToSegmentPen�PointToSegmentPen�SegmentToPointPen�GuessSmoothPointPen�ReverseContourPointPenc�"�eZdZdZddeededdfd�Zdd�Z dd e e e fd eed e d eedeededdfd �Z ddede e e e e e e fdeededdf d�Z ddededeee fdeededdf d�ZdS)r zBaseclass for all PointPens.N� identifier�kwargs�returnc ��t�)zStart a new sub path.��NotImplementedError��selfrrs �g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fontTools/pens/pointPen.py� beginPathzAbstractPointPen.beginPath#���!�!�c��t�)zEnd the current sub path.r�rs r�endPathzAbstractPointPen.endPath'rrF�pt� segmentType�smooth�namec ��t�)z$Add a point to the current sub path.r�rr#r$r%r&rrs r�addPointzAbstractPointPen.addPoint+s ��"�!r� baseGlyphName�transformationc ��t�)zAdd a sub glyph.r)rr*r+rrs r� addComponentzAbstractPointPen.addComponent7s ��"�!r� glyphName�locationc ��t�)z�Add a VarComponent sub glyph. The 'transformation' argument must be a DecomposedTransform from the fontTools.misc.transform module, and the 'location' argument must be a dictionary mapping axis tags to their locations. )�AttributeError�rr.r+r/rrs r�addVarComponentz AbstractPointPen.addVarComponentAs ���r�N)rN�NFNN)�__name__� __module__� __qualname__�__doc__r�strrrr"r�float�boolr)r-r rr3�rrr r s�������&�&�"�"�H�S�M�"�C�"�D�"�"�"�"�"�"�"�"�&*��"�$(� "� "� �%��,� � "��c�]� "�� "� �s�m� "� �S�M� "�� "� � "� "� "� "� %)� "�"��"��e�U�E�5�%��F�G�"��S�M� "� � "� � "�"�"�"�%)� ����,���s�E�z�"� � �S�M� � � � ������rr c�6�eZdZdZd�Zd d�Zd�Zd�Z d d�ZdS) ra/ Base class for retrieving the outline in a segment-oriented way. The PointPen protocol is simple yet also a little tricky, so when you need an outline presented as segments but you have as points, do use this base implementation as it properly takes care of all the edge cases. c��d|_dSr4)� currentPathr!s r�__init__zBasePointToSegmentPen.__init__[s������rNc �@�|j�td���g|_dS)NzPath already begun.)r@r rs rrzBasePointToSegmentPen.beginPath^s(�� � � '��0�1�1� 1�����rc��t�)a�Override this method. It will be called for each non-empty sub path with a list of segments: the 'segments' argument. The segments list contains tuples of length 2: (segmentType, points) segmentType is one of "move", "line", "curve" or "qcurve". "move" may only occur as the first segment, and it signifies an OPEN path. A CLOSED path does NOT start with a "move", in fact it will not contain a "move" at ALL. The 'points' field in the 2-tuple is a list of point info tuples. The list has 1 or more items, a point tuple has four items: (point, smooth, name, kwargs) 'point' is an (x, y) coordinate pair. For a closed path, the initial moveTo point is defined as the last point of the last segment. The 'points' list of "move" and "line" segments always contains exactly one point tuple. r)r�segmentss r� _flushContourz#BasePointToSegmentPen._flushContourcs ��4"�!rc��|j�td���|j}d|_|sdSt|��dkr/|d\}}}}}d||||fgfg}|�|��dSg}|dddkr@|d\}}}}}|�d||||fgf��|�d��nhd}t t|����D]} || d}|�| }n�|�|�d��n||dzd�|d|dz�z}g} |D]=\}}}}}| �||||f��|��$|�|| f��g} �>|�|��dS)NzPath not begun.�r�move)N�qcurveNNN)r@r �lenrE�append�pop�range) r�pointsr#r$r%r&rrD� firstOnCurve�i�currentSegments rr"zBasePointToSegmentPen.endPaths��� � � #��,�-�-� -��!������ � �F� �v�;�;�!� � �4:�1�I� 1�B� �V�T�6��2�v�t�V�"<�!=�>�?�H� � � �x� (� (� (� �F��� �!�9�Q�<�6� !� !�5;�1�I� 1�B� �V�T�6� �O�O�V�r�6�4��&@�%A�B� C� C� C� �J�J�q�M�M�M�M�  �L��3�v�;�;�'�'� � ��$�Q�i��l� ��*�#$�L��E�+��#�� � �@�A�A�A�A�� �q� 0� 2� 2�3�f�=O�|�a�?O�=O�6P�P����5;� � � 1�B� �V�T�6� � !� !�2�v�t�V�"<� =� =� =��"�� �O�O�[�.�9� :� :� :��N�N� ���8�$�$�$�$�$rFc �p�|j�td���|j�|||||f��dS�N�Path not begun)r@r rKr(s rr)zBasePointToSegmentPen.addPoint�sD�� � � #��+�,�,� ,� �����[�&�$�� G�H�H�H�H�Hrr4r5) r6r7r8r9rArrEr"r)r=rrrrRs��������� � � ����� "�"�"�8.%�.%�.%�bIM�I�I�I�I�I�Irrc�(�eZdZdZdd�Zd�Zdd�ZdS) rz� Adapter class that converts the PointPen protocol to the (Segment)Pen protocol. NOTE: The segment pen does not support and will drop point names, identifiers and kwargs. Fc�V�t�|��||_||_dSr4)rrA�pen�outputImpliedClosingLine)r� segmentPenrXs rrAzPointToSegmentPen.__init__�s+���&�&�t�,�,�,����(@��%�%�%rc��|std���|j}|dddkrSd}|dd}t|��dkrtdt|�������|d\}}}}|d=nd}|d\}}|d\}}}}|�n|�|��|j}t|��} |} t | ��D]�} || \}}d �|D��}|d kret|��dkrtd t|�������|d} | dz| ks |s|r| | kr|�| ��| } ��|d kr|j|�|d} ��|d kr|j|�|d} ��td|�����|r|� ��dS|� ��dS)NzMust have at least one segment.rrHFrGz"Illegal move segment point count: T�����c��g|] \}}}}|�� Sr=r=)�.0r#�_s r� <listcomp>z3PointToSegmentPen._flushContour.<locals>.<listcomp>�s ��3�3�3�[�R��A�q�b�3�3�3r�linez"Illegal line segment point count: �curverIzIllegal segmentType: ) r rWrJ�moveTorXrM�lineTo�curveTo�qCurveTo� closePathr") rrDrW�closedrN�movePtr^r$rX� nSegments�lastPtrPr#s rrEzPointToSegmentPen._flushContour�s0��� >��<�=�=� =��h�� �A�;�q�>�V� #� #��F��a�[��^�F��6�{�{�a����Q�C��K�K�Q�Q�R�R�R�$�Q�i�O�F�A�q�!��� � ��F�"*�2�,� �K��$�R�j�O�F�A�q�!� �>� � �J�J�v� � � �#'�#@� ���M�M� ����y�!�!� F� F�A�"*�1�+� �K��3�3�F�3�3�3�F��f�$�$��v�;�;�!�#�#�"�#U��F� � �#U�#U�V�V�V��A�Y����E�Y�&�&�/�'�!�'��V�|�|��J�J�r�N�N�N��F����'�'��� �V�$�$��������(�(��� �f�%�%�������D�{�D�D�E�E�E� � � �M�M�O�O�O�O�O� �K�K�M�M�M�M�MrNc �@�~~|j�||��dSr4)rWr-�rr.� transformrrs rr-zPointToSegmentPen.addComponents&�� � � ����i��3�3�3�3�3r)Fr4)r6r7r8r9rArEr-r=rrrr�sZ��������A�A�A�A� ?�?�?�B4�4�4�4�4�4rrc�J�eZdZdZd d�Zd�Zd�Zd�Zd�Zd�Z d �Z d �Z d �Z d S)rz] Adapter class that converts the (Segment)Pen protocol to the PointPen protocol. Tc�P�|rt|��|_n||_d|_dSr4)rrW�contour)r�pointPen� guessSmooths rrAzSegmentToPointPen.__init__s-�� � �*�8�4�4�D�H�H��D�H��� � � rc��|j}|���|jD]\}}|�||����|���dS)N)r$)rWrrpr)r")rrWr#r$s rrEzSegmentToPointPen._flushContoursU���h�� � � ����#�|� 6� 6�O�B� � �L�L���L� 5� 5� 5� 5� � � � � � � � rc�L�g|_|j�|df��dS)NrH)rprK�rr#s rrbzSegmentToPointPen.moveTo s)���� � � ���R��L�)�)�)�)�)rc�j�|j�td���|j�|df��dS)N�'Contour missing required initial moveTor`)rpr rKrus rrczSegmentToPointPen.lineTo$s9�� �<� ��D�E�E� E� � ���R��L�)�)�)�)�)rc���|std���|j�td���|dd�D]}|j�|df���|j�|ddf��dS)N�Must pass in at least one pointrwr[ra�� TypeErrorrpr rK�r�ptsr#s rrdzSegmentToPointPen.curveTo)s���� ?��=�>�>� >� �<� ��D�E�E� E��c�r�c�(� ,� ,�B� �L� � ��T� � +� +� +� +� � ���S��W�g�.�/�/�/�/�/rc��|std���|d�g|_n|j�td���|dd�D]}|j�|df���|d�$|j�|ddf��dSdS)Nryr[rwrIrzr|s rrezSegmentToPointPen.qCurveTo2s���� ?��=�>�>� >� �r�7�?��D�L�L��|�#��H�I�I�I��c�r�c�(� ,� ,�B� �L� � ��T� � +� +� +� +� �r�7� � �L� � ��R��(� 3� 4� 4� 4� 4� 4� � rc�h�|j�td���t|j��dkrF|jdd|jddkr|jd|jd<|jd=n"|jd\}}|dkr |df|jd<|���d|_dS)NrwrGrr[rHr`)rpr rJrE)rr#�tps rrfzSegmentToPointPen.closePath?s��� �<� ��D�E�E� E� �t�|� � �q� � �T�\�!�_�Q�%7�4�<��;K�A�;N�%N�%N�"�l�2�.�D�L��O�� �R� � ��\�!�_�F�B���V�|�|�"$�f�*�� �Q�� �������� � � rc�h�|j�td���|���d|_dS)Nrw)rpr rEr!s rr"zSegmentToPointPen.endPathNs6�� �<� ��D�E�E� E� �������� � � rc�h�|j�td���|j�||��dS)N�1Components must be added before or after contours)rpr rWr-)rr.rms rr-zSegmentToPointPen.addComponentTs7�� �<� #��N�O�O� O� ����i��3�3�3�3�3rN)T) r6r7r8r9rArErbrcrdrerfr"r-r=rrrr s��������� �������*�*�*�*�*�*� 0�0�0� 5� 5� 5� � � ���� 4�4�4�4�4rrc�J�eZdZdZd d�Zd�Zd d�Zd�Z dd �Zd d �Z d d �Z dS)rz� Filtering PointPen that tries to determine whether an on-curve point should be "smooth", ie. that it's a "tangent" point or a "curve" point. 皙�����?c�0�||_||_d|_dSr4)�_outPen�_error�_points)r�outPen�errors rrAzGuessSmoothPointPen.__init__`s���� ��� ��� � � rc�<�|j�td���|j}t|��}|sdS|dddkrtd|dz ��}n|dkrtd|dz ��}ng}|D�]}||\}}}}} |��|dz } |dz} || d�|| d��;||d}|| d} || d} || kr�|| kr�|d| dz |d| dz }}| d|dz | d|dz }}t j||��}t j||��}t ||z ��|jkr ||d|| f||<��|D]\}}}}} |jj ||||fi| ���dS)NrTrrGrHr[T) r�r rJrM�math�atan2�absr�r�r))rrN�nPoints�indicesrPr#r$r^r&r�prev�next�prevPt�nextPt�dx1�dy1�dx2�dy2�a1�a2r%s rrEz!GuessSmoothPointPen._flushContoures��� �<� ��+�,�,� ,�����f�+�+��� � �F� �!�9�Q�<�6� !� !��A�w��{�+�+�G�G� �q�[�[��B��!� �,�,�G�G��G�� D� D�A�/5�a�y� ,�B� �Q��f��"���q�5�D��q�5�D��d�|�A��*�v�d�|�A��/J�����1��B��D�\�!�_�F��D�\�!�_�F��V�|�|��f� � ��a�5�6�!�9�,�b��e�f�Q�i�.?�S��!�!�9�r�!�u�,�f�Q�i�"�Q�%�.?�S���Z��S�)�)���Z��S�)�)���r�B�w�<�<�$�+�-�-� "�K��t�V� C�F�1�I��5;� K� K� 1�B� �V�T�6� !�D�L� !�"�k�6�4� J� J�6� J� J� J� J� K� KrNc �r�|j�td���g|_|�||d<|jjdi|��dS)N�Path already begunrr=)r�r r�rrs rrzGuessSmoothPointPen.beginPath�sQ�� �<� #��/�0�0� 0��� � � !�#-�F�<� ��� ��(�(��(�(�(�(�(rc�n�|���|j���d|_dSr4)rEr�r"r�r!s rr"zGuessSmoothPointPen.endPath�s3�� ������ � �������� � � rFc �~�|j�td���|�||d<|j�||d||f��dS)NrTrF)r�r rKr(s rr)zGuessSmoothPointPen.addPoint�sR�� �<� ��+�,�,� ,� � !�#-�F�<� � � ���R��e�T�6�B�C�C�C�C�Crc �h�|j�td���|�||d<|jj||fi|��dS�Nr�r)r�r r�r-)rr.r+rrs rr-z GuessSmoothPointPen.addComponent�sN�� �<� #��N�O�O� O� � !�#-�F�<� �!�� �!�)�^�F�F�v�F�F�F�F�Frc �j�|j�td���|�||d<|jj|||fi|��dS)Nz4VarComponents must be added before or after contoursr)r�r r�r3r2s rr3z#GuessSmoothPointPen.addVarComponent�sR�� �<� #��Q�R�R� R� � !�#-�F�<� �$�� �$�Y���S�S�F�S�S�S�S�Sr)r�r4r5) r6r7r8r9rArErr"r)r-r3r=rrrrZs��������� ���� &K�&K�&K�P)�)�)�)���� IM�D�D�D�D�G�G�G�G�?C�T�T�T�T�T�Trrc�>�eZdZdZd�Zd�Zd d�Zd�Z d d�Zd d �Z dS) ra This is a PointPen that passes outline data to another PointPen, but reversing the winding direction of all contours. Components are simply passed through unchanged. Closed contours are reversed in such a way that the first point remains the first point. c�"�||_d|_dSr4)rW�currentContour)r�outputPointPens rrAzReverseContourPointPen.__init__�s��!���"����rc���|j}|j}|s1|�|j���|���dS|dddk}|sd}nn|�|�d����d}tt|����D]}||d�|}n�|�d}n||d}|� ��|s1|dd�#|�d��|dd�#|�|j���|D]#\}}} } } |�|} |}nd} |j |f| | | d�| ���$|���dS)N)rrrGrH)r$r%r&) rWr�r�currentContourIdentifierr"rKrLrMrJ�reverser)) rrWrprg�lastSegmentTyperOrPr#�nextSegmentTyper%r&rr$s rrEz$ReverseContourPointPen._flushContour�s����h���%��� � �M�M�T�%B�M� C� C� C� �K�K�M�M�M� �F����A��&�(��� ;�$�O�O� �N�N�7�;�;�q�>�>� *� *� *��L��3�w�<�<�(�(� � ���1�:�a�=�,�#$�L��E�-��#�#'���")�,�"7��":��������� ��!�*�Q�-�'�� � �A�����!�*�Q�-�'� � � ��!>� �?�?�?�9@� � � 5�B����v��*�-� �"1���"� � �C�L�� � +�F�� � �IO� � � � � � � � � � � � rNc �\�|j�td���g|_||_g|_dS)Nr�)r�r r��onCurvers rrz ReverseContourPointPen.beginPath�s5�� � � *��/�0�0� 0� ���(2��%��� � � rc�h�|j�td���|���d|_dSrS)r�r rEr!s rr"zReverseContourPointPen.endPath�s:�� � � &��+�,�,� ,� ������"����rFc �~�|j�td���|�||d<|j�|||||f��dS)NrTr)r�r rKr(s rr)zReverseContourPointPen.addPointsT�� � � &��+�,�,� ,� � !�#-�F�<� � ��"�"�B� �V�T�6�#J�K�K�K�K�Krc �^�|j�td���|jj||fd|i|��dSr�)r�r rWr-rls rr-z#ReverseContourPointPen.addComponent sD�� � � *��N�O�O� O�����i��T�T�z�T�V�T�T�T�T�Trr4r5) r6r7r8r9rArErr"r)r-r=rrrr�s���������#�#�#� 0�0�0�d����#�#�#�IM�L�L�L�L�U�U�U�U�U�Urrc�:��eZdZdZdZeZddd��fd� Zdd�Z�xZS) �DecomposingPointPena:Implements a 'addComponent' method that decomposes components (i.e. draws them onto self as simple contours). It can also be used as a mixin class (e.g. see DecomposingRecordingPointPen). You must override beginPath, addPoint, endPath. You may additionally override addVarComponent and addComponent. By default a warning message is logged when a base glyph is missing; set the class variable ``skipMissingComponents`` to False if you want all instances of a sub-class to raise a :class:`MissingComponentError` exception by default. TNF)�skipMissingComponents�reverseFlippedc���t��j|i|��||_|� |jjn||_||_dS)aTakes a 'glyphSet' argument (dict), in which the glyphs that are referenced as components are looked up by their name. If the optional 'reverseFlipped' argument is True, components whose transformation matrix has a negative determinant will be decomposed with a reversed path direction to compensate for the flip. The optional 'skipMissingComponents' argument can be set to True/False to override the homonymous class attribute for a given pen instance. N)�superrA�glyphSet� __class__r�r�)rr�r�r��argsrr�s �rrAzDecomposingPointPen.__init__#sX���$ �����$�)�&�)�)�)� �� �%�,� �N� 0� 0�&� �"� -����rc ��ddlm} |j|}|}|tkr |||��}|jr8|dd�\}} } } || z| | zz } || z| | zz dkrt |��}|�|��dS#t$r7|jst|���|j � d|z��YdSwxYw)z�Transform the points of the base glyph and draw it onto self. The `identifier` parameter and any extra kwargs are ignored. r)�TransformPointPenN�z,glyph '%s' is missing from glyphSet; skipped) �fontTools.pens.transformPenr�r�r r�r� drawPoints�KeyErrorr�r �log�warning) rr*r+rrr��glyphrW�a�b�c�d�dets rr-z DecomposingPointPen.addComponent>s%�� B�A�A�A�A�A� "��M�-�0�E��C���)�)�'�'��^�<�<���"� 6�,�B�Q�B�/� ��1�a���!�e�a�!�e�m���q�5�1�q�5�=�1�$�$�0��5�5�C� � � �S� !� !� !� !� !��#� � � ��-� ;�+�M�:�:�:� �H� � �>��N� � � � � � � ���s� B�=C�Cr4) r6r7r8r9r�r rAr-� __classcell__)r�s@rr�r�sv������� � �!��1�� #�� -�-�-�-�-�-�-�6"�"�"�"�"�"�"�"rr�)r9r��typingrrrr�fontTools.misc.loggingToolsr�fontTools.pens.basePenrr r �fontTools.misc.transformr r �__all__r rrrrrr�r=rr�<module>r�s�� � � � � � �-�-�-�-�-�-�-�-�-�-�-�-�0�0�0�0�0�0�O�O�O�O�O�O�O�O�O�O�B�B�B�B�B�B�B�B� � � ��/�/�/�/�/�/�/�/�dbI�bI�bI�bI�bI�,�bI�bI�bI�JR4�R4�R4�R4�R4�-�R4�R4�R4�jK4�K4�K4�K4�K4� �K4�K4�K4�\WT�WT�WT�WT�WT�*�WT�WT�WT�tZU�ZU�ZU�ZU�ZU�-�ZU�ZU�ZU�zG"�G"�G"�G"�G"�(�$4�G"�G"�G"�G"�G"r
Memory