| 1 |
# This is a fontforge python script; use fontforge -lang=py -script to run it |
| 2 |
# coding=utf-8 |
| 3 |
# pylint: disable=import-error |
| 4 |
|
| 5 |
|
| 6 |
""" |
| 7 |
Python fontforge script to simplify a font. This only exists |
| 8 |
because simplification doesn't work in squarize.py due to bugs |
| 9 |
in fontforge. |
| 10 |
|
| 11 |
Copyright (C) 2016-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 12 |
|
| 13 |
This file is part of Gregorio. |
| 14 |
|
| 15 |
Gregorio is free software: you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation, either version 3 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
Gregorio is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with Gregorio. If not, see <http://www.gnu.org/licenses/>. |
| 27 |
|
| 28 |
This script takes a font file, simplifies it and overwrites it. |
| 29 |
|
| 30 |
Basic use : |
| 31 |
fontforge -script simplify.py fontfile |
| 32 |
""" |
| 33 |
|
| 34 |
|
| 35 |
import sys |
| 36 |
import getopt |
| 37 |
import fontforge |
| 38 |
|
| 39 |
|
| 40 |
def usage(): |
| 41 |
"Prints help message." |
| 42 |
print(""" |
| 43 |
Python fontforge script to simplify a font. |
| 44 |
|
| 45 |
Usage: |
| 46 |
fontforge -script simplify.py fontfile |
| 47 |
""") |
| 48 |
|
| 49 |
def main(): |
| 50 |
"Main function." |
| 51 |
try: |
| 52 |
opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help"]) |
| 53 |
except getopt.GetoptError: |
| 54 |
# print help information and exit: |
| 55 |
usage() |
| 56 |
sys.exit(2) |
| 57 |
outputfile = None |
| 58 |
for opt, arg in opts: |
| 59 |
if opt in ("-h", "--help"): |
| 60 |
usage() |
| 61 |
sys.exit() |
| 62 |
if len(args) == 0: |
| 63 |
usage() |
| 64 |
sys.exit(2) |
| 65 |
fontfile = args[0] |
| 66 |
font = fontforge.open(fontfile) |
| 67 |
font.selection.all() |
| 68 |
font.simplify(0.1, ('mergelines','ignoreslopes','setstarttoextremum')) |
| 69 |
font.generate(fontfile) |
| 70 |
font.close() |
| 71 |
|
| 72 |
if __name__ == "__main__": |
| 73 |
main() |