Пример #1
0
 def getfont(self):
     if self._font is None:
         if self.fontfilename is not None:
             with config.open(self.fontfilename,
                              [config.format.type1]) as fontfile:
                 t1font = t1file.from_PF_bytes(fontfile.read())
             assert self.basepsname == t1font.name, "corrupt MAP file"
             try:
                 with config.open(os.path.splitext(self.fontfilename)[0],
                                  [config.format.afm],
                                  ascii=True) as metricfile:
                     self._font = font.T1font(t1font,
                                              afmfile.AFMfile(metricfile))
             except EnvironmentError:
                 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)
                     with config.open(
                             "%s.pfm" %
                             os.path.splitext(self.fontfilename)[0],
                         [config.format.type1]) as metricfile:
                         self._font = font.T1font(
                             t1font, pfmfile.PFMfile(metricfile, t1font))
                 except EnvironmentError:
                     # we need to continue without any metric file
                     self._font = font.T1font(t1font)
         else:
             # builtin font
             with config.open(self.basepsname, [config.format.afm],
                              ascii=True) as metricfile:
                 self._font = font.T1builtinfont(
                     self.basepsname, afmfile.AFMfile(metricfile))
     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:
                 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
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
0
 def getfont(self):
     if self._font is None:
         if self.fontfilename is not None:
             with config.open(self.fontfilename, [config.format.type1]) as fontfile:
                 t1font = t1file.from_PF_bytes(fontfile.read())
             assert self.basepsname == t1font.name, "corrupt MAP file"
             try:
                 with config.open(os.path.splitext(self.fontfilename)[0], [config.format.afm], ascii=True) as metricfile:
                     self._font = font.T1font(t1font, afmfile.AFMfile(metricfile))
             except EnvironmentError:
                 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)
                     with config.open("%s.pfm" % os.path.splitext(self.fontfilename)[0], [config.format.type1]) as metricfile:
                         self._font = font.T1font(t1font, pfmfile.PFMfile(metricfile, t1font))
                 except EnvironmentError:
                     # we need to continue without any metric file
                     self._font = font.T1font(t1font)
         else:
             # builtin font
             with config.open(self.basepsname, [config.format.afm], ascii=True) as metricfile:
                 self._font = font.T1builtinfont(self.basepsname, afmfile.AFMfile(metricfile))
     return self._font
Пример #7
0
import sys
sys.path.insert(0, "../..")

from pyx import *
from pyx.config import open, format
from pyx.font import T1font
from pyx.font.t1file import from_PF_bytes
from pyx.font.afmfile import AFMfile

f = T1font(from_PF_bytes(open("cmr10", [format.type1]).read()),
           AFMfile(open("cmr10", [format.afm], ascii=True)))

c = canvas.canvas()


def show(x_pt, y_pt, text, size_pt, **kwargs):
    t = f.text_pt(x_pt, y_pt, text, size_pt, **kwargs)
    c.insert(t)
    c.stroke(t.bbox().rect(), [style.linewidth(0)])


show(0, 0, "Hello, World!", 10)
show(0, -30, "Hello, World!", 10, spaced_pt=5)
show(0, -60, "Hello, World!", 10, spaced_pt=10)
show(0, -90, "Hello, World!", 10, kerning=True)

show(200, 0, "Hello, World!", 25)
show(200, -30, "Hello, World!", 25, spaced_pt=5)
show(200, -60, "Hello, World!", 25, spaced_pt=10)
show(200, -90, "Hello, World!", 25, kerning=True)
Пример #8
0
import sys; sys.path.insert(0, "../..")

from pyx import *
from pyx.config import open, format
from pyx.font import T1font
from pyx.font.t1file import from_PF_bytes
from pyx.font.afmfile import AFMfile

f = T1font(from_PF_bytes(open("cmr10", [format.type1]).read()),
           AFMfile(open("cmr10", [format.afm], ascii=True)))

c = canvas.canvas()

def show(x_pt, y_pt, text, size_pt, **kwargs):
    t = f.text_pt(x_pt, y_pt, text, size_pt, **kwargs)
    c.insert(t)
    c.stroke(t.bbox().rect(), [style.linewidth(0)])

show(0, 0, "Hello, World!", 10)
show(0, -30, "Hello, World!", 10, spaced_pt=5)
show(0, -60, "Hello, World!", 10, spaced_pt=10)
show(0, -90, "Hello, World!", 10, kerning=True)

show(200, 0, "Hello, World!", 25)
show(200, -30, "Hello, World!", 25, spaced_pt=5)
show(200, -60, "Hello, World!", 25, spaced_pt=10)
show(200, -90, "Hello, World!", 25, kerning=True)

c.writeEPSfile()
c.writeEPSfile("font_direct_text_as_path", write_text_as_path=True)
c.writePDFfile(write_compress=False)