def paint_single_path(self, gstate, stroke, fill, evenodd, path):
        """
        Converting a single path draw command into lines and curves objects
        """
        if len(path) < 2:
            return
        shape = "".join(x[0] for x in path)

        pts = []
        for p in path:
            for i in range(1, len(p), 2):
                pts.append(apply_matrix_pt(self.ctm, (p[i], p[i + 1])))

        # Line mode
        if self.line_only_shape.match(shape):
            # check for sloped lines first
            has_slope = False
            for i in range(len(pts) - 1):
                if pts[i][0] != pts[i + 1][0] and pts[i][1] != pts[i + 1][1]:
                    has_slope = True
                    break
            if not has_slope:
                for i in range(len(pts) - 1):
                    self.cur_item.add(LTLine(gstate.linewidth, pts[i], pts[i + 1]))

                # Adding the closing line for a polygon, especially rectangles
                if shape.endswith("h"):
                    self.cur_item.add(LTLine(gstate.linewidth, pts[0], pts[-1]))
                return

        # Add the curve as an arbitrary polyline (belzier curve info is lost here)
        self.cur_item.add(LTCurve(gstate.linewidth, pts))
def paint_single_path ( self , gstate , stroke , fill , evenodd , path ) : if len ( path ) < 2 : return shape = "" . join ( x [ 0 ] for x in path ) pts = [ ] for p in path : for i in range ( 1 , len ( p ) , 2 ) : pts . append ( apply_matrix_pt ( self . ctm , ( p [ i ] , p [ i + 1 ] ) ) ) if self . line_only_shape . match ( shape ) : has_slope = False for i in range ( len ( pts ) - 1 ) : if pts [ i ] [ 0 ] != pts [ i + 1 ] [ 0 ] and pts [ i ] [ 1 ] != pts [ i + 1 ] [ 1 ] : has_slope = True break if not has_slope : for i in range ( len ( pts ) - 1 ) : self . cur_item . add ( LTLine ( gstate . linewidth , pts [ i ] , pts [ i + 1 ] ) ) if shape . endswith ( "h" ) : self . cur_item . add ( LTLine ( gstate . linewidth , pts [ 0 ] , pts [ - 1 ] ) ) return self . cur_item . add ( LTCurve ( gstate . linewidth , pts ) )
Converting a single path draw command into lines and curves objects