Font packages (mirrors mpdf/mpdf#2161) - #2
Merged
Conversation
Thai, Khmer and Lao word boundaries come from linebrdict{T,K,L}.dat, which
Otl loaded from a hard-coded src/../data path. Now that the fonts they pair
with live in packages, the dictionaries move with them: Garuda carries T,
Khmer-OS carries K and Dhyana carries L, each declared through the new
FontRegistrationInterface::getLineBreakDictionaries().
initFontRegistry() merges the declarations with the same first-wins
precedence it applies to fontdata, and seaLineBreaking() returns early when
no dictionary is registered for the shaper. Without that early return the
$dict =& $this->lbdicts[...] reference is null and ord($dict[$dictptr])
emits a notice per character; now a document with no dictionary simply falls
back to ordinary line breaking.
Autoloading font packages needs composer.lock, and distributions that strip it (a plugin release zip, say) made every `new Mpdf()` without an explicit fontRegistry fatal. Log and register nothing instead, which leaves mPDF in the core-font mode it already falls into when no package registers a font.
getServices() already resolves httpClient, localContentLoader and assetFetcher this way. Consumers that need to recover from a font file that has gone missing on disk can now supply their own finder.
The packages/* path repositories are declared but nothing pulls them in, so a plain `composer install` leaves mPDF with no registered fonts and 56 of its own tests fail in core-font mode.
available_unifonts is built in fontdata order, and it is what an unresolvable font-family falls back to. Without this the fallback is whichever package or config entry happened to register first, which the caller does not control once several packages are in play.
add() keyed the register by get_class(), so two instances of one class collapsed into one entry. A consumer whose packages differ only by where their data comes from — a constant map versus rows from a database, say — had to write one class per package to work around it. FontRegistrationInterface::getId() defaults to the class name in the FontRegistration base, so every existing package keeps the key it had, and remove() keeps taking the same argument.
Composer installs this fork from a zipball, and packages/ is ~100MB of font files no consumer of the library itself needs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the branch behind mpdf#2161, mirrored here so the whole fork delta is reviewable in one place before Gravity PDF 7.0 depends on it.
gravitypdfis plain upstreamdevelopment(389e19e); merging this makes it "upstream + font packages" and nothing else.The upstream PR replaces mPDF's built-in font handling with registrable font packages:
Mpdf\Fonts\FontRegistry,FontRegistrationInterface, an abstractFontRegistration, andMpdf\Language\LanguageToFontRegistry.ttfonts/is deleted, the font defaults inConfigVariables/FontVariablesare emptied, and the fonts move intopackages/*Composerpathrepositories.Seven commits follow the two original ones; the last six are ours, added while working through Phase 0 of the 7.0 plan.
Try it
composer installpullsmpdf/font-bundle-allfromrequire-dev, so the suite has fonts to register. Without that the suite goes red — see the note below.Test plan
composer test— 998 tests, 2289 assertions, green.composer cs— clean.composer prefix;Test_Vendor_Prefixing(11 tests) and the full 1637-test suite pass.More info
The commits
70b90cc40aec7280aa688getLineBreakDictionaries()on the interface, merged ininitFontRegistry()with the same first-wins precedence asfontdata, plus aseaLineBreaking()early return when no dictionary is registered;linebrdict{T,K,L}.datmove fromdata/intopackages/{Garuda,Khmer-OS,Dhyana}/fonts/28bf7d8FontRegistryno longer throws whencomposer.lockis absent — logs through an optional PSR-3 logger and registers nothingcaae349fontFileFinderis container-resolvable inServiceFactory::getServices()3cb1647mpdf/font-bundle-allinrequire-dev6415052fontdata, so it headsavailable_unifonts1afecbcFontRegistrykeys by an overridablegetId(), defaulting to the class name6e45465packages/ export-ignorein.gitattributes, so a Composer zipball install does not drag ~100 MB of font binaries into everyvendor/Why
require-devmatterspackages/*was declared as apathrepository but nothing required it, so a plaincomposer installregistered no fonts, mPDF dropped into core-font mode, and the suite reported 41 failures and 15 errors. One line inrequire-devmakes it green.Behaviour changes for existing consumers
getLineBreakDictionaries(). Without one,seaLineBreaking()returns early and mPDF falls back to ordinary line breaking rather than failing.getId().FontRegistry::add()keys on$class->getId()instead ofget_class($class). The base class returnsget_class($this), so every existing package keeps its key; overriding it lets one class register twice under different ids.Not in this PR
The
MarkGlyphSetsfix is #1, and the fork-onlybranch-aliasconfig is #3. Both are independent of font packages.