def findT1File(self, ext='.pfb'):
     possible_exts = (ext.lower(), ext.upper())
     if hasattr(self,'pfbFileName'):
         r_basename = os.path.splitext(self.pfbFileName)[0]
         for e in possible_exts:
             if rl_isfile(r_basename + e):
                 return r_basename + e
     try:
         r = _fontdata.findT1File(self.name)
     except:
         afm = bruteForceSearchForAFM(self.name)
         if afm:
             if ext.lower() == '.pfb':
                 for e in possible_exts:
                     pfb = os.path.splitext(afm)[0] + e
                     if rl_isfile(pfb):
                         r = pfb
                     else:
                         r = None
             elif ext.lower() == '.afm':
                 r = afm
         else:
             r = None
     if r is None:
         warnOnce("Can't find %s for face '%s'" % (ext, self.name))
     return r
Esempio n. 2
0
 def _formatText(self, text):
     "Generates PDF text output operator(s)"
     if self._dynamicFont:
         #it's a truetype font and should be utf8.  If an error is raised,
         
         results = []
         font = pdfmetrics.getFont(self._fontname)
         try: #assume UTF8
             stuff = font.splitString(text, self._canvas._doc)
         except UnicodeDecodeError:
             #assume latin1 as fallback
             from reportlab.pdfbase.ttfonts import latin1_to_utf8
             from reportlab.lib.logger import warnOnce
             warnOnce('non-utf8 data fed to truetype font, assuming latin-1 data')
             text = latin1_to_utf8(text)
             stuff = font.splitString(text, self._canvas._doc)
         for subset, chunk in stuff:
             if subset != self._curSubset:
                 pdffontname = font.getSubsetInternalName(subset, self._canvas._doc)
                 results.append("%s %s Tf %s TL" % (pdffontname, fp_str(self._fontsize), fp_str(self._leading)))
                 self._curSubset = subset
             chunk = self._canvas._escape(chunk)
             results.append("(%s) Tj" % chunk)
         return string.join(results, ' ')
     else:
         text = self._canvas._escape(text)
         return "(%s) Tj" % text
Esempio n. 3
0
def import_zlib():
    try:
        import zlib
    except ImportError:
        zlib = None
        from reportlab.rl_config import ZLIB_WARNINGS
        if ZLIB_WARNINGS: warnOnce('zlib not available')
    return zlib
Esempio n. 4
0
def import_zlib():
    try:
        import zlib
    except ImportError:
        zlib = None
        from reportlab.rl_config import ZLIB_WARNINGS
        if ZLIB_WARNINGS: warnOnce('zlib not available')
    return zlib
def import_zlib():
    try:
        import zlib
    except ImportError, errMsg:
        _checkImportError(errMsg)
        zlib = None
        from reportlab.rl_config import ZLIB_WARNINGS
        if ZLIB_WARNINGS: warnOnce('zlib not available')
Esempio n. 6
0
 def _SWRecover(text, fontName, fontSize, encoding):
     '''This is called when _rl_accel's database doesn't know about a font.
     Currently encoding is always a dummy.
     '''
     try:
         font = getFont(fontName)
         if font._multiByte:
             return font.stringWidth(text, fontSize)
         else:
             registerFont(font)
             return _stringWidth(text,fontName,fontSize,encoding)
     except:
         warnOnce('Font %s:%s not found - using Courier:%s for widths'%(fontName,encoding,encoding))
         return _stringWidth(text,'courier',fontSize,encoding)
Esempio n. 7
0
    def __init__(self, fileName):
        if not haveImages:
            warnOnce('Imaging Library not available, unable to import bitmaps')
            return
        #start wih lots of null private fields, to be populated by
        #the relevant engine.
        self.fileName = fileName
        self._image = None
        self._width = None
        self._height = None
        self._transparent = None
        self._data = None
        self.fp = open_for_read(fileName,'b')

        #detect which library we are using and open the image
        if sys.platform[0:4] == 'java':
            from javax.imageio import ImageIO
            self._image = ImageIO.read(self.fp)
        else:
            import PIL.Image
            self._image = PIL.Image.open(self.fp)
        import zlib
    except ImportError, errMsg:
        _checkImportError(errMsg)
        zlib = None
        from reportlab.rl_config import ZLIB_WARNINGS
        if ZLIB_WARNINGS: warnOnce('zlib not available')
    return zlib

try:
    from PIL import Image
except ImportError, errMsg:
    _checkImportError(errMsg)
    from reportlab.rl_config import PIL_WARNINGS
    try:
        import Image
        if PIL_WARNINGS: warnOnce('Python Imaging Library not available as package; upgrade your installation!')
    except ImportError, errMsg:
        _checkImportError(errMsg)
        Image = None
        if PIL_WARNINGS: warnOnce('Python Imaging Library not available')
PIL_Image = Image
del Image

__StringIO=None
def getStringIO(buf=None):
    '''unified StringIO instance interface'''
    global __StringIO
    if not __StringIO:
        try:
            from cStringIO import StringIO
        except ImportError: