コード例 #1
0
ファイル: svgimage.py プロジェクト: thomaspurchas/rst2pdf
 def __init__(self, filename, width=None, height=None, kind='direct'):
     Flowable.__init__(self)
     ext = os.path.splitext(filename)[-1]
     self._kind = kind
     # Prefer svglib for SVG, as it works better
     if ext in ('.svg', '.svgz') and svglib is not None:
         self._mode = 'svglib'
         self.doc = svglib.svg2rlg(filename)
         self.width = width
         self.height = height
         _, _, self._w, self._h = self.doc.getBounds()
         if not self.width:
             self.width = self._w
         if not self.height:
             self.height = self._h
     # Use uniconvertor for the rest
     elif load is not None:
         self._mode = 'uniconvertor'
         self.doc = load.load_drawing(filename.encode('utf-8'))
         self.saver = plugins.find_export_plugin(
             plugins.guess_export_plugin('.pdf'))
         self.width = width
         self.height = height
         _, _, self._w, self._h = self.doc.BoundingRect()
         if not self.width:
             self.width = self._w
         if not self.height:
             self.height = self._h
     else:
         self._mode = None
         log.error("Vector image support not enabled,"
                   " please install svglib and/or uniconvertor.")
     if self._mode:
         self.__ratio = float(self.width) / self.height
コード例 #2
0
ファイル: svgimage.py プロジェクト: JustDevZero/bulmages
 def __init__(self,filename,width=None,height=None):
     Flowable.__init__(self)
     if HAS_UNICONVERTOR:
         self.doc = load.load_drawing(filename)
         self.saver = plugins.find_export_plugin(plugins.guess_export_plugin(".pdf"))
         self.width=width
         self.height=height
         _,_,self._w,self._h=self.doc.BoundingRect()
         if not self.width: self.width=self._w
         if not self.height: self.height=self._h
     else:
         raise ImportError("SVG image support not enabled, install uniconvertor >= 1.1.3")
コード例 #3
0
ファイル: __init__.py プロジェクト: mohisen/zdotfiles
def uniconv():	
	_pkgdir = __path__[0]
	app_dir = os.path.join(_pkgdir, 'app')
	app_ver = string.strip(open(os.path.join(app_dir, 'VERSION')).read())

	if len(sys.argv)<3 or sys.argv[1]=='--help':
		print '\nUniConvertor',app_ver
		print __doc__
		sys.exit(0)
		
	options=[]
	input_file=sys.argv[-2]
	output_file=sys.argv[-1]
	
	if len(sys.argv)>3:
		options=sys.argv[1:-2]
		
	if not os.path.isfile(input_file):
		print '\nERROR: %s file is not found!' % input_file
		print '\nUniConvertor',app_ver
		print __doc__
		sys.exit(1)
	
	sys.path.insert(1, _pkgdir)
	
	from app.io import load
	from app.plugins import plugins
	import app
	
	app.init_lib()
	
	doc = load.load_drawing(input_file)
	extension = os.path.splitext(output_file)[1]
	plugins.load_plugin_configuration()
	fileformat = plugins.guess_export_plugin(extension)
	if fileformat:
		saver = plugins.find_export_plugin(fileformat)
		saver(doc, output_file)
	else:
		sys.stderr.write('ERROR: unrecognized extension %s\n' % extension)
		sys.exit(1)
	doc.Destroy()
	sys.exit(0)