]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/compile-unifont.py
1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2013-2014 David Herrmann <dh.herrmann@gmail.com>
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 # Parse a unifont.hex file and produce a compressed binary-format.
24 from __future__
import print_function
31 # Write "bits" array as binary output.
34 def write_bin_entry(entry
):
36 if l
!= 32 and l
!= 64:
40 entry
+= "0" * (64 - l
)
42 sys
.stdout
.buffer.write(struct
.pack('B', int(l
/ 32))) # width
43 sys
.stdout
.buffer.write(struct
.pack('B', 0)) # padding
44 sys
.stdout
.buffer.write(struct
.pack('H', 0)) # padding
45 sys
.stdout
.buffer.write(struct
.pack('I', 0)) # padding
48 for j
in range(0, 16):
53 c
= int(entry
[i
:i
+2], 16)
56 sys
.stdout
.buffer.write(struct
.pack('B', c
))
59 sys
.stdout
.buffer.write(struct
.pack('B', 0x44)) # ASCII: 'D'
60 sys
.stdout
.buffer.write(struct
.pack('B', 0x56)) # ASCII: 'V'
61 sys
.stdout
.buffer.write(struct
.pack('B', 0x44)) # ASCII: 'D'
62 sys
.stdout
.buffer.write(struct
.pack('B', 0x48)) # ASCII: 'H'
63 sys
.stdout
.buffer.write(struct
.pack('B', 0x52)) # ASCII: 'R'
64 sys
.stdout
.buffer.write(struct
.pack('B', 0x4d)) # ASCII: 'M'
65 sys
.stdout
.buffer.write(struct
.pack('B', 0x55)) # ASCII: 'U'
66 sys
.stdout
.buffer.write(struct
.pack('B', 0x46)) # ASCII: 'F'
67 sys
.stdout
.buffer.write(struct
.pack('<I', 0)) # compatible-flags
68 sys
.stdout
.buffer.write(struct
.pack('<I', 0)) # incompatible-flags
69 sys
.stdout
.buffer.write(struct
.pack('<I', 32)) # header-size
70 sys
.stdout
.buffer.write(struct
.pack('<H', 8)) # glyph-header-size
71 sys
.stdout
.buffer.write(struct
.pack('<H', 2)) # glyph-stride
72 sys
.stdout
.buffer.write(struct
.pack('<Q', 32)) # glyph-body-size
75 for idx
in range(len(bits
)):
76 write_bin_entry(bits
[idx
])
79 # Parse hex file into "bits" array
82 def parse_hex_line(bits
, line
):
83 m
= re
.match(r
"^([0-9A-Fa-f]+):([0-9A-Fa-f]+)$", line
)
87 idx
= int(m
.group(1), 16)
90 # insert skipped lines
91 for i
in range(len(bits
), idx
):
99 for line
in sys
.stdin
:
102 if line
.startswith("#"):
105 parse_hex_line(bits
, line
)
110 # In normal mode we simply read line by line from standard-input and write the
111 # binary-file to standard-output.
114 if __name__
== "__main__":