diff --git a/xwords4/dawg/Makefile.langcommon b/xwords4/dawg/Makefile.langcommon index 5ae03dceb..7a89557d3 100644 --- a/xwords4/dawg/Makefile.langcommon +++ b/xwords4/dawg/Makefile.langcommon @@ -213,7 +213,7 @@ endif # For each entry in the table whose face < 32, there needs to be a pair of # pbitm files and a string giving the printing form -frankspecials.bin: ../frank_mkspecials.pl $(BMPFILES) +frankspecials.bin: ../frank_mkspecials.py $(BMPFILES) $< $(BLANK_INFO) $(LANG_SPECIAL_INFO) > $@ $(XWLANG)%.$(FRANK_EXT): dawg$(XWLANG)%.stamp $(XWLANG)%_flags.bin $(XWLANG)%_newheader.bin $(XWLANG)_charcount.bin table.bin values.bin frankspecials.bin diff --git a/xwords4/dawg/frank_mkspecials.py b/xwords4/dawg/frank_mkspecials.py new file mode 100755 index 000000000..0d69af876 --- /dev/null +++ b/xwords4/dawg/frank_mkspecials.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +# Copyright 2001 - 2020 by Eric House (xwords@eehouse.org) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Given arguments consisting of triples, first a string and then pbitm +# files representing bitmaps. For each triple, print out the string and +# then the converted bitmaps. + +import os, subprocess, struct, sys + +def doFile(bmp): + assert os.path.exists(bmp), 'no such file: {}'.format(bmp) + with open(bmp, 'r') as file: + subprocess.run(['../pbitm2bin.py'], stdin=file) + +def doOne( face, largebmp, smallbmp ): + # print('doOne({}, {}, {})'.format(face, largebmp, smallbmp), file=sys.stderr) + with os.fdopen(sys.stdout.fileno(), 'wb', closefd=False) as stdout: + encoded = face.encode('utf-8') + stdout.write(struct.pack('B', len(encoded))) + stdout.write(encoded) + + for fil in [ largebmp, smallbmp ]: + print('looking at {}'.format(fil), file=sys.stderr) + doFile(fil) + +def main(): + argv = sys.argv + for first in range(1, len(argv), 3): + (face, largebmp, smallbmp) = argv[first:first+3] + doOne(face, largebmp, smallbmp) + +############################################################################## +if __name__ == '__main__': + main() diff --git a/xwords4/dawg/pbitm2bin.py b/xwords4/dawg/pbitm2bin.py new file mode 100755 index 000000000..2e8bd78f0 --- /dev/null +++ b/xwords4/dawg/pbitm2bin.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# +# Copyright 2001-2020 by Eric House (xwords@eehouse.org). All +# rights reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# +# Given a pbitm on stdin, a text bitmap file where '#' indicates a set +# bit and '-' indicates a clear bit, convert into binary form (on +# stdout) where there's one bit per bit plus a byte each for the width +# and height. Nothing for bitdepth at this point. And no padding: if +# the number of bits in a row isn't a multiple of 8 then one byte will +# hold the last bits of one row and the first of another. + +import os, struct, sys + +lines = [ line.strip() for line in sys.stdin ] +nRows = len(lines) +nCols = 0 +bits = '' + +# first gather information and sanity-check the data + +for line in lines: + lineLen = len(line) + if nCols == 0: + nCols = lineLen + else: + assert nCols == lineLen, 'line of inconsistent length' + bits += line + +with os.fdopen(sys.stdout.fileno(), "wb", closefd=False) as stdout: + stdout.write(struct.pack('B', nCols)) + + # if we've been given an empty file, print out a single null byte + # and be done. That'll be the convention for "non-existant + # bitmap". + + if nCols > 0: + stdout.write(struct.pack( 'B', nRows ) ) + print( 'emitting {}x{} bitmap'.format(nCols, nRows), file=sys.stderr) + + while bits: + cur = bits[:8] + bits = bits[8:] + + byt = 0 + for indx in range(len(cur)): + ch = cur[indx] + assert ch == '-' or ch == '#', "char {} neither '#' nor '-'".format(ch) + if ch == '#': byt |= 1 << (7 - indx) + + stdout.write(struct.pack( 'B', byt )) + + stdout.flush()