Ejemplo n.º 1
0
    def interpolate(self, factor, minInfo, maxInfo, round=True, suppressError=True):
        """
        Interpolate all pairs between minInfo and maxInfo.
        The interpolation occurs on a 0 to 1.0 range where minInfo
        is located at 0 and maxInfo is located at 1.0.

        factor is the interpolation value. It may be less than 0
        and greater than 1.0. It may be a number (integer, float)
        or a tuple of two numbers. If it is a tuple, the first
        number indicates the x factor and the second number
        indicates the y factor.

        round indicates if the result should be rounded to integers.

        suppressError indicates if incompatible data should be ignored
        or if an error should be raised when such incompatibilities are found.
        """
        factor = normalizers.normalizeInterpolationFactor(factor)
        if not isinstance(minInfo, BaseInfo):
            raise FontPartsError("Interpolation to an instance of %r can not be performed from an instance of %r." % (self.__class__.__name__, minInfo.__class__.__name__))
        if not isinstance(maxInfo, BaseInfo):
            raise FontPartsError("Interpolation to an instance of %r can not be performed from an instance of %r." % (self.__class__.__name__, maxInfo.__class__.__name__))
        round = normalizers.normalizeBoolean(round)
        suppressError = normalizers.normalizeBoolean(suppressError)
        self._interpolate(factor, minInfo, maxInfo, round=round, suppressError=suppressError)
Ejemplo n.º 2
0
    def interpolate(self, factor, minLayer, maxLayer, round=True,
                    suppressError=True):
        """
        Interpolate all possible data in the layer. ::

            >>> layer.interpolate(0.5, otherLayer1, otherLayer2)
            >>> layer.interpolate((0.5, 2.0), otherLayer1, otherLayer2, round=False)

        The interpolation occurs on a 0 to 1.0 range where **minLayer**
        is located at 0 and **maxLayer** is located at 1.0. **factor**
        is the interpolation value. It may be less than 0 and greater
        than 1.0. It may be a :ref:`type-int-float` or a tuple of
        two :ref:`type-int-float`. If it is a tuple, the first
        number indicates the x factor and the second number indicates
        the y factor. **round** indicates if the result should be
        rounded to integers. **suppressError** indicates if incompatible
        data should be ignored or if an error should be raised when
        such incompatibilities are found.
        """
        factor = normalizers.normalizeInterpolationFactor(factor)
        if not isinstance(minLayer, BaseLayer):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.")
                            % (self.__class__.__name__, minLayer.__class__.__name__))
        if not isinstance(maxLayer, BaseLayer):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.")
                            % (self.__class__.__name__, maxLayer.__class__.__name__))
        round = normalizers.normalizeBoolean(round)
        suppressError = normalizers.normalizeBoolean(suppressError)
        self._interpolate(factor, minLayer, maxLayer,
                          round=round, suppressError=suppressError)
Ejemplo n.º 3
0
    def interpolate(self, factor, minInfo, maxInfo, round=True, suppressError=True):
        """
        Interpolate all pairs between minInfo and maxInfo.
        The interpolation occurs on a 0 to 1.0 range where minInfo
        is located at 0 and maxInfo is located at 1.0.

        factor is the interpolation value. It may be less than 0
        and greater than 1.0. It may be a number (integer, float)
        or a tuple of two numbers. If it is a tuple, the first
        number indicates the x factor and the second number
        indicates the y factor.

        round indicates if the result should be rounded to integers.

        suppressError indicates if incompatible data should be ignored
        or if an error should be raised when such incompatibilities are found.
        """
        factor = normalizers.normalizeInterpolationFactor(factor)
        if not isinstance(minInfo, BaseInfo):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.") %
                            (self.__class__.__name__, minInfo.__class__.__name__))
        if not isinstance(maxInfo, BaseInfo):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.") %
                            (self.__class__.__name__, maxInfo.__class__.__name__))
        round = normalizers.normalizeBoolean(round)
        suppressError = normalizers.normalizeBoolean(suppressError)
        self._interpolate(factor, minInfo, maxInfo,
                          round=round, suppressError=suppressError)
