Exemple #1
0
    def fill_pattern(self, obj, pdfpath, fill_trafo, pattern):
        if not fill_trafo:
            fill_trafo = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
        inv_ptrn_trafo = libgeom.invert_trafo(pattern[3])
        inv_trafo = libgeom.multiply_trafo(
            libgeom.invert_trafo(fill_trafo),
            libgeom.invert_trafo(inv_ptrn_trafo))
        paths = libgeom.apply_trafo_to_paths(obj.paths, obj.trafo)
        paths = libgeom.apply_trafo_to_paths(paths, inv_trafo)
        bbox = libgeom.get_paths_bbox(paths)
        cv_trafo = libgeom.multiply_trafo(pattern[3], fill_trafo)

        image_obj = sk2_model.Pixmap(obj.config)
        image_obj.handler.load_from_b64str(self.cms, pattern[1])
        if pattern[0] == sk2const.PATTERN_IMG and len(pattern) > 2:
            image_obj.style[3] = deepcopy(pattern[2])

        self.canvas.saveState()
        self.canvas.clipPath(pdfpath, 0, 0)
        self.canvas.transform(*cv_trafo)

        w, h = image_obj.get_size()
        x = bbox[0]
        y = bbox[3]
        while y > bbox[1] - h:
            while x < bbox[2]:
                self.canvas.saveState()
                self.canvas.transform(1.0, 0.0, 0.0, 1.0, x, y)
                self.draw_pixmap_obj(image_obj)
                self.canvas.restoreState()
                x += w
            y -= h
            x = bbox[0]
        self.canvas.restoreState()
Exemple #2
0
    def fill_radial_tr_gradient(self, obj, pdfpath, fill_trafo, gradient):
        if not fill_trafo:
            fill_trafo = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
        stops = gradient[2]
        sp, ep = gradient[1]
        dx, dy = sp
        l = libgeom.distance(sp, ep)
        trafo = [1.0, 0.0, 0.0, 1.0, dx, dy]
        inv_trafo = libgeom.multiply_trafo(libgeom.invert_trafo(fill_trafo),
                                           libgeom.invert_trafo(trafo))
        cv_trafo = libgeom.multiply_trafo(trafo, fill_trafo)
        paths = libgeom.apply_trafo_to_paths(obj.paths, obj.trafo)
        paths = libgeom.apply_trafo_to_paths(paths, inv_trafo)
        bbox = libgeom.sum_bbox(libgeom.get_paths_bbox(paths),
                                [0.0, 0.0, l, 0.0])
        bbox = libgeom.normalize_bbox(bbox)
        d = libgeom.distance(*libgeom.apply_trafo_to_points([[0.0, 0.0],
                                                             [0.0, 1.0]],
                                                            inv_trafo))

        circle_paths = libgeom.get_circle_paths(0.0, 0.0, sk2const.ARC_CHORD)
        trafo = [2.0, 0.0, 0.0, 2.0, -1.0, -1.0]
        circle_paths = libgeom.apply_trafo_to_paths(circle_paths, trafo)

        inner_paths = []
        r = 0.0
        self.canvas.saveState()
        self.canvas.clipPath(pdfpath, 0, 0)
        self.canvas.transform(*cv_trafo)
        while r < l:
            point = r / l
            self.canvas.setFillColor(self.get_grcolor_at_point(stops, point))
            if r + d < l:
                coef = (r + d)
            else:
                coef = l
            trafo = [coef, 0.0, 0.0, coef, 0.0, 0.0]
            paths = libgeom.apply_trafo_to_paths(circle_paths, trafo)
            ring = self.make_pdfpath(inner_paths + paths)[0]
            inner_paths = paths
            self.canvas.drawPath(ring, stroke=0, fill=1)
            r += d

        self.canvas.setFillColor(self.get_grcolor_at_point(stops, 1.0))
        r = max(bbox[2] - bbox[0], bbox[3] - bbox[1])
        trafo = [2.0 * r, 0.0, 0.0, 2.0 * r, 0.0, 0.0]
        paths = libgeom.apply_trafo_to_paths(circle_paths, trafo)
        ring = self.make_pdfpath(inner_paths + paths)[0]
        self.canvas.drawPath(ring, stroke=0, fill=1)

        self.canvas.restoreState()
