-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge_pbff.py
executable file
·74 lines (66 loc) · 2.95 KB
/
merge_pbff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
###############################################################################
# #
# Copies glyph data from file A to file B #
# while preserving metrics from file B. #
# #
###############################################################################
import argparse
import json
import os.path
import re
import struct
import sys
from lib.pbff import *
# Copyright (c) 2017 Johannes Neubrand
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
def process(fh1, fh2, out=sys.stdout):
font1 = Font(fh1)
font2 = Font(fh2)
processed_codepoints = []
for codepoint in font2.glyphs.keys():
processed_codepoints += [codepoint]
if codepoint not in font1.glyphs:
continue
glyph_o = font1.glyphs[codepoint]
glyph = font2.glyphs[codepoint]
glyph['data'] = [y[:] for y in font1.glyphs[codepoint]['data']]
while len(glyph['data']) < glyph['height']:
glyph['data'] += [[True * glyph['width']]]
while len(glyph['data']) > glyph['height']:
del glyph['data'][-1]
for line in glyph['data']:
while len(line) < glyph_o['width']:
line += [False]
while len(line) < glyph['width']:
line += [True]
if len(line) > glyph['width']:
line = line[:glyph['width']]
font2.glyphs[codepoint] = glyph
font2.output()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('file1',
help='file whose glyphs to take')
parser.add_argument('file2',
help='file whose glyphs to replace')
a = parser.parse_args()
with open(a.file1, 'r') as f1, open(a.file2, 'r') as f2:
process(f1, f2)