Ejemplo n.º 4
0
    def interpolate(self, factor, minKerning, maxKerning, round=True, suppressError=True):
        """
        Interpolates all pairs between two :class:`BaseKerning` objects:

        **minKerning** and **maxKerning**. The interpolation occurs on a
        0 to 1.0 range where **minKerning** is located at 0 and
        **maxKerning** is located at 1.0. The kerning data is replaced by
        the interpolated kerning.

        * **factor** is the interpolation value. It may be less than 0
          and greater than 1.0. It may be an :ref:`type-int-float`,
          ``tuple`` or ``list``. If it is a ``tuple`` or ``list``,
          the first number indicates the x factor and the second number
          indicates the y factor.
        * **round** is a ``bool`` indicating if the result should be rounded to
          ``int``\s. The default behavior is to round interpolated kerning.
        * **suppressError** is a ``bool`` indicating if incompatible data should
          be ignored or if an error should be raised when such incompatibilities
          are found. The default behavior is to ignore incompatible data.

            >>> myKerning.interpolate(kerningOne, kerningTwo)
        """
        factor = normalizers.normalizeInterpolationFactor(factor)
        if not isinstance(minKerning, BaseKerning):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.") % (
                self.__class__.__name__, minKerning.__class__.__name__))
        if not isinstance(maxKerning, BaseKerning):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.") % (
                self.__class__.__name__, maxKerning.__class__.__name__))
        round = normalizers.normalizeBoolean(round)
        suppressError = normalizers.normalizeBoolean(suppressError)
        self._interpolate(factor, minKerning, maxKerning,
                          round=round, suppressError=suppressError)
Ejemplo n.º 5
0
    def interpolate(self, factor, minKerning, maxKerning, round=True, suppressError=True):
        """
        Interpolates all pairs between two :class:`BaseKerning` objects:

        **minKerning** and **maxKerning**. The interpolation occurs on a
        0 to 1.0 range where **minKerning** is located at 0 and
        **maxKerning** is located at 1.0. The kerning data is replaced by
        the interpolated kerning.

        * **factor** is the interpolation value. It may be less than 0
          and greater than 1.0. It may be an :ref:`type-int-float`,
          ``tuple`` or ``list``. If it is a ``tuple`` or ``list``,
          the first number indicates the x factor and the second number
          indicates the y factor.
        * **round** is a ``bool`` indicating if the result should be rounded to
          ``int``\s. The default behavior is to round interpolated kerning.
        * **suppressError** is a ``bool`` indicating if incompatible data should
          be ignored or if an error should be raised when such incompatibilities
          are found. The default behavior is to ignore incompatible data.

            >>> myKerning.interpolate(kerningOne, kerningTwo)
        """
        factor = normalizers.normalizeInterpolationFactor(factor)
        if not isinstance(minKerning, BaseKerning):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.") % (
                self.__class__.__name__, minKerning.__class__.__name__))
        if not isinstance(maxKerning, BaseKerning):
            raise TypeError(("Interpolation to an instance of %r can not be "
                             "performed from an instance of %r.") % (
                self.__class__.__name__, maxKerning.__class__.__name__))
        round = normalizers.normalizeBoolean(round)
        suppressError = normalizers.normalizeBoolean(suppressError)
        self._interpolate(factor, minKerning, maxKerning,
                          round=round, suppressError=suppressError)
Ejemplo n.º 6
0
 def insertSegment(self,
                   index,
                   type=None,
                   points=None,
                   smooth=False,
                   segment=None):
     """
     Insert a segment into the contour.
     """
     if segment is not None:
         if type is not None:
             type = segment.type
         if points is None:
             points = [(point.x, point.y) for point in segment.points]
         smooth = segment.smooth
     index = normalizers.normalizeIndex(index)
     type = normalizers.normalizeSegmentType(type)
     pts = []
     for pt in points:
         pt = normalizers.normalizeCoordinateTuple(pt)
         pts.append(pt)
     points = pts
     smooth = normalizers.normalizeBoolean(smooth)
     self._insertSegment(index=index,
                         type=type,
                         points=points,
                         smooth=smooth)
