示例#1
0
 def run(self, eps):
     """ Render the string in eps to a buffer in a format suitable for
     Cairo surfaces. Return a tuple: (width, height, rowstride, ctypes string buffer)
     """
     CAIRO_FORMAT_RGB24 = gs.DISPLAY_COLORS_RGB | gs.DISPLAY_UNUSED_LAST | \
                          gs.DISPLAY_DEPTH_8 | gs.DISPLAY_LITTLEENDIAN
     dformat = "-dDisplayFormat=%d" % \
               ( CAIRO_FORMAT_RGB24 | gs.DISPLAY_TOPFIRST )
     
     self.stdin = StringIO(eps)
     
     userArgs = self.args or self._args
     #"-sDisplayHandle=123456"
     args = ['-ignored-', dformat, '-sDEVICE=display', '-r72x72', '-q'] \
            + userArgs + ['-_']
     
     try:
         gs.init_with_args(self.instance, args)
     except Exception:
         # re-raise always
         raise
     finally:
         gs.exit(self.instance)
     
     result = self.result
     self.stdin = self.width = self.height = self.result = self.buf \
                = self.rowstride = None
     return result
示例#2
0
def main(argv):
    code = 1
    use_gui, _ = Gtk.init_check(argv)
    
    # insert display device parameters as first arguments
    # this controls the format of the pixbuf that ghostscript will deliver
    # see display_sync for details
    
    # fast
    CAIRO_FORMAT_RGB24  = gs.DISPLAY_COLORS_RGB | gs.DISPLAY_UNUSED_LAST | \
                          gs.DISPLAY_DEPTH_8 | gs.DISPLAY_LITTLEENDIAN
    
    # interesting
    SEPARATION_FORMAT = gs.DISPLAY_COLORS_SEPARATION | gs.DISPLAY_ALPHA_NONE | \
                        gs.DISPLAY_DEPTH_8 | gs.DISPLAY_BIGENDIAN
    
    # if there are spot colors they are mixed into the cmyk values
    CMYK_FORMAT = gs.DISPLAY_COLORS_CMYK | gs.DISPLAY_ALPHA_NONE | \
                  gs.DISPLAY_DEPTH_8 | gs.DISPLAY_BIGENDIAN
    
    dformat = "-dDisplayFormat=%d" % \
            ( CAIRO_FORMAT_RGB24 | gs.DISPLAY_TOPFIRST )
    
    nargv = [argv[0], dformat] + argv[1:]
    
    #run Ghostscript 
    try:
        instance = gs.new_instance()
        gs.set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr)
        if use_gui:
            gs.set_display_callback(instance, c.byref(display))
        code = gs.init_with_args(instance, nargv)
        if code == 0:
            code = gs.run_string(instance, start_string)
        code1 = gs.exit(instance)
        if code == 0 or code == gs.e_Quit:
            code = code1
        if code == gs.e_Quit:
            code = 0 # user executed 'quit'
        gs.delete_instance(instance)
    except gs.GhostscriptError as e:
        code = e.code
        sys.stderr.write(e.message)
    finally:
        exit_status = 0;
        if code in [0, gs.e_Info, gs.e_Quit]:
            pass
        elif code == gs.e_Fatal:
            exit_status = 1
        else:
            exit_status = 255
    return exit_status
示例#3
0
__author__ = "Hartmut Goebel <*****@*****.**>"
__copyright__ = "Copyright 2010 by Hartmut Goebel <*****@*****.**>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
__credits__ = "Based on an example from http://www.ghostscript.com/doc/8.63/API.htm"

import sys
from ghostscript import _gsprint as gs

command = "1 2 add == flush\n"

instance = gs.new_instance()

# set_stdio() is not yet implemented
#gs.set_stdio(isntance, gsdll_stdin, gsdll_stdout, gsdll_stderr)

code = gs.init_with_args(instance, sys.argv)
if code == 0:
    gs.run_string_begin(instance)
    gs.run_string_continue(instance, command)
    gs.run_string_continue(instance, "qu")
    gs.run_string_continue(instance, "it")
    gs.run_string_end(instance)

code1 = gs.exit(instance)
if code == 0 or code == gs.e_Quit:
    code = code1
gs.delete_instance(instance)
if not (code == 0 or code == gs.e_Quit):
    sys.exit(1)
示例#4
0
__author__ = "Hartmut Goebel <*****@*****.**>"
__copyright__ = "Copyright 2010 by Hartmut Goebel <*****@*****.**>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
__credits__ = "Based on an example from http://www.ghostscript.com/doc/8.63/API.htm"

import sys
from ghostscript import _gsprint as gs

command = "1 2 add == flush\n"

instance = gs.new_instance()

# set_stdio() is not yet implemented
#gs.set_stdio(isntance, gsdll_stdin, gsdll_stdout, gsdll_stderr)

code = gs.init_with_args(instance, sys.argv)
if code == 0:
    gs.run_string_begin(instance);
    gs.run_string_continue(instance, command);
    gs.run_string_continue(instance, "qu");
    gs.run_string_continue(instance, "it");
    gs.run_string_end(instance);
    
code1 = gs.exit(instance)
if code == 0 or code == gs.e_Quit:
    code = code1
gs.delete_instance(instance)
if not (code == 0 or code == gs.e_Quit):
    sys.exit(1)
示例#5
0
__author__ = "Hartmut Goebel <*****@*****.**>"
__copyright__ = "Copyright 2010 by Hartmut Goebel <*****@*****.**>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
__credits__ = "Based on an example from http://www.ghostscript.com/doc/8.63/API.htm"

import sys
from ghostscript import _gsprint as gs

args = [
    "ps2pdf",  # actual value doesn't matter
    "-dNOPAUSE",
    "-dBATCH",
    "-dSAFER",
    "-sDEVICE=pdfwrite",
    "-sOutputFile=/tmp/out.pdf",
    "-c",
    ".setpdfwrite",
    "-f",
    "test.ps"
]

instance = gs.new_instance()
code = gs.init_with_args(instance, args)
code1 = gs.exit(instance)
if code == 0 or code == gs.e_Quit:
    code = code1
gs.delete_instance(instance)
if not (code == 0 or code == gs.e_Quit):
    sys.exit(1)
示例#6
0
__author__ = "Hartmut Goebel <*****@*****.**>"
__copyright__ = "Copyright 2010 by Hartmut Goebel <*****@*****.**>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
__credits__ = "Based on an example from http://www.ghostscript.com/doc/8.63/API.htm"

import sys
from ghostscript import _gsprint as gs

args = [
    "ps2pdf",  # actual value doesn't matter
    "-dNOPAUSE",
    "-dBATCH",
    "-dSAFER",
    "-sDEVICE=pdfwrite",
    "-sOutputFile=/tmp/out.pdf",
    "-c",
    ".setpdfwrite",
    "-f",
    "test.ps",
]

instance = gs.new_instance()
code = gs.init_with_args(instance, args)
code1 = gs.exit(instance)
if code == 0 or code == gs.e_Quit:
    code = code1
gs.delete_instance(instance)
if not (code == 0 or code == gs.e_Quit):
    sys.exit(1)