Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Font Lib Laravel Package

dompdf/php-font-lib

PHP font library used by dompdf to read, parse, and manipulate font files (TrueType, OpenType, WOFF). Provides glyph metrics, font subsetting, and embedding support, enabling accurate text rendering in generated PDFs and other font-processing tasks.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install via Composer: composer require dompdf/php-font-lib
  • This package is typically used indirectly—most developers interact with it through dompdf, not directly. However, for advanced typography or custom PDF/font tooling, direct usage is possible.
  • First step: inspect a font file programmatically:
    use FontLib\Font;
    
    $font = Font::load('path/to/font.ttf');
    $font->parse();
    echo $font->getFontName(); // e.g., "DejaVuSans"
    
  • Check supported font formats and verify parsing success using $font->isValid().

Implementation Patterns

  • Font inspection in CI/CD pipelines: Write CLI scripts to validate font integrity before deployment (e.g., check glyph coverage or font table health).
  • Custom font subsetting: For multilingual PDFs, extract only needed glyphs:
    $font = Font::load('dejavu-sans.ttf');
    $font->parse();
    $subset = $font->subset([0x41, 0x42, 0x43]); // subset for "ABC"
    $subset->save('subset-font.ttf');
    
  • Integration with dompdf: When using dompdf, enable embedded fonts via FontLib-compatible paths in dompdf_config.inc.php or via addFont() (dompdf’s internal wrapper handles this).
  • Font metrics in layout logic: Calculate text width for PDF positioning:
    $font->parse();
    $width = $font->getFontWidth('Hello', 12); // width in PDF points
    

Gotchas and Tips

  • ⚠️ Direct usage is rare: Most apps won’t call FontLib directly—check if dompdf’s built-in font handling meets needs before adding complexity.
  • 🔍 Font table parsing fails silently on invalid/corrupt fonts—always call $font->parse() and check $font->isValid() before proceeding.
  • 💡 Font subsetting requires glyph indices—not Unicode codepoints directly. Use $font->getCharacterGlyph($char) to map first.
  • 🧰 Extend via Font\Encoding or Font\Table subclasses to handle custom font tables (e.g., for unusual OT features).
  • 📁 File permissions: Font files must be readable by PHP—common failure point in Docker/containerized environments.
  • ⏱️ parse() is expensive—cache parsed fonts or reuse instances (especially in CLI tools or batch PDF generation).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4