def getTextBbox(self, text, x, y, halign, valign, textangle=0): fontname = self._fontname font = kaplot.textmod.findFont(fontname, False, False) #fontsizepixels = self._convertUnits(self.fontsize, "px") #fontsize = int(fontsizepixels * 96) #font.set_char_size(0, int(fontsize)) #worldmatrix = self.getWorldMatrix() #print worldmatrix worldmatrix = self.getWorldMatrix() matrix = ( self.getDeviceMatrix() * \ self.getViewportMatrix() *\ worldmatrix ) x, y = matrix * (x, y) #x, y = position try: textObject = kaplot.textmod.parseText(text, font, self._fontsize, fontname, self.dpi) except: kaplot.info("failed to parse text: %r" % text) raise #x, y = 0, 0 points = textObject.getBBoxTransformed(x, y, textangle, valign, halign) matrix = ( self.getDeviceMatrix() * \ self.getViewportMatrix() *\ worldmatrix ).inverse() vppoints = [matrix * k for k in points] #if self.debug: #self.plotBbox(*vppoints) #print points #import pdb #pdb.set_trace() return vppoints
def postDrawPage(self, document, page): super(AggDeviceImage, self).postDrawPage(document, page) pagefilename = kaplot.utils.getPageFilename(self.filename, page.getPageNr(), document.getPageCount()) kaplot.info("writing page to filename", pagefilename) data = self.image.get_argb_string() image = PIL.Image.frombytes("RGBA", (document.pixelWidth, document.pixelHeight), data) image.save(pagefilename)
def drawText__(self, text, position, halign, valign, textangle): fontname = self._fontname #fontname = "verdana" font = kaplot.textmod.findFont(fontname, False, False) #fontsizepixels = self._convertUnits(self.fontsize, "px") #fontsize = int(fontsizepixels * 96) #x, y = self._getTotalMatrix() * position #font.set_char_size(0, int(fontsize)) x, y = position #matrix = ( self.getDeviceMatrix() * \ # self.getViewportMatrix()\ # ) #x, y = matrix * position fontsize = self._fontsize #print self._fontsize, self.dpi dpi = self.dpi #print fontsize, textangle try: textObject = kaplot.textmod.parseText(text, font, fontsize, fontname, dpi) except: kaplot.info("failed to parse text: %r" % text) raise #color = self._findInContextStack("color") #color = "red" #print "textangle =",textangle color = self._color textObject.draw(self.getCInterface(), x, y, textangle, valign, halign, color, self) points = textObject.getBBoxTransformed(x, y, textangle, valign, halign)
def findFontFamilies(dirnames=[]): filenames = getFontFilenames(dirnames) for filename in filenames: try: font = pyfont.Font(filename) except: continue style = font.style_name family = font.family_name if family not in uselessList: if not font.is_bold and not font.is_italic: _getFamily(family).regular = filename elif font.is_bold and font.is_italic: _getFamily(family).bolditalic = filename elif font.is_bold: _getFamily(family).bold = filename elif font.is_italic: _getFamily(family).italic = filename genericfamilyfound = False for generic in generics: if generic.memberOf(fontName=family): #generic_families[genericname].append(family) _getFamily(family).genericFontFamily = generic genericfamilyfound = True generic.append(_getFamily(family)) break if not genericfamilyfound: kaplot.info("there is no generic family name found for font family %r," \ " assuming it is a 'sans-serif' font" % family) #generic_families['sans-serif'].append(family) _getFamily(family).genericFontFamily = sans_serif sans_serif.append(_getFamily(family)) for key, value in fontFamilies.items(): value.end()
def _checkAttrName(self, name): if name not in knownNames: kaplot.info( "Context.%s is not a known attribute, maybe it's misspelled" % name)
def _setPatternSize(self): kaplot.info("patternsize not implementen on device", printonce=True)
def _setLinestyle(self): kaplot.info("linestyle not implementen on device", printonce=True)
def _setLinewidth(self): kaplot.info("linewidth not implementen on device", printonce=True)
def _setAlpha(self): kaplot.info("alpha not implementen on device", printonce=True)
def _drawSymbol(self, x, y, symbolName, xscales, yscales, angles): kaplot.info("plotting symbols not implemented")
def _setClipping(self, clipping): kaplot.info("clipping not implementen on device", printonce=True)
def _setFontsize(self): kaplot.info("fontsize not implementen on device", printonce=True)
def _setFillstyle(self): kaplot.info("fillstyle not implementen on device", printonce=True)
def _setSymbolSize(self): kaplot.info("symbolsize not implementen on device", printonce=True)
def preDraw(self, document): kaplot.info("writing plot to filename", self.filename) self.psbuffer = StringIO() #self.pushContext(self.defaultContext) super(EPSDevice, self).preDraw(document)
def _setColor(self): kaplot.info("color not implementen on device", printonce=True)
def preDraw(self, document): self.file = open(self.filename, "wb") kaplot.info("writing plot to filename", self.filename) super(PSDevice, self).preDraw(document)
def clone(self, container): kaplot.info("clone not implemented for %r" % self.__class__)