Exemple #3
0
    def fill_linear_tr_gradient(self, obj, pdfpath, fill_trafo, gradient):
        if not fill_trafo:
            fill_trafo = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
        stops = gradient[2]
        sp, ep = gradient[1]
        dx, dy = sp
        l = libgeom.distance(sp, ep)
        angle = libgeom.get_point_angle(ep, sp)
        m21 = math.sin(angle)
        m11 = m22 = math.cos(angle)
        m12 = -m21
        trafo = [m11, m21, m12, m22, dx, dy]
        inv_trafo = libgeom.multiply_trafo(libgeom.invert_trafo(fill_trafo),
                                           libgeom.invert_trafo(trafo))
        cv_trafo = libgeom.multiply_trafo(trafo, fill_trafo)
        paths = libgeom.apply_trafo_to_paths(obj.paths, obj.trafo)
        paths = libgeom.apply_trafo_to_paths(paths, inv_trafo)
        bbox = libgeom.sum_bbox(libgeom.get_paths_bbox(paths),
                                [0.0, 0.0, l, 0.0])
        bbox = libgeom.normalize_bbox(bbox)

        y = bbox[1]
        d = libgeom.distance(*libgeom.apply_trafo_to_points([[0.0, 0.0],
                                                             [0.0, 1.0]],
                                                            inv_trafo))
        height = bbox[3] - bbox[1]

        self.canvas.saveState()
        self.canvas.clipPath(pdfpath, 0, 0)
        self.canvas.transform(*cv_trafo)

        self.canvas.setFillColor(self.get_grcolor_at_point(stops, 0.0))
        self.canvas.rect(bbox[0], y, 0.0 - bbox[0], height, stroke=0, fill=1)

        x = 0.0
        while x < l:
            point = x / l
            self.canvas.setFillColor(self.get_grcolor_at_point(stops, point))
            if x + d < l:
                width = d
            else:
                width = l - x
            self.canvas.rect(x, y, width, height, stroke=0, fill=1)
            x += d

        self.canvas.setFillColor(self.get_grcolor_at_point(stops, 1.0))
        self.canvas.rect(l, y, bbox[2] - l, height, stroke=0, fill=1)

        self.canvas.restoreState()
Exemple #4
0
	def fill_radial_tr_gradient(self, obj, pdfpath, fill_trafo, gradient):
		if not fill_trafo:
			fill_trafo = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
		stops = gradient[2]
		sp, ep = gradient[1]
		dx, dy = sp
		l = libgeom.distance(sp, ep)
		trafo = [1.0, 0.0, 0.0, 1.0, dx, dy]
		inv_trafo = libgeom.multiply_trafo(libgeom.invert_trafo(fill_trafo),
										libgeom.invert_trafo(trafo))
		cv_trafo = libgeom.multiply_trafo(trafo, fill_trafo)
		paths = libgeom.apply_trafo_to_paths(obj.paths, obj.trafo)
		paths = libgeom.apply_trafo_to_paths(paths, inv_trafo)
		bbox = libgeom.sum_bbox(libgeom.get_paths_bbox(paths),
							[0.0, 0.0, l, 0.0])
		bbox = libgeom.normalize_bbox(bbox)
		d = libgeom.distance(*libgeom.apply_trafo_to_points([[0.0, 0.0],
													[0.0, 1.0]], inv_trafo))

		circle_paths = libgeom.get_circle_paths(0.0, 0.0, sk2_const.ARC_CHORD)
		trafo = [2.0, 0.0, 0.0, 2.0, -1.0, -1.0]
		circle_paths = libgeom.apply_trafo_to_paths(circle_paths, trafo)

		inner_paths = []
		r = 0.0
		self.canvas.saveState()
		self.canvas.clipPath(pdfpath, 0, 0)
		self.canvas.transform(*cv_trafo)
		while r < l:
			point = r / l
			self.canvas.setFillColor(self.get_grcolor_at_point(stops, point))
			if r + d < l: coef = (r + d)
			else: coef = l
			trafo = [coef, 0.0, 0.0, coef, 0.0, 0.0]
			paths = libgeom.apply_trafo_to_paths(circle_paths, trafo)
			ring = self.make_pdfpath(inner_paths + paths)[0]
			inner_paths = paths
			self.canvas.drawPath(ring, stroke=0, fill=1)
			r += d

		self.canvas.setFillColor(self.get_grcolor_at_point(stops, 1.0))
		r = max(bbox[2] - bbox[0], bbox[3] - bbox[1])
		trafo = [2.0 * r, 0.0, 0.0, 2.0 * r, 0.0, 0.0]
		paths = libgeom.apply_trafo_to_paths(circle_paths, trafo)
		ring = self.make_pdfpath(inner_paths + paths)[0]
		self.canvas.drawPath(ring, stroke=0, fill=1)

		self.canvas.restoreState()
