def testTable(self): """ Create a presentation with a page layout called MyLayout """ presdoc = OpenDocumentPresentation() # We must describe the dimensions of the page pagelayout = style.PageLayout(name="MyLayout") presdoc.automaticstyles.addElement(pagelayout) pagelayout.addElement( style.PageLayoutProperties(margin="0cm", pagewidth="28cm", pageheight="21cm", printorientation="landscape")) # Every drawing page must have a master page assigned to it. masterpage = style.MasterPage(name="MyMaster", pagelayoutname=pagelayout) presdoc.masterstyles.addElement(masterpage) # Style for the title frame of the page # We set a centered 34pt font with yellowish background titlestyle = style.Style(name="MyMaster-title", family="presentation") titlestyle.addElement(style.ParagraphProperties(textalign="center")) titlestyle.addElement(style.TextProperties(fontsize="34pt")) titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99")) presdoc.styles.addElement(titlestyle) # Style for the photo frame mainstyle = style.Style(name="MyMaster-main", family="presentation") presdoc.styles.addElement(mainstyle) # Create style for drawing page dpstyle = style.Style(name="dp1", family="drawing-page") presdoc.automaticstyles.addElement(dpstyle) page = draw.Page(stylename=dpstyle, masterpagename=masterpage) presdoc.presentation.addElement(page) titleframe = draw.Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = draw.TextBox() titleframe.addElement(textbox) textbox.addElement(text.P(text="Presentation")) mainframe = draw.Frame(stylename=mainstyle, width="720pt", height="500pt", x="0pt", y="56pt") page.addElement(mainframe) mainframe.addElement(table.Table())
def owriteImageLink(self,obj): # see http://books.evc-cit.info/odbook/ch04.html # see rl.writer for more advanced image integration, including inline, floating, etc. # http://code.pediapress.com/hg/mwlib.rl rlwriter.py from PIL import Image as PilImage def sizeImage(w,h): """ calculate the target image size in inch. @param: (w,h): w(idth), h(eight) of image in px @type int @return: (w,h): w(idth), h(eight) of target image in inch (!) @rtype float""" if obj.isInline: scale = 1 / self.conf.paper['IMG_DPI_STANDARD'] else: scale = 1 / self.conf.paper['IMG_DPI_INLINE'] wTarget = scale * w # wTarget is in inch now hTarget = scale * h # hTarget is in inch now ##2do: obey the value of thumpnail if wTarget > self.conf.paper['IMG_MAX_WIDTH'] or hTarget > self.conf.paper['IMG_MAX_HEIGHT']: # image still to large, re-resize to max possible: scale = min(self.conf.paper['IMG_MAX_WIDTH']/w, self.conf.paper['IMG_MAX_HEIGHT']/h) return (w*scale, h*scale) else: return (wTarget, hTarget) if obj.colon == True: return # writes children if not self.env or not self.env.images: return imgPath = self.env.images.getDiskPath(obj.target)#, size=targetWidth) ???? if not imgPath: log.warning('invalid image url') return imgPath = imgPath.encode('utf-8') (wObj,hObj) = (obj.width or 0, obj.height or 0) # sometimes our parser delivers only one value, w or h, so set the other = 0 try: img = PilImage.open(imgPath) if img.info.get('interlace',0) == 1: log.warning("got interlaced PNG which can't be handeled by PIL") return except IOError: log.warning('img can not be opened by PIL') return (wImg,hImg) = img.size if wImg == 0 or wImg == 0: return aspectRatio = wImg/hImg if wObj>0 and not hObj>0: hObj = wObj / aspectRatio elif hObj>0 and not wObj>0: wObj = aspectRatio / hObj elif wObj==0 and hObj==0: wObj, hObj = wImg, hImg # sometimes the parser delivers only one value, w or h, so set the other "by hand" (width, height) = sizeImage( wObj, hObj) widthIn = "%.2fin" % (width)# * scale) heightIn= "%.2fin" % (height)# * scale) innerframe = draw.Frame(stylename=style.frmInner, width=widthIn, height=heightIn) href = self.doc.addPicture(imgPath) innerframe.addElement(draw.Image(href=href)) if obj.isInline(): return SkipChildren(innerframe) # FIXME something else formatting? else: innerframe.addAttribute( "anchortype", "paragraph") widthIn = "%.2fin" % (width + style.frmOuter.internSpacing)# * scale) heightIn= "%.2fin" % (height) # set image alignment attrs = dict(width=widthIn, anchortype="paragraph") floats = dict(right = style.frmOuterRight, center = style.frmOuterCenter, left = style.frmOuterLeft) attrs["stylename"] = floats.get(obj.align, style.frmOuterLeft) stylename=style.frmOuterLeft, frame = draw.Frame(**attrs) tb = draw.TextBox() frame.addElement(tb) p = ParagraphProxy(stylename=style.imgCaption) tb.addElement(p) p.addElement(innerframe) frame.writeto = p return frame