定制 phppdf/tex-hyphenation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phppdf/tex-hyphenation

Composer 安装命令:

composer require phppdf/tex-hyphenation

包简介

Knuth-Liang TeX hyphenation algorithm for phppdf

README 文档

README

A pure PHP implementation of the Knuth-Liang TeX hyphenation algorithm. It splits a word into the fragments allowed at valid hyphenation points, using the same pattern format as TeX (e.g. hy3ph, .ach4).

This package implements the PhpPdf\Text\Hyphenator interface from phppdf/phppdf, so it plugs directly into TextBox and other phppdf text-layout components.

Requirements

  • PHP 8.4+
  • ext-mbstring

Installation

composer require phppdf/tex-hyphenation

Usage

TeXHyphenator is constructed with an array of raw TeX pattern strings. Bundled pattern files for several locales are included under resources/hyphenation/:

use PhpPdf\Text\TeXHyphenator;

$patterns = file(
    __DIR__ . '/vendor/phppdf/tex-hyphenation/resources/hyphenation/en-US.tex',
    FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES,
) ?: [];

$hyphenator = new TeXHyphenator($patterns);

$hyphenator->breakWord('hyphenation'); // ['hy', 'phen', 'a', 'tion']

The result is a list of fragments; join consecutive fragments with a hyphen wherever a line break is needed.

Minimum margins

leftMin and rightMin control how many characters must remain before the first break and after the last break, respectively (TeX defaults: 2 and 3):

$hyphenator = new TeXHyphenator($patterns, leftMin: 3, rightMin: 3);

Bundled locales

Locale File
af-ZA resources/hyphenation/af-ZA.tex
en-GB resources/hyphenation/en-GB.tex
en-US resources/hyphenation/en-US.tex
en-ZA resources/hyphenation/en-ZA.tex
es-ES resources/hyphenation/es-ES.tex
fr-FR resources/hyphenation/fr-FR.tex
nl-NL resources/hyphenation/nl-NL.tex

Use with phppdf

use PhpPdf\Builder\TextBox;
use PhpPdf\Text\TeXHyphenator;

$box = TextBox::create($text, $metrics, 12, 200.0, hyphenator: new TeXHyphenator($patterns));

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: TeX

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固