Пример #1
0
    def handle_command(self, command, coord_string):
        isLower = command.islower()
        command = command.upper()
        # new_points are the points that will be added to the curr_points
        # list. This variable may get modified in the conditionals below.
        points = self.growing_path.points
        new_points = self.string_to_points(coord_string)

        if command == "M":  # moveto
            if isLower and len(points) > 0:
                new_points[0] += points[-1]
            if len(points) > 0:
                self.growing_path = self.add_subpath(new_points[:1])
            else:
                self.growing_path.start_at(new_points[0])

            if len(new_points) <= 1:
                return

            points = self.growing_path.points
            new_points = new_points[1:]
            command = "L"

        if isLower and len(points) > 0:
            new_points += points[-1]

        if command in ["L", "H", "V"]:  # lineto
            if command == "H":
                new_points[0, 1] = points[-1, 1]
            elif command == "V":
                if isLower:
                    new_points[0, 0] -= points[-1, 0]
                    new_points[0, 0] += points[-1, 1]
                new_points[0, 1] = new_points[0, 0]
                new_points[0, 0] = points[-1, 0]
            new_points = new_points.repeat(3, axis=0)
        elif command == "C":  # curveto
            pass  # Yay! No action required
        elif command in ["S", "T"]:  # smooth curveto
            handle1 = points[-1] + (points[-1] - points[-2])
            new_points = np.append([handle1], new_points, axis=0)
        if command in ["Q", "T"]:  # quadratic Bezier curve
            # TODO, this is a suboptimal approximation
            new_points = np.append([new_points[0]], new_points, axis=0)
        elif command == "A":  # elliptical Arc
            raise Exception("Not implemented")
        elif command == "Z":  # closepath
            if not is_closed(points):
                # Both handles and new anchor are the start
                new_points = points[[0, 0, 0]]
            # self.mark_paths_closed = True

        # Handle situations where there's multiple relative control points
        if isLower and len(new_points) > 3:
            for i in range(3, len(new_points), 3):
                new_points[i:i + 3] -= points[-1]
                new_points[i:i + 3] += new_points[i - 1]

        self.growing_path.add_control_points(new_points)
Пример #2
0
    def handle_command(self, command, coord_string):
        isLower = command.islower()
        command = command.upper()
        # new_points are the points that will be added to the curr_points
        # list. This variable may get modified in the conditionals below.
        points = self.growing_path.points
        new_points = self.string_to_points(coord_string)

        if command == "M":  # moveto
            if isLower and len(points) > 0:
                new_points[0] += points[-1]
            if len(points) > 0:
                self.growing_path = self.add_subpath(new_points[:1])
            else:
                self.growing_path.start_at(new_points[0])

            if len(new_points) <= 1:
                return

            points = self.growing_path.points
            new_points = new_points[1:]
            command = "L"

        if isLower and len(points) > 0:
            new_points += points[-1]

        if command in ["L", "H", "V"]:  # lineto
            if command == "H":
                new_points[0, 1] = points[-1, 1]
            elif command == "V":
                if isLower:
                    new_points[0, 0] -= points[-1, 0]
                    new_points[0, 0] += points[-1, 1]
                new_points[0, 1] = new_points[0, 0]
                new_points[0, 0] = points[-1, 0]
            new_points = new_points.repeat(3, axis=0)
        elif command == "C":  # curveto
            pass  # Yay! No action required
        elif command in ["S", "T"]:  # smooth curveto
            handle1 = points[-1] + (points[-1] - points[-2])
            new_points = np.append([handle1], new_points, axis=0)
        if command in ["Q", "T"]:  # quadratic Bezier curve
            # TODO, this is a suboptimal approximation
            new_points = np.append([new_points[0]], new_points, axis=0)
        elif command == "A":  # elliptical Arc
            raise Exception("Not implemented")
        elif command == "Z":  # closepath
            if not is_closed(points):
                # Both handles and new anchor are the start
                new_points = points[[0, 0, 0]]
            # self.mark_paths_closed = True

        # Handle situations where there's multiple relative control points
        if isLower and len(new_points) > 3:
            for i in range(3, len(new_points), 3):
                new_points[i:i + 3] -= points[-1]
                new_points[i:i + 3] += new_points[i - 1]

        self.growing_path.add_control_points(new_points)
Пример #3
0
 def set_anchor_points(self, points, mode="smooth"):
     if not isinstance(points, np.ndarray):
         points = np.array(points)
     if self.close_new_points and not is_closed(points):
         points = np.append(points, [points[0]], axis=0)
     if mode == "smooth":
         self.set_points_smoothly(points)
     elif mode == "corners":
         self.set_points_as_corners(points)
     else:
         raise Exception("Unknown mode")
     return self
 def set_anchor_points(self, points, mode="smooth"):
     if not isinstance(points, np.ndarray):
         points = np.array(points)
     if self.close_new_points and not is_closed(points):
         points = np.append(points, [points[0]], axis=0)
     if mode == "smooth":
         self.set_points_smoothly(points)
     elif mode == "corners":
         self.set_points_as_corners(points)
     else:
         raise Exception("Unknown mode")
     return self
Пример #5
0
 def prepare_new_anchor_points(self, points):
     if not isinstance(points, np.ndarray):
         points = np.array(points)
     if self.close_new_points and not is_closed(points):
         points = np.append(points, [points[0]], axis=0)
     return points
Пример #6
0
 def is_closed(self):
     return is_closed(self.points)
 def is_closed(self):
     return is_closed(self.points)