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()
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
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
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
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
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
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
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
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
def check_sk1(path): fileptr = get_fileptr(path) string = fileptr.read(7) fileptr.close() return string == '##sK1 1'
def check_jcw(path): fileptr = get_fileptr(path) string = fileptr.read(len(JCW_ID)) fileptr.close() return string == JCW_ID
def check_ase(path): fileptr = get_fileptr(path) string = fileptr.read(len(ASEF)) fileptr.close() return string == ASEF
def check_gpl(path): fileptr = get_fileptr(path) string = fileptr.read(len(GPL_HEADER)) fileptr.close() return string == GPL_HEADER
def check_sk2(path): fileptr = get_fileptr(path) string = fileptr.read(len(SK2DOC_ID)) fileptr.close() return string == SK2DOC_ID
def check_png(path): fileptr = get_fileptr(path) mstr = fileptr.read(len(PNG_ID)) fileptr.close() if mstr == PNG_ID: return True return False
def check_riff(path): fileptr = get_fileptr(path) fourcc = fileptr.read(4) fileptr.close() return fourcc == 'RIFF'
def check_sk(path): fileptr = get_fileptr(path) string = fileptr.read(len(sk_const.SKDOC_ID)) fileptr.close() return string == sk_const.SKDOC_ID
def check_cgm(path): fileptr = get_fileptr(path) sign = fileptr.read(len(CGM_SIGNATURE)) fileptr.close() return sign == CGM_SIGNATURE
def check_cpl(path): fileptr = get_fileptr(path) string = fileptr.read(len(CPL12)) fileptr.close() return string in CPL_IDs
def check_skp(path): fileptr = get_fileptr(path) string = fileptr.read(len(SKP_ID)) fileptr.close() return string == SKP_ID
def check_aco(path): fileptr = get_fileptr(path) string = fileptr.read(2) fileptr.close() return string in (ACO1_VER, ACO2_VER)
def check_pdf(path): fileptr = get_fileptr(path) string = fileptr.read(len(PDF_SIGNATURE)) fileptr.close() return string == PDF_SIGNATURE