コード例 #1
0
ファイル: colorctrls.py プロジェクト: Scrik/sk1-wx
	def draw_pattern(self):
		w, h = self.get_size()
		pattern = self.fill[2]
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
		ctx = cairo.Context(surface)
		self.draw_cairo_background(ctx)
		bmpstr = b64decode(pattern[1])
		if self.cms.app.current_doc:
			config = self.cms.app.current_doc.model.config
		else:
			config = sk2_config.SK2_Config()
			config_file = os.path.join(self.cms.app.appdata.app_config_dir,
									'sk2_config.xml')
			config.load(config_file)
		image_obj = sk2_model.Pixmap(config)
		libimg.set_image_data(self.cms, image_obj, bmpstr)
		libimg.flip_left_to_right(image_obj)
		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)
		sp = cairo.SurfacePattern(image_obj.cache_cdata)
		sp.set_extend(cairo.EXTEND_REPEAT)
		trafo = [-1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
		if len(pattern) > 3:
			trafo = libgeom.multiply_trafo(pattern[3], trafo)
		pattern_matrix = cairo.Matrix(*trafo)
		pattern_matrix.invert()
		sp.set_matrix(pattern_matrix)
		ctx.set_source(sp)
		ctx.rectangle(0, 0, w, h)
		ctx.fill()
		image_obj.cache_cdata = None
		self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0)
コード例 #2
0
 def draw_pattern(self):
     w, h = self.get_size()
     pattern = self.fill[2]
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
     ctx = cairo.Context(surface)
     self.draw_cairo_background(ctx)
     bmpstr = b64decode(pattern[1])
     if self.cms.app.current_doc:
         config = self.cms.app.current_doc.model.config
     else:
         config = sk2_config.SK2_Config()
         config_file = os.path.join(self.cms.app.appdata.app_config_dir,
                                    'sk2_config.xml')
         config.load(config_file)
     image_obj = sk2_model.Pixmap(config)
     libimg.set_image_data(self.cms, image_obj, bmpstr)
     libimg.flip_left_to_right(image_obj)
     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)
     sp = cairo.SurfacePattern(image_obj.cache_cdata)
     sp.set_extend(cairo.EXTEND_REPEAT)
     trafo = [-1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
     if len(pattern) > 3:
         trafo = libgeom.multiply_trafo(pattern[3], trafo)
     pattern_matrix = cairo.Matrix(*trafo)
     pattern_matrix.invert()
     sp.set_matrix(pattern_matrix)
     ctx.set_source(sp)
     ctx.rectangle(0, 0, w, h)
     ctx.fill()
     image_obj.cache_cdata = None
     self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0)
コード例 #3
0
    def translate_image(self, dest_parent, source_image):
        trafo = self.get_sk2_trafo(source_image)
        dest_image = sk2_model.Pixmap(dest_parent.config)

        image = source_image.image
        image_stream = StringIO()
        image.save(image_stream, 'PNG')
        content = image_stream.getvalue()

        libimg.set_image_data(self.sk2_doc.cms, dest_image, content)
        dest_image.trafo = trafo
        return dest_image
コード例 #4
0
 def _create_pattern_image(self, obj, force_proofing=False, gray=False):
     fill = obj.style[0]
     pattern_fill = fill[2]
     bmpstr = b64decode(pattern_fill[1])
     image_obj = sk2_model.Pixmap(obj.config)
     libimg.set_image_data(self.cms, image_obj, bmpstr)
     libimg.flip_top_to_bottom(image_obj)
     if pattern_fill[0] == sk2const.PATTERN_IMG and len(pattern_fill) > 2:
         image_obj.style[3] = deepcopy(pattern_fill[2])
     if gray:
         libimg.update_gray_image(self.cms, image_obj)
     else:
         libimg.update_image(self.cms, image_obj, force_proofing)
     return image_obj
