예제 #1
0
파일: sk2_model.py 프로젝트: THS-on/sk1-wx
 def __init__(self, config, parent=None,
              bitmap=None,
              alpha_channel=None,
              trafo=[] + sk2const.NORMAL_TRAFO,
              style=[] + sk2const.EMPTY_STYLE):
     self.cid = PIXMAP
     self.config = config
     self.parent = parent
     self.handler = EditableImageHandler(self)
     self.handler.set_images_from_str(bitmap, alpha_channel)
     self.trafo = trafo
     self.style = style
예제 #2
0
파일: sk2_model.py 프로젝트: THS-on/sk1-wx
class Pixmap(PrimitiveObject):
    """
    Represents pixmap object. 
    Raster graphics is stored as a TIFF bitmaps for CMYK colorspace and as 
    a PNG bitmap for others. 'bitmap' field contains raster info, but
    transparency data is stored as a grayscale image in 'alpha_channel'.
    Images are stored as a base64 encoded string to resolve EOL and other 
    special character issues. 'colorspace' describes 'bitmap' type. 
    Possible types are: monochrome, grayscale, RGB and CMYK.
    For monochrome and grayscale colorspaces is available duotone mode. Duotone
    colors (foreground and background) are defined in 'style' field.
    It is assumed that initial lower left corner of pixmap is [0.0,0.0] point 
    and pixmap size is defined by 72 dpi resolution.
    """

    cid = PIXMAP

    bitmap = None
    alpha_channel = None

    handler = None

    cache_paths = None
    cache_cpath = None
    cache_cdata = None
    cache_ps_cdata = None
    cache_gray_cdata = None
    is_pixmap = True

    def __init__(self, config, parent=None,
                 bitmap=None,
                 alpha_channel=None,
                 trafo=[] + sk2const.NORMAL_TRAFO,
                 style=[] + sk2const.EMPTY_STYLE):
        self.cid = PIXMAP
        self.config = config
        self.parent = parent
        self.handler = EditableImageHandler(self)
        self.handler.set_images_from_str(bitmap, alpha_channel)
        self.trafo = trafo
        self.style = style

    @property
    def colorspace(self):
        return self.handler.get_mode()

    @property
    def size(self):
        return self.handler.get_size()

    def has_alpha(self):
        return self.handler.has_alpha()

    def set_bitmap(self, bitmap, b64=False):
        if b64:
            self.handler.set_images_from_b64str(bitmap)
        else:
            self.handler.set_images_from_str(bitmap)

    def get_bitmap(self):
        return self.handler.get_bitmap_b64str()

    def set_alpha_channel(self, alpha, b64=False):
        if b64:
            self.handler.set_images_from_b64str(None, alpha)
        else:
            self.handler.set_images_from_str(None, alpha)

    def get_alpha_channel(self):
        return self.handler.get_alpha_b64str()

    def get_size(self):
        width = float(self.size[0]) * uc2const.px_to_pt
        height = float(self.size[1]) * uc2const.px_to_pt
        return width, height

    def get_initial_paths(self):
        width, height = self.get_size()
        return libgeom.get_rect_paths([0, 0], width, height,
                                      [] + sk2const.CORNERS)

    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

    def update(self):
        PrimitiveObject.update(self)

    def copy(self, src=None, dst=None):
        obj = PrimitiveObject.copy(self, src, dst)
        obj.handler = self.handler.copy(obj)
        return obj

    def clear_color_cache(self):
        self.handler.clear_cache()