Ejemplo n.º 1
0
def save(document, file, filename, options={}):
    if options.get('box'):
        bbox = document.BoundingRect(visible=0, printable=1)
    else:
        bbox = document.PageRect()
    bbox = tuple(bbox)
    llx, lly, urx, ury = bbox
    resolution = config.preferences.pdf_export_resolution
    compat = config.preferences.pdf_compatibility_level
    width = (urx - llx) * resolution / 72
    height = (ury - lly) * resolution / 72
    offx = -llx
    offy = -lly

    if options.get('images'):
        imfilter = "-dAutoFilterColorImages=false -sColorImageFilter=FlateEncode"
    else:
        imfilter = ''

    filename = util.sh_quote(filename)
    file = os.popen(gs_command % locals(), 'w')
    ps = PostScriptDevice(file,
                          document=document,
                          as_eps=1,
                          embed_fonts=1,
                          bounding_box=bbox,
                          Title=os.path.basename(filename),
                          For=util.get_real_username(),
                          CreationDate=util.current_date())
    document.Draw(ps)
    ps.Close()
    file.close()
Ejemplo n.º 2
0
def render_preview(filename, startx, starty, width, height, resolution = None):
    import tempfile
    temp = tempfile.mktemp()

    try:
        # quote the filename so that it can have spaces and to avoid a
        # security hole
        filename = util.sh_quote(filename)
        if resolution is None:
            resolution = config.preferences.eps_preview_resolution
        factor = resolution / 72.0
        width = int(math.ceil(width * factor))
        height = int(math.ceil(height * factor))
	offx = -startx
	offy = -starty
	os.system(gs_command % locals())

	image = PIL.Image.open(temp)
	image.load()
	return image
    finally:
	try:
	    os.unlink(temp)
	except:
	    pass
Ejemplo n.º 3
0
def render_preview(filename, startx, starty, width, height, resolution = None):
    import tempfile
    temp = tempfile.mktemp()

    try:
        # quote the filename so that it can have spaces and to avoid a
        # security hole
        filename = util.sh_quote(filename)
        if resolution is None:
            resolution = config.preferences.eps_preview_resolution
        factor = resolution / 72.0
        width = int(math.ceil(width * factor))
        height = int(math.ceil(height * factor))
        offx = -startx
        offy = -starty
        os.system(gs_command % locals())

        image = PIL.Image.open(temp)
        image.load()
        return image
    finally:
        try:
            os.unlink(temp)
        except:
            pass
Ejemplo n.º 4
0
 def Load(self):
     basename, ext = os.path.splitext(self.filename)
     if ext != '.bz2':
         basename = self.filename
     stream = os.popen('bzip2 -d -c ' + sh_quote(self.filename))
     doc = load.load_drawing_from_file(stream, basename,
                                       doc_class = self.doc_class)
     if doc:
         doc.meta.compressed = "bzip2"
         doc.meta.compressed_file = self.filename
         self.messages = doc.meta.load_messages
     return doc
Ejemplo n.º 5
0
 def Load(self):
     basename, ext = os.path.splitext(self.filename)
     if ext != '.bz2':
         basename = self.filename
     stream = os.popen('bzip2 -d -c ' + sh_quote(self.filename))
     doc = load.load_drawing_from_file(stream,
                                       basename,
                                       doc_class=self.doc_class)
     if doc:
         doc.meta.compressed = "bzip2"
         doc.meta.compressed_file = self.filename
         self.messages = doc.meta.load_messages
     return doc
Ejemplo n.º 6
0
 def Load(self):
     if self.filename:
         basename, ext = os.path.splitext(self.filename)
         if ext != '.gz':
             basename = self.filename
         stream = os.popen('gzip -d -c ' + sh_quote(self.filename))
         doc = load.load_drawing_from_file(stream, basename,
                                           doc_class = self.doc_class)
         if doc:
             doc.meta.compressed = "gzip"
             doc.meta.compressed_file = self.filename
             self.messages = doc.meta.load_messages
         return doc
     raise SketchLoadError('gziploader must be instantiated with filename')
Ejemplo n.º 7
0
 def Load(self):
     if self.filename:
         basename, ext = os.path.splitext(self.filename)
         if ext != '.gz':
             basename = self.filename
         stream = os.popen('gzip -d -c ' + sh_quote(self.filename))
         doc = load.load_drawing_from_file(stream,
                                           basename,
                                           doc_class=self.doc_class)
         if doc:
             doc.meta.compressed = "gzip"
             doc.meta.compressed_file = self.filename
             self.messages = doc.meta.load_messages
         return doc
     raise SketchLoadError('gziploader must be instantiated with filename')
Ejemplo n.º 8
0
def save(document, file, filename, options = {}):
    bbox = tuple(document.PageRect())
    llx, lly, urx, ury = bbox
    resolution = config.preferences.pdf_export_resolution
    compat = config.preferences.pdf_compatibility_level
    width = (urx-llx)*resolution/72
    height = (ury-lly)*resolution/72

    filename = util.sh_quote(filename)
    file = os.popen(gs_command % locals(),'w')
    ps = PostScriptDevice(file, document = document, as_eps = 0, embed_fonts = 1,
                          bounding_box = bbox,
                          Title = os.path.basename(filename),
                          For = util.get_real_username(),
                          CreationDate = util.current_date())
    document.Draw(ps)
    ps.Close()
    file.close()