def _getGState(w, h, bg, backend='_renderPM', fmt='RGB24'):
     if backend=='_renderPM':
         return _renderPM.gstate(w,h,bg=bg)
     elif backend=='rlPyCairo':
         try:
             from rlPyCairo import GState
         except ImportError:
             raise RenderPMError('cannot import rlPyCairo; perhaps it needs to be installed!')
         else:
             return GState(w,h,bg,fmt=fmt)
     else:
         raise RenderPMError('Invalid backend, %r, given to PMCanvas' % backend)
 def __init__(self,w,h,dpi=72,bg=0xffffff,configPIL=None):
     '''configPIL dict is passed to image save method'''
     scale = dpi/72.0
     w = int(w*scale+0.5)
     h = int(h*scale+0.5)
     self.__dict__['_gs'] = _renderPM.gstate(w,h,bg=bg)
     self.__dict__['_bg'] = bg
     self.__dict__['_baseCTM'] = (scale,0,0,scale,0,0)
     self.__dict__['_clipPaths'] = []
     self.__dict__['configPIL'] = configPIL
     self.__dict__['_dpi'] = dpi
     self.ctm = self._baseCTM
Exemple #3
0
 def __init__(self,w,h,dpi=72,bg=0xffffff,configPIL=None):
     '''configPIL dict is passed to image save method'''
     scale = dpi/72.0
     w = int(w*scale+0.5)
     h = int(h*scale+0.5)
     self.__dict__['_gs'] = _renderPM.gstate(w,h,bg=bg)
     self.__dict__['_bg'] = bg
     self.__dict__['_baseCTM'] = (scale,0,0,scale,0,0)
     self.__dict__['_clipPaths'] = []
     self.__dict__['configPIL'] = configPIL
     self.__dict__['_dpi'] = dpi
     self.ctm = self._baseCTM
 def __init__(self, w, h, dpi=72, bg=0xFFFFFF, configPIL=None):
     """configPIL dict is passed to image save method"""
     scale = dpi / 72.0
     w = int(w * scale + 0.5)
     h = int(h * scale + 0.5)
     self.__dict__["_gs"] = _renderPM.gstate(w, h, bg=bg)
     self.__dict__["_bg"] = bg
     self.__dict__["_baseCTM"] = (scale, 0, 0, scale, 0, 0)
     self.__dict__["_clipPaths"] = []
     self.__dict__["configPIL"] = configPIL
     self.__dict__["_dpi"] = dpi
     self.ctm = self._baseCTM
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 _drawTimeResize(self,w,h,bg=None):
     if bg is None: bg = self._bg
     self._drawing.width, self._drawing.height = w, h
     A = {'ctm':None, 'strokeWidth':None, 'strokeColor':None, 'lineCap':None, 'lineJoin':None, 'dashArray':None, 'fillColor':None}
     gs = self._gs
     fN,fS = gs.fontName, gs.fontSize
     for k in A.keys():
         A[k] = getattr(gs,k)
     del gs, self._gs
     gs = self.__dict__['_gs'] = _renderPM.gstate(w,h,bg=bg)
     for k in A.keys():
         setattr(self,k,A[k])
     gs.setFont(fN,fS)
 def _drawTimeResize(self,w,h,bg=None):
     if bg is None: bg = self._bg
     self._drawing.width, self._drawing.height = w, h
     A = {'ctm':None, 'strokeWidth':None, 'strokeColor':None, 'lineCap':None, 'lineJoin':None, 'dashArray':None, 'fillColor':None}
     gs = self._gs
     fN,fS = gs.fontName, gs.fontSize
     for k in A.keys():
         A[k] = getattr(gs,k)
     del gs, self._gs
     gs = self.__dict__['_gs'] = _renderPM.gstate(w,h,bg=bg)
     for k in A.keys():
         setattr(self,k,A[k])
     gs.setFont(fN,fS)
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
Exemple #9
0
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
Exemple #10
0
        def _text2PathDescription(text, x, y):
            from reportlab.graphics._renderPM import gstate
            from reportlab.graphics.utils import text2PathDescription
            gs = gstate(1, 1)

            def _text2PathDescription(text, x, y):
                return text2PathDescription(
                    text,
                    x=x,
                    y=y,
                    fontName=self.fontName,
                    fontSize=self.fontSize,
                    truncate=False,
                    gs=gs,
                )

            self._text2PathDescription = _text2PathDescription
            return _text2PathDescription(text, x, y)
 def _drawTimeResize(self, w, h, bg=None):
     if bg is None:
         bg = self._bg
     self._drawing.width, self._drawing.height = w, h
     A = {
         "ctm": None,
         "strokeWidth": None,
         "strokeColor": None,
         "lineCap": None,
         "lineJoin": None,
         "dashArray": None,
         "fillColor": None,
     }
     gs = self._gs
     fN, fS = gs.fontName, gs.fontSize
     for k in A.keys():
         A[k] = getattr(gs, k)
     del gs, self._gs
     gs = self.__dict__["_gs"] = _renderPM.gstate(w, h, bg=bg)
     for k in A.keys():
         setattr(self, k, A[k])
     gs.setFont(fN, fS)