コード例 #5
0
ファイル: sk1_translators.py プロジェクト: sk1project/sk1-wx
	def translate_image(self, dest_parent, source_image):
		trafo = self.get_sk2_trafo(source_image)
		dest_image = sk2_model.Pixmap(dest_parent.config)

		image = source_image.image
		image_stream = StringIO()
		if image.mode == "CMYK":
			image.save(image_stream, 'JPEG', quality=100)
		else:
			image.save(image_stream, 'PNG')
		content = image_stream.getvalue()

		libimg.set_image_data(self.sk2_doc.cms, dest_image, content)
		dest_image.trafo = trafo
		return dest_image
コード例 #6
0
ファイル: wmf_translators.py プロジェクト: sk1project/sk1-wx
	def tr_stretch_dib(self, chunk):
		src_h, src_w, = get_data('<hh', chunk[6:10])
		dst_h, dst_w, dst_y, dst_x = get_data('<hhhh', chunk[14:22])
		imagestr = wmflib.dib_to_imagestr(chunk[22:])

		tr = self.get_trafo()
		p0 = apply_trafo_to_point([dst_x, dst_y], tr)
		p1 = apply_trafo_to_point([dst_w + dst_x, dst_h + dst_y], tr)
		w = abs(p1[0] - p0[0])
		h = abs(p1[1] - p0[1])
		trafo = [w / src_w, 0.0, 0.0, h / src_h, p0[0], p0[1] - h]

		pixmap = sk2_model.Pixmap(self.layer.config)

		libimg.set_image_data(self.sk2_doc.cms, pixmap, imagestr)
		pixmap.trafo = trafo
		self.layer.childs.append(pixmap)
コード例 #7
0
    def tr_stretch_dib(self, chunk):
        src_h, src_w, = get_data('<hh', chunk[6:10])
        dst_h, dst_w, dst_y, dst_x = get_data('<hhhh', chunk[14:22])
        imagestr = wmflib.dib_to_imagestr(chunk[22:])

        tr = self.get_trafo()
        p0 = apply_trafo_to_point([dst_x, dst_y], tr)
        p1 = apply_trafo_to_point([dst_w + dst_x, dst_h + dst_y], tr)
        w = abs(p1[0] - p0[0])
        h = abs(p1[1] - p0[1])
        trafo = [w / src_w, 0.0, 0.0, h / src_h, p0[0], p0[1] - h]

        pixmap = sk2_model.Pixmap(self.layer.config)

        libimg.set_image_data(self.sk2_doc.cms, pixmap, imagestr)
        pixmap.trafo = trafo
        self.layer.childs.append(pixmap)
コード例 #8
0
ファイル: fallback.py プロジェクト: Acidburn0zzz/sk1-wx
def im_loader(appdata,
              filename=None,
              fileptr=None,
              translate=True,
              cnf={},
              **kw):
    if filename and not fileptr:
        try:
            fileptr = open(filename, 'rb')
        except:
            errtype, value, traceback = sys.exc_info()
            msg = _('Cannot read %s file') % (filename)
            events.emit(events.MESSAGES, msgconst.ERROR, msg)
            raise IOError(errtype, msg + '\n' + value, traceback)

    content = fileptr.read()
    fileptr.close()

    sk2_doc = SK2_Presenter(appdata, cnf)
    sk2_doc.doc_file = filename
    sk2_doc.methods.set_doc_origin(sk2_const.DOC_ORIGIN_LU)
    sk2_doc.methods.set_doc_units(uc2const.UNIT_PX)
    page = sk2_doc.methods.get_page()

    image_obj = sk2_model.Pixmap(sk2_doc.config)
    libimg.set_image_data(sk2_doc.cms, image_obj, content)

    orient = uc2const.PORTRAIT
    w = image_obj.size[0] * uc2const.px_to_pt
    h = image_obj.size[1] * uc2const.px_to_pt
    if image_obj.size[0] > image_obj.size[1]: orient = uc2const.LANDSCAPE

    image_obj.trafo = [1.0, 0.0, 0.0, 1.0, -w / 2.0, -h / 2.0]

    sk2_doc.methods.set_page_format(page, ['Custom', (w, h), orient])
    sk2_doc.methods.set_default_page_format(['Custom', (w, h), orient])
    grid_layer = sk2_doc.methods.get_grid_layer()
    grid_layer.grid = [0, 0, uc2const.px_to_pt, uc2const.px_to_pt]
    grid_layer.properties = [1, 0, 0]

    layer = sk2_doc.methods.get_layer(page)

    layer.childs.append(image_obj)
    sk2_doc.update()
    return sk2_doc
コード例 #9
0
ファイル: fallback.py プロジェクト: Scrik/sk1-wx
def im_loader(appdata, filename=None, fileptr=None, translate=True, cnf={}, **kw):
	if filename and not fileptr:
		try:
			fileptr = open(filename, 'rb')
		except:
			errtype, value, traceback = sys.exc_info()
			msg = _('Cannot read %s file') % (filename)
			events.emit(events.MESSAGES, msgconst.ERROR, msg)
			raise IOError(errtype, msg + '\n' + value, traceback)

	content = fileptr.read()
	fileptr.close()

	sk2_doc = SK2_Presenter(appdata, cnf)
	sk2_doc.doc_file = filename
	sk2_doc.methods.set_doc_origin(sk2_const.DOC_ORIGIN_LU)
	sk2_doc.methods.set_doc_units(uc2const.UNIT_PX)
	page = sk2_doc.methods.get_page()

	image_obj = sk2_model.Pixmap(sk2_doc.config)
	libimg.set_image_data(sk2_doc.cms, image_obj, content)

	orient = uc2const.PORTRAIT
	w = image_obj.size[0] * uc2const.px_to_pt
	h = image_obj.size[1] * uc2const.px_to_pt
	if image_obj.size[0] > image_obj.size[1]:orient = uc2const.LANDSCAPE

	image_obj.trafo = [1.0, 0.0, 0.0, 1.0, -w / 2.0, -h / 2.0]

	sk2_doc.methods.set_page_format(page, ['Custom', (w, h), orient])
	sk2_doc.methods.set_default_page_format(['Custom', (w, h), orient])
	grid_layer = sk2_doc.methods.get_grid_layer()
	grid_layer.grid = [0, 0, uc2const.px_to_pt, uc2const.px_to_pt]
	grid_layer.properties = [1, 0, 0]

	layer = sk2_doc.methods.get_layer(page)

	layer.childs.append(image_obj)
	sk2_doc.update()
	return sk2_doc
コード例 #10
0
def im_loader(appdata,
              filename=None,
              fileptr=None,
              translate=True,
              cnf=None,
              **kw):
    cnf = merge_cnf(cnf, kw)
    if filename and not fileptr:
        fileptr = get_fileptr(filename)
    content = fileptr.read()
    fileptr.close()

    sk2_doc = SK2_Presenter(appdata, cnf)
    sk2_doc.doc_file = filename
    sk2_doc.methods.set_doc_origin(sk2const.DOC_ORIGIN_LU)
    sk2_doc.methods.set_doc_units(uc2const.UNIT_PX)
    page = sk2_doc.methods.get_page()

    image_obj = sk2_model.Pixmap(sk2_doc.config)
    libimg.set_image_data(sk2_doc.cms, image_obj, content)

    orient = uc2const.PORTRAIT
    w = image_obj.size[0] * uc2const.px_to_pt
    h = image_obj.size[1] * uc2const.px_to_pt
    if image_obj.size[0] > image_obj.size[1]:
        orient = uc2const.LANDSCAPE

    image_obj.trafo = [1.0, 0.0, 0.0, 1.0, -w / 2.0, -h / 2.0]

    sk2_doc.methods.set_page_format(page, ['Custom', (w, h), orient])
    sk2_doc.methods.set_default_page_format(['Custom', (w, h), orient])
    grid_layer = sk2_doc.methods.get_grid_layer()
    grid_layer.grid = [0, 0, uc2const.px_to_pt, uc2const.px_to_pt]
    grid_layer.properties = [1, 0, 0]

    layer = sk2_doc.methods.get_layer(page)

    layer.childs.append(image_obj)
    sk2_doc.update()
    return sk2_doc
