§
    ¢”jô  ã                   ó’   — d Z ddlmZmZ ddlZ ej        e¦  «        Zg d¢ZdZ	de
ded	e
fd
„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )a„  
The `OpenType specification <https://docs.microsoft.com/en-us/typography/opentype/spec/otff#data-types>`_
defines two fixed-point data types:

``Fixed``
	A 32-bit signed fixed-point number with a 16 bit twos-complement
	magnitude component and 16 fractional bits.
``F2DOT14``
	A 16-bit signed fixed-point number with a 2 bit twos-complement
	magnitude component and 14 fractional bits.

To support reading and writing data with these data types, this module provides
functions for converting between fixed-point, float and string representations.

.. data:: MAX_F2DOT14

	The maximum value that can still fit in an F2Dot14. (1.99993896484375)
é   )ÚotRoundÚnearestMultipleShortestRepré    N)
ÚMAX_F2DOT14ÚfixedToFloatÚfloatToFixedÚfloatToFixedToFloatÚfloatToFixedToStrÚ
fixedToStrÚ
strToFixedÚstrToFixedToFloatÚensureVersionIsLongÚversionToFixedg    Àÿÿ?ÚvalueÚprecisionBitsÚreturnc                 ó   — | d|z  z  S )a®  Converts a fixed-point number to a float given the number of
    precision bits.

    Args:
            value (int): Number in fixed-point format.
            precisionBits (int): Number of precision bits.

    Returns:
            Floating point value.

    Examples::

            >>> import math
            >>> f = fixedToFloat(-10139, precisionBits=14)
            >>> math.isclose(f, -0.61883544921875)
            True
    r   © ©r   r   s     úh/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/fontTools/misc/fixedTools.pyr   r   *   s   € ð$ �A˜Ñ&Ñ'Ð'ó    c                 ó,   — t          | d|z  z  ¦  «        S )a¹  Converts a float to a fixed-point number given the number of
    precision bits.

    Args:
            value (float): Floating point value.
            precisionBits (int): Number of precision bits.

    Returns:
            int: Fixed-point representation.

    Examples::

            >>> floatToFixed(-0.61883544921875, precisionBits=14)
            -10139
            >>> floatToFixed(-0.61884, precisionBits=14)
            -10139
    r   ©r   r   s     r   r   r   ?   s   € õ$ �5˜A Ñ.Ñ/Ñ0Ô0Ð0r   c                 ó6   — d|z  }t          | |z  ¦  «        |z  S )a
  Converts a float to a fixed-point number and back again.

    By converting the float to fixed, rounding it, and converting it back
    to float again, this returns a floating point values which is exactly
    representable in fixed-point format.

    Note: this **is** equivalent to ``fixedToFloat(floatToFixed(value))``.

    Args:
            value (float): The input floating point value.
            precisionBits (int): Number of precision bits.

    Returns:
            float: The transformed and rounded value.

    Examples::
            >>> import math
            >>> f1 = -0.61884
            >>> f2 = floatToFixedToFloat(-0.61884, precisionBits=14)
            >>> f1 != f2
            True
            >>> math.isclose(f2, -0.61883544921875)
            True
    r   r   ©r   r   Úscales      r   r	   r	   T   s%   € ð2 �Ñ€EÝ�5˜5‘=Ñ!Ô! EÑ)Ð)r   c                 ó:   — d|z  }t          | |z  d|z  ¬¦  «        S )aR  Converts a fixed-point number to a string representing a decimal float.

    This chooses the float that has the shortest decimal representation (the least
    number of fractional decimal digits).

    For example, to convert a fixed-point number in a 2.14 format, use
    ``precisionBits=14``::

            >>> fixedToStr(-10139, precisionBits=14)
            '-0.61884'

    This is pretty slow compared to the simple division used in ``fixedToFloat``.
    Use sporadically when you need to serialize or print the fixed-point number in
    a human-readable form.
    It uses nearestMultipleShortestRepr under the hood.

    Args:
            value (int): The fixed-point value to convert.
            precisionBits (int): Number of precision bits, *up to a maximum of 16*.

    Returns:
            str: A string representation of the value.
    r   ç      ð?©Úfactor©r   r   s      r   r   r   q   s)   € ð0 �Ñ€EÝ& u¨u¡}¸SÀ5¹[ÐIÑIÔIÐIr   c                 óJ   — t          | ¦  «        }t          |d|z  z  ¦  «        S )aÏ  Converts a string representing a decimal float to a fixed-point number.

    Args:
            string (str): A string representing a decimal float.
            precisionBits (int): Number of precision bits, *up to a maximum of 16*.

    Returns:
            int: Fixed-point representation.

    Examples::

            >>> ## to convert a float string to a 2.14 fixed-point number:
            >>> strToFixed('-0.61884', precisionBits=14)
            -10139
    r   ©Úfloatr   )Ústringr   r   s      r   r   r   �   s'   € õ  �&‰MŒM€EÝ�5˜A Ñ.Ñ/Ñ0Ô0Ð0r   c                 óT   — t          | ¦  «        }d|z  }t          ||z  ¦  «        |z  S )a[  Convert a string to a decimal float with fixed-point rounding.

    This first converts string to a float, then turns it into a fixed-point
    number with ``precisionBits`` fractional binary digits, then back to a
    float again.

    This is simply a shorthand for fixedToFloat(floatToFixed(float(s))).

    Args:
            string (str): A string representing a decimal float.
            precisionBits (int): Number of precision bits.

    Returns:
            float: The transformed and rounded value.

    Examples::

            >>> import math
            >>> s = '-0.61884'
            >>> bits = 14
            >>> f = strToFixedToFloat(s, precisionBits=bits)
            >>> math.isclose(f, -0.61883544921875)
            True
            >>> f == fixedToFloat(floatToFixed(float(s), precisionBits=bits), precisionBits=bits)
            True
    r   r#   )r%   r   r   r   s       r   r   r   ¡   s0   € õ6 �&‰MŒM€EØ�Ñ€EÝ�5˜5‘=Ñ!Ô! EÑ)Ð)r   c                 ó4   — d|z  }t          | d|z  ¬¦  «        S )ai  Convert float to string with fixed-point rounding.

    This uses the shortest decimal representation (ie. the least
    number of fractional decimal digits) to represent the equivalent
    fixed-point number with ``precisionBits`` fractional binary digits.
    It uses nearestMultipleShortestRepr under the hood.

    >>> floatToFixedToStr(-0.61883544921875, precisionBits=14)
    '-0.61884'

    Args:
            value (float): The float value to convert.
            precisionBits (int): Number of precision bits, *up to a maximum of 16*.

    Returns:
            str: A string representation of the value.

    r   r   r   r!   r   s      r   r
   r
   Á   s%   € ð& �Ñ€EÝ& u°S¸5±[ÐAÑAÔAÐAr   c                 ón   — | dk     r.t          | d¦  «        }t                               d| |¦  «         |} | S )a3  Ensure a table version is an unsigned long.

    OpenType table version numbers are expressed as a single unsigned long
    comprising of an unsigned short major version and unsigned short minor
    version. This function detects if the value to be used as a version number
    looks too small (i.e. is less than ``0x10000``), and converts it to
    fixed-point using :func:`floatToFixed` if so.

    Args:
            value (Number): a candidate table version number.

    Returns:
            int: A table version number, possibly corrected to fixed-point.
    i   é   zDTable version value is a float: %.4f; fix to use hex instead: 0x%08x)r   ÚlogÚwarning)r   ÚnewValues     r   r   r   Ø   sG   € ð ˆw‚€Ý  rÑ*Ô*ˆÝ�ŠØUØØñ	
ô 	
ð 	
ð
 ˆØ€Lr   c                 óŒ   — |                       d¦  «        rt          | d¦  «        nt          | ¦  «        } t          | ¦  «        } | S )zÒEnsure a table version number is fixed-point.

    Args:
            value (str): a candidate table version number.

    Returns:
            int: A table version number, possibly corrected to fixed-point.
    Ú0r   )Ú
startswithÚintr$   r   )r   s    r   r   r   ò   s@   € ð #×-Ò-¨cÑ2Ô2ÐD�C��q‰MŒMˆM½¸e¹¼€EÝ Ñ&Ô&€EØ€Lr   )Ú__doc__Ú
roundToolsr   r   ÚloggingÚ	getLoggerÚ__name__r*   Ú__all__r   r$   r0   r   r   r	   r   r   r   r
   r   r   r   r   r   ú<module>r7      s  ððð ð& =Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø €€€à€gÔ˜Ñ!Ô!€ðð ð €ð !€ð(˜ð (¨cð (°eð (ð (ð (ð (ð*1ð 1ð 1ð**ð *ð *ð:Jð Jð Jð81ð 1ð 1ð(*ð *ð *ð@Bð Bð Bð.ð ð ð4ð ð ð ð r   