Ejemplo n.º 1
0
 def paint_path(self, gstate, stroke, fill, evenodd, path):
   shape = ''.join(x[0] for x in path)
   if shape == 'ml': # horizontal/vertical line
     (_,x0,y0) = path[0]
     (_,x1,y1) = path[1]
     (x0,y0) = apply_matrix_pt(self.ctm, (x0,y0))
     (x1,y1) = apply_matrix_pt(self.ctm, (x1,y1))
     if y0 == y1:
       # horizontal ruler
       self.cur_item.add(LTLine(gstate.linewidth, 'H', (x0,y0,x1,y1)))
     elif x0 == x1:
       # vertical ruler
       self.cur_item.add(LTLine(gstate.linewidth, 'V', (x0,y0,x1,y1)))
   elif shape == 'mlllh':
     # rectangle
     (_,x0,y0) = path[0]
     (_,x1,y1) = path[1]
     (_,x2,y2) = path[2]
     (_,x3,y3) = path[3]
     (x0,y0) = apply_matrix_pt(self.ctm, (x0,y0))
     (x1,y1) = apply_matrix_pt(self.ctm, (x1,y1))
     (x2,y2) = apply_matrix_pt(self.ctm, (x2,y2))
     (x3,y3) = apply_matrix_pt(self.ctm, (x3,y2))
     if ((x0 == x1 and y1 == y2 and x2 == x3 and y3 == y0) or
         (y0 == y1 and x1 == x2 and y2 == y3 and x3 == x0)):
       self.cur_item.add(LTRect(gstate.linewidth, (x0,y0,x2,y2)))
   return
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
 def paint_path(self, gstate, stroke, fill, evenodd, path):
     shape = ''.join(x[0] for x in path)
     if shape == 'ml':
         # horizontal/vertical line
         (_, x0, y0) = path[0]
         (_, x1, y1) = path[1]
         (x0, y0) = apply_matrix_pt(self.ctm, (x0, y0))
         (x1, y1) = apply_matrix_pt(self.ctm, (x1, y1))
         if x0 == x1 or y0 == y1:
             self.cur_item.add(LTLine(gstate.linewidth, (x0, y0), (x1, y1)))
             return
     if shape == 'mlllh':
         # rectangle
         (_, x0, y0) = path[0]
         (_, x1, y1) = path[1]
         (_, x2, y2) = path[2]
         (_, x3, y3) = path[3]
         (x0, y0) = apply_matrix_pt(self.ctm, (x0, y0))
         (x1, y1) = apply_matrix_pt(self.ctm, (x1, y1))
         (x2, y2) = apply_matrix_pt(self.ctm, (x2, y2))
         (x3, y3) = apply_matrix_pt(self.ctm, (x3, y3))
         if ((x0 == x1 and y1 == y2 and x2 == x3 and y3 == y0)
                 or (y0 == y1 and x1 == x2 and y2 == y3 and x3 == x0)):
             self.cur_item.add(LLTRect(gstate.linewidth, (x0, y0, x2, y2)))
             print self.interpreter.scs, self.interpreter.ncs, gstate, stroke, fill, (
                 x0, y0, x2, y2)
             return
     # other shapes
     pts = []
     for p in path:
         for i in xrange(1, len(p), 2):
             pts.append(apply_matrix_pt(self.ctm, (p[i], p[i + 1])))
     self.cur_item.add(LTCurve(gstate.linewidth, pts))
     return
 def paint_path(self, gstate, stroke, fill, evenodd, path):
     shape = ''.join(x[0] for x in path)
     if shape == 'ml':
         # horizontal/vertical line
         (_, x0, y0) = path[0]
         (_, x1, y1) = path[1]
         (x0, y0) = utils.apply_matrix_pt(self.ctm, (x0, y0))
         (x1, y1) = utils.apply_matrix_pt(self.ctm, (x1, y1))
         if x0 == x1 or y0 == y1:
             self.cur_item.add(LTLine(gstate.linewidth, (x0, y0), (x1, y1),
                 stroke, fill, evenodd, gstate.scolor, gstate.ncolor))
             return
     if shape == 'mlllh':
         #print("Painting rectangle!")
         # rectangle
         (_, x0, y0) = path[0]
         (_, x1, y1) = path[1]
         (_, x2, y2) = path[2]
         (_, x3, y3) = path[3]
         (x0, y0) = utils.apply_matrix_pt(self.ctm, (x0, y0))
         (x1, y1) = utils.apply_matrix_pt(self.ctm, (x1, y1))
         (x2, y2) = utils.apply_matrix_pt(self.ctm, (x2, y2))
         (x3, y3) = utils.apply_matrix_pt(self.ctm, (x3, y3))
         if ((x0 == x1 and y1 == y2 and x2 == x3 and y3 == y0) or
             (y0 == y1 and x1 == x2 and y2 == y3 and x3 == x0)):
             xlist = [x0,x1,x2,x3]
             ylist = [y0,y1,y2,y3]
             minx = min(xlist)
             maxx = max(xlist)
             miny = min(ylist)
             maxy = max(ylist)
             self.rectangles.append(Rectangle(minx, miny, maxx-minx, maxy-miny))
             self.cur_item.add(LTRect(gstate.linewidth, (x0, y0, x2, y2),
                 stroke, fill, evenodd, gstate.scolor, gstate.ncolor))
             return
     # other shapes
     pts = []
     for p in path:
         for i in range(1, len(p), 2):
             pts.append(utils.apply_matrix_pt(self.ctm, (p[i], p[i+1])))
     self.cur_item.add(LTCurve(gstate.linewidth, pts, stroke, fill,
         evenodd, gstate.scolor, gstate.ncolor))
     return