def test(): def ext(x): if x=='tiff': x='tif' return x #grab all drawings from the test module and write out. #make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir('pmout'): os.mkdir('pmout') htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] i = 0 #print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM,'ft_get_face')): fnRoot = 'renderPM%d' % i if 1 or i==10: w = int(drawing.width) h = int(drawing.height) html.append('<hr><h2>Drawing %s %d</h2>\n<pre>%s</pre>' % (name, i, docstring)) for k in ['gif','tiff', 'png', 'jpg', 'pct']: if k in ['gif','png','jpg','pct']: html.append('<p>%s format</p>\n' % string.upper(k)) try: filename = '%s.%s' % (fnRoot, ext(k)) fullpath = os.path.join('pmout', filename) if os.path.isfile(fullpath): os.remove(fullpath) if k=='pct': from reportlab.lib.colors import white drawToFile(drawing,fullpath,fmt=k,configPIL={'transparent':white}) else: drawToFile(drawing,fullpath,fmt=k) if k in ['gif','png','jpg']: html.append('<img src="%s" border="1"><br>\n' % filename) print 'wrote',fullpath except AttributeError: print 'Problem drawing %s file'%k raise if os.environ.get('RL_NOEPSPREVIEW','0')=='1': drawing.__dict__['preview'] = 0 drawing.save(formats=['eps','pdf'],outDir='pmout',fnRoot=fnRoot) i = i + 1 #if i==10: break html.append(htmlBottom) htmlFileName = os.path.join('pmout', 'index.html') open(htmlFileName, 'w').writelines(html) if sys.platform=='mac': from reportlab.lib.utils import markfilename markfilename(htmlFileName,ext='HTML') print 'wrote %s' % htmlFileName
def save(self,f=None): if not hasattr(f,'write'): file = open(f,'wb') else: file = f if self.code[-1]!='showpage': self.clear() self.code.insert(0,'''\ %%!PS-Adobe-3.0 EPSF-3.0 %%%%BoundingBox: 0 0 %d %d %%%% Initialization: /m {moveto} bind def /l {lineto} bind def /c {curveto} bind def %s ''' % (self.width,self.height, PS_WinAnsiEncoding)) # for each font used, reencode the vectors fontReencode = [] for fontName in self._fontsUsed: fontReencode.append('WinAnsiEncoding /%s /%s RE' % (fontName, fontName)) self.code.insert(1, string.join(fontReencode, self._sep)) file.write(string.join(self.code,self._sep)) if file is not f: file.close() from reportlab.lib.utils import markfilename markfilename(f,creatorcode='XPR3',filetype='EPSF')
def save(self, f=None): if not hasattr(f, "write"): file = open(f, "wb") else: file = f if self.code[-1] != "showpage": self.clear() self.code.insert( 0, """\ %%!PS-Adobe-3.0 EPSF-3.0 %%%%BoundingBox: 0 0 %d %d %%%% Initialization: /m {moveto} bind def /l {lineto} bind def /c {curveto} bind def """ % (self.width, self.height), ) self._t1_re_encode() file.write(string.join(self.code, self._sep)) if file is not f: file.close() from reportlab.lib.utils import markfilename markfilename(f, creatorcode="XPR3", filetype="EPSF")
def save(self, fn, preview=None, dviPreview=None): cf = not hasattr(fn, 'write') if cf: f = open(fn, 'wb') else: f = fn try: ps = self._postscript(dviPreview) if preview: import struct A = (b'\xc5', b'\xd0', b'\xd3', b'\xc6') hdr = struct.pack( *(("<4c7i", ) + A + (32, len(ps), 0, 0, 32 + len(ps), len(preview), 0xffff))) f.write(hdr) f.write(rawBytes(ps)) f.write(preview) else: f.write(rawBytes(ps)) finally: if cf: f.close() if cf and os.name == 'mac': from reportlab.lib.utils import markfilename markfilename(fn, ext='EPSF')
def save(self,fn, preview=None, dviPreview=None): cf = not hasattr(fn,'write') if cf: f = open(fn,'wb') else: f = fn try: ps = self._postscript(dviPreview) if preview: import struct A = (b'\xc5',b'\xd0',b'\xd3',b'\xc6')if isPy3 else (chr(0xc5),chr(0xd0),chr(0xd3),chr(0xc6)) hdr=struct.pack(*( ("<4c7i",) +A +( 32,len(ps),0,0,32+len(ps),len(preview),0xffff) ) ) f.write(hdr) f.write(rawBytes(ps)) f.write(preview) else: f.write(rawBytes(ps)) finally: if cf: f.close() if cf and os.name=='mac': from reportlab.lib.utils import markfilename markfilename(fn,ext='EPSF')
def saveToFile(self, fn, fmt=None): im = self.toPIL() if fmt is None: if type(fn) is not StringType: raise ValueError, "Invalid type '%s' for fn when fmt is None" % type( fn) fmt = os.path.splitext(fn)[1] if fmt.startswith('.'): fmt = fmt[1:] configPIL = self.configPIL or {} fmt = string.upper(fmt) if fmt in ('GIF', 'TIFFP'): im = _convert2pilp(im) if fmt == 'TIFFP': fmt = 'TIFF' if fmt in ('PCT', 'PICT'): return _saveAsPICT(im, fn, fmt, transparent=configPIL.get('transparent', None)) elif fmt in ['PNG', 'TIFF', 'BMP', 'PPM', 'TIF']: if fmt == 'TIF': fmt = 'TIFF' if fmt == 'PNG': try: from PIL import PngImagePlugin except ImportError: import PngImagePlugin elif fmt == 'BMP': try: from PIL import BmpImagePlugin except ImportError: import BmpImagePlugin elif fmt in ('JPG', 'JPEG'): fmt = 'JPEG' elif fmt in ('GIF', ): pass else: raise RenderPMError, "Unknown image kind %s" % fmt if fmt == 'TIFF': tc = configPIL.get('transparent', None) if tc: from PIL import ImageChops, Image T = 768 * [0] for o, c in zip((0, 256, 512), tc.bitmap_rgb()): T[o + c] = 255 #if type(fn) is type(''): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF') im = Image.merge( 'RGBA', im.split() + (ImageChops.invert( im.point(T).convert('L').point(255 * [0] + [255])), )) #if type(fn) is type(''): im.save(fn+'_masked.gif','GIF') for a, d in ('resolution', self._dpi), ('resolution unit', 'inch'): configPIL[a] = configPIL.get(a, d) apply(im.save, (fn, fmt), configPIL) if not hasattr(fn, 'write') and os.name == 'mac': from reportlab.lib.utils import markfilename markfilename(fn, ext=fmt)
def saveToFile(self, fn, fmt=None): im = self.toPIL() if fmt is None: if type(fn) is not StringType: raise ValueError, "Invalid type '%s' for fn when fmt is None" % type(fn) fmt = os.path.splitext(fn)[1] if fmt.startswith("."): fmt = fmt[1:] configPIL = self.configPIL or {} fmt = string.upper(fmt) if fmt in ("GIF", "TIFFP"): im = _convert2pilp(im) if fmt == "TIFFP": fmt = "TIFF" if fmt in ("PCT", "PICT"): return _saveAsPICT(im, fn, fmt, transparent=configPIL.get("transparent", None)) elif fmt in ["PNG", "TIFF", "BMP", "PPM", "TIF"]: if fmt == "TIF": fmt = "TIFF" if fmt == "PNG": try: from PIL import PngImagePlugin except ImportError: import PngImagePlugin elif fmt == "BMP": try: from PIL import BmpImagePlugin except ImportError: import BmpImagePlugin elif fmt in ("JPG", "JPEG"): fmt = "JPEG" elif fmt in ("GIF",): pass else: raise RenderPMError, "Unknown image kind %s" % fmt if fmt == "TIFF": tc = configPIL.get("transparent", None) if tc: from PIL import ImageChops, Image T = 768 * [0] for o, c in zip((0, 256, 512), tc.bitmap_rgb()): T[o + c] = 255 # if type(fn) is type(''): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF') im = Image.merge( "RGBA", im.split() + (ImageChops.invert(im.point(T).convert("L").point(255 * [0] + [255])),) ) # if type(fn) is type(''): im.save(fn+'_masked.gif','GIF') for a, d in ("resolution", self._dpi), ("resolution unit", "inch"): configPIL[a] = configPIL.get(a, d) apply(im.save, (fn, fmt), configPIL) if not hasattr(fn, "write") and os.name == "mac": from reportlab.lib.utils import markfilename markfilename(fn, ext=fmt)
def saveToFile(self,fn,fmt=None): im = self.toPIL() if fmt is None: if not isinstance(fn,str): raise ValueError("Invalid value '%s' for fn when fmt is None" % ascii(fn)) fmt = os.path.splitext(fn)[1] if fmt.startswith('.'): fmt = fmt[1:] configPIL = self.configPIL or {} configPIL.setdefault('preConvertCB',None) preConvertCB=configPIL.pop('preConvertCB') if preConvertCB: im = preConvertCB(im) fmt = fmt.upper() if fmt in ('GIF',): im = _convert2pilp(im) elif fmt in ('TIFF','TIFFP','TIFFL','TIF','TIFF1'): if fmt.endswith('P'): im = _convert2pilp(im) elif fmt.endswith('L'): im = _convert2pilL(im) elif fmt.endswith('1'): im = _convert2pil1(im) fmt='TIFF' elif fmt in ('PCT','PICT'): return _saveAsPICT(im,fn,fmt,transparent=configPIL.get('transparent',None)) elif fmt in ('PNG','BMP', 'PPM'): pass elif fmt in ('JPG','JPEG'): fmt = 'JPEG' else: raise RenderPMError("Unknown image kind %s" % fmt) if fmt=='TIFF': tc = configPIL.get('transparent',None) if tc: from PIL import ImageChops, Image T = 768*[0] for o, c in zip((0,256,512), tc.bitmap_rgb()): T[o+c] = 255 #if isinstance(fn,str): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF') im = Image.merge('RGBA', im.split()+(ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])),)) #if isinstance(fn,str): im.save(fn+'_masked.gif','GIF') for a,d in ('resolution',self._dpi),('resolution unit','inch'): configPIL[a] = configPIL.get(a,d) configPIL.setdefault('chops_invert',0) if configPIL.pop('chops_invert'): from PIL import ImageChops im = ImageChops.invert(im) configPIL.setdefault('preSaveCB',None) preSaveCB=configPIL.pop('preSaveCB') if preSaveCB: im = preSaveCB(im) im.save(fn,fmt,**configPIL) if not hasattr(fn,'write') and os.name=='mac': from reportlab.lib.utils import markfilename markfilename(fn,ext=fmt)
def _saveAsPICT(im,fn,fmt,transparent=None): im = _convert2pilp(im) cols, rows = im.size #s = _renderPM.pil2pict(cols,rows,im.tostring(),im.im.getpalette(),transparent is not None and Color2Hex(transparent) or -1) s = _renderPM.pil2pict(cols,rows,im.tostring(),im.im.getpalette()) if not hasattr(fn,'write'): open(os.path.splitext(fn)[0]+'.'+string.lower(fmt),'wb').write(s) if os.name=='mac': from reportlab.lib.utils import markfilename markfilename(fn,ext='PICT') else: fn.write(s)
def saveToFile(self,fn,fmt=None): im = self.toPIL() if fmt is None: if type(fn) is not StringType: raise ValueError, "Invalid type '%s' for fn when fmt is None" % type(fn) fmt = os.path.splitext(fn)[1] if fmt.startswith('.'): fmt = fmt[1:] configPIL = self.configPIL or {} fmt = string.upper(fmt) if fmt in ('GIF','TIFFP'): im = _convert2pilp(im) if fmt=='TIFFP': fmt='TIFF' if fmt in ('PCT','PICT'): return _saveAsPICT(im,fn,fmt,transparent=configPIL.get('transparent',None)) elif fmt in ['PNG','TIFF','BMP', 'PPM', 'TIF']: if fmt=='TIF': fmt = 'TIFF' if fmt=='PNG': try: from PIL import PngImagePlugin except ImportError: import PngImagePlugin elif fmt=='BMP': try: from PIL import BmpImagePlugin except ImportError: import BmpImagePlugin elif fmt in ('JPG','JPEG'): fmt = 'JPEG' elif fmt in ('GIF',): pass else: raise RenderPMError,"Unknown image kind %s" % fmt if fmt=='TIFF': tc = configPIL.get('transparent',None) if tc: from PIL import ImageChops, Image T = 768*[0] for o, c in zip((0,256,512), tc.bitmap_rgb()): T[o+c] = 255 #if type(fn) is type(''): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF') im = Image.merge('RGBA', im.split()+(ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])),)) #if type(fn) is type(''): im.save(fn+'_masked.gif','GIF') for a,d in ('resolution',self._dpi),('resolution unit','inch'): configPIL[a] = configPIL.get(a,d) apply(im.save,(fn,fmt),configPIL) if not hasattr(fn,'write') and os.name=='mac': from reportlab.lib.utils import markfilename markfilename(fn,ext=fmt)
def save(self,f=None): if not hasattr(f,'write'): _f = open(f,'wb') else: _f = f if self.code[-1]!='showpage': self.clear() self.code.insert(0,'''\ %%!PS-Adobe-3.0 EPSF-3.0 %%%%BoundingBox: 0 0 %d %d %%%% Initialization: /m {moveto} bind def /l {lineto} bind def /c {curveto} bind def ''' % (self.width,self.height)) self._t1_re_encode() _f.write(rawBytes(self._sep.join(self.code))) if _f is not f: _f.close() from reportlab.lib.utils import markfilename markfilename(f,creatorcode='XPR3',filetype='EPSF')
def test(outDir="pmout", shout=False): def ext(x): if x == "tiff": x = "tif" return x # grab all drawings from the test module and write out. # make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes from reportlab.rl_config import verbose getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir(outDir): os.mkdir(outDir) htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] names = {} argv = sys.argv[1:] E = [a for a in argv if a.startswith("--ext=")] if not E: E = ["gif", "tiff", "png", "jpg", "pct", "py", "svg"] else: for a in E: argv.remove(a) E = (",".join([a[6:] for a in E])).split(",") errs = [] import traceback from xml.sax.saxutils import escape def handleError(name, fmt): msg = "Problem drawing %s fmt=%s file" % (name, fmt) if shout or verbose > 2: print(msg) errs.append('<br/><h2 style="color:red">%s</h2>' % msg) buf = getStringIO() traceback.print_exc(file=buf) errs.append("<pre>%s</pre>" % escape(buf.getvalue())) # print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM, "ft_get_face")): i = names[name] = names.setdefault(name, 0) + 1 if i > 1: name += ".%02d" % (i - 1) if argv and name not in argv: continue fnRoot = name w = int(drawing.width) h = int(drawing.height) html.append("<hr><h2>Drawing %s</h2>\n<pre>%s</pre>" % (name, docstring)) for k in E: if k in ["gif", "png", "jpg", "pct"]: html.append("<p>%s format</p>\n" % k.upper()) try: filename = "%s.%s" % (fnRoot, ext(k)) fullpath = os.path.join(outDir, filename) if os.path.isfile(fullpath): os.remove(fullpath) if k == "pct": from reportlab.lib.colors import white drawToFile(drawing, fullpath, fmt=k, configPIL={"transparent": white}) elif k in ["py", "svg"]: drawing.save(formats=["py", "svg"], outDir=outDir, fnRoot=fnRoot) else: drawToFile(drawing, fullpath, fmt=k) if k in ["gif", "png", "jpg"]: html.append('<img src="%s" border="1"><br>\n' % filename) elif k == "py": html.append('<a href="%s">python source</a><br>\n' % filename) elif k == "svg": html.append('<a href="%s">SVG</a><br>\n' % filename) if shout or verbose > 2: print("wrote %s" % ascii(fullpath)) except AttributeError: handleError(name, k) if os.environ.get("RL_NOEPSPREVIEW", "0") == "1": drawing.__dict__["preview"] = 0 for k in ("eps", "pdf"): try: drawing.save(formats=[k], outDir=outDir, fnRoot=fnRoot) except: handleError(name, k) if errs: html[0] = html[0].replace("</h1>", ' <a href="#errors" style="color: red">(errors)</a></h1>') html.append('<a name="errors"/>') html.extend(errs) html.append(htmlBottom) htmlFileName = os.path.join(outDir, "pm-index.html") open(htmlFileName, "w").writelines(html) if sys.platform == "mac": from reportlab.lib.utils import markfilename markfilename(htmlFileName, ext="HTML") if shout or verbose > 2: print("wrote %s" % htmlFileName)
def test(): def ext(x): if x == "tiff": x = "tif" return x # grab all drawings from the test module and write out. # make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir("pmout"): os.mkdir("pmout") htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] names = {} argv = sys.argv[1:] E = [a for a in argv if a.startswith("--ext=")] if not E: E = ["gif", "tiff", "png", "jpg", "pct", "py", "svg"] else: for a in E: argv.remove(a) E = (",".join([a[6:] for a in E])).split(",") # print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM, "ft_get_face")): i = names[name] = names.setdefault(name, 0) + 1 if i > 1: name += ".%02d" % (i - 1) if argv and name not in argv: continue fnRoot = name w = int(drawing.width) h = int(drawing.height) html.append("<hr><h2>Drawing %s</h2>\n<pre>%s</pre>" % (name, docstring)) for k in E: if k in ["gif", "png", "jpg", "pct"]: html.append("<p>%s format</p>\n" % string.upper(k)) try: filename = "%s.%s" % (fnRoot, ext(k)) fullpath = os.path.join("pmout", filename) if os.path.isfile(fullpath): os.remove(fullpath) if k == "pct": from reportlab.lib.colors import white drawToFile(drawing, fullpath, fmt=k, configPIL={"transparent": white}) elif k in ["py", "svg"]: drawing.save(formats=["py", "svg"], outDir="pmout", fnRoot=fnRoot) else: drawToFile(drawing, fullpath, fmt=k) if k in ["gif", "png", "jpg"]: html.append('<img src="%s" border="1"><br>\n' % filename) elif k == "py": html.append('<a href="%s">python source</a><br>\n' % filename) elif k == "svg": html.append('<a href="%s">SVG</a><br>\n' % filename) print "wrote", fullpath except AttributeError: print "Problem drawing %s file" % k raise if os.environ.get("RL_NOEPSPREVIEW", "0") == "1": drawing.__dict__["preview"] = 0 drawing.save(formats=["eps", "pdf"], outDir="pmout", fnRoot=fnRoot) html.append(htmlBottom) htmlFileName = os.path.join("pmout", "index.html") open(htmlFileName, "w").writelines(html) if sys.platform == "mac": from reportlab.lib.utils import markfilename markfilename(htmlFileName, ext="HTML") print "wrote %s" % htmlFileName
def test(): def ext(x): if x=='tiff': x='tif' return x #grab all drawings from the test module and write out. #make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir('pmout'): os.mkdir('pmout') htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] names = {} argv = sys.argv[1:] E = [a for a in argv if a.startswith('--ext=')] if not E: E = ['gif','tiff', 'png', 'jpg', 'pct', 'py', 'svg'] else: for a in E: argv.remove(a) E = (','.join([a[6:] for a in E])).split(',') #print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM,'ft_get_face')): i = names[name] = names.setdefault(name,0)+1 if i>1: name += '.%02d' % (i-1) if argv and name not in argv: continue fnRoot = name w = int(drawing.width) h = int(drawing.height) html.append('<hr><h2>Drawing %s</h2>\n<pre>%s</pre>' % (name, docstring)) for k in E: if k in ['gif','png','jpg','pct']: html.append('<p>%s format</p>\n' % string.upper(k)) try: filename = '%s.%s' % (fnRoot, ext(k)) fullpath = os.path.join('pmout', filename) if os.path.isfile(fullpath): os.remove(fullpath) if k=='pct': from reportlab.lib.colors import white drawToFile(drawing,fullpath,fmt=k,configPIL={'transparent':white}) elif k in ['py','svg']: drawing.save(formats=['py','svg'],outDir='pmout',fnRoot=fnRoot) else: drawToFile(drawing,fullpath,fmt=k) if k in ['gif','png','jpg']: html.append('<img src="%s" border="1"><br>\n' % filename) elif k=='py': html.append('<a href="%s">python source</a><br>\n' % filename) elif k=='svg': html.append('<a href="%s">SVG</a><br>\n' % filename) print 'wrote',fullpath except AttributeError: print 'Problem drawing %s file'%k raise if os.environ.get('RL_NOEPSPREVIEW','0')=='1': drawing.__dict__['preview'] = 0 drawing.save(formats=['eps','pdf'],outDir='pmout',fnRoot=fnRoot) html.append(htmlBottom) htmlFileName = os.path.join('pmout', 'index.html') open(htmlFileName, 'w').writelines(html) if sys.platform=='mac': from reportlab.lib.utils import markfilename markfilename(htmlFileName,ext='HTML') print 'wrote %s' % htmlFileName
def test(outDir='pmout', shout=False): def ext(x): if x=='tiff': x='tif' return x #grab all drawings from the test module and write out. #make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes from reportlab.rl_config import verbose getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir(outDir): os.mkdir(outDir) htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] names = {} argv = sys.argv[1:] E = [a for a in argv if a.startswith('--ext=')] if not E: E = ['gif','tiff', 'png', 'jpg', 'pct', 'py', 'svg'] else: for a in E: argv.remove(a) E = (','.join([a[6:] for a in E])).split(',') errs = [] import traceback from xml.sax.saxutils import escape def handleError(name,fmt): msg = 'Problem drawing %s fmt=%s file'%(name,fmt) if shout or verbose>2: print(msg) errs.append('<br/><h2 style="color:red">%s</h2>' % msg) buf = getStringIO() traceback.print_exc(file=buf) errs.append('<pre>%s</pre>' % escape(buf.getvalue())) #print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM,'ft_get_face')): i = names[name] = names.setdefault(name,0)+1 if i>1: name += '.%02d' % (i-1) if argv and name not in argv: continue fnRoot = name w = int(drawing.width) h = int(drawing.height) html.append('<hr><h2>Drawing %s</h2>\n<pre>%s</pre>' % (name, docstring)) for k in E: if k in ['gif','png','jpg','pct']: html.append('<p>%s format</p>\n' % k.upper()) try: filename = '%s.%s' % (fnRoot, ext(k)) fullpath = os.path.join(outDir, filename) if os.path.isfile(fullpath): os.remove(fullpath) if k=='pct': from reportlab.lib.colors import white drawToFile(drawing,fullpath,fmt=k,configPIL={'transparent':white}) elif k in ['py','svg']: drawing.save(formats=['py','svg'],outDir=outDir,fnRoot=fnRoot) else: drawToFile(drawing,fullpath,fmt=k) if k in ['gif','png','jpg']: html.append('<img src="%s" border="1"><br>\n' % filename) elif k=='py': html.append('<a href="%s">python source</a><br>\n' % filename) elif k=='svg': html.append('<a href="%s">SVG</a><br>\n' % filename) if shout or verbose>2: print('wrote %s'%ascii(fullpath)) except AttributeError: handleError(name,k) if os.environ.get('RL_NOEPSPREVIEW','0')=='1': drawing.__dict__['preview'] = 0 for k in ('eps', 'pdf'): try: drawing.save(formats=[k],outDir=outDir,fnRoot=fnRoot) except: handleError(name,k) if errs: html[0] = html[0].replace('</h1>',' <a href="#errors" style="color: red">(errors)</a></h1>') html.append('<a name="errors"/>') html.extend(errs) html.append(htmlBottom) htmlFileName = os.path.join(outDir, 'pm-index.html') open(htmlFileName, 'w').writelines(html) if sys.platform=='mac': from reportlab.lib.utils import markfilename markfilename(htmlFileName,ext='HTML') if shout or verbose>2: print('wrote %s' % htmlFileName)
def saveToFile(self,fn,fmt=None): im = self.toPIL() if fmt is None: if not isinstance(fn,str): raise ValueError("Invalid value '%s' for fn when fmt is None" % ascii(fn)) fmt = os.path.splitext(fn)[1] if fmt.startswith('.'): fmt = fmt[1:] configPIL = self.configPIL or {} configPIL.setdefault('preConvertCB',None) preConvertCB=configPIL.pop('preConvertCB') if preConvertCB: im = preConvertCB(im) fmt = fmt.upper() if fmt in ('GIF',): im = _convert2pilp(im) elif fmt in ('TIFF','TIFFP','TIFFL','TIF','TIFF1'): if fmt.endswith('P'): im = _convert2pilp(im) elif fmt.endswith('L'): im = _convert2pilL(im) elif fmt.endswith('1'): im = _convert2pil1(im) fmt='TIFF' elif fmt in ('PCT','PICT'): return _saveAsPICT(im,fn,fmt,transparent=configPIL.get('transparent',None)) elif fmt in ('PNG','BMP', 'PPM'): if fmt=='PNG': try: from PIL import PngImagePlugin except ImportError: import PngImagePlugin elif fmt=='BMP': try: from PIL import BmpImagePlugin except ImportError: import BmpImagePlugin elif fmt in ('JPG','JPEG'): fmt = 'JPEG' elif fmt in ('GIF',): pass else: raise RenderPMError("Unknown image kind %s" % fmt) if fmt=='TIFF': tc = configPIL.get('transparent',None) if tc: from PIL import ImageChops, Image T = 768*[0] for o, c in zip((0,256,512), tc.bitmap_rgb()): T[o+c] = 255 #if isinstance(fn,str): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF') im = Image.merge('RGBA', im.split()+(ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])),)) #if isinstance(fn,str): im.save(fn+'_masked.gif','GIF') for a,d in ('resolution',self._dpi),('resolution unit','inch'): configPIL[a] = configPIL.get(a,d) configPIL.setdefault('chops_invert',0) if configPIL.pop('chops_invert'): from PIL import ImageChops im = ImageChops.invert(im) configPIL.setdefault('preSaveCB',None) preSaveCB=configPIL.pop('preSaveCB') if preSaveCB: im = preSaveCB(im) im.save(fn,fmt,**configPIL) if not hasattr(fn,'write') and os.name=='mac': from reportlab.lib.utils import markfilename markfilename(fn,ext=fmt)
def test(): def ext(x): if x == "tiff": x = "tif" return x # grab all drawings from the test module and write out. # make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir("pmout"): os.mkdir("pmout") htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] i = 0 # print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM, "ft_get_face")): fnRoot = "renderPM%d" % i if 1 or i == 10: w = int(drawing.width) h = int(drawing.height) html.append("<hr><h2>Drawing %s %d</h2>\n<pre>%s</pre>" % (name, i, docstring)) for k in ["gif", "tiff", "png", "jpg", "pct"]: if k in ["gif", "png", "jpg", "pct"]: html.append("<p>%s format</p>\n" % string.upper(k)) try: filename = "%s.%s" % (fnRoot, ext(k)) fullpath = os.path.join("pmout", filename) if os.path.isfile(fullpath): os.remove(fullpath) if k == "pct": from reportlab.lib.colors import white drawToFile(drawing, fullpath, fmt=k, configPIL={"transparent": white}) else: drawToFile(drawing, fullpath, fmt=k) if k in ["gif", "png", "jpg"]: html.append('<img src="%s" border="1"><br>\n' % filename) print "wrote", fullpath except AttributeError: print "Problem drawing %s file" % k raise if os.environ.get("RL_NOEPSPREVIEW", "0") == "1": drawing.__dict__["preview"] = 0 drawing.save(formats=["eps", "pdf"], outDir="pmout", fnRoot=fnRoot) i = i + 1 # if i==10: break html.append(htmlBottom) htmlFileName = os.path.join("pmout", "index.html") open(htmlFileName, "w").writelines(html) if sys.platform == "mac": from reportlab.lib.utils import markfilename markfilename(htmlFileName, ext="HTML") print "wrote %s" % htmlFileName
def main(): LP = tuple( enumerate((None, 'top', 'top_right', 'right', 'bottom_right', 'bottom', 'bottom_left', 'left', 'top_left'))) HLEGS = tuple(enumerate((None, False, True))) LEGENDMODES = tuple(enumerate((None, 'fullWidth', 'fullHeight'))) ALLOWED_CHART_TYPES.sort() html = [] for chartType in ALLOWED_CHART_TYPES: makeDrawing(html, '', chartType=chartType) makeDrawing(html, "0.1 Line chart should have both x and y gridlines", chartType='linechart', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1) makeDrawing(html, "0.11 Line plot should have both x and y gridlines", chartType='lineplot', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, data=[[1.5, 3, 4.5], [1, 2, 3], [1.5, 2.5, 3.5]]) makeDrawing( html, "0.12 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,2,'.',''))s'", chartType='linechart', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat="$%(decfmt(value*10000,2,'.',''))s") makeDrawing( html, "0.13 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,-2,'.',','))s'", chartType='linechart', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat="$%(decfmt(value*10000,-2,'.',','))s") makeDrawing( html, "0.14 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,(1 if notAllInt else 0),'.',','))s'", chartType='linechart', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat= "$%(decfmt(value*10000,(1 if notAllInt else 0),'.',','))s") makeDrawing( html, "0.15 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,2,',','.'))s'", chartType='linechart', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat="$%(decfmt(value*10000,2,',','.'))s") makeDrawing( html, '1.1 Clustered_bar with the yAxisVisible and yAxisGridlines on', chartType='clustered_bar', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=0) makeDrawing(html, '1.2 Stacked_bar with the yAxisVisible and yAxisGridlines on', chartType='stacked_bar', yAxisVisible=1, yAxisGridLines=1, xAxisVisible=0) makeDrawing( html, '1.3 Clustered_bar with the xAxisVisible and xAxisGridlines on', chartType='clustered_bar', xAxisVisible=1, xAxisGridLines=1, yAxisVisible=0) makeDrawing(html, '1.4 Stacked_bar with the xAxisVisible and xAxisGridlines on', chartType='stacked_bar', xAxisVisible=1, xAxisGridLines=1, yAxisVisible=0) makeDrawing( html, '2.1 Clustered_bar with both the x Axis and y Axis invisible - should resize correctly', chartType='stacked_bar', xAxisVisible=0, yAxisVisible=0, showBoundaries=1) makeDrawing( html, '2.2 Stacked_bar with both the x Axis and y Axis invisible - should resize correctly', chartType='clustered_bar', xAxisVisible=0, yAxisVisible=0, showBoundaries=1) makeDrawing(html, '3.1 Stacked_bar with dataLabelsType set to None', chartType='stacked_bar', dataLabelsType=None) makeDrawing(html, '3.2 Clustered_bar with dataLabelsType set to None', chartType='clustered_bar', dataLabelsType=None) makeDrawing(html, '3.3 Pie with dataLabelsType set to None', chartType='pie', dataLabelsType=None) makeDrawing(html, "3.4 Stacked_bar with dataLabelsType set to 'values'", chartType='stacked_bar', dataLabelsType='values') makeDrawing(html, "3.5 Clustered_bar with dataLabelsType set to 'values'", chartType='clustered_bar', dataLabelsType='values') makeDrawing(html, "3.6 Pie with dataLabelsType set to 'values'", chartType='pie', dataLabelsType='values') makeDrawing(html, "3.7 Stacked_bar with dataLabelsType set to 'percent'", chartType='stacked_bar', dataLabelsType='percent') makeDrawing(html, "3.8 Clustered_bar with dataLabelsType set to 'percent'", chartType='clustered_bar', dataLabelsType='percent') makeDrawing(html, "3.9 Pie with dataLabelsType set to 'percent'", chartType='pie', dataLabelsType='percent') makeDrawing(html, "3.71 Stacked_bar with dataLabelsType set to 'percent,2'", chartType='stacked_bar', dataLabelsType='percent,2') makeDrawing(html, "3.81 Clustered_bar with dataLabelsType set to 'percent,2'", chartType='clustered_bar', dataLabelsType='percent,2') makeDrawing(html, "3.91 Pie with dataLabelsType set to 'percent,2'", chartType='pie', dataLabelsType='percent,2') makeDrawing( html, "3.72 Stacked_bar with dataLabelsType set to '%(percent).1f%%'", chartType='stacked_bar', dataLabelsType='%(percent).1f%%') makeDrawing( html, "3.82 Clustered_bar with dataLabelsType set to '%(percent).2f%%'", chartType='clustered_bar', dataLabelsType='%(percent).2f%%') makeDrawing( html, "3.92 Pie with dataLabelsType set to '%(percent).3f%% per Annum'", chartType='pie', dataLabelsType='%(percent).3f%% per Annum') makeDrawing( html, "3.73 Stacked_bar with dataLabelsType set to '$%(decfmt(value*10000,2,'.',''))s'", chartType='stacked_bar', dataLabelsType='$%(decfmt(value*10000,2,\'.\',\'\'))s') makeDrawing( html, "3.74 Stacked_bar with dataLabelsType set to '$%(decfmt(value*10000,2,'.',','))s'", chartType='stacked_bar', dataLabelsType='$%(decfmt(value*10000,2,\'.\',\',\'))s') makeDrawing( html, "3.83 Clustered_bar with dataLabelsType set to '$%(decfmt(value*14000,2,',','.'))s'", chartType='clustered_bar', dataLabelsType='$%(decfmt(value*14000,1,\',\',\'.\'))s') makeDrawing( html, "3.93 Pie with dataLabelsType set to '$%(decfmt(value*12000,2))s/Year'", chartType='pie', dataLabelsType='$%(decfmt(value*12000,2))s/Year') makeDrawing( html, "4.1 Pie with dataLabelsType unset - no datalabels should be printed", chartType='pie') makeDrawing( html, "4.2 Pie with dataLabelsType set to 'values' - values should be used for dataLabels", chartType='pie', dataLabelsType='values') makeDrawing( html, "4.3 Pie with dataLabelsType set to 'percent' - percentages should be used for dataLabels", chartType='pie', dataLabelsType='percent') makeDrawing( html, "4.4 Pie with with category names - set dataLabelsType '%(category)s'", chartType='pie', dataLabelsType='%(category)s', categoryNames=['A', 'B', 'C', 'D']) makeDrawing(html, "4.5.0 Pie with overlap", chartType='pie', dataLabelsType='%(percent).3f%% per Annum', data=[0.9, 1.1, 2.2, 40, 57], categoryNames=['0.9', '1.1', '2.2', '40', '57']) makeDrawing(html, "4.5.1 Pie with overlap orderMode='alternate'", chartType='pie', orderMode='alternate', dataLabelsType='%(percent).3f%% per Annum', data=[0.9, 1.1, 2.2, 40, 57], categoryNames=['0.9', '1.1', '2.2', '40', '57']) makeDrawing(html, "4.5.2 Pie with overlap checkLabelOverlap=1", chartType='pie', checkLabelOverlap=1, dataLabelsType='%(percent).3f%% per Annum', data=[0.9, 1.1, 2.2, 40, 57], categoryNames=['0.9', '1.1', '2.2', '40', '57']) makeDrawing( html, "4.5.3 Pie with overlap orderMode='alternate' checkLabelOverlap=1", chartType='pie', checkLabelOverlap=1, orderMode='alternate', dataLabelsType='%(percent).3f%% per Annum', data=[0.9, 1.1, 2.2, 40, 57], categoryNames=['0.9', '1.1', '2.2', '40', '57']) makeDrawing(html, "5.1 Title should be (ascent * 1.5) from the font base line ", chartType='pie', titleText="This is the Title") makeDrawing( html, "6.1 Bar with integer data - axis should display without decimals", chartType='bar', data=[[100, 200, 300, 400]], xAxisVisible=1, yAxisVisible=1) makeDrawing( html, "6.2 Column with integer data - axis should display without decimals", chartType='column', data=[[100, 200, 300, 400]], xAxisVisible=1, yAxisVisible=1) makeDrawing( html, "6.3 Bar with floating point data - axis should display with decimals", chartType='bar', data=[[0.01, 0.02, 0.03, 0.04]], xAxisVisible=1, yAxisVisible=1) makeDrawing( html, "6.4 Bar with floating point data - axis should display with decimals", chartType='column', data=[[0.01, 0.02, 0.03, 0.04]], xAxisVisible=1, yAxisVisible=1) makeDrawing(html, "7.1 x Axis and y Axis gridlines should be the same width", chartType='bar', xAxisVisible=1, yAxisVisible=1, xAxisGridLines=1, yAxisGridLines=1) makeDrawing(html, "7.2 x Axis and y Axis gridlines should be the same width", chartType='column', xAxisVisible=1, yAxisVisible=1, xAxisGridLines=1, yAxisGridLines=1) makeDrawing( html, "8.1 When using data = [[120,20]], the value axis should no longer show negative values of (-50,0,50,100,150)", chartType='column', data=[[120, 20]]) makeDrawing( html, "8.1a When using data = [[120,20]], the value axis should no longer show negative values of (-50,0,50,100,150)", chartType='bar', data=[[120, 20]]) makeDrawing( html, "8.2 When using negative data the gridline of the category axis should be correctly sized", chartType='column', data=[[-120, -20, 20]], xAxisGridLines=1) makeDrawing( html, "8.2a When using negative data the gridline of the category axis should be correctly sized", chartType='bar', data=[[-120, -20, 20]], yAxisGridLines=1) for k, legendMode in LEGENDMODES: for j, hleg in HLEGS: for i, p in LP: makeDrawing( html, "9.1.%d.%d.%d Blue border round background, no fill on background legendPos=%s hleg=%s legendMode=%s" % (k, j, i, p, hleg, legendMode), chartType='column', bgColor=None, bgStrokeColor='blue', seriesNames=('A long series name', 'Another very long series name'), legendPos=p, hleg=hleg, legendMaxWFrac=0.5, legendMaxHFrac=0.5, legendMode=legendMode) makeDrawing(html, "9.2 Blue border round background, yellow fill on background", chartType='bar', bgColor='yellow', bgStrokeColor='blue') makeDrawing( html, "10.1 Test piechart with data of '[[230,340]]' and dataLabelsType of 'percent' (as per Nardi's test)", chartType='pie', data=[[230, 340]], categoryNames=['category1', 'category2'], seriesNames=[], bgColor=None, plotColor=CMYKColor(0, 0, 1, 0), legendPos='left', legendFontName='Helvetica', legendFontColor=CMYKColor(0, 0, 0, 2), titleText='This is the main title', titleFontName='Helvetica-Bold', titleFontSize=18, titleFontColor=CMYKColor(0, 1, 1, 1), dataLabelsType='percent', dataLabelsFontName='Helvetica', dataLabelsFontSize=14, dataLabelsFontColor=CMYKColor(0, 1, 1, 0)) for k, legendMode in LEGENDMODES: for j, hleg in HLEGS: for i, p in LP: makeDrawing( html, "10.2.%d.%d.%d piechart with more than 10 slices legendPos=%s hleg=%s legendMode=%s" % (k, j, i, p, hleg, legendMode), chartType='exploded_pie', data=[[ 27.00000, 3.00000, 10.00000, 5.00000, 5.00000, 15.00000, 35.00000, 12, 17, 11, 19, 23, 32 ]], categoryNames=[ 'Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6', 'Category 7', 'Cat 8', 'Cat 9', 'Cat 10', 'Cat 11', 'Cat 12', 'Cat 13' ], seriesNames=[], chartColors=[ CMYKColor(0.00, 1.00, 0.00, 0.00), CMYKColor(1.00, 1.00, 0.00, 0.00), CMYKColor(0.00, 0.00, 1.00, 0.00), CMYKColor(0.00, 1.00, 1.00, 0.00), CMYKColor(0.00, 0.80, 1.00, 0.00), CMYKColor(0.00, 0.40, 1.00, 0.00), CMYKColor(0.80, 0.00, 1.00, 0.00), toColor('red'), toColor('grey'), toColor('brown'), toColor('magenta'), toColor('darkblue'), toColor('pink') ], bgColor=None, plotColor=None, legendPos=p, legendFontName='Helvetica', legendFontSize=9.00, legendFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), titleText='', titleFontName='Helvetica-Bold', titleFontSize=14.00, titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), dataLabelsType='%.1f', dataLabelsFontName='Helvetica', dataLabelsFontSize=9.00, dataLabelsFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), width=401.54384, height=150.86375, hleg=hleg, legendMaxWFrac=0.5, legendMaxHFrac=0.5, legendMode=legendMode) makeDrawing(html, "11.1 Test for black lines in 3D exploded piechart", chartType='exploded_pie3d', data=[[ 27.00000, 3.00000, 10.00000, 5.00000, 5.00000, 15.00000, 35.00000 ]], categoryNames=[ 'Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6', 'Category 7' ], seriesNames=[], chartColors=[ CMYKColor(0.00, 1.00, 0.00, 0.00), CMYKColor(1.00, 1.00, 0.00, 0.00), CMYKColor(0.00, 0.00, 1.00, 0.00), CMYKColor(0.00, 1.00, 1.00, 0.00), CMYKColor(0.00, 0.80, 1.00, 0.00), CMYKColor(0.00, 0.40, 1.00, 0.00), CMYKColor(0.80, 0.00, 1.00, 0.00) ], bgColor=None, plotColor=None, legendPos='right', legendFontName='Helvetica', legendFontSize=9.00, legendFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), titleText='', titleFontName='Helvetica-Bold', titleFontSize=14.00, titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), dataLabelsType='%.1f', dataLabelsFontName='Helvetica', dataLabelsFontSize=9.00, dataLabelsFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), width=401.54384, height=150.86375) for k, legendMode in LEGENDMODES: for j, hleg in HLEGS: for i, p in LP: makeDrawing( html, "11.2.%d.%d.%d 3D exploded piechart with more than 10 slices legendPos=%s hleg=%s legendMode=%s" % (k, j, i, p, hleg, legendMode), chartType='exploded_pie3d', data=[[ 27.00000, 3.00000, 10.00000, 5.00000, 5.00000, 15.00000, 35.00000, 12, 17, 11, 19, 23, 32 ]], categoryNames=[ 'Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6', 'Category 7', 'Cat 8', 'Cat 9', 'Cat 10', 'Cat 11', 'Cat 12', 'Cat 13' ], seriesNames=[], chartColors=[ CMYKColor(0.00, 1.00, 0.00, 0.00), CMYKColor(1.00, 1.00, 0.00, 0.00), CMYKColor(0.00, 0.00, 1.00, 0.00), CMYKColor(0.00, 1.00, 1.00, 0.00), CMYKColor(0.00, 0.80, 1.00, 0.00), CMYKColor(0.00, 0.40, 1.00, 0.00), CMYKColor(0.80, 0.00, 1.00, 0.00), toColor('red'), toColor('grey'), toColor('brown'), toColor('magenta'), toColor('darkblue'), toColor('pink') ], bgColor=None, plotColor=None, legendPos=p, legendFontName='Helvetica', legendFontSize=9.00, legendFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), titleText='', titleFontName='Helvetica-Bold', titleFontSize=14.00, titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), dataLabelsType='%.1f', dataLabelsFontName='Helvetica', dataLabelsFontSize=9.00, dataLabelsFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), width=401.54384, height=150.86375, hleg=hleg, legendMaxWFrac=0.5, legendMaxHFrac=0.5, legendMode=legendMode) makeDrawing( html, "11.211 3D exploded piechart with more than 10 slices legend at top legendMaxHFrac=0.125", chartType='exploded_pie3d', legendMaxHFrac=0.125, data=[[ 27.00000, 3.00000, 10.00000, 5.00000, 5.00000, 15.00000, 35.00000, 12, 17, 11, 19, 23, 32 ]], categoryNames=[ 'Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6', 'Category 7', 'Cat 8', 'Cat 9', 'Cat 10', 'Cat 11', 'Cat 12', 'Cat 13' ], seriesNames=[], chartColors=[ CMYKColor(0.00, 1.00, 0.00, 0.00), CMYKColor(1.00, 1.00, 0.00, 0.00), CMYKColor(0.00, 0.00, 1.00, 0.00), CMYKColor(0.00, 1.00, 1.00, 0.00), CMYKColor(0.00, 0.80, 1.00, 0.00), CMYKColor(0.00, 0.40, 1.00, 0.00), CMYKColor(0.80, 0.00, 1.00, 0.00), toColor('red'), toColor('grey'), toColor('brown'), toColor('magenta'), toColor('darkblue'), toColor('pink') ], bgColor=None, plotColor=None, legendPos='top', legendFontName='Helvetica', legendFontSize=9.00, legendFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), titleText='', titleFontName='Helvetica-Bold', titleFontSize=14.00, titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), dataLabelsType='%.1f', dataLabelsFontName='Helvetica', dataLabelsFontSize=9.00, dataLabelsFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), width=401.54384, height=150.86375) makeDrawing( html, "11.212 3D exploded piechart with more than 10 slices legend at top legendMaxHFrac=0.09", chartType='exploded_pie3d', legendMaxHFrac=0.09, data=[[ 27.00000, 3.00000, 10.00000, 5.00000, 5.00000, 15.00000, 35.00000, 12, 17, 11, 19, 23, 32 ]], categoryNames=[ 'Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6', 'Category 7', 'Cat 8', 'Cat 9', 'Cat 10', 'Cat 11', 'Cat 12', 'Cat 13' ], seriesNames=[], chartColors=[ CMYKColor(0.00, 1.00, 0.00, 0.00), CMYKColor(1.00, 1.00, 0.00, 0.00), CMYKColor(0.00, 0.00, 1.00, 0.00), CMYKColor(0.00, 1.00, 1.00, 0.00), CMYKColor(0.00, 0.80, 1.00, 0.00), CMYKColor(0.00, 0.40, 1.00, 0.00), CMYKColor(0.80, 0.00, 1.00, 0.00), toColor('red'), toColor('grey'), toColor('brown'), toColor('magenta'), toColor('darkblue'), toColor('pink') ], bgColor=None, plotColor=None, legendPos='top', legendFontName='Helvetica', legendFontSize=9.00, legendFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), titleText='', titleFontName='Helvetica-Bold', titleFontSize=14.00, titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), dataLabelsType='%.1f', dataLabelsFontName='Helvetica', dataLabelsFontSize=9.00, dataLabelsFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), width=401.54384, height=150.86375) makeDrawing( html, "11.213 3D exploded piechart with more than 10 slices legend at top legendMaxWFrac=0.8", chartType='exploded_pie3d', legendMaxWFrac=0.8, data=[[ 27.00000, 3.00000, 10.00000, 5.00000, 5.00000, 15.00000, 35.00000, 12, 17, 11, 19, 23, 32 ]], categoryNames=[ 'Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6', 'Category 7', 'Cat 8', 'Cat 9', 'Cat 10', 'Cat 11', 'Cat 12', 'Cat 13' ], seriesNames=[], chartColors=[ CMYKColor(0.00, 1.00, 0.00, 0.00), CMYKColor(1.00, 1.00, 0.00, 0.00), CMYKColor(0.00, 0.00, 1.00, 0.00), CMYKColor(0.00, 1.00, 1.00, 0.00), CMYKColor(0.00, 0.80, 1.00, 0.00), CMYKColor(0.00, 0.40, 1.00, 0.00), CMYKColor(0.80, 0.00, 1.00, 0.00), toColor('red'), toColor('grey'), toColor('brown'), toColor('magenta'), toColor('darkblue'), toColor('pink') ], bgColor=None, plotColor=None, legendPos='top', legendFontName='Helvetica', legendFontSize=9.00, legendFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), titleText='', titleFontName='Helvetica-Bold', titleFontSize=14.00, titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), dataLabelsType='%.1f', dataLabelsFontName='Helvetica', dataLabelsFontSize=9.00, dataLabelsFontColor=CMYKColor(0.05, 0.45, 1.00, 0.00), width=401.54384, height=150.86375) makeDrawing(html, "12.1 xAxisLabelAngle=-70", chartType='linechart', dataLabelsType='values', categoryNames=['Oranges', 'Lemons', 'Apples', 'Pears'], xAxisLabelAngle=-70) makeDrawing(html, "12.2 yAxisLabelAngle=-70", chartType='linechart', dataLabelsType='values', categoryNames=['Oranges', 'Lemons', 'Apples', 'Pears'], yAxisLabelAngle=-70) makeDrawing(html, "12.3 xAxisLabelAngle=70", chartType='linechart', dataLabelsType='values', categoryNames=['Oranges', 'Lemons', 'Apples', 'Pears'], xAxisLabelAngle=70) makeDrawing(html, "12.3 yAxisLabelAngle=70", chartType='linechart', dataLabelsType='values', categoryNames=['Oranges', 'Lemons', 'Apples', 'Pears'], yAxisLabelAngle=70) makeDrawing(html, "13.1 textData", chartType='linechart', dataLabelsType='values', textData="A B C D\na b c d") makeDrawing(html, "13.2 textData", chartType='column', dataLabelsType='values', textData="A B C D\na b c d") makeDrawing(html, "13.3 textData", chartType='bar', dataLabelsType='values', textData="A B C D\na b c d") makeDrawing(html, "14.1 Ron Error Empty Chart", chartType='clustered_column', data=[[0], [0], [0]], categoryNames=['Oct'], seriesNames=['Series 1', 'Series 2', 'Series 3'], chartColors=[ CMYKColor(0.00, 0.20, 0.34, 0.00), CMYKColor(0.00, 0.00, 0.40, 0.00), CMYKColor(0.20, 0.00, 0.09, 0.00) ], bgColor=None, plotColor=None, legendPos='right', legendFontName='Helvetica', legendFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), titleText='Banzai!', titleFontName='Helvetica-Bold', titleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), xTitleText='', xTitleFontName='Helvetica', xTitleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), yTitleText='', yTitleFontName='Helvetica', yTitleFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), xAxisVisible=1, xAxisLabelAngle=30, xAxisFontName='Helvetica', xAxisFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), yAxisVisible=1, yAxisFontName='Helvetica', yAxisFontColor=CMYKColor(0.00, 0.00, 0.00, 1.00), xAxisGridLines=0, yAxisGridLines=1, dataLabelsType=None, width=366.00000, height=347.50000) makeDrawing(html, "14.2 Liron Axis error", chartType='linechart', data=[[0.00, 0.00, 0.00, 0.00, -1.07]], categoryNames=['a', 'b', 'c', 'd', 'e'], seriesNames=['Series 1'], chartColors=[ Color(0.82, 0, 0), Color(0.32, 0, 0), Color(0.32, 0.16, 0.06), Color(0.32, 0.16, 0.06), Color(0.32, 0.16, 0.06) ], bgColor=None, plotColor=None, legendPos='right', legendFontName='Times-Roman', legendFontSize=12.00, legendFontColor=Color(0.00, 0.00, 0.00), titleText='', titleFontName='Times-Roman', titleFontSize=12.00, titleFontColor=Color(0.00, 0.00, 0.00), xTitleText='', xTitleFontName='Times-Roman', xTitleFontSize=12.00, xTitleFontColor=Color(0.00, 0.00, 0.00), yTitleText='', yTitleFontName='Times-Roman', yTitleFontSize=12.00, yTitleFontColor=Color(0.00, 0.00, 0.00), xAxisVisible=1, xAxisLabelAngle=30, xAxisFontName='Times-Roman', xAxisFontSize=12.00, xAxisFontColor=Color(0.00, 0.00, 0.00), yAxisVisible=1, yAxisFontName='Times-Roman', yAxisFontSize=12.00, yAxisFontColor=Color(0.00, 0.00, 0.00), xAxisGridLines=0, yAxisGridLines=0, dataLabelsType=None, width=431.00, height=343.00) import os, sys fn = os.path.join('pmout', 'qctests.html') open(fn, 'w').write('<html><head></head><body>%s</body></html>' % ('<hr width=100%>'.join(html))) if sys.platform == 'mac': from reportlab.lib.utils import markfilename markfilename(fn, ext='HTML')
def main(): LP = tuple(enumerate((None,'top','top_right','right','bottom_right','bottom','bottom_left','left','top_left'))) HLEGS = tuple(enumerate((None,False,True))) LEGENDMODES = tuple(enumerate((None,'fullWidth','fullHeight'))) ALLOWED_CHART_TYPES.sort() html = [] for chartType in ALLOWED_CHART_TYPES: makeDrawing(html, '', chartType=chartType) makeDrawing(html,"0.1 Line chart should have both x and y gridlines",chartType='linechart',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1) makeDrawing(html,"0.11 Line plot should have both x and y gridlines",chartType='lineplot',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, data=[[1.5,3,4.5],[1,2,3],[1.5,2.5,3.5]]) makeDrawing(html,"0.12 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,2,'.',''))s'",chartType='linechart',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat= "$%(decfmt(value*10000,2,'.',''))s") makeDrawing(html,"0.13 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,-2,'.',','))s'",chartType='linechart',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat= "$%(decfmt(value*10000,-2,'.',','))s") makeDrawing(html,"0.14 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,(1 if notAllInt else 0),'.',','))s'",chartType='linechart',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat= "$%(decfmt(value*10000,(1 if notAllInt else 0),'.',','))s") makeDrawing(html,"0.15 0.1+yAxisLabelTextFormat='$%(decfmt(value*10000,2,',','.'))s'",chartType='linechart',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=1, xAxisGridLines=1, yAxisLabelTextFormat= "$%(decfmt(value*10000,2,',','.'))s") makeDrawing(html,'1.1 Clustered_bar with the yAxisVisible and yAxisGridlines on',chartType='clustered_bar',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=0) makeDrawing(html,'1.2 Stacked_bar with the yAxisVisible and yAxisGridlines on',chartType='stacked_bar',yAxisVisible=1, yAxisGridLines=1, xAxisVisible=0) makeDrawing(html,'1.3 Clustered_bar with the xAxisVisible and xAxisGridlines on',chartType='clustered_bar',xAxisVisible=1, xAxisGridLines=1, yAxisVisible=0) makeDrawing(html,'1.4 Stacked_bar with the xAxisVisible and xAxisGridlines on',chartType='stacked_bar',xAxisVisible=1, xAxisGridLines=1, yAxisVisible=0) makeDrawing(html,'2.1 Clustered_bar with both the x Axis and y Axis invisible - should resize correctly',chartType='stacked_bar',xAxisVisible=0, yAxisVisible=0,showBoundaries=1) makeDrawing(html,'2.2 Stacked_bar with both the x Axis and y Axis invisible - should resize correctly',chartType='clustered_bar',xAxisVisible=0, yAxisVisible=0,showBoundaries=1) makeDrawing(html,'3.1 Stacked_bar with dataLabelsType set to None',chartType='stacked_bar',dataLabelsType=None) makeDrawing(html,'3.2 Clustered_bar with dataLabelsType set to None',chartType='clustered_bar',dataLabelsType=None) makeDrawing(html,'3.3 Pie with dataLabelsType set to None',chartType='pie',dataLabelsType=None) makeDrawing(html,"3.4 Stacked_bar with dataLabelsType set to 'values'",chartType='stacked_bar',dataLabelsType='values') makeDrawing(html,"3.5 Clustered_bar with dataLabelsType set to 'values'",chartType='clustered_bar',dataLabelsType='values') makeDrawing(html,"3.6 Pie with dataLabelsType set to 'values'",chartType='pie',dataLabelsType='values') makeDrawing(html,"3.7 Stacked_bar with dataLabelsType set to 'percent'",chartType='stacked_bar',dataLabelsType='percent') makeDrawing(html,"3.8 Clustered_bar with dataLabelsType set to 'percent'",chartType='clustered_bar',dataLabelsType='percent') makeDrawing(html,"3.9 Pie with dataLabelsType set to 'percent'",chartType='pie',dataLabelsType='percent') makeDrawing(html,"3.71 Stacked_bar with dataLabelsType set to 'percent,2'",chartType='stacked_bar',dataLabelsType='percent,2') makeDrawing(html,"3.81 Clustered_bar with dataLabelsType set to 'percent,2'",chartType='clustered_bar',dataLabelsType='percent,2') makeDrawing(html,"3.91 Pie with dataLabelsType set to 'percent,2'",chartType='pie',dataLabelsType='percent,2') makeDrawing(html,"3.72 Stacked_bar with dataLabelsType set to '%(percent).1f%%'",chartType='stacked_bar',dataLabelsType='%(percent).1f%%') makeDrawing(html,"3.82 Clustered_bar with dataLabelsType set to '%(percent).2f%%'",chartType='clustered_bar',dataLabelsType='%(percent).2f%%') makeDrawing(html,"3.92 Pie with dataLabelsType set to '%(percent).3f%% per Annum'",chartType='pie',dataLabelsType='%(percent).3f%% per Annum') makeDrawing(html,"3.73 Stacked_bar with dataLabelsType set to '$%(decfmt(value*10000,2,'.',''))s'",chartType='stacked_bar',dataLabelsType='$%(decfmt(value*10000,2,\'.\',\'\'))s') makeDrawing(html,"3.74 Stacked_bar with dataLabelsType set to '$%(decfmt(value*10000,2,'.',','))s'",chartType='stacked_bar',dataLabelsType='$%(decfmt(value*10000,2,\'.\',\',\'))s') makeDrawing(html,"3.83 Clustered_bar with dataLabelsType set to '$%(decfmt(value*14000,2,',','.'))s'",chartType='clustered_bar',dataLabelsType='$%(decfmt(value*14000,1,\',\',\'.\'))s') makeDrawing(html,"3.93 Pie with dataLabelsType set to '$%(decfmt(value*12000,2))s/Year'",chartType='pie',dataLabelsType='$%(decfmt(value*12000,2))s/Year') makeDrawing(html,"4.1 Pie with dataLabelsType unset - no datalabels should be printed",chartType='pie') makeDrawing(html,"4.2 Pie with dataLabelsType set to 'values' - values should be used for dataLabels",chartType='pie',dataLabelsType='values') makeDrawing(html,"4.3 Pie with dataLabelsType set to 'percent' - percentages should be used for dataLabels",chartType='pie',dataLabelsType='percent') makeDrawing(html,"4.4 Pie with with category names - set dataLabelsType '%(category)s'",chartType='pie',dataLabelsType='%(category)s',categoryNames=['A','B','C','D']) makeDrawing(html,"4.5.0 Pie with overlap",chartType='pie',dataLabelsType='%(percent).3f%% per Annum',data=[0.9,1.1,2.2,40,57],categoryNames=['0.9','1.1','2.2','40','57']) makeDrawing(html,"4.5.1 Pie with overlap orderMode='alternate'",chartType='pie',orderMode='alternate',dataLabelsType='%(percent).3f%% per Annum',data=[0.9,1.1,2.2,40,57],categoryNames=['0.9','1.1','2.2','40','57']) makeDrawing(html,"4.5.2 Pie with overlap checkLabelOverlap=1",chartType='pie',checkLabelOverlap=1,dataLabelsType='%(percent).3f%% per Annum',data=[0.9,1.1,2.2,40,57],categoryNames=['0.9','1.1','2.2','40','57']) makeDrawing(html,"4.5.3 Pie with overlap orderMode='alternate' checkLabelOverlap=1",chartType='pie',checkLabelOverlap=1,orderMode='alternate', dataLabelsType='%(percent).3f%% per Annum',data=[0.9,1.1,2.2,40,57],categoryNames=['0.9','1.1','2.2','40','57']) makeDrawing(html,"5.1 Title should be (ascent * 1.5) from the font base line ",chartType='pie', titleText="This is the Title") makeDrawing(html,"6.1 Bar with integer data - axis should display without decimals",chartType='bar', data=[[100, 200, 300, 400]], xAxisVisible=1, yAxisVisible=1) makeDrawing(html,"6.2 Column with integer data - axis should display without decimals",chartType='column', data=[[100, 200, 300, 400]], xAxisVisible=1, yAxisVisible=1) makeDrawing(html,"6.3 Bar with floating point data - axis should display with decimals",chartType='bar', data=[[0.01, 0.02, 0.03, 0.04]], xAxisVisible=1, yAxisVisible=1) makeDrawing(html,"6.4 Bar with floating point data - axis should display with decimals",chartType='column', data=[[0.01, 0.02, 0.03, 0.04]], xAxisVisible=1, yAxisVisible=1) makeDrawing(html,"7.1 x Axis and y Axis gridlines should be the same width",chartType='bar', xAxisVisible=1, yAxisVisible=1, xAxisGridLines=1, yAxisGridLines=1) makeDrawing(html,"7.2 x Axis and y Axis gridlines should be the same width",chartType='column', xAxisVisible=1, yAxisVisible=1, xAxisGridLines=1, yAxisGridLines=1) makeDrawing(html,"8.1 When using data = [[120,20]], the value axis should no longer show negative values of (-50,0,50,100,150)",chartType='column', data=[[120,20]]) makeDrawing(html,"8.1a When using data = [[120,20]], the value axis should no longer show negative values of (-50,0,50,100,150)",chartType='bar', data=[[120,20]]) makeDrawing(html,"8.2 When using negative data the gridline of the category axis should be correctly sized",chartType='column', data=[[-120,-20,20]], xAxisGridLines=1) makeDrawing(html,"8.2a When using negative data the gridline of the category axis should be correctly sized",chartType='bar', data=[[-120,-20,20]], yAxisGridLines=1) for k,legendMode in LEGENDMODES: for j,hleg in HLEGS: for i,p in LP: makeDrawing(html,"9.1.%d.%d.%d Blue border round background, no fill on background legendPos=%s hleg=%s legendMode=%s" % (k,j,i,p,hleg,legendMode),chartType='column', bgColor = None, bgStrokeColor='blue', seriesNames=('A long series name','Another very long series name'),legendPos=p,hleg=hleg,legendMaxWFrac=0.5,legendMaxHFrac=0.5,legendMode=legendMode) makeDrawing(html,"9.2 Blue border round background, yellow fill on background",chartType='bar', bgColor = 'yellow', bgStrokeColor='blue') makeDrawing(html,"10.1 Test piechart with data of '[[230,340]]' and dataLabelsType of 'percent' (as per Nardi's test)", chartType='pie',data=[[230,340]],categoryNames=['category1','category2'],seriesNames=[],bgColor=None,plotColor=CMYKColor(0,0,1,0),legendPos='left',legendFontName='Helvetica',legendFontColor=CMYKColor(0,0,0,2),titleText='This is the main title',titleFontName='Helvetica-Bold',titleFontSize=18,titleFontColor=CMYKColor(0,1,1,1),dataLabelsType='percent',dataLabelsFontName='Helvetica',dataLabelsFontSize=14,dataLabelsFontColor=CMYKColor(0,1,1,0)) for k,legendMode in LEGENDMODES: for j,hleg in HLEGS: for i,p in LP: makeDrawing(html,"10.2.%d.%d.%d piechart with more than 10 slices legendPos=%s hleg=%s legendMode=%s"%(k,j,i,p,hleg,legendMode), chartType = 'exploded_pie',data = [[27.00000,3.00000,10.00000,5.00000,5.00000,15.00000,35.00000,12,17,11,19,23,32]],categoryNames = ['Category 1','Category 2','Category 3','Category 4','Category 5','Category 6','Category 7','Cat 8','Cat 9','Cat 10','Cat 11','Cat 12','Cat 13'],seriesNames = [],chartColors = [CMYKColor(0.00,1.00,0.00,0.00),CMYKColor(1.00,1.00,0.00,0.00),CMYKColor(0.00,0.00,1.00,0.00),CMYKColor(0.00,1.00,1.00,0.00),CMYKColor(0.00,0.80,1.00,0.00),CMYKColor(0.00,0.40,1.00,0.00),CMYKColor(0.80,0.00,1.00,0.00),toColor('red'),toColor('grey'),toColor('brown'),toColor('magenta'),toColor('darkblue'),toColor('pink')],bgColor = None,plotColor = None,legendPos = p,legendFontName = 'Helvetica',legendFontSize = 9.00,legendFontColor = CMYKColor(0.05,0.45,1.00,0.00),titleText = '',titleFontName = 'Helvetica-Bold',titleFontSize = 14.00,titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),dataLabelsType = '%.1f',dataLabelsFontName = 'Helvetica',dataLabelsFontSize = 9.00,dataLabelsFontColor = CMYKColor(0.05,0.45,1.00,0.00),width = 401.54384,height = 150.86375,hleg=hleg,legendMaxWFrac=0.5,legendMaxHFrac=0.5,legendMode=legendMode) makeDrawing(html,"11.1 Test for black lines in 3D exploded piechart", chartType = 'exploded_pie3d',data = [[27.00000,3.00000,10.00000,5.00000,5.00000,15.00000,35.00000]],categoryNames = ['Category 1','Category 2','Category 3','Category 4','Category 5','Category 6','Category 7'],seriesNames = [],chartColors = [CMYKColor(0.00,1.00,0.00,0.00),CMYKColor(1.00,1.00,0.00,0.00),CMYKColor(0.00,0.00,1.00,0.00),CMYKColor(0.00,1.00,1.00,0.00),CMYKColor(0.00,0.80,1.00,0.00),CMYKColor(0.00,0.40,1.00,0.00),CMYKColor(0.80,0.00,1.00,0.00)],bgColor = None,plotColor = None,legendPos = 'right',legendFontName = 'Helvetica',legendFontSize = 9.00,legendFontColor = CMYKColor(0.05,0.45,1.00,0.00),titleText = '',titleFontName = 'Helvetica-Bold',titleFontSize = 14.00,titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),dataLabelsType = '%.1f',dataLabelsFontName = 'Helvetica',dataLabelsFontSize = 9.00,dataLabelsFontColor = CMYKColor(0.05,0.45,1.00,0.00),width = 401.54384,height = 150.86375) for k,legendMode in LEGENDMODES: for j,hleg in HLEGS: for i,p in LP: makeDrawing(html,"11.2.%d.%d.%d 3D exploded piechart with more than 10 slices legendPos=%s hleg=%s legendMode=%s"%(k,j,i,p,hleg,legendMode), chartType = 'exploded_pie3d',data = [[27.00000,3.00000,10.00000,5.00000,5.00000,15.00000,35.00000,12,17,11,19,23,32]],categoryNames = ['Category 1','Category 2','Category 3','Category 4','Category 5','Category 6','Category 7','Cat 8','Cat 9','Cat 10','Cat 11','Cat 12','Cat 13'],seriesNames = [],chartColors = [CMYKColor(0.00,1.00,0.00,0.00),CMYKColor(1.00,1.00,0.00,0.00),CMYKColor(0.00,0.00,1.00,0.00),CMYKColor(0.00,1.00,1.00,0.00),CMYKColor(0.00,0.80,1.00,0.00),CMYKColor(0.00,0.40,1.00,0.00),CMYKColor(0.80,0.00,1.00,0.00),toColor('red'),toColor('grey'),toColor('brown'),toColor('magenta'),toColor('darkblue'),toColor('pink')],bgColor = None,plotColor = None,legendPos = p,legendFontName = 'Helvetica',legendFontSize = 9.00,legendFontColor = CMYKColor(0.05,0.45,1.00,0.00),titleText = '',titleFontName = 'Helvetica-Bold',titleFontSize = 14.00,titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),dataLabelsType = '%.1f',dataLabelsFontName = 'Helvetica',dataLabelsFontSize = 9.00,dataLabelsFontColor = CMYKColor(0.05,0.45,1.00,0.00),width = 401.54384,height = 150.86375,hleg=hleg,legendMaxWFrac=0.5,legendMaxHFrac=0.5,legendMode=legendMode) makeDrawing(html,"11.211 3D exploded piechart with more than 10 slices legend at top legendMaxHFrac=0.125", chartType = 'exploded_pie3d',legendMaxHFrac=0.125,data = [[27.00000,3.00000,10.00000,5.00000,5.00000,15.00000,35.00000,12,17,11,19,23,32]],categoryNames = ['Category 1','Category 2','Category 3','Category 4','Category 5','Category 6','Category 7','Cat 8','Cat 9','Cat 10','Cat 11','Cat 12','Cat 13'],seriesNames = [],chartColors = [CMYKColor(0.00,1.00,0.00,0.00),CMYKColor(1.00,1.00,0.00,0.00),CMYKColor(0.00,0.00,1.00,0.00),CMYKColor(0.00,1.00,1.00,0.00),CMYKColor(0.00,0.80,1.00,0.00),CMYKColor(0.00,0.40,1.00,0.00),CMYKColor(0.80,0.00,1.00,0.00),toColor('red'),toColor('grey'),toColor('brown'),toColor('magenta'),toColor('darkblue'),toColor('pink')],bgColor = None,plotColor = None,legendPos = 'top',legendFontName = 'Helvetica',legendFontSize = 9.00,legendFontColor = CMYKColor(0.05,0.45,1.00,0.00),titleText = '',titleFontName = 'Helvetica-Bold',titleFontSize = 14.00,titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),dataLabelsType = '%.1f',dataLabelsFontName = 'Helvetica',dataLabelsFontSize = 9.00,dataLabelsFontColor = CMYKColor(0.05,0.45,1.00,0.00),width = 401.54384,height = 150.86375) makeDrawing(html,"11.212 3D exploded piechart with more than 10 slices legend at top legendMaxHFrac=0.09", chartType = 'exploded_pie3d',legendMaxHFrac=0.09,data = [[27.00000,3.00000,10.00000,5.00000,5.00000,15.00000,35.00000,12,17,11,19,23,32]],categoryNames = ['Category 1','Category 2','Category 3','Category 4','Category 5','Category 6','Category 7','Cat 8','Cat 9','Cat 10','Cat 11','Cat 12','Cat 13'],seriesNames = [],chartColors = [CMYKColor(0.00,1.00,0.00,0.00),CMYKColor(1.00,1.00,0.00,0.00),CMYKColor(0.00,0.00,1.00,0.00),CMYKColor(0.00,1.00,1.00,0.00),CMYKColor(0.00,0.80,1.00,0.00),CMYKColor(0.00,0.40,1.00,0.00),CMYKColor(0.80,0.00,1.00,0.00),toColor('red'),toColor('grey'),toColor('brown'),toColor('magenta'),toColor('darkblue'),toColor('pink')],bgColor = None,plotColor = None,legendPos = 'top',legendFontName = 'Helvetica',legendFontSize = 9.00,legendFontColor = CMYKColor(0.05,0.45,1.00,0.00),titleText = '',titleFontName = 'Helvetica-Bold',titleFontSize = 14.00,titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),dataLabelsType = '%.1f',dataLabelsFontName = 'Helvetica',dataLabelsFontSize = 9.00,dataLabelsFontColor = CMYKColor(0.05,0.45,1.00,0.00),width = 401.54384,height = 150.86375) makeDrawing(html,"11.213 3D exploded piechart with more than 10 slices legend at top legendMaxWFrac=0.8", chartType = 'exploded_pie3d',legendMaxWFrac=0.8,data = [[27.00000,3.00000,10.00000,5.00000,5.00000,15.00000,35.00000,12,17,11,19,23,32]],categoryNames = ['Category 1','Category 2','Category 3','Category 4','Category 5','Category 6','Category 7','Cat 8','Cat 9','Cat 10','Cat 11','Cat 12','Cat 13'],seriesNames = [],chartColors = [CMYKColor(0.00,1.00,0.00,0.00),CMYKColor(1.00,1.00,0.00,0.00),CMYKColor(0.00,0.00,1.00,0.00),CMYKColor(0.00,1.00,1.00,0.00),CMYKColor(0.00,0.80,1.00,0.00),CMYKColor(0.00,0.40,1.00,0.00),CMYKColor(0.80,0.00,1.00,0.00),toColor('red'),toColor('grey'),toColor('brown'),toColor('magenta'),toColor('darkblue'),toColor('pink')],bgColor = None,plotColor = None,legendPos = 'top',legendFontName = 'Helvetica',legendFontSize = 9.00,legendFontColor = CMYKColor(0.05,0.45,1.00,0.00),titleText = '',titleFontName = 'Helvetica-Bold',titleFontSize = 14.00,titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),dataLabelsType = '%.1f',dataLabelsFontName = 'Helvetica',dataLabelsFontSize = 9.00,dataLabelsFontColor = CMYKColor(0.05,0.45,1.00,0.00),width = 401.54384,height = 150.86375) makeDrawing(html,"12.1 xAxisLabelAngle=-70",chartType='linechart', dataLabelsType='values', categoryNames=['Oranges','Lemons','Apples','Pears'], xAxisLabelAngle=-70) makeDrawing(html,"12.2 yAxisLabelAngle=-70",chartType='linechart', dataLabelsType='values', categoryNames=['Oranges','Lemons','Apples','Pears'], yAxisLabelAngle=-70) makeDrawing(html,"12.3 xAxisLabelAngle=70",chartType='linechart', dataLabelsType='values', categoryNames=['Oranges','Lemons','Apples','Pears'], xAxisLabelAngle=70) makeDrawing(html,"12.3 yAxisLabelAngle=70",chartType='linechart', dataLabelsType='values', categoryNames=['Oranges','Lemons','Apples','Pears'], yAxisLabelAngle=70) makeDrawing(html,"13.1 textData", chartType='linechart', dataLabelsType='values', textData="A B C D\na b c d") makeDrawing(html,"13.2 textData", chartType='column', dataLabelsType='values', textData="A B C D\na b c d") makeDrawing(html,"13.3 textData", chartType='bar', dataLabelsType='values', textData="A B C D\na b c d") makeDrawing(html,"14.1 Ron Error Empty Chart", chartType = 'clustered_column',data =[[0],[0],[0]],categoryNames = ['Oct'],seriesNames = ['Series 1','Series 2','Series 3'],chartColors = [CMYKColor(0.00,0.20,0.34,0.00),CMYKColor(0.00,0.00,0.40,0.00),CMYKColor (0.20,0.00,0.09,0.00)],bgColor = None,plotColor = None,legendPos = 'right',legendFontName = 'Helvetica',legendFontColor = CMYKColor(0.00,0.00,0.00,1.00),titleText = 'Banzai!',titleFontName = 'Helvetica-Bold',titleFontColor = CMYKColor(0.00,0.00,0.00,1.00),xTitleText = '',xTitleFontName = 'Helvetica',xTitleFontColor = CMYKColor(0.00,0.00,0.00,1.00),yTitleText = '',yTitleFontName = 'Helvetica',yTitleFontColor = CMYKColor(0.00,0.00,0.00,1.00),xAxisVisible = 1,xAxisLabelAngle = 30,xAxisFontName = 'Helvetica',xAxisFontColor = CMYKColor(0.00,0.00,0.00,1.00),yAxisVisible = 1,yAxisFontName = 'Helvetica',yAxisFontColor = CMYKColor(0.00,0.00,0.00,1.00),xAxisGridLines = 0,yAxisGridLines = 1,dataLabelsType = None,width = 366.00000,height = 347.50000) makeDrawing(html,"14.2 Liron Axis error",chartType = 'linechart',data = [[0.00,0.00,0.00,0.00,-1.07]],categoryNames = ['a','b','c','d','e'],seriesNames = ['Series 1'],chartColors = [Color(0.82,0,0),Color(0.32,0,0),Color(0.32,0.16,0.06),Color(0.32,0.16,0.06),Color(0.32,0.16,0.06)],bgColor = None,plotColor = None,legendPos = 'right',legendFontName = 'Times-Roman',legendFontSize = 12.00,legendFontColor = Color(0.00,0.00,0.00),titleText = '',titleFontName = 'Times-Roman',titleFontSize = 12.00,titleFontColor = Color(0.00,0.00,0.00),xTitleText = '',xTitleFontName = 'Times-Roman',xTitleFontSize = 12.00,xTitleFontColor = Color(0.00,0.00,0.00),yTitleText = '',yTitleFontName = 'Times-Roman',yTitleFontSize = 12.00,yTitleFontColor = Color(0.00,0.00,0.00),xAxisVisible = 1,xAxisLabelAngle = 30,xAxisFontName = 'Times-Roman',xAxisFontSize = 12.00,xAxisFontColor = Color(0.00,0.00,0.00),yAxisVisible = 1,yAxisFontName = 'Times-Roman',yAxisFontSize = 12.00,yAxisFontColor = Color(0.00,0.00,0.00),xAxisGridLines = 0,yAxisGridLines = 0,dataLabelsType = None,width = 431.00,height = 343.00) import os, sys fn = os.path.join('pmout', 'qctests.html') open(fn,'w').write('<html><head></head><body>%s</body></html>' % ('<hr width=100%>'.join(html))) if sys.platform=='mac': from reportlab.lib.utils import markfilename markfilename(fn,ext='HTML')
def test(outDir='pmout', shout=False): def ext(x): if x=='tiff': x='tif' return x #grab all drawings from the test module and write out. #make a page of links in HTML to assist viewing. import os from reportlab.graphics import testshapes from reportlab.rl_config import verbose getAllTestDrawings = testshapes.getAllTestDrawings drawings = [] if not os.path.isdir(outDir): os.mkdir(outDir) htmlTop = """<html><head><title>renderPM output results</title></head> <body> <h1>renderPM results of output</h1> """ htmlBottom = """</body> </html> """ html = [htmlTop] names = {} argv = sys.argv[1:] E = [a for a in argv if a.startswith('--ext=')] if not E: E = ['gif','tiff', 'png', 'jpg', 'pct', 'py', 'svg'] else: for a in E: argv.remove(a) E = (','.join([a[6:] for a in E])).split(',') errs = [] import traceback from xml.sax.saxutils import escape def handleError(name,fmt): msg = 'Problem drawing %s fmt=%s file'%(name,fmt) if shout or verbose>2: print(msg) errs.append('<br/><h2 style="color:red">%s</h2>' % msg) buf = StringIO() traceback.print_exc(file=buf) errs.append('<pre>%s</pre>' % escape(buf.getvalue())) #print in a loop, with their doc strings for (drawing, docstring, name) in getAllTestDrawings(doTTF=hasattr(_renderPM,'ft_get_face')): i = names[name] = names.setdefault(name,0)+1 if i>1: name += '.%02d' % (i-1) if argv and name not in argv: continue fnRoot = name w = int(drawing.width) h = int(drawing.height) html.append('<hr><h2>Drawing %s</h2>\n<pre>%s</pre>' % (name, docstring)) for k in E: if k in ['gif','png','jpg','pct']: html.append('<p>%s format</p>\n' % k.upper()) try: filename = '%s.%s' % (fnRoot, ext(k)) fullpath = os.path.join(outDir, filename) if os.path.isfile(fullpath): os.remove(fullpath) if k=='pct': from reportlab.lib.colors import white drawToFile(drawing,fullpath,fmt=k,configPIL={'transparent':white}) elif k in ['py','svg']: drawing.save(formats=['py','svg'],outDir=outDir,fnRoot=fnRoot) else: drawToFile(drawing,fullpath,fmt=k) if k in ['gif','png','jpg']: html.append('<img src="%s" border="1"><br>\n' % filename) elif k=='py': html.append('<a href="%s">python source</a><br>\n' % filename) elif k=='svg': html.append('<a href="%s">SVG</a><br>\n' % filename) if shout or verbose>2: print('wrote %s'%ascii(fullpath)) except AttributeError: handleError(name,k) if os.environ.get('RL_NOEPSPREVIEW','0')=='1': drawing.__dict__['preview'] = 0 for k in ('eps', 'pdf'): try: drawing.save(formats=[k],outDir=outDir,fnRoot=fnRoot) except: handleError(name,k) if errs: html[0] = html[0].replace('</h1>',' <a href="#errors" style="color: red">(errors)</a></h1>') html.append('<a name="errors"/>') html.extend(errs) html.append(htmlBottom) htmlFileName = os.path.join(outDir, 'pm-index.html') with open(htmlFileName, 'w') as f: f.writelines(html) if sys.platform=='mac': from reportlab.lib.utils import markfilename markfilename(htmlFileName,ext='HTML') if shout or verbose>2: print('wrote %s' % htmlFileName)
def saveToFile(self, fn, fmt=None): im = self.toPIL() if fmt is None: if not isinstance(fn, str): raise ValueError("Invalid value '%s' for fn when fmt is None" % ascii(fn)) fmt = os.path.splitext(fn)[1] if fmt.startswith("."): fmt = fmt[1:] configPIL = self.configPIL or {} configPIL.setdefault("preConvertCB", None) preConvertCB = configPIL.pop("preConvertCB") if preConvertCB: im = preConvertCB(im) fmt = fmt.upper() if fmt in ("GIF",): im = _convert2pilp(im) elif fmt in ("TIFF", "TIFFP", "TIFFL", "TIF", "TIFF1"): if fmt.endswith("P"): im = _convert2pilp(im) elif fmt.endswith("L"): im = _convert2pilL(im) elif fmt.endswith("1"): im = _convert2pil1(im) fmt = "TIFF" elif fmt in ("PCT", "PICT"): return _saveAsPICT(im, fn, fmt, transparent=configPIL.get("transparent", None)) elif fmt in ("PNG", "BMP", "PPM"): if fmt == "PNG": try: from PIL import PngImagePlugin except ImportError: import PngImagePlugin elif fmt == "BMP": try: from PIL import BmpImagePlugin except ImportError: import BmpImagePlugin elif fmt in ("JPG", "JPEG"): fmt = "JPEG" elif fmt in ("GIF",): pass else: raise RenderPMError("Unknown image kind %s" % fmt) if fmt == "TIFF": tc = configPIL.get("transparent", None) if tc: from PIL import ImageChops, Image T = 768 * [0] for o, c in zip((0, 256, 512), tc.bitmap_rgb()): T[o + c] = 255 # if isinstance(fn,str): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF') im = Image.merge( "RGBA", im.split() + (ImageChops.invert(im.point(T).convert("L").point(255 * [0] + [255])),) ) # if isinstance(fn,str): im.save(fn+'_masked.gif','GIF') for a, d in ("resolution", self._dpi), ("resolution unit", "inch"): configPIL[a] = configPIL.get(a, d) configPIL.setdefault("chops_invert", 0) if configPIL.pop("chops_invert"): from PIL import ImageChops im = ImageChops.invert(im) configPIL.setdefault("preSaveCB", None) preSaveCB = configPIL.pop("preSaveCB") if preSaveCB: im = preSaveCB(im) im.save(fn, fmt, **configPIL) if not hasattr(fn, "write") and os.name == "mac": from reportlab.lib.utils import markfilename markfilename(fn, ext=fmt)