Skip to content

[Feature] Slim down foreign fonts during build#98

Merged
newtonick merged 1 commit intoSeedSigner:mainfrom
newtonick:slim-fonts
Mar 5, 2026
Merged

[Feature] Slim down foreign fonts during build#98
newtonick merged 1 commit intoSeedSigner:mainfrom
newtonick:slim-fonts

Conversation

@newtonick
Copy link
Copy Markdown
Collaborator

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:

  • Move the large foreign language font files from the seedsigner app repo to the translation repo (a submodule in the app repo)
  • Update the build script to include slimed down versions the foreign language font files that only include the character set used in seedsigner-translations. This should allow the final image to be ~10MB smaller (or more) than it is today.

This pull request makes these changes:

  • create compile_translations_and_fonts function
  • move existing create virtual env to compile translation files to this new function
  • add steps in compile_translations_and_fonts to slim down the foreign language fonts to only include required characters

 - create compile_translations_and_fonts function
 - move existing create virtual env to compile translation files to this new function
 - add steps in compile_translations_and_fonts to slim down the foreign language fonts to only include required characters
Comment thread opt/build.sh
Comment on lines +73 to +77
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread opt/build.sh
Comment on lines +80 to +84
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@kdmukai
Copy link
Copy Markdown
Contributor

kdmukai commented Jan 22, 2026

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 Asian fonts all seem to have some degree of redundant character sets (e.g. the Japanese font might include all the Korean characters). With this PR building a single master char list, that means those redundant character sets will be included multiple times (e.g. the Korean chars will be in the Korean font AND will be kept in the Japanese font). The heaviest consequence would probably be the Japanese font which also includes a lot of (all?) the complex Chinese characters.

  • In the other direction, Persian and Arabic would both use the same font file. So we would want at least some kind of smart char set selection.

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.

@kdmukai
Copy link
Copy Markdown
Contributor

kdmukai commented Jan 22, 2026

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.

@newtonick newtonick merged commit 2bca43f into SeedSigner:main Mar 5, 2026
@newtonick newtonick moved this from 0.8.7 Needs Code Review to 0.8.7 Merged in @SeedSigner Development Board Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 0.8.7 Merged

Development

Successfully merging this pull request may close these issues.

2 participants