def _push_dvistring(self, dvi, fonts, afterpos, fontsize, fontmap): """ push dvi string with defined fonts on top of reader stack. Every positions gets scaled relatively by the factor scale. After interpretating the dvi chunk, continue with self.pos=afterpos. The designsize of the virtual font is passed as a fix_word """ #if self.debug: # self.debugfile.write("executing new dvi chunk\n") self.debugstack.append(self.debug) self.debug = 0 self.statestack.append((self.file, self.fonts, self.activefont, afterpos, self.stack, self.scale)) # units in vf files are relative to the size of the font and given as fix_words # which can be converted to floats by diving by 2**20. # This yields the following scale factor for the height and width of rects: self.scale = fontsize/2**20/self.pyxconv self.file = reader.bytesreader(dvi) self.fonts = fonts self.stack = [] self.filepos = 0 self.usefont(0, 0, fontmap)
def _push_dvistring(self, dvi, fonts, afterpos, fontsize, fontmap): """ push dvi string with defined fonts on top of reader stack. Every positions gets scaled relatively by the factor scale. After interpretating the dvi chunk, continue with self.pos=afterpos. The designsize of the virtual font is passed as a fix_word """ #if self.debug: # self.debugfile.write("executing new dvi chunk\n") self.debugstack.append(self.debug) self.debug = 0 self.statestack.append((self.file, self.fonts, self.activefont, afterpos, self.stack, self.scale)) # units in vf files are relative to the size of the font and given as fix_words # which can be converted to floats by diving by 2**20. # This yields the following scale factor for the height and width of rects: self.scale = fontsize / 2**20 / self.pyxconv self.file = reader.bytesreader(dvi) self.fonts = fonts self.stack = [] self.filepos = 0 self.usefont(0, 0, fontmap)
def __init__(self, file, debug=0): with reader.bytesreader(file.read()) as file: # # read pre header # self.lf = file.readint16() self.lh = file.readint16() self.bc = file.readint16() self.ec = file.readint16() self.nw = file.readint16() self.nh = file.readint16() self.nd = file.readint16() self.ni = file.readint16() self.nl = file.readint16() self.nk = file.readint16() self.ne = file.readint16() self.np = file.readint16() if not (self.bc-1 <= self.ec <= 255 and self.ne <= 256 and self.lf == 6+self.lh+(self.ec-self.bc+1)+self.nw+self.nh+self.nd +self.ni+self.nl+self.nk+self.ne+self.np): raise RuntimeError("error in TFM pre-header") if debug: print("lh=%d" % self.lh) # # read header # self.checksum = file.readint32() self.designsize = file.readint32() assert self.designsize > 0, "invald design size" if self.lh > 2: assert self.lh > 11, "inconsistency in TFM file: incomplete field" self.charcoding = file.readstring(40) else: self.charcoding = None if self.lh > 12: assert self.lh > 16, "inconsistency in TFM file: incomplete field" self.fontfamily = file.readstring(20) else: self.fontfamily = None if debug: print("(FAMILY %s)" % self.fontfamily) print("(CODINGSCHEME %s)" % self.charcoding) print("(DESINGSIZE R %f)" % (16.0*self.designsize/16777216)) if self.lh > 17: self.sevenbitsave = file.readuchar() # ignore the following two bytes file.readint16() facechar = file.readuchar() # decode ugly face specification into the Knuth suggested string if facechar < 18: if facechar >= 12: self.face = "E" facechar -= 12 elif facechar >= 6: self.face = "C" facechar -= 6 else: self.face = "R" if facechar >= 4: self.face = "L" + self.face facechar -= 4 elif facechar >= 2: self.face = "B" + self.face facechar -= 2 else: self.face = "M" + self.face if facechar == 1: self.face = self.face[0] + "I" + self.face[1] else: self.face = self.face[0] + "R" + self.face[1] else: self.face = None else: self.sevenbitsave = self.face = None if self.lh > 18: # just ignore the rest print(file.read((self.lh-18)*4)) # # read char_info # self.char_info = [None]*(self.ec+1) for charcode in range(self.bc, self.ec+1): self.char_info[charcode] = char_info_word(file.readint32()) if self.char_info[charcode].width_index == 0: # disable character if width_index is zero self.char_info[charcode] = None # # read widths # self.width = [None for width_index in range(self.nw)] for width_index in range(self.nw): self.width[width_index] = file.readint32() # # read heights # self.height = [None for height_index in range(self.nh)] for height_index in range(self.nh): self.height[height_index] = file.readint32() # # read depths # self.depth = [None for depth_index in range(self.nd)] for depth_index in range(self.nd): self.depth[depth_index] = file.readint32() # # read italic # self.italic = [None for italic_index in range(self.ni)] for italic_index in range(self.ni): self.italic[italic_index] = file.readint32() # # read lig_kern # # XXX decode to lig_kern_command self.lig_kern = [None for lig_kern_index in range(self.nl)] for lig_kern_index in range(self.nl): self.lig_kern[lig_kern_index] = file.readint32() # # read kern # self.kern = [None for kern_index in range(self.nk)] for kern_index in range(self.nk): self.kern[kern_index] = file.readint32() # # read exten # # XXX decode to extensible_recipe self.exten = [None for exten_index in range(self.ne)] for exten_index in range(self.ne): self.exten[exten_index] = file.readint32() # # read param # # XXX decode self.param = [None for param_index in range(self.np)] for param_index in range(self.np): self.param[param_index] = file.readint32()
def __init__(self, file, scale, tfmconv, pyxconv, debug=0): self.scale = scale self.tfmconv = tfmconv self.pyxconv = pyxconv self.debug = debug self.fonts = {} # used fonts self.widths = {} # widths of defined chars self.chardefs = {} # dvi chunks for defined chars afile = reader.bytesreader(file.read()) cmd = afile.readuchar() if cmd == _VF_PRE: if afile.readuchar() != _VF_ID: raise VFError comment = afile.read(afile.readuchar()) self.cs = afile.readuint32() self.ds = afile.readuint32() else: raise VFError while True: cmd = afile.readuchar() if cmd >= _VF_FNTDEF1234 and cmd < _VF_FNTDEF1234 + 4: # font definition if cmd == _VF_FNTDEF1234: num = afile.readuchar() elif cmd == _VF_FNTDEF1234 + 1: num = afile.readuint16() elif cmd == _VF_FNTDEF1234 + 2: num = afile.readuint24() elif cmd == _VF_FNTDEF1234 + 3: num = afile.readint32() c = afile.readint32() s = afile.readint32( ) # relative scaling used for font (fix_word) d = afile.readint32() # design size of font fontname = afile.read(afile.readuchar() + afile.readuchar()).decode("ascii") # rescaled size of font: s is relative to the scaling # of the virtual font itself. Note that realscale has # to be a fix_word (like s) # XXX: check rounding reals = int(round(self.scale * (16 * self.ds / 16777216) * s)) # print ("defining font %s -- VF scale: %g, VF design size: %d, relative font size: %d => real size: %d" % # (fontname, self.scale, self.ds, s, reals) # ) # XXX allow for virtual fonts here too from . import texfont self.fonts[num] = texfont.TeXfont(fontname, c, reals, d, self.tfmconv, self.pyxconv, self.debug > 1) elif cmd == _VF_LONG_CHAR: # character packet (long form) pl = afile.readuint32() # packet length cc = afile.readuint32( ) # char code (assumed unsigned, but anyhow only 0 <= cc < 255 is actually used) tfm = afile.readuint24() # character width dvi = afile.read(pl) # dvi code of character self.widths[cc] = tfm self.chardefs[cc] = dvi elif cmd < _VF_LONG_CHAR: # character packet (short form) cc = afile.readuchar() # char code tfm = afile.readuint24() # character width dvi = afile.read(cmd) self.widths[cc] = tfm self.chardefs[cc] = dvi elif cmd == _VF_POST: break else: raise VFError
def __init__(self, file, scale, tfmconv, pyxconv, debug=0): self.scale = scale self.tfmconv = tfmconv self.pyxconv = pyxconv self.debug = debug self.fonts = {} # used fonts self.widths = {} # widths of defined chars self.chardefs = {} # dvi chunks for defined chars afile = reader.bytesreader(file.read()) cmd = afile.readuchar() if cmd == _VF_PRE: if afile.readuchar() != _VF_ID: raise VFError comment = afile.read(afile.readuchar()) self.cs = afile.readuint32() self.ds = afile.readuint32() else: raise VFError while True: cmd = afile.readuchar() if cmd >= _VF_FNTDEF1234 and cmd < _VF_FNTDEF1234 + 4: # font definition if cmd == _VF_FNTDEF1234: num = afile.readuchar() elif cmd == _VF_FNTDEF1234+1: num = afile.readuint16() elif cmd == _VF_FNTDEF1234+2: num = afile.readuint24() elif cmd == _VF_FNTDEF1234+3: num = afile.readint32() c = afile.readint32() s = afile.readint32() # relative scaling used for font (fix_word) d = afile.readint32() # design size of font fontname = afile.read(afile.readuchar() + afile.readuchar()).decode("ascii") # rescaled size of font: s is relative to the scaling # of the virtual font itself. Note that realscale has # to be a fix_word (like s) # XXX: check rounding reals = int(round(self.scale * (16*self.ds/16777216) * s)) # print ("defining font %s -- VF scale: %g, VF design size: %d, relative font size: %d => real size: %d" % # (fontname, self.scale, self.ds, s, reals) # ) from pyx import config from . import texfont try: with config.open(fontname, [config.format.vf]) as fontfile: self.fonts[num] = texfont.virtualfont(fontname, fontfile, c, reals, d, self.tfmconv, self.pyxconv, self.debug>1) except EnvironmentError: self.fonts[num] = texfont.TeXfont(fontname, c, reals, d, self.tfmconv, self.pyxconv, self.debug>1) elif cmd == _VF_LONG_CHAR: # character packet (long form) pl = afile.readuint32() # packet length cc = afile.readuint32() # char code (assumed unsigned, but anyhow only 0 <= cc < 255 is actually used) tfm = afile.readuint24() # character width dvi = afile.read(pl) # dvi code of character self.widths[cc] = tfm self.chardefs[cc] = dvi elif cmd < _VF_LONG_CHAR: # character packet (short form) cc = afile.readuchar() # char code tfm = afile.readuint24() # character width dvi = afile.read(cmd) self.widths[cc] = tfm self.chardefs[cc] = dvi elif cmd == _VF_POST: break else: raise VFError