diff options
Diffstat (limited to 'Master/texmf-dist/scripts/dviasm/dviasm.py')
-rwxr-xr-x | Master/texmf-dist/scripts/dviasm/dviasm.py | 61 |
1 files changed, 21 insertions, 40 deletions
diff --git a/Master/texmf-dist/scripts/dviasm/dviasm.py b/Master/texmf-dist/scripts/dviasm/dviasm.py index 24cb6568883..a516fd398aa 100755 --- a/Master/texmf-dist/scripts/dviasm/dviasm.py +++ b/Master/texmf-dist/scripts/dviasm/dviasm.py @@ -145,13 +145,6 @@ def PutUnsigned(q): return (0, PutByte(q)) def PutSigned(q): - if 0 <= q < 0x800000: return PutUnsigned(q) - if q < -0x800000 or q >= 0x800000: return (3, PutSignedQuad(q)) - if q < -0x8000: q += 0x1000000; return (2, Put3Bytes(q)) - if q < -0x80: q += 0x10000; return (1, Put2Bytes(q)) - return (0, PutByte(q)) - -def PutSignedLength(q): if q < -0x800000 or q >= 0x800000: return (3, PutSignedQuad(q)) if q >= 0x8000: return (2, Put3Bytes(q)) if q < -0x8000: q += 0x1000000; return (2, Put3Bytes(q)) @@ -239,7 +232,7 @@ def PutStrUTF8(t): # used in Dump() s = '' if is_subfont: for o in t: - s += chr((subfont_idx << 8) + o).encode('utf8') + s += chr((subfont_idx << 8) + o) else: # not the case of subfont for o in t: if o == 92: s += '\\\\' @@ -250,16 +243,6 @@ def PutStrUTF8(t): # used in Dump() else: s += chr(o) return "'%s'" % s -def PutStrSJIS(t): # used in Dump() - s = '' - for o in t: - if o == 92: s += '\\\\' - elif 32 <= o < 127: s += chr(o) - elif o < 128: s += ('\\x%02x' % o) - else: - s += DecodeISO2022JP(o).encode('sjis') - return "'%s'" % s - def IsFontChanged(f, z): global cur_font, cur_ssize, subfont_idx, is_subfont for n in subfont_list: @@ -633,13 +616,13 @@ class DVI(object): if cmd[0] == SET1: for o in cmd[1]: if o < 128: s.append(bytes.fromhex('%02x' % (SET_CHAR_0 + o))) - else: s.append(self.CmdPair([SET1, o])) + else: s.append(self.CmdPairU([SET1, o])) elif cmd[0] in (SET_RULE, PUT_RULE): s.append(bytes.fromhex('%02x' % cmd[0]) + PutSignedQuad(cmd[1][0]) + PutSignedQuad(cmd[1][1])) elif cmd[0] == PUT1: - s.append(self.CmdPair([PUT1, cmd[1][0]])) + s.append(self.CmdPairU([PUT1, cmd[1][0]])) elif cmd[0] in (RIGHT1, DOWN1): - s.append(self.CmdPairLength(cmd)) + s.append(self.CmdPair(cmd)) elif cmd[0] in (W0, X0, Y0, Z0): s.append(bytes.fromhex('%02x' % cmd[0])) elif cmd[0] == PUSH: @@ -650,16 +633,16 @@ class DVI(object): s.append(bytes.fromhex('%02x' % POP)) w, x, y, z = stack.pop() elif cmd[0] == W1: - w = cmd[1]; s.append(self.CmdPairLength(cmd)) + w = cmd[1]; s.append(self.CmdPair(cmd)) elif cmd[0] == X1: - x = cmd[1]; s.append(self.CmdPairLength(cmd)) + x = cmd[1]; s.append(self.CmdPair(cmd)) elif cmd[0] == Y1: - y = cmd[1]; s.append(self.CmdPairLength(cmd)) + y = cmd[1]; s.append(self.CmdPair(cmd)) elif cmd[0] == Z1: - z = cmd[1]; s.append(self.CmdPairLength(cmd)) + z = cmd[1]; s.append(self.CmdPair(cmd)) elif cmd[0] == FNT1: if cmd[1] < 64: s.append(bytes.fromhex('%02x' % (FNT_NUM_0 + cmd[1]))) - else: s.append(self.CmdPair(cmd)) + else: s.append(self.CmdPairU(cmd)) elif cmd[0] == XXX1: cmd1 = cmd[1].encode('utf8') l = len(cmd[1]) @@ -722,19 +705,19 @@ class DVI(object): s.append(self.font_def[e]['name'].encode('utf8')) fp.write(b''.join(s)) - def CmdPair(self, cmd): - l, q = PutSigned(cmd[1]) + def CmdPairU(self, cmd): + l, q = PutUnsigned(cmd[1]) return bytes.fromhex('%02x' % (cmd[0] + l)) + q - def CmdPairLength(self, cmd): - l, q = PutSignedLength(cmd[1]) + def CmdPair(self, cmd): + l, q = PutSigned(cmd[1]) return bytes.fromhex('%02x' % (cmd[0] + l)) + q ########################################################## # Parse: Text -> Internal Format ########################################################## def Parse(self, fn, encoding=''): - fp = open(fn, 'r') + fp = open(fn, 'r', encoding=encoding) s = fp.read() fp.close() self.ParseFromString(s, encoding=encoding) @@ -911,7 +894,7 @@ class DVI(object): # Dump: Internal Format -> Text ########################################################## def Dump(self, fn, tabsize=2, encoding=''): - fp = open(fn, 'w') + fp = open(fn, 'w', encoding=encoding) self.DumpToFile(fp, tabsize=tabsize, encoding=encoding) fp.close() @@ -919,7 +902,6 @@ class DVI(object): global PutStr if encoding == 'ascii': PutStr = PutStrASCII elif encoding == 'latin1': PutStr = PutStrLatin1 - elif encoding == 'sjis': PutStr = PutStrSJIS else: PutStr = PutStrUTF8 # DumpPreamble fp.write("[preamble]\n") @@ -937,10 +919,10 @@ class DVI(object): # DumpFontDefinitions fp.write("\n[font definitions]\n") for e in sorted(self.font_def.keys()): - fp.write("fntdef: %s" % self.font_def[e]['name']) + fp.write("fntdef: %s " % self.font_def[e]['name']) if self.font_def[e]['design_size'] != self.font_def[e]['scaled_size']: - fp.write(" (%s) " % self.byconv(self.font_def[e]['design_size'])) - fp.write(" at %s\n" % self.byconv(self.font_def[e]['scaled_size'])) + fp.write("(%s) " % self.byconv(self.font_def[e]['design_size'])) + fp.write("at %s\n" % self.byconv(self.font_def[e]['scaled_size'])) # DumpPages for page in self.pages: fp.write("\n[page" + (" %d"*10 % tuple(page['count'])) + "]\n") @@ -1108,7 +1090,6 @@ class DVI(object): f['slant'] = slant f['embolden'] = embolden else: - f['native'] = False f['name'] = n if q[:2] == "at": q = q[2:] @@ -1166,7 +1147,7 @@ binary format. It is fully documented at Please report bugs to https://github.com/aminophen/dviasm""" - version = """This is %prog-20200905 + version = """This is %prog-20200912 Copyright (C) 2007-2008 by Jin-Hwan Cho <chofchof@ktug.or.kr> Copyright (C) 2011-2017 by Khaled Hosny <khaledhosny@eglug.org> @@ -1208,12 +1189,12 @@ the Free Software Foundation, either version 3 of the License, or parser.error("invalid unit name '%s'!" % options.unit) if options.tabsize < 0: parser.error("negative tabsize!") - if not options.encoding in ['ascii', 'latin1', 'utf8', 'sjis']: + if not options.encoding in ['ascii', 'latin1', 'utf8', 'sjis', 'eucjp']: parser.error("invalid encoding '%s'!" % options.encoding) if options.ptex: global is_ptex is_ptex = True - if not options.encoding in ['utf8', 'sjis']: + if not options.encoding in ['utf8', 'sjis', 'eucjp']: parser.error("invalid encoding '%s' for Japanese pTeX!" % options.encoding) if options.subfont: global subfont_list |