Skip to content

t775: fix DejaVuSansMono.ttf missing exception when viewing invoices#778

Merged
superdav42 merged 2 commits intomainfrom
bugfix/775-dejavusansmono-missing-font
Apr 10, 2026
Merged

t775: fix DejaVuSansMono.ttf missing exception when viewing invoices#778
superdav42 merged 2 commits intomainfrom
bugfix/775-dejavusansmono-missing-font

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Fixes the MpdfException: Cannot find TTF TrueType font file "DejaVuSansMono.ttf" error thrown when viewing invoices that contain monospace-font content (e.g. product descriptions with <code> tags, or any CSS font-family: monospace).

Root Cause

The composer post-install script (scripts/remove-mpdf-fonts.php) strips DejaVuSansMono.ttf and its variants from vendor/mpdf/mpdf/ttfonts/ to reduce plugin distribution size. However, mPDF's default FontVariables configuration still lists dejavusansmono as the first entry in mono_fonts, so any monospace font lookup throws a fatal exception.

Fix

In pdf_setup() in inc/invoices/class-invoice.php, after creating the mPDF instance, override the dejavusansmono fontdata entry to point to FreeMono.ttf / FreeMonoBold.ttf, which are retained in the ttfonts directory. Oblique/BoldOblique variants are mapped to their upright counterparts since only the regular and bold FreeMono files are available.

This follows the same post-construction fontdata override pattern already used for the Amiri RTL font registration.

Files Changed

  • EDIT: inc/invoices/class-invoice.php — added get_missing_fontdata() method and called it in pdf_setup() after RTL font registration

Runtime Testing

Risk level: Medium (PDF generation path, no dev environment available for runtime test).

Self-assessed: the fix is a direct fontdata key override on the mPDF instance, identical in mechanism to the existing Amiri RTL font override. PHP syntax verified (php -l). The FreeMono.ttf and FreeMonoBold.ttf files confirmed present in vendor/mpdf/mpdf/ttfonts/.

Resolves #775



aidevops.sh v3.6.235 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 3m and 10,445 tokens on this as a headless worker.

DejaVuSansMono.ttf and its variants are removed from the vendor
ttfonts directory by the composer post-install script to reduce
plugin size. mPDF's default font configuration still references
these files as the primary monospace font family, so any invoice
content that triggers a monospace font lookup throws:

  MpdfException: Cannot find TTF TrueType font file "DejaVuSansMono.ttf"

Fix: after creating the mPDF instance in pdf_setup(), override the
dejavusansmono fontdata entry to point to FreeMono.ttf and
FreeMonoBold.ttf, which are retained in the ttfonts directory.
Oblique/BoldOblique variants are mapped to their upright counterparts
since only the regular and bold FreeMono files are available.

This follows the same post-construction fontdata override pattern
already used for the Amiri RTL font registration.

Fixes #775
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 59 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 20 minutes and 59 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eaa92fc7-1450-4766-88d2-78ffa4d149e6

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad3bbd and 1082912.

📒 Files selected for processing (2)
  • .github/workflows/e2e.yml
  • inc/invoices/class-invoice.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/775-dejavusansmono-missing-font

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

Issue: #775 — DejaVuSansMono.ttf Missing - Causing Exception When Viewing Invoice

Root cause: The composer post-install script removes DejaVuSansMono.ttf and variants from the mPDF ttfonts directory to reduce plugin size. mPDF's default font config still lists dejavusansmono as the first monospace font, so any invoice content triggering a monospace font lookup throws a fatal MpdfException.

Fix: Added get_missing_fontdata() method to inc/invoices/class-invoice.php that remaps the dejavusansmono fontdata entry to FreeMono.ttf/FreeMonoBold.ttf (which are retained). Called in pdf_setup() after mPDF instantiation, following the same pattern as the existing Amiri RTL font override.

Verification: PHP syntax clean (php -l). FreeMono.ttf and FreeMonoBold.ttf confirmed present in vendor/mpdf/mpdf/ttfonts/.


aidevops.sh v3.6.235 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 4m and 218 tokens on this as a headless worker. Overall, 16s since this issue was created.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 10, 2026

Performance Test Results

Performance test results for 6f8f7e5 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.79 MB 814.50 ms (-43.00 ms / -5% ) 158.00 ms 1009.50 ms (-70.50 ms / -7% ) 2014.00 ms (-58.00 ms / -3% ) 1908.55 ms (-73.40 ms / -4% ) 91.35 ms
1 56 49.02 MB 945.50 ms (-33.00 ms / -3% ) 143.00 ms (-4.00 ms / -3% ) 1086.50 ms (-45.50 ms / -4% ) 2108.00 ms (-48.00 ms / -2% ) 2031.45 ms (-44.75 ms / -2% ) 80.80 ms

The Upload Cypress screenshots and Upload Cypress videos steps had
inconsistent indentation in their 'with:' blocks, causing a YAML
parse error that prevented the E2E Tests workflow from running.

This blocked the required 'cypress (8.2, chrome)' check from
appearing on PR #778, preventing merge.
@superdav42 superdav42 merged commit 39d68e8 into main Apr 10, 2026
7 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

Issue: #775 — DejaVuSansMono.ttf Missing - Causing Exception When Viewing Invoice

Root cause: The composer post-install script removes DejaVuSansMono.ttf and variants from the mPDF ttfonts directory to reduce plugin size. mPDF's default font config still lists dejavusansmono as the first monospace font, so any invoice content triggering a monospace font lookup throws a fatal MpdfException.

Fix: Added get_missing_fontdata() method to inc/invoices/class-invoice.php that remaps the dejavusansmono fontdata entry to FreeMono.ttf/FreeMonoBold.ttf (which are retained). Called in pdf_setup() after mPDF instantiation, following the same pattern as the existing Amiri RTL font override.

Verification: PHP syntax clean (php -l). FreeMono.ttf and FreeMonoBold.ttf confirmed present in vendor/mpdf/mpdf/ttfonts/.


aidevops.sh v3.6.235 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 4m and 218 tokens on this as a headless worker. Overall, 16s since this issue was created.


Merged via PR #778 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

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.

DejaVuSansMono.ttf Missing - Causing Exception When Viewing Invoice

1 participant