Skip to content

Commit 62c2a5d

Browse files
committed
Add merge python version script
1 parent 2217dbf commit 62c2a5d

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

change-familyname.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import fontforge
4+
5+
def change_font_family_name(input_font, output_font, new_family_name):
6+
"""
7+
Change the font family name of a font file.
8+
9+
Args:
10+
input_font (str): Path to the input font file
11+
output_font (str): Path to save the modified font
12+
new_family_name (str): New family name for the font
13+
"""
14+
try:
15+
# Open the font
16+
font = fontforge.open(input_font)
17+
18+
# Get the current font information
19+
old_family_name = font.familyname
20+
print(f"Current font family name: {old_family_name}")
21+
22+
# Change the family name
23+
font.familyname = new_family_name
24+
25+
# Update related font names to maintain consistency
26+
if font.fontname:
27+
font.fontname = font.fontname.replace(old_family_name, new_family_name).replace(" ", "")
28+
29+
if font.fullname:
30+
font.fullname = font.fullname.replace(old_family_name, new_family_name)
31+
32+
# Update PostScript names if they exist
33+
for name_id in (1, 2, 3, 4, 6, 16, 17, 18, 20, 21, 22):
34+
try:
35+
if font.sfnt_names:
36+
for index, (lang, string_type, string_value) in enumerate(font.sfnt_names):
37+
if string_type == name_id:
38+
new_value = string_value.replace(old_family_name, new_family_name)
39+
font.sfnt_names = (font.sfnt_names[:index] +
40+
((lang, string_type, new_value),) +
41+
font.sfnt_names[index+1:])
42+
except:
43+
pass
44+
45+
# Save the modified font
46+
print(f"Saving font with new family name: {new_family_name}")
47+
font.generate(output_font)
48+
font.close()
49+
print(f"Font saved successfully to: {output_font}")
50+
51+
except Exception as e:
52+
print(f"Error: {e}")
53+
sys.exit(1)
54+
55+
if __name__ == "__main__":
56+
if len(sys.argv) != 4:
57+
print("Usage: python change_font_family.py <input_font> <output_font> <new_family_name>")
58+
sys.exit(1)
59+
60+
input_font = sys.argv[1]
61+
output_font = sys.argv[2]
62+
new_family_name = sys.argv[3]
63+
64+
change_font_family_name(input_font, output_font, new_family_name)

merge-kr-on-jp.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
import fontforge
3+
import time
4+
import sys
5+
import os
6+
7+
family_name = "Monoplex Nerd"
8+
wide_family_name = "Monoplex Wide Nerd"
9+
10+
safe_family_name = "MonoplexNerd"
11+
safe_wide_family_name = "MonoplexWideNerd"
12+
13+
def merge_font(base_font_path, second_font_path, style, is_wide=False):
14+
"""Merge two fonts and save the result"""
15+
if is_wide:
16+
print(f"Merge {wide_family_name} {style}...")
17+
family = wide_family_name
18+
safe_family = safe_wide_family_name
19+
fullname_prefix = "Monoplex Wide Nerd Font "
20+
else:
21+
print(f"Merge {family_name} {style}...")
22+
family = family_name
23+
safe_family = safe_family_name
24+
fullname_prefix = "Monoplex Nerd Font "
25+
26+
# Open the base font
27+
font = fontforge.open(base_font_path)
28+
29+
print("Before changes:")
30+
print(f" - Font name: {font.fontname}")
31+
print(f" - Family name: {font.familyname}")
32+
print(f" - Full name: {font.fullname}")
33+
34+
# Merge the second font
35+
font.mergeFonts(second_font_path)
36+
37+
# Change the font family name
38+
font.fontname = f"{safe_family}-{style}"
39+
font.familyname = family
40+
font.fullname = f"{fullname_prefix}{style}"
41+
42+
print("After changes:")
43+
print(f" - Font name: {font.fontname}")
44+
print(f" - Family name: {font.familyname}")
45+
print(f" - Full name: {font.fullname}")
46+
47+
# Save the merged font
48+
output_path = f"build/{safe_family_name}-{style}.ttf" if not is_wide else f"build/{safe_wide_family_name}-{style}.ttf"
49+
font.generate(output_path)
50+
# font.close()
51+
52+
# List of all styles
53+
styles = [
54+
"Bold", "SemiBold", "Medium", "Text", "Regular", "Light", "ExtraLight", "Thin",
55+
"BoldItalic", "SemiBoldItalic", "MediumItalic", "TextItalic", "Italic", "LightItalic", "ExtraLightItalic", "ThinItalic"
56+
]
57+
58+
# Process wide fonts
59+
for style in styles:
60+
base_font_path = f"build/PlemolJP35Console_NF/PlemolJP35ConsoleNF-{style}.ttf"
61+
second_font_path = f"build/MonoplexKRWide/MonoplexKRWide-{style}.ttf"
62+
merge_font(base_font_path, second_font_path, style, is_wide=True)
63+
64+
# Process normal width fonts
65+
for style in styles:
66+
base_font_path = f"build/PlemolJPConsole_NF/PlemolJPConsoleNF-{style}.ttf"
67+
second_font_path = f"build/MonoplexKR/MonoplexKR-{style}.ttf"
68+
merge_font(base_font_path, second_font_path, style, is_wide=False)
69+
70+
print("Font merging completed successfully.")

0 commit comments

Comments
 (0)