Exemple #5
0
 def draw_curve(self, curve_obj):
     paths = libgeom.apply_trafo_to_paths(curve_obj.paths, curve_obj.trafo)
     arrow_paths = []
     if curve_obj.cache_arrows:
         for pair in curve_obj.cache_arrows:
             for item in pair:
                 if item:
                     arrow_paths += libcairo.get_path_from_cpath(item)
         arrow_paths = self.make_pdfpath(arrow_paths)[0]
     arrow_fill_style = None
     if arrow_paths and curve_obj.style[1]:
         color = curve_obj.style[1][2]
         arrow_fill_style = [
             sk2const.FILL_NONZERO, sk2const.FILL_SOLID, color
         ]
     pdfpath, closed = self.make_pdfpath(paths)
     fill_style = curve_obj.style[0]
     stroke_style = curve_obj.style[1]
     if stroke_style and stroke_style[7]:
         self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
         if arrow_paths and arrow_fill_style:
             self.fill_pdfpath(None, arrow_paths, arrow_fill_style, None)
     if fill_style and fill_style[0] & sk2const.FILL_CLOSED_ONLY and closed:
         self.fill_pdfpath(curve_obj, pdfpath, fill_style,
                           curve_obj.fill_trafo)
     elif fill_style and not fill_style[0] & sk2const.FILL_CLOSED_ONLY:
         self.fill_pdfpath(curve_obj, pdfpath, fill_style,
                           curve_obj.fill_trafo)
     if stroke_style and not stroke_style[7]:
         self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
         if arrow_paths and arrow_fill_style:
             self.fill_pdfpath(None, arrow_paths, arrow_fill_style, None)
Exemple #6
0
 def convert_stroke_to_curve(self):
     doc = self.app.current_doc
     selection = self.app.current_doc.selection
     doc.canvas.set_mode(modes.WAIT_MODE)
     try:
         objs = []
         for obj in selection.objs:
             if obj.is_primitive() and not obj.is_pixmap() and obj.style[1] \
             and obj.style[1][1]:
                 pths = apply_trafo_to_paths(obj.get_initial_paths(),
                                             obj.trafo)
                 style = doc.model.get_def_style()
                 style[0] = [
                     sk2_const.FILL_SOLID,
                     deepcopy(obj.style[1][2])
                 ]
                 pths = stroke_to_curve(pths, obj.style[1])
                 objs.append(doc.api.create_curve(pths, style))
         selection.set(objs)
     except:
         doc.canvas.set_mode()
         msg = _('Error occurred during this operation.')
         msg += '\n' + _(
             'Perhaps this was due to the imperfection of the algorithm.')
         error_dialog(self.app.mw, self.app.appdata.app_name, msg)
     doc.canvas.set_mode()
