|
| 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