helv = TypeFace('Helvetica')
    registerTypeFace(helv)
    print(helv.glyphNames[0:30])

    wombat = TypeFace('Wombat')
    print(wombat.glyphNames)
    registerTypeFace(wombat)

    dumpFontData()

#preserve the initial values here
def _reset(
        initial_dicts = dict(
            _typefaces = _typefaces.copy(),
            _encodings = _encodings.copy(),
            _fonts = _fonts.copy(),
            )
        ):
    for k,v in initial_dicts.items():
        d=globals()[k]
        d.clear()
        d.update(v)

from reportlab.rl_config import register_reset
register_reset(_reset)
del register_reset

if __name__=='__main__':
    test()
    testStringWidthAlgorithms()
Esempio n. 2
0
                fn = os.path.join(D,'Fonts',ttf)
                if os.path.isfile(fn):
                    try:
                        f = ttfonts.TTFont(name, fn)
                        pdfmetrics.registerFont(f)
                        F.append(name)
                    except:
                        pass
    return F

def resetFonts():
    for f in _setup():
        if f not in _FONTS:
            _FONTS.append(f)
from reportlab.rl_config import register_reset
register_reset(resetFonts)
resetFonts()

#########################################################
#
#   Collections of shape drawings.
#
#########################################################
def getFailedDrawing(funcName):
    """Generate a drawing in case something goes really wrong.

    This will create a drawing to be displayed whenever some
    other drawing could not be executed, because the generating
    function does something terribly wrong! The box contains
    an attention triangle, plus some error message.
    """
Esempio n. 3
0
    pdfmetrics.registerFont(ttfonts.TTFont("VeraIt", "VeraIt.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBI", "VeraBI.ttf"))
    for f in ('Times-Roman','Courier','Helvetica','Vera', 'VeraBd', 'VeraIt',
              'VeraBI'):
        if f not in testshapes._FONTS:
            testshapes._FONTS.append(f)
    fonts._ps2tt_map = copy.deepcopy(_ps2tt_map_original)
    fonts._tt2ps_map = copy.deepcopy(_tt2ps_map_original)

def setSideLabels():
    from reportlab.graphics.charts import piecharts
    piecharts.Pie3d.sideLabels = 0
setSideLabels()

from reportlab.rl_config import register_reset
register_reset(resetPdfForm)
register_reset(resetFonts)
del register_reset

# Support more enumeration formats.

from z3c.rml import num2words
from reportlab.lib.sequencer import _type2formatter

_type2formatter.update({
    'l': lambda v: num2words.num2words(v),
    'L': lambda v: num2words.num2words(v).upper(),
    'o': lambda v: num2words.num2words(v, ordinal=True),
    'O': lambda v: num2words.num2words(v, ordinal=True).upper(),
    'r': lambda v: num2words.toOrdinal(v),
    'R': lambda v: num2words.toOrdinal(v).upper(),
Esempio n. 4
0
["Name"], '\r\n',
' /Subtype '
' /Type1 '
' /Type '
' /Font '
'>>' ]

def resetPdfForm():
    global PDFDOCENC,ENCODING,GLOBALFONTSDICTIONARY,GLOBALRESOURCES,ZADB
    PDFDOCENC = PDFPattern(PDFDocEncodingPattern)
    ENCODING = PDFPattern(EncodingPattern, PDFDocEncoding=PDFDOCENC)
    ZADB = PDFPattern(ZaDbPattern)
    GLOBALFONTSDICTIONARY = FormFontsDictionary()
    GLOBALRESOURCES = FormResources()
from reportlab.rl_config import register_reset
register_reset(resetPdfForm)
resetPdfForm()

def TextField(title, value, xmin, ymin, xmax, ymax, page,
              maxlen=1000000, font="Helvetica-Bold", fontsize=9, R=0, G=0, B=0.627, multiline=0):
    from reportlab.pdfbase.pdfdoc import PDFString, PDFName
    Flags = 0
    if multiline:
        Flags = Flags | (1<<12) # bit 13 is at position 12 :)
    fontname = FORMFONTNAMES[font]
    return PDFPattern(TextFieldPattern,
                      value=PDFString(value), maxlen=maxlen, page=page,
                      title=PDFString(title),
                      xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax,
                      fontname=PDFName(fontname), fontsize=fontsize, R=R, G=G, B=B, Flags=Flags)
Esempio n. 5
0
    reportlab.rl_config.warnOnMissingFontGlyphs = 0

    for font_name, font_file in font_map.items():
        registerTTFont(font_name, font_file)

    addMapping('Arial_Normal', 0, 0, 'Arial_Normal')
    addMapping('Arial_Normal', 0, 1, 'Arial_Italic')
    addMapping('Arial_Normal', 1, 0, 'Arial_Bold')
    addMapping('Arial_Normal', 1, 1, 'Arial_Bold_Italic')

    addMapping('Times_New_Roman', 0, 0, 'Times_New_Roman')
    addMapping('Times_New_Roman', 0, 1, 'Times_New_Roman_Italic')
    addMapping('Times_New_Roman', 1, 0, 'Times_New_Roman_Bold')
    addMapping('Times_New_Roman', 1, 1, 'Times_New_Roman_Bold_Italic')

    # XXX: Rename to Ubuntu
    addMapping('Ubuntu_Regular', 0, 0, 'Ubuntu_Regular')
    addMapping('Ubuntu_Regular', 0, 1, 'Ubuntu_Italic')
    addMapping('Ubuntu_Regular', 1, 0, 'Ubuntu_Bold')
    addMapping('Ubuntu_Regular', 1, 1, 'Ubuntu_Bold_Italic')

    global enabled
    enabled = True


# z3c.rml >= 1.1.0 calls _reset when processing each document
# We need to register our fonts again
from reportlab.rl_config import register_reset
register_reset(setUpFonts)
del register_reset
Esempio n. 6
0
FormFontPattern = [
    '<<', ' /BaseFont ', ["BaseFont"], '\r\n', ' /Encoding ', ["Encoding"],
    '\r\n', ' /Name ', ["Name"], '\r\n', ' /Subtype '
    ' /Type1 '
    ' /Type '
    ' /Font '
    '>>'
]


def resetPdfForm():
    pass


from reportlab.rl_config import register_reset
register_reset(resetPdfForm)
resetPdfForm()


def TextField(title,
              value,
              xmin,
              ymin,
              xmax,
              ymax,
              page,
              maxlen=1000000,
              font="Helvetica-Bold",
              fontsize=9,
              R=0,
              G=0,
                        f = ttfonts.TTFont(name, fn)
                        pdfmetrics.registerFont(f)
                        F.append(name)
                    except:
                        pass
    return F


def resetFonts():
    for f in _setup():
        if f not in _FONTS:
            _FONTS.append(f)


from reportlab.rl_config import register_reset
register_reset(resetFonts)
resetFonts()


#########################################################
#
#   Collections of shape drawings.
#
#########################################################
def getFailedDrawing(funcName):
    """Generate a drawing in case something goes really wrong.

    This will create a drawing to be displayed whenever some
    other drawing could not be executed, because the generating
    function does something terribly wrong! The box contains
    an attention triangle, plus some error message.
Esempio n. 8
0
    def __init__(self, fileName):
        if isinstance(fileName, PmlImageReader):
            self.__dict__ = fileName.__dict__  # borgize
            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
        imageReaderFlags = 0
        if PILImage and isinstance(fileName, PILImage.Image):
            self._image = fileName
            self.fp = getattr(fileName, 'fp', None)
            try:
                self.fileName = fileName
            except AttributeError:
                self.fileName = 'PILIMAGE_%d' % id(self)
        else:
            try:
                self.fp = open_for_read(fileName, 'b')
                if isinstance(self.fp, six.BytesIO().__class__):
                    # avoid messing with already internal files
                    imageReaderFlags = 0
                if imageReaderFlags > 0:  # interning
                    data = self.fp.read()
                    if imageReaderFlags & 2:  # autoclose
                        try:
                            self.fp.close()
                        except:
                            pass
                    if imageReaderFlags & 4:  # cache the data
                        if not self._cache:
                            register_reset(self._cache.clear)

                        data = self._cache.setdefault(md5(data).digest(), data)
                    self.fp = getStringIO(data)
                elif imageReaderFlags == -1 and isinstance(
                        fileName, six.text_type):
                    #try Ralf Schmitt's re-opening technique of avoiding too many open files
                    self.fp.close()
                    del self.fp  # will become a property in the next statement
                    self.__class__ = LazyImageReader
                if haveImages:
                    #detect which library we are using and open the image
                    if not self._image:
                        self._image = self._read_image(self.fp)
                    if getattr(self._image, 'format', None) == 'JPEG':
                        self.jpeg_fh = self._jpeg_fh
                else:
                    from reportlab.pdfbase.pdfutils import readJPEGInfo

                    try:
                        self._width, self._height, c = readJPEGInfo(self.fp)
                    except:
                        raise RuntimeError(
                            'Imaging Library not available, unable to import bitmaps only jpegs'
                        )
                    self.jpeg_fh = self._jpeg_fh
                    self._data = self.fp.read()
                    self._dataA = None
                    self.fp.seek(0)
            except:  # TODO: Kill the catch-all
                et, ev, tb = sys.exc_info()
                if hasattr(ev, 'args'):
                    a = str(ev.args[-1]) + (' fileName=%r' % fileName)
                    ev.args = ev.args[:-1] + (a, )
                    raise RuntimeError("{0} {1} {2}".format(et, ev, tb))
                else:
                    raise
Esempio n. 9
0
def resetPdfForm():
    pdfform.PDFDOCENC = PDFPattern(pdfform.PDFDocEncodingPattern)
    pdfform.ENCODING = PDFPattern(
        pdfform.EncodingPattern, PDFDocEncoding=pdfform.PDFDOCENC)
    pdfform.GLOBALFONTSDICTIONARY = pdfform.FormFontsDictionary()
    pdfform.GLOBALRESOURCES = pdfform.FormResources()
    pdfform.ZADB = PDFPattern(pdfform.ZaDbPattern)

def resetFonts():
    # testshapes._setup registers the Vera fonts every time which is a little
    # slow on all platforms. On Windows it lists the entire system font
    # directory and registers them all which is very slow.
    pdfmetrics.registerFont(ttfonts.TTFont("Vera", "Vera.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBd", "VeraBd.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraIt", "VeraIt.ttf"))
    pdfmetrics.registerFont(ttfonts.TTFont("VeraBI", "VeraBI.ttf"))
    for f in ('Times-Roman','Courier','Helvetica','Vera', 'VeraBd', 'VeraIt',
              'VeraBI'):
        if f not in testshapes._FONTS:
            testshapes._FONTS.append(f)

def setSideLabels():
    from reportlab.graphics.charts import piecharts
    piecharts.Pie3d.sideLabels = 0
setSideLabels()

from reportlab.rl_config import register_reset
register_reset(resetPdfForm)
register_reset(resetFonts)
del register_reset
Esempio n. 10
0
    reportlab.rl_config.warnOnMissingFontGlyphs = 0

    for font_name, font_file in font_map.items():
        registerTTFont(font_name, font_file)

    addMapping('Arial_Normal', 0, 0, 'Arial_Normal')
    addMapping('Arial_Normal', 0, 1, 'Arial_Italic')
    addMapping('Arial_Normal', 1, 0, 'Arial_Bold')
    addMapping('Arial_Normal', 1, 1, 'Arial_Bold_Italic')

    addMapping('Times_New_Roman', 0, 0, 'Times_New_Roman')
    addMapping('Times_New_Roman', 0, 1, 'Times_New_Roman_Italic')
    addMapping('Times_New_Roman', 1, 0, 'Times_New_Roman_Bold')
    addMapping('Times_New_Roman', 1, 1, 'Times_New_Roman_Bold_Italic')

    # XXX: Rename to Ubuntu
    addMapping('Ubuntu_Regular', 0, 0, 'Ubuntu_Regular')
    addMapping('Ubuntu_Regular', 0, 1, 'Ubuntu_Italic')
    addMapping('Ubuntu_Regular', 1, 0, 'Ubuntu_Bold')
    addMapping('Ubuntu_Regular', 1, 1, 'Ubuntu_Bold_Italic')

    global enabled
    enabled = True


# z3c.rml >= 1.1.0 calls _reset when processing each document
# We need to register our fonts again
from reportlab.rl_config import register_reset
register_reset(setUpFonts)
del register_reset