Skip to content

Commit 1555e8d

Browse files
committed
first commit
0 parents  commit 1555e8d

35 files changed

+2973
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__pycache__/
2+
3+
*.log
4+
*.sfd
5+
*.[0-9][0-9][0-9][0-9]gf
6+
7+
examples/example_inputs/

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018--2023
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 267 additions & 0 deletions
Large diffs are not rendered by default.

examples/cmr10/run_cmr10.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
from pathlib import Path
3+
from time import time, sleep
4+
from urllib.request import urlretrieve
5+
from urllib.error import URLError
6+
7+
from mf2ff import Mf2ff
8+
9+
if __name__ == '__main__':
10+
example_dir = Path(__file__).parent
11+
inputs_dir = example_dir / '..' / 'example_inputs' / 'cm'
12+
inputs_dir.mkdir(parents=True, exist_ok=True)
13+
os.chdir(inputs_dir) # mf will search in cwd
14+
15+
urls = [
16+
'http://mirrors.ctan.org/fonts/cm/mf/accent.mf',
17+
'http://mirrors.ctan.org/fonts/cm/mf/cmbase.mf',
18+
'http://mirrors.ctan.org/fonts/cm/mf/cmr10.mf',
19+
'http://mirrors.ctan.org/fonts/cm/mf/comlig.mf',
20+
'http://mirrors.ctan.org/fonts/cm/mf/greeku.mf',
21+
'http://mirrors.ctan.org/fonts/cm/mf/punct.mf',
22+
'http://mirrors.ctan.org/fonts/cm/mf/roman.mf',
23+
'http://mirrors.ctan.org/fonts/cm/mf/romand.mf',
24+
'http://mirrors.ctan.org/fonts/cm/mf/romanl.mf',
25+
'http://mirrors.ctan.org/fonts/cm/mf/romanp.mf',
26+
'http://mirrors.ctan.org/fonts/cm/mf/romanu.mf',
27+
'http://mirrors.ctan.org/fonts/cm/mf/romlig.mf',
28+
'http://mirrors.ctan.org/fonts/cm/mf/romspl.mf',
29+
'http://mirrors.ctan.org/fonts/cm/mf/romspu.mf',
30+
'http://mirrors.ctan.org/fonts/cm/mf/romsub.mf',
31+
'http://mirrors.ctan.org/fonts/cm/mf/sym.mf',
32+
]
33+
print(f'retrieving {len(urls)} mf files...')
34+
for i_url, url in enumerate(urls):
35+
filename = url.rsplit('/', 1)[1]
36+
i_attempt = 0
37+
while True:
38+
try:
39+
urlretrieve(url, inputs_dir / filename)
40+
break
41+
except URLError as e:
42+
if i_attempt < 5:
43+
print(f'error in attempt {i_attempt+1}/5 of retrieving URL {i_url+1}/{len(urls)} ({url})')
44+
sleep(5)
45+
i_attempt += 1
46+
else:
47+
print('tried 5 times, doesn\'t work')
48+
raise e
49+
50+
start = time()
51+
mf2ff = Mf2ff()
52+
mf2ff.input_file = str(inputs_dir / 'cmr10')
53+
jobname = example_dir / 'cmr10'
54+
mf2ff.jobname = str(jobname)
55+
mf2ff.mf_options.append('-jobname=' + str(jobname))
56+
mf2ff.fontname = 'cmr10'
57+
mf2ff.options['cull-at-shipout'] = True
58+
mf2ff.options['remove-artifacts'] = True
59+
mf2ff.run()
60+
print(f'took {time()-start:.3f} sec')
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
from pathlib import Path
3+
from time import time
4+
from urllib.request import urlopen
5+
6+
from mf2ff import Mf2ff
7+
8+
if __name__ == '__main__':
9+
example_dir = Path(__file__).parent
10+
inputs_dir = example_dir / '..' / 'example_inputs' / 'dangerous_bend_symbol'
11+
inputs_dir.mkdir(parents=True, exist_ok=True)
12+
os.chdir(inputs_dir) # mf will search in cwd
13+
14+
url = 'http://mirrors.ctan.org/fonts/manual/mf/mfman.mf'
15+
response = urlopen(url)
16+
data = response.read()
17+
file_content = data.decode('utf-8')
18+
# everything between the line after the first 'Dangerous bend symbol' and the line
19+
# before the next 'Figure' line is the code
20+
symbol_code = file_content.split('Dangerous bend symbol', 1)[1].split('\n', 1)[1].split('Figure', 1)[0].rsplit('\n', 1)[0]
21+
symbol_mf_str = (
22+
# everything before the line of the first figure is important
23+
file_content.split('Figure',1)[0].rsplit('\n',1)[0]
24+
+ '\n\n'
25+
+ symbol_code
26+
# everything after the last char is important
27+
+ file_content.rsplit('endchar;',1)[1]
28+
)
29+
input_file = inputs_dir / 'dangerous_bend_symbol.mf'
30+
with open(input_file, 'w') as f:
31+
f.write(symbol_mf_str)
32+
33+
start = time()
34+
mf2ff = Mf2ff()
35+
mf2ff.input_file = str(input_file)
36+
jobname = example_dir / 'dangerous_bend_symbol'
37+
mf2ff.jobname = str(jobname)
38+
mf2ff.mf_options.append('-jobname=' + str(jobname))
39+
mf2ff.options['cull-at-shipout'] = True
40+
mf2ff.run()
41+
print(f'took {time()-start:.3f} sec')
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
from pathlib import Path
3+
from time import time
4+
from urllib.request import urlopen
5+
6+
from mf2ff import Mf2ff
7+
8+
if __name__ == '__main__':
9+
example_dir = Path(__file__).parent
10+
inputs_dir = example_dir / '..' / 'example_inputs' / 'el_palo_alto'
11+
inputs_dir.mkdir(parents=True, exist_ok=True)
12+
os.chdir(inputs_dir) # mf will search in cwd
13+
14+
url = 'http://mirrors.ctan.org/fonts/manual/mf/mfman.mf'
15+
response = urlopen(url)
16+
data = response.read()
17+
file_content = data.decode('utf-8')
18+
# everything between the line after the first 'El Palo Alto' and the line
19+
# before the next 'Figure' line is the code
20+
tree_code = file_content.split('El Palo Alto', 1)[1].split('\n', 1)[1].split('Figure', 1)[0].rsplit('\n', 1)[0]
21+
tree_paths = tree_code.split('\n', 1)[1].rsplit('\n', 10)[0]
22+
tree_mf_str = (
23+
# everything before the line of the first figure is important
24+
file_content.split('Figure', 1)[0].rsplit('\n', 1)[0]
25+
+ '\n\n'
26+
+ 'beginchar("T", .5in#, 1.25in#, 0);\n' # see The METAFONTbook, p. 126
27+
+ tree_paths
28+
+ '\n' # below: see The METAFONTbook, p. 126
29+
+ 'fill superellipse((w, .5h), (.5w, h), (0, .5h), (.5w, 0), .8);\n'
30+
+ 'branch0 = trunk;\n'
31+
+ 'for n = 0 upto 12:\n'
32+
+ ' unfill branch[n] shifted (150, 50) scaled (w/300);\n'
33+
+ 'endfor endchar;\n'
34+
# everything after the last char is important
35+
+ file_content.rsplit('endchar;', 1)[1]
36+
) # TODO mode
37+
input_file = inputs_dir / 'el_palo_alto.mf'
38+
with open(input_file, 'w') as f:
39+
f.write(tree_mf_str)
40+
41+
start = time()
42+
mf2ff = Mf2ff()
43+
mf2ff.input_file = str(input_file)
44+
jobname = example_dir / 'el_palo_alto'
45+
mf2ff.jobname = str(jobname)
46+
mf2ff.mf_options.append('-jobname=' + str(jobname))
47+
mf2ff.options['cull-at-shipout'] = True
48+
mf2ff.run()
49+
print(f'took {time()-start:.3f} sec')
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pathlib import Path
2+
from time import time
3+
from urllib.request import urlopen
4+
5+
from mf2ff import Mf2ff
6+
7+
if __name__ == '__main__':
8+
example_dir = Path(__file__).parent
9+
inputs_dir = example_dir / '..' / 'example_inputs' / 'jofa_logo'
10+
inputs_dir.mkdir(parents=True, exist_ok=True)
11+
12+
url = 'http://mirrors.ctan.org/fonts/manual/mf/mfman.mf'
13+
filename = 'jofa.mf'
14+
response = urlopen(url)
15+
data = response.read()
16+
file_content = data.decode('utf-8')
17+
# everything between the line after the first 'JofA logo' and the line
18+
# before the next 'Figure' line is the code
19+
logo_code = file_content.split('JofA logo', 1)[1].split('\n', 1)[1].split('Figure', 1)[0].rsplit('\n', 1)[0]
20+
logo_mf_str = (
21+
# everything before the line of the first figure is important
22+
file_content.split('Figure',1)[0].rsplit('\n',1)[0]
23+
+ '\n\n'
24+
+ logo_code
25+
# everything after the last char is important
26+
+ file_content.rsplit('endchar;',1)[1]
27+
)
28+
input_file = inputs_dir / 'jofa_logo.mf'
29+
with open(input_file, 'w') as f:
30+
f.write(logo_mf_str)
31+
32+
start = time()
33+
mf2ff = Mf2ff()
34+
mf2ff.input_file = str(input_file)
35+
jobname = example_dir / 'jofa_logo'
36+
mf2ff.jobname = str(jobname)
37+
mf2ff.mf_options.append('-jobname=' + str(jobname))
38+
mf2ff.options['cull-at-shipout'] = True
39+
mf2ff.run()
40+
print(f'took {time()-start:.3f} sec')

img/examples/cmr10/cmr10.png

74.7 KB
Loading
42.7 KB
Loading
49.6 KB
Loading

0 commit comments

Comments
 (0)