Example #1
0
def png_saver(sk2_doc,
              filename=None,
              fileptr=None,
              translate=True,
              cnf={},
              **kw):
    if filename and not fileptr:
        fileptr = get_fileptr(filename, True)
    page = sk2_doc.methods.get_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 = CairoRenderer(sk2_doc.cms)
    antialias_flag = True
    if 'antialiasing' in kw.keys():
        if not kw['antialiasing'] in ('True', '1'):
            antialias_flag = False
    rend.antialias_flag = antialias_flag
    layers = sk2_doc.methods.get_visible_layers(page)

    for item in layers:
        if not item.properties[3] and antialias_flag:
            rend.antialias_flag = False
        rend.render(ctx, item.childs)
        if not item.properties[3] and antialias_flag:
            rend.antialias_flag = True

    surface.write_to_png(fileptr)
    fileptr.close()
Example #2
0
def png_saver(sk2_doc, filename=None, fileptr=None, translate=True, cnf={}, **kw):
	if filename and not fileptr:
		fileptr = get_fileptr(filename, True)
	page = sk2_doc.methods.get_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 = CairoRenderer(sk2_doc.cms)
	antialias_flag = True
	if 'antialiasing' in kw.keys():
		if not kw['antialiasing'] in ('True', '1'):
			antialias_flag = False
	rend.antialias_flag = antialias_flag
	layers = sk2_doc.methods.get_visible_layers(page)

	for item in layers:
		if not item.properties[3] and antialias_flag:
			rend.antialias_flag = False
		rend.render(ctx, item.childs)
		if not item.properties[3] and antialias_flag:
			rend.antialias_flag = True

	surface.write_to_png(fileptr)
	fileptr.close()
Example #3
0
def check_cdr(path):
    fileptr = get_fileptr(path)
    header = fileptr.read(12)
    fileptr.close()
    if not header[:4] == cdr_const.RIFF_ID: return False
    if header[8:] in cdr_const.CDR_VERSIONS: return True
    else: return False
Example #4
0
def check_cdr(path):
	fileptr = get_fileptr(path)
	header = fileptr.read(12)
	fileptr.close()
	if not header[:4] == cdr_const.RIFF_ID: return False
	if header[8:] in cdr_const.CDR_VERSIONS: return True
	else: return False
Example #5
0
def check_wmf(path):
	fileptr = get_fileptr(path)
	sign = fileptr.read(len(WMF_SIGNATURE))
	fileptr.seek(0)
	metatype = fileptr.read(2)
	fileptr.read(2)
	metaver = fileptr.read(2)
	fileptr.close()
	if sign == WMF_SIGNATURE: return True
	if metatype in METAFILETYPES and metaver in METAVERSIONS: return True
	return False
Example #6
0
def check_wmf(path):
	fileptr = get_fileptr(path)
	sign = fileptr.read(len(WMF_SIGNATURE))
	fileptr.seek(0)
	metatype = fileptr.read(2)
	fileptr.read(2)
	metaver = fileptr.read(2)
	fileptr.close()
	if sign == WMF_SIGNATURE: return True
	if metatype in METAFILETYPES and metaver in METAVERSIONS: return True
	return False
Example #7
0
def check_xml_(path):
    fileptr = get_fileptr(path)
    ret = False
    i = 0
    while i < 20:
        line = fileptr.readline()
        if not line.find('<?xml ') == -1:
            ret = True
            break
        i += 1
    fileptr.close()
    return ret
Example #8
0
def check_corel_pal(path):
    fileptr = get_fileptr(path)
    ret = False
    i = 0
    while i < 20:
        line = fileptr.readline()
        if not line.find('<palette') == -1:
            ret = True
            break
        i += 1
    fileptr.close()
    return ret
Example #9
0
def check_scribus_pal(path):
	fileptr = get_fileptr(path)
	ret = False
	i = 0
	while i < 20:
		line = fileptr.readline()
		if not line.find(SP_TAG) == -1:
			ret = True
			break
		i += 1
	fileptr.close()
	return ret
Example #10
0
def check_corel_pal(path):
	fileptr = get_fileptr(path)
	ret = False
	i = 0
	while i < 20:
		line = fileptr.readline()
		if not line.find('<palette') == -1:
			ret = True
			break
		i += 1
	fileptr.close()
	return ret
Example #11
0
def check_plt(path):
	file_size = os.path.getsize(path)
	fileptr = get_fileptr(path)

	if file_size > 200:
		string = fileptr.read(200)
	else:
		string = fileptr.read()

	fileptr.close()
	if len(string.split("IN;")) > 1 and len(string.split(";")) > 2:
		if len(string.split(";PD")) > 1:
			return True
	return False
Example #12
0
def check_plt(path):
    file_size = os.path.getsize(path)
    fileptr = get_fileptr(path)

    if file_size > 200:
        string = fileptr.read(200)
    else:
        string = fileptr.read()

    fileptr.close()
    if len(string.split("IN;")) > 1 and len(string.split(";")) > 2:
        if len(string.split(";PD")) > 1:
            return True
    return False
