示例#1
0
 def getfont(self):
     if self._font is None:
         if self.fontfilename is not None:
             fontfile = filelocator.open(self.fontfilename, [filelocator.format.type1], "rb")
             t1font = t1file.from_PF_bytes(fontfile.read())
             fontfile.close()
             assert self.basepsname == t1font.name, "corrupt MAP file"
             try:
                 metricfile = filelocator.open(os.path.splitext(self.fontfilename)[0], [filelocator.format.afm])
             except IOError:
                 try:
                     # fallback by using the pfm instead of the afm font metric
                     # (in all major TeX distributions there is no pfm file format defined by kpsewhich, but
                     # we can use the type1 format and search for the file including the expected suffix)
                     metricfile = filelocator.open("%s.pfm" % os.path.splitext(self.fontfilename)[0], [filelocator.format.type1])
                 except IOError:
                     self._font = font.T1font(t1font)
                 else:
                     self._font = font.T1font(t1font, pfmfile.PFMfile(metricfile, t1font))
                     metricfile.close()
             else:
                 self._font = font.T1font(t1font, afmfile.AFMfile(metricfile))
                 metricfile.close()
         else:
             metricfile = filelocator.open(self.basepsname, [filelocator.format.afm])
             self._font = font.T1builtinfont(self.basepsname, afmfile.AFMfile(metricfile))
             metricfile.close()
     return self._font
示例#2
0
 def getfont(self):
     if self._font is None:
         if self.fontfilename is not None:
             fontfile = filelocator.open(self.fontfilename,
                                         [filelocator.format.type1], "rb")
             t1font = t1file.from_PF_bytes(fontfile.read())
             fontfile.close()
             assert self.basepsname == t1font.name, "corrupt MAP file"
             try:
                 metricfile = filelocator.open(
                     os.path.splitext(self.fontfilename)[0],
                     [filelocator.format.afm])
             except IOError:
                 self._font = font.T1font(t1font, None)
             else:
                 self._font = font.T1font(t1font,
                                          afmfile.AFMfile(metricfile))
                 metricfile.close()
         else:
             metricfile = filelocator.open(self.basepsname,
                                           [filelocator.format.afm])
             self._font = font.T1builtinfont(self.basepsname,
                                             afmfile.AFMfile(metricfile))
             metricfile.close()
     return self._font
示例#3
0
    def __init__(self, name, c, q, d, tfmconv, pyxconv, debug=0):
        self.name = name
        self.q = q  # desired size of font (fix_word) in TeX points
        self.d = d  # design size of font (fix_word) in TeX points
        self.tfmconv = tfmconv  # conversion factor from tfm units to dvi units
        self.pyxconv = pyxconv  # conversion factor from dvi units to PostScript points
        file = filelocator.open(self.name, [filelocator.format.tfm], "rb")
        self.TFMfile = tfmfile.TFMfile(file, debug)
        file.close()

        # We only check for equality of font checksums if none of them
        # is zero. The case c == 0 happend in some VF files and
        # according to the VFtoVP documentation, paragraph 40, a check
        # is only performed if TFMfile.checksum > 0. Anyhow, being
        # more generous here seems to be reasonable
        if self.TFMfile.checksum != c and self.TFMfile.checksum != 0 and c != 0:
            raise TeXFontError("check sums do not agree: %d vs. %d" %
                               (self.TFMfile.checksum, c))

        # Check whether the given design size matches the one defined in the tfm file
        if abs(self.TFMfile.designsize - d) > 4:  # XXX: why the deviation?
            raise TeXFontError("design sizes do not agree: %d vs. %d" %
                               (self.TFMfile.designsize, d))
        #if q < 0 or q > 134217728:
        #    raise TeXFontError("font '%s' not loaded: bad scale" % self.name)
        if d < 0 or d > 134217728:
            raise TeXFontError("font '%s' not loaded: bad design size" %
                               self.name)
