Repository navigation
PDFs: Switch to DomPDF & use Noto Sans (plus KR, SC, and Arabic) for Invoices & Docs. - #1552
Conversation
|
Noting that there's also |
| <meta charset="UTF-8"> | ||
| <link href="http://fonts.googleapis.com/css?family=Open+Sans:300,600,700" rel="stylesheet" type="text/css" /> | ||
| <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet -- This is rendered by wkhtmltopdf, so additional libraries are included directly. ?> | ||
| <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300..700&family=Noto+Sans+KR:wght@300..700&family=Noto+Sans+SC:wght@300..700" rel="stylesheet" type="text/css" /> |
There was a problem hiding this comment.
Thanks for your PR to resolve my issue!
How about swap font resolve order?
/* Current... */
font-family: 'Noto Sans KR', 'Noto Sans SC', 'Open Sans', sans-serif;
/* to this */
font-family: 'Noto Sans SC', 'Noto Sans KR', 'Open Sans', sans-serif;KR might use the same glyph points as of Chinese.
Note: I cannot reproduce same character missing(we call it "TOFU").
|
It looks like this isn't loading Open Sans at all now, because the Notos have latin characters, so it never falls back to Open Sans. I'd recommend updating the font stack to … Actually, that won't work either. I don't think wkhtmltopdf supports multiple fonts. If you do that, everything is "tofu". The tofu in Simplified Chinese goes away if you put Noto Sans SC first, but then Korean breaks. So it appears to only load the first font.
Maybe switching to something like dompdf would fix that, they have addressed CJK font support in this issue. |
|
I've tried on my local machine, but because of network error, wkhtmltopdf failed to download google fonts. I also tried another approach — installing
The complete diff of docker file is below: before__Dockerfile.php-fpm | Dockerfile.php-fpm – 2 Additions.pdf |
I thought that might be the case...
This too, except that as far as I could tell it definitely does because KR doesn't work without the KR font, and Chinese didn't work without the SC font, but with both they did load...
I did consider that, but I was hopeful that a quick font-change here would suffice :)
@fumikito Unfortunately we don't use the included Dockerfile in production, so it's a little more involved than just the change here :( |
|
🤷 I guess I was very wrong, or improperly tested :) Let's try |
|
After the subsetting work, I'm pretty familiar with these fonts 😅 |
|
Took forever to figure out why this wasn't working with invoices.. Turns out that if an embedded image is 404 / broken, then DomPdf seems to enter an endless forever loop. It seems to be that the broken-image fallback is well broken. Additionally; Before merging some performance profiling should be done to figure out if this is going to be too slow.. For invoices, I suspect the better solution will be to remove invoice generation from during the checkout, and moving it to be able to be downloaded from the Successful purchase landing page (ala #1555) |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… invoice layout Follow-up to the DomPDF switch, from rendering real invoices and every WordCamp Docs template with DomPDF 3.1.6. - Arabic came out as disconnected letters in reverse order: DomPDF draws characters one at a time, left to right. A small shaper now swaps in the presentation form for each letter's position, joins lam-alef, and reverses each Arabic run into visual order. Persian letters too. ar-php does the same but requires ext-calendar, which our containers don't have. - DomPDF runs in the web process, unlike the sandboxed wkhtmltopdf it replaces. Remote fetches are limited to the two Google Fonts hosts, and local reads to the working folder and the font cache. The invoice logo is copied in as an asset rather than fetched by URL, which also fixes it rendering as a broken image. - The font cache moves from /tmp to wp-content/uploads/wordcamp-docs-fonts, and CampTix's daily cron warms it. A cold cache downloads about 80MB, taking ~15s, which the first invoice after a reboot would otherwise spend in checkout. Warm renders take ~0.4s. - Bold (700) isn't loaded, and DomPDF falls back to Helvetica rather than the nearest weight, so CJK in table headers would have been blank. Bold maps to 600, and the font family is set on body, not just @page. - The From/To addresses were floats in an overflow: hidden box, which DomPDF collapsed to nothing. They're a two-cell table now. - A rendering exception leaves no PDF, which the invoice code already logs as a failure, now with the reason, instead of erroring out of checkout. The broken-image hang reported earlier doesn't reproduce on 3.1.6 with a 404, a missing local file, or an unresolvable host. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
I picked this up. I merged What I found rendering real invoices and every Docs template with DomPDF 3.1.6:
Security: DomPDF runs as the web user, not the sandboxed Font cache (e00028f): a cold cache downloads ~80MB (5-15s), a warm render takes ~0.5s, and CampTix's daily cron warms it. With ms-files, One thing to know: DomPDF missing (e00028f): if a deploy skips Composer, Deploy needs: the Composer lock used on deploy must include Testing
To test: @obenland could you review, especially the |
With ms-files, wp-content/uploads is on each web server's local disk, so one warm-up only covered one server. blogs.dir is the shared mount. A deploy that skipped Composer would make every invoice a fatal error at checkout. Now it's a logged failure instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The visa letter tests assumed WordCamp_Docs_PDF_Generator is never loaded. Since #1552 the invoice PDF tests load it, and PHPUnit includes every test file before running any, so seven visa letter tests started generating real PDFs and failed. Production's CI has been red since #1552 merged. Add a ctx_vl_pdf_generator_available filter and turn it off in the suite's bootstrap, so the tests no longer depend on which other suites ran. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…#2198) * PDFs: fall back to the temp folder when the font cache isn't writable The font cache from #1552 lives in blogs.dir. On a server that can't write there (the sandbox's NFS mount refuses it), DomPDF failed to save the font metrics and rendered nothing, so every invoice and Docs PDF broke. Now the cache moves to the temp folder instead, per server and lost on reboot, but PDFs keep working. Also stop serve_pdf_to_browser() from reading a PDF that doesn't exist after it has already said "File not found.", which added PHP warnings to the 404. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Visa letters: switch the PDF generator off in tests with a filter The visa letter tests assumed WordCamp_Docs_PDF_Generator is never loaded. Since #1552 the invoice PDF tests load it, and PHPUnit includes every test file before running any, so seven visa letter tests started generating real PDFs and failed. Production's CI has been red since #1552 merged. Add a ctx_vl_pdf_generator_available filter and turn it off in the suite's bootstrap, so the tests no longer depend on which other suites ran. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>








Fixes #1433
It seems that the only thing missing on Invoices to make non-western characters work is that a) The system doesn't have any chinese/korean/japanese fonts installed and b) isn't specifying a webfont that supports these laguages.
Screenshots
Attempting to render #1433 (comment)
The Simplified Chinese still has a few missing characters, but much better than before. I'm not sure why these are missing, as the font appears to support those unicode characters.. It may be something in how I'm testing it.