Exemple #7
0
    def draw_container(self, obj):
        container = obj.childs[0].to_curve()
        paths = libgeom.apply_trafo_to_paths(container.paths, container.trafo)
        pdfpath, closed = self.make_pdfpath(paths)
        fill_style = container.style[0]
        stroke_style = container.style[1]
        if stroke_style and stroke_style[7]:
            self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)

        self.canvas.saveState()
        self.canvas.clipPath(pdfpath, 0, 0)

        if fill_style and fill_style[0] & sk2const.FILL_CLOSED_ONLY and closed:
            self.fill_pdfpath(container, pdfpath, fill_style,
                              container.fill_trafo)
        elif fill_style and not fill_style[0] & sk2const.FILL_CLOSED_ONLY:
            self.fill_pdfpath(container, pdfpath, fill_style,
                              container.fill_trafo)

        self.render(obj.childs[1:])

        self.canvas.restoreState()

        if stroke_style and not stroke_style[7]:
            self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)
Exemple #8
0
 def convert_stroke_to_curve(self):
     doc = self.app.current_doc
     selection = self.app.current_doc.selection
     doc.canvas.set_mode(modes.WAIT_MODE)
     try:
         objs = []
         for obj in selection.objs:
             if obj.is_primitive and not obj.is_pixmap and obj.style[1] \
                     and obj.style[1][1]:
                 pths = libgeom.apply_trafo_to_paths(obj.get_initial_paths(),
                                                     obj.trafo)
                 style = [
                     [sk2const.FILL_EVENODD,
                      sk2const.FILL_SOLID,
                      deepcopy(obj.style[1][2])],
                     [], [], []]
                 pths = libgeom.stroke_to_curve(pths, obj.style[1])
                 objs.append(doc.api.create_curve(pths, style))
                 if obj.cache_arrows:
                     for pair in obj.cache_arrows:
                         [objs.append(doc.api.create_curve(
                             libcairo.get_path_from_cpath(item), style))
                             for item in pair if item]
         selection.set(objs)
         if len(objs) > 1:
             doc.api.group_selected()
     except Exception as e:
         LOG.error('Error in convert_stroke_to_curve(), %s', e)
         doc.canvas.set_mode()
         msg = _('Error occurred during this operation.')
         msg += '\n' + _(
             'Perhaps this was due to the imperfection of the algorithm.')
         error_dialog(self.app.mw, self.app.appdata.app_name, msg)
     doc.canvas.set_mode()
Exemple #9
0
	def fill_linear_tr_gradient(self, obj, pdfpath, fill_trafo, gradient):
		if not fill_trafo:
			fill_trafo = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
		stops = gradient[2]
		sp, ep = gradient[1]
		dx, dy = sp
		l = libgeom.distance(sp, ep)
		angle = libgeom.get_point_angle(ep, sp)
		m21 = math.sin(angle)
		m11 = m22 = math.cos(angle)
		m12 = -m21
		trafo = [m11, m21, m12, m22, dx, dy]
		inv_trafo = libgeom.multiply_trafo(libgeom.invert_trafo(fill_trafo),
										libgeom.invert_trafo(trafo))
		cv_trafo = libgeom.multiply_trafo(trafo, fill_trafo)
		paths = libgeom.apply_trafo_to_paths(obj.paths, obj.trafo)
		paths = libgeom.apply_trafo_to_paths(paths, inv_trafo)
		bbox = libgeom.sum_bbox(libgeom.get_paths_bbox(paths),
							[0.0, 0.0, l, 0.0])
		bbox = libgeom.normalize_bbox(bbox)

		y = bbox[1]
		d = libgeom.distance(*libgeom.apply_trafo_to_points([[0.0, 0.0],
													[0.0, 1.0]], inv_trafo))
		height = bbox[3] - bbox[1]

		self.canvas.saveState()
		self.canvas.clipPath(pdfpath, 0, 0)
		self.canvas.transform(*cv_trafo)

		self.canvas.setFillColor(self.get_grcolor_at_point(stops, 0.0))
		self.canvas.rect(bbox[0], y, 0.0 - bbox[0], height, stroke=0, fill=1)

		x = 0.0
		while x < l:
			point = x / l
			self.canvas.setFillColor(self.get_grcolor_at_point(stops, point))
			if x + d < l: width = d
			else: width = l - x
			self.canvas.rect(x, y, width, height, stroke=0, fill=1)
			x += d

		self.canvas.setFillColor(self.get_grcolor_at_point(stops, 1.0))
		self.canvas.rect(l, y, bbox[2] - l, height, stroke=0, fill=1)

		self.canvas.restoreState()