コード例 #11
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] == sk2const.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()
コード例 #12
0
ファイル: pdfgen.py プロジェクト: sk1project/sk1-wx
	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()
コード例 #13
0
ファイル: crenderer.py プロジェクト: Scrik/sk1-wx
	def process_fill(self, ctx, obj):
		fill = obj.style[0]
		fill_rule = fill[0]
		if fill_rule & sk2_const.FILL_CLOSED_ONLY and not obj.is_closed():
			ctx.set_source_rgba(0.0, 0.0, 0.0, 0.0)
			return
		if fill_rule & sk2_const.FILL_EVENODD:
			ctx.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
		else:
			ctx.set_fill_rule(cairo.FILL_RULE_WINDING)
		if fill[1] == sk2_const.FILL_SOLID:
			if obj.fill_trafo: obj.fill_trafo = []
			color = fill[2]
			ctx.set_source_rgba(*self.get_color(color))
		elif fill[1] == sk2_const.FILL_GRADIENT:
			if not obj.fill_trafo:
				obj.fill_trafo = [] + sk2_const.NORMAL_TRAFO
			gradient = fill[2]
			points = gradient[1]
			if not points:
				obj.fill_trafo = [] + sk2_const.NORMAL_TRAFO
				points = libgeom.bbox_middle_points(obj.cache_bbox)
				if gradient[0] == sk2_const.GRADIENT_LINEAR:
					points = [points[0], points[2]]
				else:
					points = [[points[1][0], points[2][1]], points[2]]
				gradient[1] = points
			coords = points[0] + points[1]
			if gradient[0] == sk2_const.GRADIENT_LINEAR:
				grd = cairo.LinearGradient(*coords)
			else:
				x0, y0 = coords[:2]
				radius = libgeom.distance(*points)
				grd = cairo.RadialGradient(x0, y0, 0, x0, y0, radius)
			for stop in gradient[2]:
				grd.add_color_stop_rgba(stop[0], *self.get_color(stop[1]))
			matrix = cairo.Matrix(*obj.fill_trafo)
			matrix.invert()
			grd.set_matrix(matrix)
			ctx.set_source(grd)
		elif fill[1] == sk2_const.FILL_PATTERN:
			if not obj.fill_trafo:
				obj.fill_trafo = [] + sk2_const.NORMAL_TRAFO
				obj.fill_trafo = obj.fill_trafo[:4] + \
					[obj.cache_bbox[0], obj.cache_bbox[3]]
			pattern_fill = fill[2]
			if not obj.cache_pattern_img:
				bmpstr = b64decode(pattern_fill[1])
				image_obj = model.Pixmap(obj.config)
				libimg.set_image_data(self.cms, image_obj, bmpstr)
				libimg.flip_top_to_bottom(image_obj)
				if pattern_fill[0] == sk2_const.PATTERN_IMG and \
				 len(pattern_fill) > 2:
					image_obj.style[3] = deepcopy(pattern_fill[2])
				libimg.update_image(self.cms, image_obj)
				obj.cache_pattern_img = image_obj.cache_cdata
				image_obj.cache_cdata = None
			sp = cairo.SurfacePattern(obj.cache_pattern_img)
			sp.set_extend(cairo.EXTEND_REPEAT)
			flip_matrix = cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
			if len(pattern_fill) > 3:
				pattern_matrix = cairo.Matrix(*pattern_fill[3])
				pattern_matrix.invert()
				flip_matrix = flip_matrix * pattern_matrix
			trafo_matrix = cairo.Matrix(*obj.fill_trafo)
			trafo_matrix.invert()
			flip_matrix = flip_matrix * trafo_matrix
			sp.set_matrix(flip_matrix)
			ctx.set_source(sp)

			canvas_matrix = ctx.get_matrix()
			canvas_trafo = libcairo.get_trafo_from_matrix(canvas_matrix)
			zoom = canvas_trafo[0]
			if zoom * abs(obj.fill_trafo[0]) > .98:
				ctx.get_source().set_filter(cairo.FILTER_NEAREST)
