Overview
tc-lib-unicode-data is a data-centric package that ships Unicode lookup tables, mappings, and constants consumed by tc-lib-unicode and related libraries.
Keeping the tables in their own package means a UCD update is a version bump here, with nothing to review in the algorithms that read them.
Repository and API Docs
- GitHub: https://github.com/tecnickcom/tc-lib-unicode-data
- API docs: https://tcpdf.org/docs/srcdoc/tc-lib-unicode-data
- Packagist: https://packagist.org/packages/tecnickcom/tc-lib-unicode-data
Project Metadata
| Item | Value |
|---|---|
| Namespace | \Com\Tecnick\Unicode\Data |
| License | GNU LGPL v3 |
Installation
composer require tecnickcom/tc-lib-unicode-data
Where It Fits
Usually indirectly, through tc-lib-unicode. Reach for it directly when you need to inspect a code point’s properties yourself.
Features
Data Coverage
| Class | Content |
|---|---|
Type | Bidi_Class of every code point, with getType() and getBidiClass() |
BidiClass | Backed enum of the strong, weak and neutral bidirectional classes |
Constant | Code points of the bidirectional formatting characters and of some common separators |
Pattern | Regular expressions matching right-to-left and Arabic text |
Mirror | Mirrored form of the characters mirrored in a right-to-left context |
Bracket | Paired brackets, by opening and by closing code point |
Arabic | Joining types, presentation forms and ligatures, with getJoiningType() |
Encoding | Character code to glyph name maps of 22 font encodings |
Latin | Unicode to Latin1 character substitutions |
Identity | CMap stream for the Identity-H encoding |
Integration Role
- Runtime dependency of tc-lib-unicode and tc-lib-pdf-font
- Data only: no algorithms, and no dependencies of its own beyond PHP
Generated Unicode Data
Arabic, Bracket, Mirror, Pattern, and Type are generated from the Unicode Character Database, currently UCD 17.0.0. Type::UNICODE_VERSION reports the release the shipped tables were built from.
| Class | UCD source | Content |
|---|---|---|
Type | extracted/DerivedBidiClass.txt | Bidi_Class of every code point (UAX #9) |
Pattern | extracted/DerivedBidiClass.txt | Regular expressions matching right-to-left and Arabic text |
Mirror | BidiMirroring.txt | Bidi_Mirroring_Glyph values used by rule L4 |
Bracket | BidiBrackets.txt | Paired brackets used by rule N0 |
Arabic | ArabicShaping.txt, UnicodeData.txt | Joining types, presentation forms, and ligatures |
Type::UNI lists only the code points whose Bidi_Class is not L; Type::getType() resolves any code point, including the blocks whose unassigned code points default to R, AL, or ET.
\Com\Tecnick\Unicode\Data\Type::getType(0x05D0); // 'R'
\Com\Tecnick\Unicode\Data\Type::getBidiClass(0x0660); // BidiClass::AN
\Com\Tecnick\Unicode\Data\Arabic::getJoiningType(0x0628); // 'D'
To rebuild the tables from a newer UCD release:
make gendata UCDVERSION=17.0.0
make qa
Typed Enums
\Com\Tecnick\Unicode\Data\BidiClass is a backed enum of the bidirectional character classes (L, R, AL, EN, ES, ET, AN, CS, NSM, BN, B, S, WS, ON). The backing value is the canonical class abbreviation used in the UCD.
Upgrading from 2.x
Version 3.0 is a breaking release. The relevant API changes:
Type::UNIno longer contains the code points whose Bidi_Class isL. Read the class throughType::getType()instead ofType::UNI[$ord] ?? $fallback.Type::getBidiClass()returnsBidiClass::Lfor unlisted code points, andnullonly for the explicit formatting codes (LRE, LRO, RLE, RLO, PDF, LRI, RLI, FSI, PDI).Pattern::RTLandPattern::ARABICare code-point based (umodifier) and require a valid UTF-8 subject.Mirror::UNIfollowsBidiMirroring.txt: the quotation marks U+2018, U+2019, U+201C, U+201D, U+301D, and U+301E are no longer mirrored.Arabic::SUBSTITUTErows always hold the four[isolated, final, initial, medial]forms, repeating the isolated and final ones where a letter has no initial or medial form.Arabic::ENDis derived from the Joining_Type property and now lists every character that does not join to the following one.Arabic::JOININGandArabic::getJoiningType()expose the Joining_Type property.
Consumers should upgrade tc-lib-unicode and tc-lib-pdf-font at the same time; both read the bidi class through the Type::getType() and Type::getBidiClass() accessors rather than through the raw table.
Integration Notes
Upgrade this package together with tc-lib-unicode and tc-lib-pdf-font, which read the same tables through accessors that changed alongside them.
Read the data through the accessors rather than indexing the constants. Type::UNI holds only the code points whose Bidi_Class is not L, so a direct lookup misses the blocks whose unassigned code points default to R, AL, or ET.
A UCD release adds code points and occasionally reclassifies existing ones. Run the multilingual cases you care about after an update.
Requirements
- PHP 8.2 or later
- Composer
Example
<?php
require_once __DIR__ . '/vendor/autoload.php';
echo md5(\Com\Tecnick\Unicode\Data\Identity::CIDHMAP);
Development and Packaging
- QA and local checks:
make deps,make help,make qa - Coverage report:
make qa-coverage - Packaging:
make rpm,make deb
Support and Contribution
- Sponsor: https://github.com/sponsors/tecnickcom
- Contribution guide: https://github.com/tecnickcom/tc-lib-unicode-data/blob/main/CONTRIBUTING.md
- Security policy: https://github.com/tecnickcom/tc-lib-unicode-data/blob/main/SECURITY.md