Exemple #10
0
 def translate_curve(self, dest_parent, source_obj):
     paths = source_obj.paths
     trafo = [] + source_obj.trafo
     trafo[4] += self.dx
     trafo[5] += self.dy
     paths = libgeom.apply_trafo_to_paths(paths, trafo)
     style = get_sk_style(source_obj, self.sk2_doc.cms)
     dest_curve = sk_model.SKPolyBezier(paths_list=paths, properties=style)
     return dest_curve
Exemple #11
0
	def translate_curve(self, dest_parent, source_obj):
		paths = source_obj.paths
		trafo = [] + source_obj.trafo
		trafo[4] += self.dx
		trafo[5] += self.dy
		paths = libgeom.apply_trafo_to_paths(paths, trafo)
		style = get_sk1_style(source_obj, self.sk2_doc.cms)
		dest_curve = model.PolyBezier(paths_list=paths, properties=style)
		return dest_curve
 def translate_primitive(self, obj):
     curve = obj.to_curve()
     if curve.is_group:
         self.translate_group(curve)
         return
     curve.update()
     trafo = libgeom.multiply_trafo(curve.trafo, self.trafo)
     paths = libgeom.apply_trafo_to_paths(curve.paths, trafo)
     paths = libgeom.flat_paths(paths)
     self.translate_paths(obj.style, paths)
Exemple #13
0
	def get_resolution(self):
		path = libgeom.apply_trafo_to_paths(self.cache_paths, self.trafo)[0]
		p0 = path[0]
		p1 = path[1][0]
		p2, p3 = path[1][-2:]
		m11 = (libgeom.distance(p0, p1)) / float(self.size[1])
		m22 = (libgeom.distance(p2, p3)) / float(self.size[0])
		v_dpi = int(round(uc2const.in_to_pt / m11))
		h_dpi = int(round(uc2const.in_to_pt / m22))
		return (h_dpi, v_dpi)
Exemple #14
0
	def update_from_obj(self):
		self.paths = apply_trafo_to_paths(self.obj.paths, self.obj.trafo)
		path = self.paths[-1]
		if path[-1] == const.CURVE_OPENED:
			self.path = path
			self.points = self.path[1]
			paths = self.canvas.paths_doc_to_win(self.paths)
			self.canvas.renderer.paint_curve(paths)
		else:
			paths = self.canvas.paths_doc_to_win(self.paths)
			self.canvas.renderer.paint_curve(paths)
		self.draw = True
Exemple #15
0
    def translate_primitive(self, obj):
        curve = obj.to_curve()
        if curve.is_group():
            self.translate_group(curve)
            return
        curve.update()
        self.translate_style(obj)
        trafo = libgeom.multiply_trafo(curve.trafo, self.trafo)
        paths = libgeom.apply_trafo_to_paths(curve.paths, trafo)

        for item in [] + self.latest_objs:
            self.delete_obj(item)
Exemple #16
0
	def translate_primitive(self, obj):
		curve = obj.to_curve()
		if curve.is_group():
			self.translate_group(curve)
			return
		curve.update()
		self.translate_style(obj)
		trafo = libgeom.multiply_trafo(curve.trafo, self.trafo)
		paths = libgeom.apply_trafo_to_paths(curve.paths, trafo)

		for item in [] + self.latest_objs:
			self.delete_obj(item)
Exemple #17
0
 def update_from_obj(self):
     self.paths = apply_trafo_to_paths(self.obj.paths, self.obj.trafo)
     path = self.paths[-1]
     if path[-1] == sk2const.CURVE_OPENED:
         self.path = path
         self.points = self.path[1]
         paths = self.canvas.paths_doc_to_win(self.paths)
         self.canvas.renderer.paint_curve(paths)
     else:
         paths = self.canvas.paths_doc_to_win(self.paths)
         self.canvas.renderer.paint_curve(paths)
     self.draw = True