コード例 #14
0
ファイル: crenderer.py プロジェクト: Scrik/sk1-wx
    def process_fill(self, ctx, obj):
        fill = obj.style[0]
        fill_rule = fill[0]
        if fill_rule & sk2_const.FILL_CLOSED_ONLY and not obj.is_closed():
            ctx.set_source_rgba(0.0, 0.0, 0.0, 0.0)
            return
        if fill_rule & sk2_const.FILL_EVENODD:
            ctx.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
        else:
            ctx.set_fill_rule(cairo.FILL_RULE_WINDING)
        if fill[1] == sk2_const.FILL_SOLID:
            if obj.fill_trafo: obj.fill_trafo = []
            color = fill[2]
            ctx.set_source_rgba(*self.get_color(color))
        elif fill[1] == sk2_const.FILL_GRADIENT:
            if not obj.fill_trafo:
                obj.fill_trafo = [] + sk2_const.NORMAL_TRAFO
            gradient = fill[2]
            points = gradient[1]
            if not points:
                obj.fill_trafo = [] + sk2_const.NORMAL_TRAFO
                points = libgeom.bbox_middle_points(obj.cache_bbox)
                if gradient[0] == sk2_const.GRADIENT_LINEAR:
                    points = [points[0], points[2]]
                else:
                    points = [[points[1][0], points[2][1]], points[2]]
                gradient[1] = points
            coords = points[0] + points[1]
            if gradient[0] == sk2_const.GRADIENT_LINEAR:
                grd = cairo.LinearGradient(*coords)
            else:
                x0, y0 = coords[:2]
                radius = libgeom.distance(*points)
                grd = cairo.RadialGradient(x0, y0, 0, x0, y0, radius)
            for stop in gradient[2]:
                grd.add_color_stop_rgba(stop[0], *self.get_color(stop[1]))
            matrix = cairo.Matrix(*obj.fill_trafo)
            matrix.invert()
            grd.set_matrix(matrix)
            ctx.set_source(grd)
        elif fill[1] == sk2_const.FILL_PATTERN:
            if not obj.fill_trafo:
                obj.fill_trafo = [] + sk2_const.NORMAL_TRAFO
                obj.fill_trafo = obj.fill_trafo[:4] + \
                 [obj.cache_bbox[0], obj.cache_bbox[3]]
            pattern_fill = fill[2]
            if not obj.cache_pattern_img:
                bmpstr = b64decode(pattern_fill[1])
                image_obj = model.Pixmap(obj.config)
                libimg.set_image_data(self.cms, image_obj, bmpstr)
                libimg.flip_top_to_bottom(image_obj)
                if pattern_fill[0] == sk2_const.PATTERN_IMG and \
                 len(pattern_fill) > 2:
                    image_obj.style[3] = deepcopy(pattern_fill[2])
                libimg.update_image(self.cms, image_obj)
                obj.cache_pattern_img = image_obj.cache_cdata
                image_obj.cache_cdata = None
            sp = cairo.SurfacePattern(obj.cache_pattern_img)
            sp.set_extend(cairo.EXTEND_REPEAT)
            flip_matrix = cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
            if len(pattern_fill) > 3:
                pattern_matrix = cairo.Matrix(*pattern_fill[3])
                pattern_matrix.invert()
                flip_matrix = flip_matrix * pattern_matrix
            trafo_matrix = cairo.Matrix(*obj.fill_trafo)
            trafo_matrix.invert()
            flip_matrix = flip_matrix * trafo_matrix
            sp.set_matrix(flip_matrix)
            ctx.set_source(sp)

            canvas_matrix = ctx.get_matrix()
            canvas_trafo = libcairo.get_trafo_from_matrix(canvas_matrix)
            zoom = canvas_trafo[0]
            if zoom * abs(obj.fill_trafo[0]) > .98:
                ctx.get_source().set_filter(cairo.FILTER_NEAREST)