Ejemplo n.º 7
0
 def insertPoint(self, index, position=None, type="line", smooth=False, name=None, identifier=None, point=None):
     """
     Insert a point into the contour.
     """
     if point is not None:
         if position is None:
             position = point.position
         type = point.type
         smooth = point.smooth
         if name is None:
             name = point.name
         if identifier is not None:
             identifier = point.identifier
     index = normalizers.normalizeIndex(index)
     position = normalizers.normalizeCoordinateTuple(position)
     type = normalizers.normalizePointType(type)
     smooth = normalizers.normalizeBoolean(smooth)
     if name is not None:
         name = normalizers.normalizePointName(name)
     if identifier is not None:
         identifier = normalizers.normalizeIdentifier(identifier)
     self._insertPoint(
         index,
         position=position,
         type=type,
         smooth=smooth,
         name=name,
         identifier=identifier
     )
Ejemplo n.º 8
0
 def insertPoint(self, index, position=None, type="line", smooth=False, name=None, identifier=None, point=None):
     """
     Insert a point into the contour.
     """
     if point is not None:
         if position is None:
             position = point.position
         type = point.type
         smooth = point.smooth
         if name is None:
             name = point.name
         if identifier is not None:
             identifier = point.identifier
     index = normalizers.normalizeIndex(index)
     position = normalizers.normalizeCoordinateTuple(position)
     type = normalizers.normalizePointType(type)
     smooth = normalizers.normalizeBoolean(smooth)
     if name is not None:
         name = normalizers.normalizePointName(name)
     if identifier is not None:
         identifier = normalizers.normalizeIdentifier(identifier)
     self._insertPoint(
         index,
         position=position,
         type=type,
         smooth=smooth,
         name=name,
         identifier=identifier
     )
Ejemplo n.º 9
0
 def appendSegment(self, type, points, smooth=False):
     """
     Append a segment to the contour.
     """
     type = normalizers.normalizeSegmentType(type)
     pts = []
     for pt in points:
         pt = normalizers.normalizeCoordinateTuple(pt)
         pts.append(pt)
     points = pts
     smooth = normalizers.normalizeBoolean(smooth)
     self._appendSegment(type=type, points=points, smooth=smooth)
Ejemplo n.º 10
0
 def removeSegment(self, segment, preserveCurve=False):
     """
     Remove segment from the contour.
     If ``preserveCurve`` is set to ``True`` an attempt
     will be made to preserve the shape of the curve
     if the environment supports that functionality.
     """
     if not isinstance(segment, int):
         segment = self.segments.index(segment)
     segment = normalizers.normalizeIndex(segment)
     if segment >= self._len__segments():
         raise ValueError("No segment located at index %d." % segment)
     preserveCurve = normalizers.normalizeBoolean(preserveCurve)
     self._removeSegment(segment, preserveCurve)
Ejemplo n.º 11
0
 def removeSegment(self, segment, preserveCurve=False):
     """
     Remove segment from the contour.
     If ``preserveCurve`` is set to ``True`` an attempt
     will be made to preserve the shape of the curve
     if the environment supports that functionality.
     """
     if not isinstance(segment, int):
         segment = self.segments.index(segment)
     segment = normalizers.normalizeIndex(segment)
     if segment >= self._len__segments():
         raise ValueError("No segment located at index %d." % segment)
     preserveCurve = normalizers.normalizeBoolean(preserveCurve)
     self._removeSegment(segment, preserveCurve)