Exemple #18
0
	def draw_curve(self, curve_obj):
		paths = libgeom.apply_trafo_to_paths(curve_obj.paths, curve_obj.trafo)
		pdfpath, closed = self.make_pdfpath(paths)
		fill_style = curve_obj.style[0]
		stroke_style = curve_obj.style[1]
		if stroke_style and stroke_style[7]:
			self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
		if fill_style and fill_style[0] & sk2_const.FILL_CLOSED_ONLY and closed:
			self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo)
		elif fill_style and not fill_style[0] & sk2_const.FILL_CLOSED_ONLY:
			self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo)
		if stroke_style and not stroke_style[7]:
			self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
Exemple #19
0
 def _analyze_path(self, obj, info):
     info['subpaths'] += len(obj.paths)
     for path in libgeom.apply_trafo_to_paths(obj.paths, obj.trafo):
         # try:
         #     info['path_length'] += libgeom.get_path_length(path)
         # except RuntimeError:
         #     info['path_length'] = float('nan')
         if path[2] == sk2const.CURVE_CLOSED:
             info['path_closed'] += 1
             nodes = len(path[1])
         else:
             info['path_opened'] += 1
             nodes = len(path[1]) + 1
         info['max_path_point'] = max(nodes, info['max_path_point'])
         info['node'] += nodes
Exemple #20
0
	def fill_pattern(self, obj, pdfpath, fill_trafo, pattern):
		if not fill_trafo:
			fill_trafo = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
		inv_ptrn_trafo = libgeom.invert_trafo(pattern[3])
		inv_trafo = libgeom.multiply_trafo(libgeom.invert_trafo(fill_trafo),
										libgeom.invert_trafo(inv_ptrn_trafo))
		paths = libgeom.apply_trafo_to_paths(obj.paths, obj.trafo)
		paths = libgeom.apply_trafo_to_paths(paths, inv_trafo)
		bbox = libgeom.get_paths_bbox(paths)
		cv_trafo = libgeom.multiply_trafo(pattern[3], fill_trafo)

		bmpstr = b64decode(pattern[1])
		image_obj = sk2_model.Pixmap(obj.config)
		libimg.set_image_data(self.cms, image_obj, bmpstr)
		if pattern[0] == sk2_const.PATTERN_IMG and \
		 len(pattern) > 2:
			image_obj.style[3] = deepcopy(pattern[2])
		libimg.update_image(self.cms, image_obj)

		self.canvas.saveState()
		self.canvas.clipPath(pdfpath, 0, 0)
		self.canvas.transform(*cv_trafo)

		w, h = image_obj.get_size()
		x = bbox[0]
		y = bbox[3]
		while y > bbox[1] - h:
			while x < bbox[2]:
				self.canvas.saveState()
				self.canvas.transform(1.0, 0.0, 0.0, 1.0, x, y)
				self.draw_pixmap_obj(image_obj)
				self.canvas.restoreState()
				x += w
			y -= h
			x = bbox[0]
		self.canvas.restoreState()
Exemple #21
0
 def translate_primitive(self, obj):
     obj.update()
     curve = obj.to_curve()
     if curve.is_group:
         return self.translate_group(curve)
     param = self.get_fill(obj)
     param.update(self.get_stroke(obj))
     trafo = libgeom.multiply_trafo(curve.trafo, self.trafo)
     paths = libgeom.apply_trafo_to_paths(curve.paths, trafo)
     # TODO: implement support behind flag
     for path in paths:
         if all(map(lambda a: len(a) == 2, path[1])):
             self.add_polyline(path, **param)
         else:
             # TODO: implement translate obj as spline
             path = libgeom.flat_path(path, tlr=0.05)
             self.add_polyline(path, **param)