示例#4
0
    def __init__(self, name, c, q, d, tfmconv, pyxconv, debug=0):
        self.name = name
        self.q = q                  # desired size of font (fix_word) in TeX points
        self.d = d                  # design size of font (fix_word) in TeX points
        self.tfmconv = tfmconv      # conversion factor from tfm units to dvi units
        self.pyxconv = pyxconv      # conversion factor from dvi units to PostScript points
        file = filelocator.open(self.name, [filelocator.format.tfm], "rb")
        self.TFMfile = tfmfile.TFMfile(file, debug)
        file.close()

        # We only check for equality of font checksums if none of them
        # is zero. The case c == 0 happend in some VF files and
        # according to the VFtoVP documentation, paragraph 40, a check
        # is only performed if TFMfile.checksum > 0. Anyhow, being
        # more generous here seems to be reasonable
        if self.TFMfile.checksum != c and self.TFMfile.checksum != 0 and c != 0:
            raise TeXFontError("check sums do not agree: %d vs. %d" %
                               (self.TFMfile.checksum, c))

        # Check whether the given design size matches the one defined in the tfm file
        if abs(self.TFMfile.designsize - d) > 4: # XXX: why the deviation?
            raise TeXFontError("design sizes do not agree: %d vs. %d" % (self.TFMfile.designsize, d))
        #if q < 0 or q > 134217728:
        #    raise TeXFontError("font '%s' not loaded: bad scale" % self.name)
        if d < 0 or d > 134217728:
            raise TeXFontError("font '%s' not loaded: bad design size" % self.name)
示例#5
0
    def definefont(self, cmdnr, num, c, q, d, fontname):
        # cmdnr: type of fontdef command (only used for debugging output)
        # c:     checksum
        # q:     scaling factor (fix_word)
        #        Note that q is actually s in large parts of the documentation.
        # d:     design size (fix_word)

        # check whether it's a virtual font by trying to open it. if this fails, it is an ordinary TeX font
        try:
            fontfile = filelocator.open(fontname, [filelocator.format.vf])
        except IOError:
            afont = texfont.TeXfont(fontname, c, q / self.tfmconv,
                                    d / self.tfmconv, self.tfmconv,
                                    self.pyxconv, self.debug > 1)
        else:
            afont = texfont.virtualfont(fontname, fontfile, c,
                                        q / self.tfmconv, d / self.tfmconv,
                                        self.tfmconv, self.pyxconv,
                                        self.debug > 1)

        self.fonts[num] = afont

        if self.debug:
            self.debugfile.write("%d: fntdef%d %i: %s\n" %
                                 (self.filepos, cmdnr, num, fontname))
示例#6
0
 def getfont(self):
     if self._font is None:
         if self.fontfilename is not None:
             fontfile = filelocator.open(self.fontfilename, [filelocator.format.type1], "rb")
             t1font = t1file.from_PF_bytes(fontfile.read())
             fontfile.close()
             assert self.basepsname == t1font.name, "corrupt MAP file"
             try:
                 metricfile = filelocator.open(os.path.splitext(self.fontfilename)[0], [filelocator.format.afm])
             except IOError:
                 self._font = font.T1font(t1font, None)
             else:
                 self._font = font.T1font(t1font, afmfile.AFMfile(metricfile))
                 metricfile.close()
         else:
             metricfile = filelocator.open(self.basepsname, [filelocator.format.afm])
             self._font = font.T1builtinfont(self.basepsname, afmfile.AFMfile(metricfile))
             metricfile.close()
     return self._font
示例#7
0
    def getencoding(self):
        if self._encoding is _marker:
            if self.encodingfilename is not None:
                encodingfile = filelocator.open(self.encodingfilename, [filelocator.format.tex_ps_header], "rb")
                ef = encfile.ENCfile(encodingfile.read())
                encodingfile.close()
                assert ef.name == "/%s" % self.reencodefont
                self._encoding = ef.vector

            else:
                self._encoding = None
        return self._encoding
示例#8
0
    def getencoding(self):
        if self._encoding is _marker:
            if self.encodingfilename is not None:
                encodingfile = filelocator.open(
                    self.encodingfilename, [filelocator.format.tex_ps_header],
                    "rb")
                ef = encfile.ENCfile(encodingfile.read())
                encodingfile.close()
                assert ef.name == "/%s" % self.reencodefont
                self._encoding = ef.vector

            else:
                self._encoding = None
        return self._encoding
