Skip to content

TrueType.php: Convert encoding of naming table strings#14

Merged
nicolaasuni merged 3 commits into
tecnickcom:mainfrom
mreiden:name-table-string-encoding
Feb 4, 2026
Merged

TrueType.php: Convert encoding of naming table strings#14
nicolaasuni merged 3 commits into
tecnickcom:mainfrom
mreiden:name-table-string-encoding

Conversation

@mreiden

@mreiden mreiden commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

The strings in the TTF name table are encoded differently depending on platformId and encodingId. Convert using mb_convert_encoding or iconv if those functions are available.

Unicode uses UTF-16BE encoding for all strings, Macintosh encoding 0 uses MacRoman, and Windows uses UTF-16BE with 3 exceptions.

Converting the encoding prevents gibberish when creating a font subset while maintaining Unicode and Windows UTF-16BE tables while dropping others. Dropping the single License Description string in DejaVuSans-Bold saves around 74k when the string is encoded in UTF-16BE.

Noticed when using https://fontdrop.info/ comparing subset files generated with this package to those created via https://www.lddgo.net/en/convert/font-subset.

The strings in the TTF name table are encoded differently depending on platformId and encodingId.  Convert using mb_convert_encoding or iconv if those functions are available.

Unicode uses UTF-16BE encoding for all strings, Macintosh encoding 0 uses MacRoman, and Windows uses UTF-16BE with 3 exceptions.

Converting the encoding prevents gibberish when creating a font subset while maintaining Unicode and Windows UTF-16BE tables while dropping others.
@mreiden
mreiden requested a review from nicolaasuni as a code owner January 26, 2026 20:13
@codecov-commenter

codecov-commenter commented Jan 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.85185% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.29%. Comparing base (5036996) to head (6348dbc).

Files with missing lines Patch % Lines
src/Import/TrueType.php 51.85% 13 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #14      +/-   ##
============================================
- Coverage     86.82%   86.29%   -0.54%     
- Complexity      550      561      +11     
============================================
  Files            12       12              
  Lines          1822     1846      +24     
============================================
+ Hits           1582     1593      +11     
- Misses          240      253      +13     
Flag Coverage Δ
php-8.1-ubuntu-latest 86.29% <51.85%> (-0.54%) ⬇️
php-8.2-ubuntu-latest 86.29% <51.85%> (-0.54%) ⬇️
php-8.3-ubuntu-latest 86.29% <51.85%> (-0.54%) ⬇️
php-8.4-ubuntu-latest 86.29% <51.85%> (-0.54%) ⬇️
php-8.5-ubuntu-latest 86.29% <51.85%> (-0.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicolaasuni
nicolaasuni merged commit 6908ec5 into tecnickcom:main Feb 4, 2026
6 checks passed
@nicolaasuni

Copy link
Copy Markdown
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants