diff --git a/fonts/CMakeLists.txt b/fonts/CMakeLists.txt index 38f3c36..643cf70 100644 --- a/fonts/CMakeLists.txt +++ b/fonts/CMakeLists.txt @@ -10,12 +10,9 @@ find_program(PYFTSUBSET_FOUND pyftsubset) if (PYFTSUBSET_FOUND) add_custom_target(fonts - pyftsubset SourceHanSerifJP-Regular.otf --text-file=uchars.txt --output-file=${CMAKE_CURRENT_SOURCE_DIR}/mincho.otf - DEPENDS uchars.txt SourceHanSerifJP-Regular.otf) - - add_custom_command(OUTPUT uchars.txt - COMMAND uchars > uchars.txt) - - add_custom_command(OUTPUT SourceHanSerifJP-Regular.otf - COMMAND wget -O SourceHanSerifJP-Regular.otf https://github.com/adobe-fonts/source-han-serif/blob/release/SubsetOTF/JP/SourceHanSerifJP-Regular.otf?raw=true) + COMMAND uchars > uchars.txt + COMMAND wget -O SourceHanSerifJP-Regular.otf https://github.com/adobe-fonts/source-han-serif/blob/release/SubsetOTF/JP/SourceHanSerifJP-Regular.otf?raw=true + COMMAND pyftsubset SourceHanSerifJP-Regular.otf --text-file=uchars.txt --output-file=subset.otf + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/adjust_metrics.py subset.otf ${CMAKE_CURRENT_SOURCE_DIR}/mincho.otf + ) endif() diff --git a/fonts/adjust_metrics.py b/fonts/adjust_metrics.py new file mode 100755 index 0000000..ce85551 --- /dev/null +++ b/fonts/adjust_metrics.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +import sys +from fontTools.ttLib import TTFont + +if len(sys.argv) != 3: + print('Usage: adjust_metrics.py infile outfile') + exit(1) + +font = TTFont(sys.argv[1]) + +hhea = font['hhea'] +os2 = font['OS/2'] + +if hhea.ascent != os2.sTypoAscender: + print(f'Changing hhea.ascent from {hhea.ascent} to {os2.sTypoAscender}') + hhea.ascent = os2.sTypoAscender + +if hhea.descent != os2.sTypoDescender: + print(f'Changing hhea.descent from {hhea.descent} to {os2.sTypoDescender}') + hhea.descent = os2.sTypoDescender + +font.save(sys.argv[2]) diff --git a/fonts/mincho.otf b/fonts/mincho.otf index d17b2ca..822d7d0 100644 Binary files a/fonts/mincho.otf and b/fonts/mincho.otf differ