示例#9
0
 def getfont(self):
     if self._font is None:
         if self.fontfilename is not None:
             fontfile = filelocator.open(self.fontfilename,
                                         [filelocator.format.type1], "rb")
             t1font = t1file.from_PF_bytes(fontfile.read())
             fontfile.close()
             assert self.basepsname == t1font.name, "corrupt MAP file"
             try:
                 metricfile = filelocator.open(
                     os.path.splitext(self.fontfilename)[0],
                     [filelocator.format.afm])
             except IOError:
                 try:
                     # fallback by using the pfm instead of the afm font metric
                     # (in all major TeX distributions there is no pfm file format defined by kpsewhich, but
                     # we can use the type1 format and search for the file including the expected suffix)
                     metricfile = filelocator.open(
                         "%s.pfm" % os.path.splitext(self.fontfilename)[0],
                         [filelocator.format.type1])
                 except IOError:
                     self._font = font.T1font(t1font)
                 else:
                     self._font = font.T1font(
                         t1font, pfmfile.PFMfile(metricfile, t1font))
                     metricfile.close()
             else:
                 self._font = font.T1font(t1font,
                                          afmfile.AFMfile(metricfile))
                 metricfile.close()
         else:
             metricfile = filelocator.open(self.basepsname,
                                           [filelocator.format.afm])
             self._font = font.T1builtinfont(self.basepsname,
                                             afmfile.AFMfile(metricfile))
             metricfile.close()
     return self._font
示例#10
0
def readfontmap(filenames):
    """ read font map from filename (without path) """
    fontmap = {}
    for filename in filenames:
        mapfile = filelocator.open(filename, [filelocator.format.fontmap, filelocator.format.dvips_config], mode="rU")
        lineno = 0
        for line in mapfile.readlines():
            lineno += 1
            line = line.rstrip()
            if not (line=="" or line[0] in (" ", "%", "*", ";" , "#")):
                try:
                    fm = MAPline(line)
                except (ParseError, UnsupportedPSFragment), e:
                    warnings.warn("Ignoring line %i in mapping file '%s': %s" % (lineno, filename, e))
                except UnsupportedFontFormat, e:
                    pass
                else:
                    fontmap[fm.texname] = fm
示例#11
0
def readfontmap(filenames):
    """ read font map from filename (without path) """
    fontmap = {}
    for filename in filenames:
        mapfile = filelocator.open(
            filename,
            [filelocator.format.fontmap, filelocator.format.dvips_config],
            mode="rU")
        lineno = 0
        for line in mapfile.readlines():
            lineno += 1
            line = line.rstrip()
            if not (line == "" or line[0] in (" ", "%", "*", ";", "#")):
                try:
                    fm = MAPline(line)
                except (ParseError, UnsupportedPSFragment), e:
                    warnings.warn("Ignoring line %i in mapping file '%s': %s" %
                                  (lineno, filename, e))
                except UnsupportedFontFormat, e:
                    pass
                else:
                    fontmap[fm.texname] = fm
示例#12
0
    def definefont(self, cmdnr, num, c, q, d, fontname):
        # cmdnr: type of fontdef command (only used for debugging output)
        # c:     checksum
        # q:     scaling factor (fix_word)
        #        Note that q is actually s in large parts of the documentation.
        # d:     design size (fix_word)

        # check whether it's a virtual font by trying to open it. if this fails, it is an ordinary TeX font
        try:
            fontfile = filelocator.open(fontname, [filelocator.format.vf], mode="rb")
        except IOError:
            afont = texfont.TeXfont(
                fontname, c, q / self.tfmconv, d / self.tfmconv, self.tfmconv, self.pyxconv, self.debug > 1
            )
        else:
            afont = texfont.virtualfont(
                fontname, fontfile, c, q / self.tfmconv, d / self.tfmconv, self.tfmconv, self.pyxconv, self.debug > 1
            )

        self.fonts[num] = afont

        if self.debug:
            self.debugfile.write("%d: fntdef%d %i: %s\n" % (self.filepos, cmdnr, num, fontname))