Пример #1
0
    def _calc_right_skew_trafo(self, event):
        is_centering = event.is_shift()
        is_constraining = event.is_ctrl()

        start_point = self.canvas.win_to_doc(self.start)
        end_point = self.canvas.win_to_doc(self.end)
        bbox = self.presenter.selection.bbox
        h = libgeom.bbox_size(bbox)[1]
        m11, m21, m12, m22, dx, dy = sk2const.NORMAL_TRAFO
        change_y = end_point[1] - start_point[1]

        cx = bbox[0]
        if is_centering:
            center_offset = self.presenter.selection.center_offset
            cx = libgeom.add_points(libgeom.bbox_center(bbox),
                                    center_offset)[0]

        if is_constraining:
            step = math.radians(config.skew_fixed_angle)
            angle = (math.atan2(change_y, h) + step / 2.0) // step * step
            m21 = math.tan(angle)
        else:
            m21 = change_y / h if h else 1.0

        dy = -cx * m21
        return [m11 or EPSILON, m21, m12, m22 or EPSILON, dx, dy]
Пример #2
0
    def render(self, sel_flag=False):
        doc = self.app.current_doc
        if sel_flag:
            if not doc.selection.objs:
                return None
            w, h = libgeom.bbox_size(doc.selection.bbox)
            x, y = libgeom.bbox_center(doc.selection.bbox)
            trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
        else:
            page = doc.active_page
            w, h = page.page_format[1]
            trafo = (1.0, 0, 0, -1.0, w / 2.0, h / 2.0)

        canvas_matrix = cairo.Matrix(*trafo)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
        ctx = cairo.Context(surface)
        ctx.set_matrix(canvas_matrix)

        rend = crenderer.CairoRenderer(doc.cms)

        if sel_flag:
            objs = doc.selection.objs
            for obj in objs:
                layer = doc.methods.get_parent_layer(obj)
                rend.antialias_flag = layer.properties[3] == 1
                rend.render(ctx, [obj])
        else:
            layers = doc.methods.get_visible_layers(page)
            for item in layers:
                rend.antialias_flag = item.properties[3] == 1
                rend.render(ctx, item.childs)

        image_stream = StringIO()
        surface.write_to_png(image_stream)
        return image_stream
Пример #3
0
	def _draw_center(self, *args):
		if self.end:
			start = self.canvas.win_to_doc(self.start)
			end = self.canvas.win_to_doc(self.end)
			dx = end[0] - start[0]
			dy = end[1] - start[1]
			x, y = self.offset_start
			cp = libgeom.bbox_center(self.selection.bbox)
			f, win_p, doc_p = self.snap.snap_point([cp[0] + x + dx, cp[1] + y + dy], False)
			self.selection.center_offset = [doc_p[0] - cp[0], doc_p[1] - cp[1]]
			self.canvas.renderer.paint_selection()
		return True
Пример #4
0
 def _draw_center(self, *args):
     if self.end:
         start = self.canvas.win_to_doc(self.start)
         end = self.canvas.win_to_doc(self.end)
         dx = end[0] - start[0]
         dy = end[1] - start[1]
         x, y = self.offset_start
         cp = libgeom.bbox_center(self.selection.bbox)
         doc_p = \
             self.snap.snap_point([cp[0] + x + dx, cp[1] + y + dy], False)[2]
         self.selection.center_offset = [doc_p[0] - cp[0], doc_p[1] - cp[1]]
         self.canvas.selection_redraw()
     # self.canvas.renderer.paint_selection()
     return True
Пример #5
0
def render(objs, cms):
    bbox = reduce(lambda a, b: libgeom.sum_bbox(a, b.cache_bbox), objs, [])
    w, h = libgeom.bbox_size(bbox)
    x, y = libgeom.bbox_center(bbox)
    trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
    canvas_matrix = cairo.Matrix(*trafo)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
    ctx = cairo.Context(surface)
    ctx.set_matrix(canvas_matrix)
    rend = crenderer.CairoRenderer(cms)
    rend.antialias_flag = True
    rend.render(ctx, objs)

    image_stream = StringIO()
    surface.write_to_png(image_stream)
    return image_stream
Пример #6
0
    def render(self, sel_flag=False):
        doc = self.app.current_doc
        if not doc:
            return
        if sel_flag:
            if not doc.selection.objs:
                return None
            w, h = libgeom.bbox_size(doc.selection.bbox)
            x, y = libgeom.bbox_center(doc.selection.bbox)
            trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
        else:
            page = doc.active_page
            w, h = page.page_format[1]
            trafo = (1.0, 0, 0, -1.0, w / 2.0, h / 2.0)

        canvas_matrix = cairo.Matrix(*trafo)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
        ctx = cairo.Context(surface)
        ctx.set_matrix(canvas_matrix)

        rend = crenderer.CairoRenderer(doc.cms)

        if sel_flag:
            objs = doc.selection.objs
            for obj in objs:
                layer = doc.methods.get_parent_layer(obj)
                rend.antialias_flag = layer.properties[3] == 1
                rend.render(ctx, [
                    obj,
                ])
        else:
            page = doc.active_page
            layers = doc.methods.get_visible_layers(page)
            for item in layers:
                rend.antialias_flag = item.properties[3] == 1
                rend.render(ctx, item.childs)

        image_stream = StringIO()
        surface.write_to_png(image_stream)
        return image_stream
Пример #7
0
    def _calc_bottom_left_rotate_trafo(self, event):
        is_centering = not event.is_shift()
        is_constraining = event.is_ctrl()

        start_point = self.canvas.win_to_doc(self.start)
        end_point = self.canvas.win_to_doc(self.end)
        bbox = self.presenter.selection.bbox

        if is_centering:
            bbox_center = libgeom.bbox_center(bbox)
            center_offset = self.selection.center_offset
            center = libgeom.add_points(bbox_center, center_offset)
        else:
            center = libgeom.bbox_points(bbox)[3]

        a1 = libgeom.get_point_angle(start_point, center)
        a2 = libgeom.get_point_angle(end_point, center)
        angle = a2 - a1
        if is_constraining:
            step = math.radians(config.rotation_step)
            angle = (angle + step / 2.0) // step * step

        return libgeom.trafo_rotate(angle, center[0], center[1])
Пример #8
0
    def mouse_move(self, event):
        is_constraining = event.is_ctrl()
        is_snapping = not event.is_shift()

        if not self.start:
            point = self.canvas.win_to_doc(event.get_point())
            ret = self.selection.is_point_over_marker(point)
            if not ret:
                self.canvas.restore_mode()
            elif not ret[0] == self.canvas.resize_marker:
                self.canvas.resize_marker = ret[0]
                self.set_cursor()

        else:
            self.end = event.get_point()
            if not self.canvas.resize_marker == MARK_ROTATE:
                self.trafo = self._calc_trafo(event)
                self.moved = True
            else:
                start = self.canvas.win_to_doc(self.start)
                end = self.canvas.win_to_doc(self.end)

                center = libgeom.bbox_center(self.selection.bbox)
                offset = libgeom.add_points(center, self.offset_start)
                dp = libgeom.sub_points(end, start)
                cursor = libgeom.add_points(offset, dp)

                if is_constraining:
                    step = config.rotation_step
                    cursor = libgeom.round_angle_point(center, cursor, step)
                if is_snapping:
                    cursor = self.snap.snap_point(cursor, False)[2]

                center_offset = libgeom.sub_points(cursor, center)
                self.selection.center_offset = center_offset
                self.canvas.selection_redraw()