def _text2PathDescription(text, x=0, y=0, fontName=_baseGFontName, fontSize=1000, anchor='start', truncate=1, pathReverse=0): from reportlab.graphics import renderPM, _renderPM font = getFont(fontName) if font._multiByte and not font._dynamicFont: raise ValueError( "_text2PathDescription doesn't support multi byte fonts like %r" % fontName) P = [] if not anchor == 'start': textLen = stringWidth(text, fontName, fontSize) if anchor == 'end': x = x - textLen elif anchor == 'middle': x = x - textLen / 2. _gs = _renderPM.gstate(1, 1) renderPM._setFont(_gs, fontName, fontSize) if font._dynamicFont: for g in _gs._stringPath(text, x, y): P.extend( _processGlyph(g, truncate=truncate, pathReverse=pathReverse)) else: if isBytes(text): try: text = text.decode('utf8') except UnicodeDecodeError as e: i, j = e.args[2:4] raise UnicodeDecodeError(*(e.args[:4] + ('%s\n%s-->%s<--%s' % (e.args[4], text[max(i - 10, 0):i], text[i:j], text[j:j + 10]), ))) fc = font FT = unicode2T1(text, [font] + font.substitutionFonts) nm1 = len(FT) - 1 for i, (f, t) in enumerate(FT): if f != fc: renderPM._setFont(_gs, f.fontName, fontSize) fc = f for g in _gs._stringPath(t, x, y): P.extend( _processGlyph(g, truncate=truncate, pathReverse=pathReverse)) if i != nm1: x += f.stringWidth(t.decode(f.encName), fontSize) return P
def _text2PathDescription(text, x=0, y=0, fontName=_baseGFontName, fontSize=1000, anchor='start', truncate=1, pathReverse=0): from reportlab.graphics import renderPM, _renderPM _gs = _renderPM.gstate(1,1) renderPM._setFont(_gs,fontName,fontSize) P = [] if not anchor=='start': textLen = stringWidth(text, fontName,fontSize) if anchor=='end': x = x-textLen elif anchor=='middle': x = x - textLen/2. for g in _gs._stringPath(text,x,y): P.extend(_processGlyph(g,truncate=truncate,pathReverse=pathReverse)) return P
def _text2PathDescription( text, x=0, y=0, fontName=_baseGFontName, fontSize=1000, anchor="start", truncate=1, pathReverse=0 ): global _gs if not _gs: import _renderPM _gs = _renderPM.gstate(1, 1) from reportlab.graphics import renderPM renderPM._setFont(_gs, fontName, fontSize) P = [] if not anchor == "start": textLen = stringWidth(text, fontName, fontSize) if anchor == "end": x = x - textLen elif anchor == "middle": x = x - textLen / 2.0 for g in _gs._stringPath(text, x, y): P.extend(_processGlyph(g, truncate=truncate, pathReverse=pathReverse)) return P