[Feature] Slim down foreign fonts during build#98
Conversation
| mv ${ss_translations_repo}/fonts/NotoSansAR-Regular.ttf ${ss_translations_repo}/fonts/NotoSansAR-Regular-Original.ttf | ||
| mv ${ss_translations_repo}/fonts/NotoSansJP-Regular.ttf ${ss_translations_repo}/fonts/NotoSansJP-Regular-Original.ttf | ||
| mv ${ss_translations_repo}/fonts/NotoSansKR-Regular.ttf ${ss_translations_repo}/fonts/NotoSansKR-Regular-Original.ttf | ||
| mv ${ss_translations_repo}/fonts/NotoSansSC-Regular.ttf ${ss_translations_repo}/fonts/NotoSansSC-Regular-Original.ttf | ||
| mv ${ss_translations_repo}/fonts/NotoSansTH-Regular.ttf ${ss_translations_repo}/fonts/NotoSansTH-Regular-Original.ttf |
There was a problem hiding this comment.
Not a bash expert, but googling yields this as a way to avoid hard-coded maintenance burden:
for font_file in "${ss_translations_repo}/fonts/*.ttf"; do
# Extract filename without extension
name="${font_file%.*}"
new_name="${name}-Original.ttf"
mv "$file" "${new_name}"
done| pyftsubset ${ss_translations_repo}/fonts/NotoSansAR-Regular-Original.ttf --text="${all_chars}" --output-file=${ss_translations_repo}/fonts/NotoSansAR-Regular.ttf || exit | ||
| pyftsubset ${ss_translations_repo}/fonts/NotoSansJP-Regular-Original.ttf --text="${all_chars}" --output-file=${ss_translations_repo}/fonts/NotoSansJP-Regular.ttf || exit | ||
| pyftsubset ${ss_translations_repo}/fonts/NotoSansKR-Regular-Original.ttf --text="${all_chars}" --output-file=${ss_translations_repo}/fonts/NotoSansKR-Regular.ttf || exit | ||
| pyftsubset ${ss_translations_repo}/fonts/NotoSansSC-Regular-Original.ttf --text="${all_chars}" --output-file=${ss_translations_repo}/fonts/NotoSansSC-Regular.ttf || exit | ||
| pyftsubset ${ss_translations_repo}/fonts/NotoSansTH-Regular-Original.ttf --text="${all_chars}" --output-file=${ss_translations_repo}/fonts/NotoSansTH-Regular.ttf || exit |
There was a problem hiding this comment.
Similarly, this could be something like:
for font_file in "${ss_translations_repo}/fonts/*.ttf"; do
# Extract filename without extension
name="${font_file%.*}"
# Replace "-Original" with empty string
final_name="${name/-Original/}.ttf"
# Trim the font file to our specified subset
pyftsubset "${ss_translations_repo}/fonts/${font_file}" --text="${all_chars}" --output-file="${ss_translations_repo}/fonts/${final_name}" || exit
done|
Now that I've dug into this PR and the related SeedSigner/seedsigner-translations#48 a bit, a couple of thoughts are leading me toward a slightly different implementation.
The bash scripting here isn't terrible but doing anything more advanced really calls for python. A python script could:
Having this as a python script would also make it easier to run in local dev. And maybe even write some unit tests for it in the translations repo. |
|
That all being said, while I prefer what I laid out above, I don't view any of the current approach in this PR to be objectionable. Judgment call: Is this PR enough of a win to move it more quickly so it can be in the next release or does it just not matter if the next release is slightly bloated but subsequent releases will be quite optimal? I'm fine with either. |
Dependency on SeedSigner/seedsigner-translations#48 and SeedSigner/seedsigner#819. Do not merge until both of these are merged first.
This pull requests is related to at least 2 other other pull requests. One in the seedsigner app repo and the other in the seedsigner-translations repo.
The objective of these 3 pull requests is:
This pull request makes these changes: