예제 #1
0
 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
예제 #2
0
	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)
예제 #3
0
 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)
예제 #4
0
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()
예제 #5
0
 def _checkAttrName(self, name):
     if name not in knownNames:
         kaplot.info(
             "Context.%s is not a known attribute, maybe it's misspelled" %
             name)
예제 #6
0
 def _setPatternSize(self):
     kaplot.info("patternsize not implementen on device", printonce=True)
예제 #7
0
 def _setLinestyle(self):
     kaplot.info("linestyle not implementen on device", printonce=True)
예제 #8
0
 def _setLinewidth(self):
     kaplot.info("linewidth not implementen on device", printonce=True)
예제 #9
0
 def _setAlpha(self):
     kaplot.info("alpha not implementen on device", printonce=True)
예제 #10
0
 def _drawSymbol(self, x, y, symbolName, xscales, yscales, angles):
     kaplot.info("plotting symbols not implemented")
예제 #11
0
 def _setClipping(self, clipping):
     kaplot.info("clipping not implementen on device", printonce=True)
예제 #12
0
 def _setFontsize(self):
     kaplot.info("fontsize not implementen on device", printonce=True)
예제 #13
0
 def _setFillstyle(self):
     kaplot.info("fillstyle not implementen on device", printonce=True)
예제 #14
0
 def _setSymbolSize(self):
     kaplot.info("symbolsize not implementen on device", printonce=True)
예제 #15
0
 def preDraw(self, document):
     kaplot.info("writing plot to filename", self.filename)
     self.psbuffer = StringIO()
     #self.pushContext(self.defaultContext)
     super(EPSDevice, self).preDraw(document)
예제 #16
0
 def _setColor(self):
     kaplot.info("color not implementen on device", printonce=True)
예제 #17
0
 def preDraw(self, document):
     self.file = open(self.filename, "wb")
     kaplot.info("writing plot to filename", self.filename)
     super(PSDevice, self).preDraw(document)
예제 #18
0
	def clone(self, container):
		kaplot.info("clone not implemented for %r" % self.__class__)