Ejemplo n.º 12
0
 def insertSegment(self, index, type, points, smooth=False):
     """
     Insert a segment into the contour.
     """
     index = normalizers.normalizeIndex(index)
     type = normalizers.normalizeSegmentType(type)
     pts = []
     for pt in points:
         pt = normalizers.normalizeCoordinateTuple(pt)
         pts.append(pt)
     points = pts
     smooth = normalizers.normalizeBoolean(smooth)
     self._insertSegment(index=index, type=type,
                         points=points, smooth=smooth)
Ejemplo n.º 13
0
 def removePoint(self, point, preserveCurve=False):
     """
     Remove the point from the contour.
     point can be a point object or an index.
     If ``preserveCurve`` is set to ``True`` an attempt
     will be made to preserve the shape of the curve
     if the environment supports that functionality.
     """
     if not isinstance(point, int):
         point = self.points.index(point)
     point = normalizers.normalizeIndex(point)
     if point >= self._len__points():
         raise ValueError("No point located at index %d." % point)
     preserveCurve = normalizers.normalizeBoolean(preserveCurve)
     self._removePoint(point, preserveCurve)
Ejemplo n.º 14
0
 def removePoint(self, point, preserveCurve=False):
     """
     Remove the point from the contour.
     point can be a point object or an index.
     If ``preserveCurve`` is set to ``True`` an attempt
     will be made to preserve the shape of the curve
     if the environment supports that functionality.
     """
     if not isinstance(point, int):
         point = self.points.index(point)
     point = normalizers.normalizeIndex(point)
     if point >= self._len__points():
         raise ValueError("No point located at index %d." % point)
     preserveCurve = normalizers.normalizeBoolean(preserveCurve)
     self._removePoint(point, preserveCurve)
Ejemplo n.º 15
0
 def appendSegment(self, type=None, points=None, smooth=False, segment=None):
     """
     Append a segment to the contour.
     """
     if segment is not None:
         if type is not None:
             type = segment.type
         if points is None:
             points = [(point.x, point.y) for point in segment.points]
         smooth = segment.smooth
     type = normalizers.normalizeSegmentType(type)
     pts = []
     for pt in points:
         pt = normalizers.normalizeCoordinateTuple(pt)
         pts.append(pt)
     points = pts
     smooth = normalizers.normalizeBoolean(smooth)
     self._appendSegment(type=type, points=points, smooth=smooth)
Ejemplo n.º 16
0
 def _set_base_smooth(self, value):
     value = normalizers.normalizeBoolean(value)
     self._set_smooth(value)
Ejemplo n.º 17
0
 def _get_base_selected(self):
     value = self._get_selected()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 18
0
 def _get_base_clockwise(self):
     value = self._get_clockwise()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 19
0
 def _get_base_open(self):
     value = self._get_open()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 20
0
 def _get_base_smooth(self):
     value = self._get_smooth()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 21
0
 def _get_base_smooth(self):
     value = self._get_smooth()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 22
0
 def _set_base_selected(self, value):
     value = normalizers.normalizeBoolean(value)
     self._set_selected(value)
Ejemplo n.º 23
0
 def _get_base_selected(self):
     value = self._get_selected()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 24
0
 def _get_base_open(self):
     value = self._get_open()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 25
0
 def _get_base_clockwise(self):
     value = self._get_clockwise()
     value = normalizers.normalizeBoolean(value)
     return value
Ejemplo n.º 26
0
 def _set_base_clockwise(self, value):
     value = normalizers.normalizeBoolean(value)
     self._set_clockwise(value)
Ejemplo n.º 27
0
 def _set_base_clockwise(self, value):
     value = normalizers.normalizeBoolean(value)
     self._set_clockwise(value)
Ejemplo n.º 28
0
 def _set_base_smooth(self, value):
     value = normalizers.normalizeBoolean(value)
     self._set_smooth(value)
Ejemplo n.º 29
0
 def _set_base_selected(self, value):
     value = normalizers.normalizeBoolean(value)
     self._set_selected(value)