Exemple #22
0
	def update_from_obj(self):
		self.paths = apply_trafo_to_paths(self.obj.paths, self.obj.trafo)
		path = self.paths[-1]
		if path[-1] == const.CURVE_OPENED:
			self.path = path
			self.points = self.path[1]
			paths = self.canvas.paths_doc_to_win(self.paths)
			self.canvas.renderer.paint_curve(paths)
			last = bezier_base_point(self.points[-1])
			self.control_point0 = self.canvas.point_doc_to_win(last)
			self.control_point0_doc = [] + last
			self.point = [] + self.control_point0
			self.point_doc = [] + last
			self.control_point2 = [] + self.control_point0
			self.control_point2_doc = [] + last
			self.curve_point = [] + self.control_point0
			self.curve_point_doc = [] + last
		else:
			paths = self.canvas.paths_doc_to_win(self.paths)
			self.canvas.renderer.paint_curve(paths)
		self.draw = True
Exemple #23
0
	def convert_stroke_to_curve(self):
		doc = self.app.current_doc
		selection = self.app.current_doc.selection
		doc.canvas.set_mode(modes.WAIT_MODE)
		try:
			objs = []
			for obj in selection.objs:
				if obj.is_primitive() and not obj.is_pixmap() and obj.style[1] \
				and obj.style[1][1]:
					pths = apply_trafo_to_paths(obj.get_initial_paths(), obj.trafo)
					style = doc.model.get_def_style()
					style[0] = [sk2_const.FILL_SOLID, deepcopy(obj.style[1][2])]
					pths = stroke_to_curve(pths, obj.style[1])
					objs.append(doc.api.create_curve(pths, style))
			selection.set(objs)
		except:
			doc.canvas.set_mode()
			msg = _('Error occurred during this operation.')
			msg += '\n' + _('Perhaps this was due to the imperfection of the algorithm.')
			error_dialog(self.app.mw, self.app.appdata.app_name, msg)
		doc.canvas.set_mode()
Exemple #24
0
 def update_from_obj(self):
     self.paths = apply_trafo_to_paths(self.obj.paths, self.obj.trafo)
     path = self.paths[-1]
     if path[-1] == sk2const.CURVE_OPENED:
         self.path = path
         self.points = self.path[1]
         paths = self.canvas.paths_doc_to_win(self.paths)
         self.canvas.renderer.paint_curve(paths)
         last = bezier_base_point(self.points[-1])
         self.control_point0 = self.canvas.point_doc_to_win(last)
         self.control_point0_doc = [] + last
         self.point = [] + self.control_point0
         self.point_doc = [] + last
         self.control_point2 = [] + self.control_point0
         self.control_point2_doc = [] + last
         self.curve_point = [] + self.control_point0
         self.curve_point_doc = [] + last
     else:
         paths = self.canvas.paths_doc_to_win(self.paths)
         self.canvas.renderer.paint_curve(paths)
     self.draw = True
Exemple #25
0
	def draw_container(self, obj):
		container = obj.childs[0].to_curve()
		paths = libgeom.apply_trafo_to_paths(container.paths, container.trafo)
		pdfpath, closed = self.make_pdfpath(paths)
		fill_style = container.style[0]
		stroke_style = container.style[1]
		if stroke_style and stroke_style[7]:
			self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)

		self.canvas.saveState()
		self.canvas.clipPath(pdfpath, 0, 0)

		if fill_style and fill_style[0] & sk2_const.FILL_CLOSED_ONLY and closed:
			self.fill_pdfpath(container, pdfpath, fill_style, container.fill_trafo)
		elif fill_style and not fill_style[0] & sk2_const.FILL_CLOSED_ONLY:
			self.fill_pdfpath(container, pdfpath, fill_style, container.fill_trafo)

		self.render(obj.childs[1:])

		self.canvas.restoreState()

		if stroke_style and not stroke_style[7]:
			self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)
Exemple #26
0
	def get_paths_list(self, objs):
		paths_list = []
		for obj in objs:
			paths = apply_trafo_to_paths(obj.get_initial_paths(), obj.trafo)
			paths_list.append(paths)
		return paths_list
Exemple #27
0
 def get_paths_list(objs):
     return [
         apply_trafo_to_paths(obj.get_initial_paths(), obj.trafo)
         for obj in objs
     ]
