1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Daniel Standage <daniel.standage@gmail.com>
# Copyright (c) 2008 Sascha Steinbiss <steinbiss@zbh.uni-hamburg.de>
# Copyright (c) 2008 Center for Bioinformatics, University of Hamburg
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
from gt.dlload import gtlib
from gt.annotationsketch.style import Style
from gt.annotationsketch.image_info import ImageInfo
from gt.core.error import Error, gterror
from gt.core.gtstr import Str
GRAPHICS_PDF = 0
GRAPHICS_PNG = 1
GRAPHICS_PS = 2
GRAPHICS_SVG = 3
class Canvas:
def __init__(self, *args):
raise NotImplementedError("Please call the constructor of a Canvas " +
"implementation.")
def __del__(self):
try:
gtlib.gt_canvas_delete(self.canvas)
except AttributeError:
pass
def from_param(cls, obj):
if not isinstance(obj, Canvas):
raise TypeError("argument must be a Canvas")
return obj._as_parameter_
from_param = classmethod(from_param)
class CanvasCairoFileBase(Canvas):
def from_param(cls, obj):
if not isinstance(obj, CanvasCairoFile):
raise TypeError("argument must be a CanvasCairoFile")
return obj._as_parameter_
from_param = classmethod(from_param)
def to_file(self, filename):
err = Error()
rval = gtlib.gt_canvas_cairo_file_to_file(self.canvas,
str(filename).encode(
'UTF-8'),
err)
if rval != 0:
gterror(err)
def to_stream(self):
from ctypes import string_at
str = Str(None)
gtlib.gt_canvas_cairo_file_to_stream(self.canvas, str._as_parameter_)
return string_at(str.get_mem(), str.length())
def register(cls, gtlib):
from ctypes import c_char_p, c_void_p, c_ulong, c_int
gtlib.gt_canvas_delete.restype = None
gtlib.gt_canvas_delete.argtypes = [c_void_p]
gtlib.gt_canvas_cairo_file_to_file.restype = c_int
gtlib.gt_canvas_cairo_file_to_file.argtypes = [c_void_p,
c_char_p, c_void_p]
gtlib.gt_canvas_cairo_file_to_stream.restype = c_char_p
gtlib.gt_canvas_cairo_file_to_stream.argtypes = [c_void_p, c_void_p]
gtlib.gt_canvas_cairo_file_new.restype = c_void_p
gtlib.gt_canvas_cairo_file_new.argtypes = [c_void_p, c_int, c_ulong,
c_ulong, c_void_p, c_void_p]
register = classmethod(register)
class CanvasCairoFile(CanvasCairoFileBase):
def __init__(self, style, width, height, ii=None):
Style.from_param(style)
err = Error()
iip = None
if ii:
iip = ii._as_parameter_
canvas = gtlib.gt_canvas_cairo_file_new(style._as_parameter_,
GRAPHICS_PNG, width, height, iip, err._as_parameter_)
if canvas == None:
gterror(err)
self.canvas = canvas
self._as_parameter_ = self.canvas
class CanvasCairoFilePNG(CanvasCairoFileBase):
def __init__(self, style, width, height, ii=None):
err = Error()
iip = None
if ii:
iip = ii._as_parameter_
canvas = gtlib.gt_canvas_cairo_file_new(style._as_parameter_,
GRAPHICS_PNG, width, height, iip, err._as_parameter_)
if canvas == None:
gterror(err)
self.canvas = canvas
self._as_parameter_ = self.canvas
class CanvasCairoFilePDF(CanvasCairoFileBase):
def __init__(self, style, width, height, ii=None):
err = Error()
iip = None
if ii:
iip = ii._as_parameter_
canvas = gtlib.gt_canvas_cairo_file_new(style._as_parameter_,
GRAPHICS_PDF, width, height, iip, err._as_parameter_)
if canvas == None:
gterror(err)
self.canvas = canvas
self._as_parameter_ = self.canvas
class CanvasCairoFilePS(CanvasCairoFileBase):
def __init__(self, style, width, height, ii=None):
err = Error()
iip = None
if ii:
iip = ii._as_parameter_
canvas = gtlib.gt_canvas_cairo_file_new(style._as_parameter_,
GRAPHICS_PS, width, height, iip, err._as_parameter_)
if canvas == None:
gterror(err)
self.canvas = canvas
self._as_parameter_ = self.canvas
class CanvasCairoFileSVG(CanvasCairoFileBase):
def __init__(self, style, width, height, ii=None):
err = Error()
iip = None
if ii:
iip = ii._as_parameter_
canvas = gtlib.gt_canvas_cairo_file_new(style._as_parameter_,
GRAPHICS_SVG, width, height, iip, err._as_parameter_)
if canvas == None:
gterror(err)
self.canvas = canvas
self._as_parameter_ = self.canvas
|