Example #13
0
def check_soc(path):
	fileptr = get_fileptr(path)
	ret = False
	i = 0
	while i < 20:
		line = fileptr.readline()
		if not line.find(SOC_PAL_TAG) == -1:
			ret = True
			break
		if not line.find(SOC_PAL_OO_TAG) == -1:
			ret = True
			break
		i += 1
	fileptr.close()
	return ret
Example #14
0
def check_sk2(path):
    ret = False
    fileptr = get_fileptr(path)
    ln = fileptr.readline()
    if ln[:len(SK2DOC_ID)] == SK2DOC_ID:
        if int(ln[len(SK2DOC_ID):]) <= int(SK2VER): ret = True
        else:
            fileptr.close()
            raise RuntimeError(_('Newer version of SK2 format is found!'))
    else:
        ln2 = fileptr.readline()
        if ln2[:len(SK2XML_ID)] == SK2XML_ID:
            if int(ln2[len(SK2XML_ID):]) <= int(SK2VER): ret = True
            else:
                fileptr.close()
                raise RuntimeError(_('Newer version of SK2 format is found!'))
    fileptr.close()
    return ret
Example #15
0
def check_sk2(path):
	ret = False
	fileptr = get_fileptr(path)
	ln = fileptr.readline()
	if ln[:len(SK2DOC_ID)] == SK2DOC_ID:
		if int(ln[len(SK2DOC_ID):]) <= int(SK2VER): ret = True
		else:
			fileptr.close()
			raise RuntimeError(_('Newer version of SK2 format is found!'))
	else:
		ln2 = fileptr.readline()
		if ln2[:len(SK2XML_ID)] == SK2XML_ID:
			if int(ln2[len(SK2XML_ID):]) <= int(SK2VER): ret = True
			else:
				fileptr.close()
				raise RuntimeError(_('Newer version of SK2 format is found!'))
	fileptr.close()
	return ret
Example #16
0
def check_sk1(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(7)
    fileptr.close()
    return string == '##sK1 1'
Example #17
0
def check_jcw(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(len(JCW_ID))
	fileptr.close()
	return string == JCW_ID
Example #18
0
def check_ase(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(ASEF))
    fileptr.close()
    return string == ASEF
Example #19
0
def check_gpl(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(GPL_HEADER))
    fileptr.close()
    return string == GPL_HEADER
Example #20
0
def check_sk2(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(len(SK2DOC_ID))
	fileptr.close()
	return string == SK2DOC_ID
Example #21
0
def check_png(path):
	fileptr = get_fileptr(path)
	mstr = fileptr.read(len(PNG_ID))
	fileptr.close()
	if mstr == PNG_ID: return True
	return False
Example #22
0
def check_riff(path):
	fileptr = get_fileptr(path)
	fourcc = fileptr.read(4)
	fileptr.close()
	return fourcc == 'RIFF'
Example #23
0
def check_ase(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(ASEF))
    fileptr.close()
    return string == ASEF
Example #24
0
def check_riff(path):
    fileptr = get_fileptr(path)
    fourcc = fileptr.read(4)
    fileptr.close()
    return fourcc == 'RIFF'
Example #25
0
def check_sk1(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(7)
	fileptr.close()
	return string == '##sK1 1'
Example #26
0
def check_png(path):
    fileptr = get_fileptr(path)
    mstr = fileptr.read(len(PNG_ID))
    fileptr.close()
    if mstr == PNG_ID: return True
    return False
Example #27
0
def check_sk(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(len(sk_const.SKDOC_ID))
	fileptr.close()
	return string == sk_const.SKDOC_ID
Example #28
0
def check_cgm(path):
    fileptr = get_fileptr(path)
    sign = fileptr.read(len(CGM_SIGNATURE))
    fileptr.close()
    return sign == CGM_SIGNATURE
Example #29
0
def check_cpl(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(len(CPL12))
	fileptr.close()
	return string in CPL_IDs
Example #30
0
def check_skp(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(len(SKP_ID))
	fileptr.close()
	return string == SKP_ID
Example #31
0
def check_jcw(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(JCW_ID))
    fileptr.close()
    return string == JCW_ID
Example #32
0
def check_cpl(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(CPL12))
    fileptr.close()
    return string in CPL_IDs
Example #33
0
def check_aco(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(2)
    fileptr.close()
    return string in (ACO1_VER, ACO2_VER)
Example #34
0
def check_gpl(path):
	fileptr = get_fileptr(path)
	string = fileptr.read(len(GPL_HEADER))
	fileptr.close()
	return string == GPL_HEADER
Example #35
0
def check_sk(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(sk_const.SKDOC_ID))
    fileptr.close()
    return string == sk_const.SKDOC_ID
Example #36
0
def check_pdf(path):
    fileptr = get_fileptr(path)
    string = fileptr.read(len(PDF_SIGNATURE))
    fileptr.close()
    return string == PDF_SIGNATURE