Exemple #28
0
 def get_paths_list(self, objs):
     paths_list = []
     for obj in objs:
         paths = apply_trafo_to_paths(obj.get_initial_paths(), obj.trafo)
         paths_list.append(paths)
     return paths_list
    def make_v1_objects(self, parent_instr, obj):
        if obj.is_group and obj.childs:
            kwargs = {
                'bbox': (0, 0, 0, 0),
                'tail': '\x00\x00',
            }
            group_instr = mkinstr(self.cmx_cfg,
                                  identifier=cmx_const.BEGIN_GROUP,
                                  **kwargs)
            parent_instr.add(group_instr)

            for item in obj.childs:
                self.make_v1_objects(group_instr, item)

            group_instr.add(
                mkinstr(self.cmx_cfg, identifier=cmx_const.END_GROUP))

            group_instr.data['bbox'] = group_instr.get_bbox()

        elif obj.is_primitive:
            curve = obj.to_curve()
            curve.update()
            if not curve:
                return
            elif curve.is_group:
                self.make_v1_objects(parent_instr, curve)
            elif curve.paths:
                close_flag = False
                style = curve.style
                attrs = {
                    'style_flags': 1 if style[0] else 0,
                    'fill_type': cmx_const.INSTR_FILL_EMPTY,
                }
                attrs['style_flags'] += 2 if style[1] else 0
                if style[0] and style[0][1] == sk2const.FILL_SOLID:
                    attrs['fill_type'] = cmx_const.INSTR_FILL_UNIFORM
                    attrs['fill'] = (self._add_color(style[0][2]), 1)
                    close_flag = not style[0][0] & sk2const.FILL_CLOSED_ONLY
                if style[1]:
                    outline = style[1]
                    if curve.stroke_trafo:
                        points = [[0.0, 0.0], [1.0, 0.0]]
                        points = libgeom.apply_trafo_to_points(
                            points, obj.stroke_trafo)
                        coef = libgeom.distance(*points)
                        outline = deepcopy(outline)
                        outline[1] *= coef
                    attrs['outline'] = self._add_outline(outline)
                trafo = libgeom.multiply_trafo(
                    curve.trafo, [self.coef, 0.0, 0.0, self.coef, 0.0, 0.0])
                paths = libgeom.apply_trafo_to_paths(curve.paths, trafo)
                attrs['points'] = []
                attrs['nodes'] = []
                for path in paths:
                    # Force path closing
                    if close_flag and not path[2] == sk2const.CURVE_CLOSED:
                        path = deepcopy(path)
                        path[2] = sk2const.CURVE_CLOSED
                        p = path[1][-1] if len(path[1][-1]) == 2 \
                            else path[1][-1][-1]
                        if not path[0] == p:
                            path[1].append([] + path[0])
                    x, y = path[0]
                    attrs['points'].append((int(x), int(y)))
                    node = cmx_const.NODE_MOVE + cmx_const.NODE_USER
                    if path[2] == sk2const.CURVE_CLOSED:
                        node += cmx_const.NODE_CLOSED
                    attrs['nodes'].append(node)

                    for point in path[1]:
                        if len(point) == 2:
                            x, y = point
                            attrs['points'].append((int(x), int(y)))
                            node = cmx_const.NODE_LINE + cmx_const.NODE_USER
                            attrs['nodes'].append(node)
                        else:
                            p0, p1, p2, flag = point
                            for item in (p0, p1, p2):
                                x, y = item
                                attrs['points'].append((int(x), int(y)))
                            node = cmx_const.NODE_ARC
                            attrs['nodes'].append(node)
                            attrs['nodes'].append(node)
                            node = cmx_const.NODE_CURVE + cmx_const.NODE_USER
                            attrs['nodes'].append(node)

                    if path[2] == sk2const.CURVE_CLOSED:
                        attrs['nodes'][-1] += cmx_const.NODE_CLOSED

                attrs['bbox'] = self._make_bbox(curve.cache_bbox)

                attrs['tail'] = ''

                curve_instr = mkinstr(self.cmx_cfg,
                                      identifier=cmx_const.POLYCURVE,
                                      **attrs)
                parent_instr.add(curve_instr)