def test3widths(texts): # checks all 3 algorithms give same answer, note speed import time for fontName in standardFonts[0:1]: ## t0 = time.time() ## for text in texts: ## l1 = stringWidth(text, fontName, 10) ## t1 = time.time() ## print 'fast stringWidth took %0.4f' % (t1 - t0) t0 = time.time() w = getFont(fontName).widths for text in texts: l2 = 0 for ch in text: l2 = l2 + w[ord(ch)] t1 = time.time() print 'slow stringWidth took %0.4f' % (t1 - t0) t0 = time.time() for text in texts: l3 = getFont(fontName).stringWidth(text, 10) t1 = time.time() print 'class lookup and stringWidth took %0.4f' % (t1 - t0) print
def getAscentDescent(fontName, fontSize=None): font = getFont(fontName) try: ascent = font.ascent descent = font.descent except: ascent = font.face.ascent descent = font.face.descent if fontSize: norm = fontSize / 1000. return ascent * norm, descent * norm else: return ascent, descent
def getAscentDescent(fontName,fontSize=None): font = getFont(fontName) try: ascent = font.ascent descent = font.descent except: ascent = font.face.ascent descent = font.face.descent if fontSize: norm = fontSize/1000. return ascent*norm, descent*norm else: return ascent, descent
def _py_stringWidth(text, fontName, fontSize, encoding='utf8'): """Define this anyway so it can be tested, but whether it is used or not depends on _rl_accel""" return getFont(fontName).stringWidth(text, fontSize, encoding=encoding)
Names of form 'face-encoding' will be built if face and encoding are known. Also if the name is just one of the standard 14, it will make up a font in the default encoding.""" try: return _fonts[fontName] except KeyError: return findFontAndRegister(fontName) try: from _rl_accel import getFontU as getFont except ImportError: getFont = _py_getFont _notdefFont, _notdefChar = getFont('ZapfDingbats'), chr(110) standardT1SubstitutionFonts.extend( [getFont('Symbol'), getFont('ZapfDingbats')]) def getAscentDescent(fontName, fontSize=None): font = getFont(fontName) try: ascent = font.ascent descent = font.descent except: ascent = font.face.ascent descent = font.face.descent if fontSize: norm = fontSize / 1000. return ascent * norm, descent * norm
Names of form 'face-encoding' will be built if face and encoding are known. Also if the name is just one of the standard 14, it will make up a font in the default encoding.""" try: return _fonts[fontName] except KeyError: return findFontAndRegister(fontName) try: from _rl_accel import getFontU as getFont except ImportError: getFont = _py_getFont _notdefFont,_notdefChar = getFont('ZapfDingbats'),chr(110) standardT1SubstitutionFonts.extend([getFont('Symbol'),getFont('ZapfDingbats')]) def getAscentDescent(fontName,fontSize=None): font = getFont(fontName) try: ascent = font.ascent descent = font.descent except: ascent = font.face.ascent descent = font.face.descent if fontSize: norm = fontSize/1000. return ascent*norm, descent*norm else: return ascent, descent
def getAscentDescent(fontName): font = getFont(fontName) try: return font.ascent,font.descent except: return font.face.ascent,font.face.descent
def getAscentDescent(fontName): font = getFont(fontName) try: return font.ascent, font.descent except: return font.face.ascent, font.face.descent