� ��g�B���dZddlmZmZddlmZddlmZmZgd�Z Gd�de ��Z Gd�d e ��Z Gd �d ��Z Gd �d e ��ZGd�dee ��ZGd�de��ZGd�de��ZGd�de��Zd�Zd�ZGd�de��Zedkr�ed��Ze�d��e�d��e�ddd d��e���ed��Ze�ddd!d"d��e���dSdS)#a�fontTools.pens.basePen.py -- Tools and base classes to build pen objects. The Pen Protocol A Pen is a kind of object that standardizes the way how to "draw" outlines: it is a middle man between an outline and a drawing. In other words: it is an abstraction for drawing outlines, making sure that outline objects don't need to know the details about how and where they're being drawn, and that drawings don't need to know the details of how outlines are stored. The most basic pattern is this:: outline.draw(pen) # 'outline' draws itself onto 'pen' Pens can be used to render outlines to the screen, but also to construct new outlines. Eg. an outline object can be both a drawable object (it has a draw() method) as well as a pen itself: you *build* an outline using pen methods. The AbstractPen class defines the Pen protocol. It implements almost nothing (only no-op closePath() and endPath() methods), but is useful for documentation purposes. Subclassing it basically tells the reader: "this class implements the Pen protocol.". An examples of an AbstractPen subclass is :py:class:`fontTools.pens.transformPen.TransformPen`. The BasePen class is a base implementation useful for pens that actually draw (for example a pen renders outlines using a native graphics engine). BasePen contains a lot of base functionality, making it very easy to build a pen that fully conforms to the pen protocol. Note that if you subclass BasePen, you *don't* override moveTo(), lineTo(), etc., but _moveTo(), _lineTo(), etc. See the BasePen doc string for details. Examples of BasePen subclasses are fontTools.pens.boundsPen.BoundsPen and fontTools.pens.cocoaPen.CocoaPen. Coordinates are usually expressed as (x, y) tuples, but generally any sequence of length 2 will do. �)�Tuple�Dict)�LogMixin)�DecomposedTransform�Identity)� AbstractPen�NullPen�BasePen�PenError�decomposeSuperBezierSegment�decomposeQuadraticSegmentc��eZdZdZdS)r z#Represents an error during penning.N��__name__� __module__� __qualname__�__doc__���f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fontTools/pens/basePen.pyr r 6s������-�-�-�-rr c��eZdZdS)�OpenContourErrorN)rrrrrrrr:s�������Drrc ���eZdZdeeefddfd�Zdeeefddfd�Zdeeefddfd�Zdeeefddfd�Zdd �Z dd �Z d e d eeeeeeefddfd �Z d e d e dee efddfd�ZdS)r�pt�returnNc��t�)z�Begin a new sub path, set the current point to 'pt'. You must end each sub path with a call to pen.closePath() or pen.endPath(). ��NotImplementedError��selfrs r�moveTozAbstractPen.moveTo?s ��"�!rc��t�)z4Draw a straight line from the current point to 'pt'.rrs r�lineTozAbstractPen.lineToEs��!�!r�pointsc��t�)a�Draw a cubic bezier with an arbitrary number of control points. The last point specified is on-curve, all others are off-curve (control) points. If the number of control points is > 2, the segment is split into multiple bezier segments. This works like this: Let n be the number of control points (which is the number of arguments to this call minus 1). If n==2, a plain vanilla cubic bezier is drawn. If n==1, we fall back to a quadratic segment and if n==0 we draw a straight line. It gets interesting when n>2: n-1 PostScript-style cubic segments will be drawn as if it were one curve. See decomposeSuperBezierSegment(). The conversion algorithm used for n>2 is inspired by NURB splines, and is conceptually equivalent to the TrueType "implied points" principle. See also decomposeQuadraticSegment(). r�r r$s r�curveTozAbstractPen.curveToIs ��&"�!rc��t�)a\Draw a whole string of quadratic curve segments. The last point specified is on-curve, all others are off-curve points. This method implements TrueType-style curves, breaking up curves using 'implied points': between each two consequtive off-curve points, there is one implied point exactly in the middle between them. See also decomposeQuadraticSegment(). The last argument (normally the on-curve point) may be None. This is to support contours that have NO on-curve points (a rarely seen feature of TrueType outlines). rr&s r�qCurveTozAbstractPen.qCurveTo^s ��"�!rc��dS)zwClose the current sub path. You must call either pen.closePath() or pen.endPath() after each sub path. Nr�r s r� closePathzAbstractPen.closePatho� �� �rc��dS)z�End the current sub path, but don't close it. You must call either pen.closePath() or pen.endPath() after each sub path. Nrr+s r�endPathzAbstractPen.endPathur-r� glyphName�transformationc��t�)aAdd a sub glyph. The 'transformation' argument must be a 6-tuple containing an affine transformation, or a Transform object from the fontTools.misc.transform module. More precisely: it should be a sequence containing 6 numbers. r�r r0r1s r� addComponentzAbstractPen.addComponent{s ��"�!r�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�r r0r1r5s r�addVarComponentzAbstractPen.addVarComponent�s ���r)rN)rrrr�floatr!r#r'r)r,r/�strr4rrr:rrrrr>sm������"��u�e�|�,�"��"�"�"�"� "��u�e�|�,�"��"�"�"�"�"�u�U�E�\�2�"�t�"�"�"�"�*"��e�U�l� 3�"��"�"�"�"�" � � � �  � � � � "�� "��e�U�E�5�%��F�G� "� � "� "� "� "� �� �,� ��s�E�z�"� � � � � � � � rrc�B�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z d S) r zA pen that does nothing.c��dS�Nrrs rr!zNullPen.moveTo���� �rc��dSr?rrs rr#zNullPen.lineTo�r@rc��dSr?rr&s rr'zNullPen.curveTo�r@rc��dSr?rr&s rr)zNullPen.qCurveTo�r@rc��dSr?rr+s rr,zNullPen.closePath�r@rc��dSr?rr+s rr/zNullPen.endPath�r@rc��dSr?rr3s rr4zNullPen.addComponent�r@rc��dSr?rr9s rr:zNullPen.addVarComponent�r@rN) rrrrr!r#r'r)r,r/r4r:rrrr r �s�������"�"� � � � � � � � � � � � � � � � � � � � � � � � � � rr c��eZdZdZdS)� LoggingPenzHA pen with a ``log`` property (see fontTools.misc.loggingTools.LogMixin)NrrrrrIrI�s������R�R��DrrIc��eZdZdZdS)�MissingComponentErrorzGIndicates a component pointing to a non-existent glyph in the glyphset.NrrrrrKrK�s������Q�Q�Q�QrrKc�>��eZdZdZdZeZddd��fd� Zd�Zd�Z�xZ S) �DecomposingPena<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 ContourRecordingPen). You must override moveTo, lineTo, curveTo and qCurveTo. You may additionally override closePath, endPath 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���tt|��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)�superrM�__init__�glyphSet� __class__rNrO)r rSrNrO�args�kwargsrTs �rrRzDecomposingPen.__init__�s^���$ -��n�d�#�#�,�d�=�f�=�=�=� �� �%�,� �N� 0� 0�&� �"� -����rc��ddlm} |j|}|}|tkr |||��}|jr1|dd�\}}}} || z||zz } | dkrddlm} | |��}|�|��dS#t$r7|j st|���|j � d|z��YdSwxYw)z=Transform the points of the base glyph and draw it onto self.r)� TransformPenN�)�ReverseContourPenz,glyph '%s' is missing from glyphSet; skipped) �fontTools.pens.transformPenrXrSrrO� fontTools.pens.reverseContourPenrZ�draw�KeyErrorrNrK�log�warning) r r0r1rX�glyph�pen�a�b�c�d�detrZs rr4zDecomposingPen.addComponent�s��<�<�<�<�<�<� ��M�)�,�E� �C���)�)�"�l�3��7�7���"� 1�,�B�Q�B�/� ��1�a���!�e�a�!�e�m����7�7�R�R�R�R�R�R�+�+�C�0�0�C� �J�J�s�O�O�O�O�O��#� Y� Y� Y��-� 7�+�I�6�6�6� �H� � �K�i�W� X� X� X� X� X� X� Y���s� A=�==B>�=B>c��t�r?r7r9s rr:zDecomposingPen.addVarComponents���r) rrrrrNrKrRr4r:� __classcell__�rTs@rrMrM�s�������� � �!��1�� #�� -�-�-�-�-�-�-�6���2������rrMc�r��eZdZdZd�fd� Zd�Zd�Zd�Zd�Zd�Z d �Z d �Z d �Z d �Z d �Zd�Zd�Zd�Z�xZS)r z�Base class for drawing pens. You must override _moveTo, _lineTo and _curveToOne. You may additionally override _closePath, _endPath, addComponent, addVarComponent, and/or _qCurveToOne. You should not override any other methods. Nc�f��tt|���|��d|_dSr?)rQr rR�_BasePen__currentPoint)r rSrTs �rrRzBasePen.__init__s/��� �g�t���%�%�h�/�/�/�"����rc��t�r?rrs r�_moveTozBasePen._moveTo���!�!rc��t�r?rrs r�_lineTozBasePen._lineTorprc��t�r?r)r �pt1�pt2�pt3s r� _curveToOnezBasePen._curveToOnerprc��dSr?rr+s r� _closePathzBasePen._closePathr@rc��dSr?rr+s r�_endPathzBasePen._endPath"r@rc��|j\}}|\}}|\}}|d||z zz} |d||z zz} |d||z zz} |d||z zz} |�| | f| | f|��dS)z�This method implements the basic quadratic curve type. The default implementation delegates the work to the cubic curve function. Optionally override with a native implementation. gUUUUUU�?N)rmrw) r rtru�pt0x�pt0y�pt1x�pt1y�pt2x�pt2y�mid1x�mid1y�mid2x�mid2ys r� _qCurveToOnezBasePen._qCurveToOne%s��� �(� ��d�� ��d�� ��d��*�d�T�k�:�:���*�d�T�k�:�:���*�d�T�k�:�:���*�d�T�k�:�:�� ���%���%����=�=�=�=�=rc��|jS)zrReturn the current point. This is not part of the public interface, yet is useful for subclasses. )rmr+s r�_getCurrentPointzBasePen._getCurrentPoint5s ���"�"rc�<�|���d|_dSr?)ryrmr+s rr,zBasePen.closePath;s �� ������"����rc�<�|���d|_dSr?)r{rmr+s rr/zBasePen.endPath?s�� � � ����"����rc�>�|�|��||_dSr?)rormrs rr!zBasePen.moveToC�"�� � � �R���� ����rc�>�|�|��||_dSr?)rrrmrs rr#zBasePen.lineToGr�rc�n�t|��dz }|dksJ�|dkr|j|�|d|_dS|dkr3|j}t|��D]\}}}||||��||_�dS|dkr |j|�dS|dkr|�|d��dSt d���)N�r������zcan't get there from here)�lenrwrmr r)r#�AssertionError)r r$�nrwrtrurvs rr'zBasePen.curveToKs��� ��K�K�!�O���A�v�v�v�v� ��6�6� �D� �f� %� %�"(��*�D� � � � ��U�U��*�K�!<�V�!D�!D� *� *� ��S�#�� �C��c�*�*�*�&)��#�#� *� *��!�V�V� �D�M�6� "� "� "� "� �!�V�V� �K�K��q� � "� "� "� "� "� �!<�=�=� =rc��t|��dz }|dksJ�|d�P|d\}}|d\}}d||zzd||zzf}||_|�|��|dd�|fz}|dkr1|j}t |��D]\} } || | ��| |_�dS|�|d��dS)Nr�rr��������?)r�rmror�r r#) r r$r��x�y�nx�ny�impliedStartPointr�rtrus rr)zBasePen.qCurveTohs�� ��K�K�!�O���A�v�v�v�v� �"�:� ��"�:�D�A�q��A�Y�F�B��!$��B�����B��� @� �"3�D� � �L�L�*� +� +� +��C�R�C�[�$5�#7�7�F� �q�5�5�  �,�L�5�f�=�=� *� *���S�� �S�#�&�&�&�&)��#�#� *� *� �K�K��q� � "� "� "� "� "rr?)rrrrrRrorrrwryr{r�r�r,r/r!r#r'r)rirjs@rr r s ��������� #�#�#�#�#�#� "�"�"�"�"�"�"�"�"�  � � � � � � >� >� >� #�#�#� #�#�#�#�#�#�!�!�!�!�!�!�>�>�>�:#�#�#�#�#�#�#rr c�^�t|��dz }|dksJ�g}|ddd}}}td|dz��D]�}t|d||z dz��}td|��D]�}||z } ||dz } ||dz } | d| | d| dz zz| d| | d| dz zzf} |�| }�\d|d| dzzd|d| dzzf}|�|||f��| dd}}}����|�||d|df��|S) a�Split the SuperBezier described by 'points' into a list of regular bezier segments. The 'points' argument must be a sequence with length 3 or greater, containing (x, y) coordinates. The last point is the destination on-curve point, the rest of the points are off-curve points. The start point should not be supplied. This function returns a list of (pt1, pt2, pt3) tuples, which each specify a regular curveto-style bezier segment. r�rNr��r�r�r�)r��range�min�append) r$r��bezierSegmentsrtrurv�i� nDivisions�j�factor�temp1�temp2�temps rr r �s~�� �F� � �a��A� �q�5�5�5�5��N��1�I�t�T�c��C� �1�a�!�e�_�_�1�1����A�q�1�u�q�y�)�)� ��q�*�%�%� 1� 1�A���^�F��1�q�5�M�E��1�q�5�M�E��a��6�U�1�X��a��%8�9�9��a��6�U�1�X��a��%8�9�9��D��{�����c�!�f�t�A�w�.�/���A���a��8H�1I�J���%�%�s�C��o�6�6�6� $�d�D�#�S��� 1����3��r� �F�2�J�7�8�8�8� �rc�:�t|��dz }|dksJ�g}t|dz ��D]H}||\}}||dz\}}d||zzd||zzf}|�|||f���I|�|d|df��|S)a�Split the quadratic curve segment described by 'points' into a list of "atomic" quadratic segments. The 'points' argument must be a sequence with length 2 or greater, containing (x, y) coordinates. The last point is the destination on-curve point, the rest of the points are off-curve points. The start point should not be supplied. This function returns a list of (pt1, pt2) tuples, which each specify a plain quadratic bezier segment. r�rr�r�r�)r�r�r�) r$r�� quadSegmentsr�r�r�r�r�� impliedPts rr r �s��� �F� � �a��A� �q�5�5�5�5��L� �1�q�5�\�\�4�4���a�y���1���A�����B��A��F�^�S�A��F�^�4� ����V�A�Y� �2�3�3�3�3�������V�B�Z�0�1�1�1� �rc�*�eZdZdZd�Zd�Zd�Zd�ZdS)�_TestPenz,Test class that prints PostScript to stdout.c�H�t|d�d|d�d���dS)Nr� r�z moveto��printrs rroz_TestPen._moveTo��+�� ��1����r�!�u�u�u�-�.�.�.�.�.rc�H�t|d�d|d�d���dS)Nrr�r�z linetor�rs rrrz_TestPen._lineTo�r�rc��t|d�d|d�d|d�d|d�d|d�d|d�d� ��dS)Nrr�r�z curvetor�)r �bcp1�bcp2rs rrwz_TestPen._curveToOne�sa�� ��A�w�w�w��Q�����a����$�q�'�'�'�2�a�5�5�5�"�Q�%�%�%� A� � � � � rc�$�td��dS)N� closepathr�r+s rryz_TestPen._closePath�s�� �k�����rN)rrrrrorrrwryrrrr�r��sV������6�6�/�/�/�/�/�/� � � � ����rr��__main__N)rr)r�d)�2�K)�<r�)r��)r�r�)r�r)r�typingrr�fontTools.misc.loggingToolsr�fontTools.misc.transformrr�__all__� Exceptionr rrr rIr^rKrMr r r r�rrbr!r#r'r,r)rrr�<module>r�s���$�$�L��������0�0�0�0�0�0�B�B�B�B�B�B�B�B� � � ��.�.�.�.�.�y�.�.�.� � � � � �x� � � �U�U�U�U�U�U�U�U�p � � � � �k� � � �8 � � � � ��;� � � � R�R�R�R�R�H�R�R�R�H�H�H�H�H�Z�H�H�H�V{#�{#�{#�{#�{#�n�{#�{#�{#�| � � �F���,�����w����& �z��� �(�4�.�.�C��J�J�v�����J�J�x�����K�K��(�H�f�5�5�5��M�M�O�O�O� �(�4�.�.�C��L�L���:�x��>�>�>��M�M�O�O�O�O�O��r
Memory