Class HyphenationRegistry
- Namespace
- NetPdf.Hyphenation
- Assembly
- NetPdf.Text.dll
The public extension seam for language hyphenation. The core ships American-English patterns
(pre-registered as "en"); the optional NetPdf.Languages.* NuGet packages register
additional languages here (via an explicit Register(…) call, which the packs also drive from a
[ModuleInitializer]) by handing over TeX-style Liang pattern text + an optional exception list.
Patterns registered through this seam are reachable via TryHyphenate(string, ReadOnlySpan<char>, out int[], int, int) and
IsRegistered(string).
public static class HyphenationRegistry
- Inheritance
-
HyphenationRegistry
- Inherited Members
Remarks
Language keys. Keys are normalized to the primary subtag, lower-cased (BCP-47
de-DE → de, en-GB → en), so a pack registering "de" serves all
German locales. A tag with no primary subtag after normalization (e.g. "-DE" or "-") is
rejected by Register(string, string, string?).
Thread-safety. Registration and lookup are concurrent-safe. Registering a language that is already present replaces it (last registration wins) — a pack can override the built-in English.
Layout routing. The block layout pass resolves the hyphens: auto hyphenator from a
block's effective HTML lang (nearest lang/xml:lang up the ancestor chain) through
this registry, via the internal ResolveOrDefault(string) seam. So a language a pack registered
here is used automatically during rendering. An unregistered/unknown language falls back to the bundled
English hyphenator. Still a follow-up: per-run routing (a single block that mixes languages uses
the block language for all of it) and UAX #29 tokenization.
Methods
IsRegistered(string)
Whether a hyphenator is registered for language (by primary subtag).
public static bool IsRegistered(string language)
Parameters
languagestring
Returns
Register(string, string, string?)
Register (or replace) the hyphenator for language from TeX-style Liang
patternBlock text (whitespace/newline-separated patterns like .aus1,
TeX % comments stripped) and an optional exceptionBlock of explicit
hyphenations (whitespace-separated words like Sil-ben-tren-nung). Called by the
NetPdf.Languages.* packs on load; may also be called directly to supply custom patterns.
public static void Register(string language, string patternBlock, string? exceptionBlock = null)
Parameters
RegisterNoHyphenation(string)
Register language as one that does NOT soft-hyphenate — a script whose line
breaking is handled elsewhere rather than by inserting hyphens (CJK: per-character breaking, UAX #14;
Arabic: kashida/tatweel justification). This registers a no-op hyphenator, so hyphens: auto
resolves to zero break points for the language (via ResolveOrDefault(string)) instead of
falling back to the bundled English hyphenator — which would otherwise hyphenate any embedded
Latin-script runs in a document tagged for such a language. Same primary-subtag normalization +
validation as Register(string, string, string?).
public static void RegisterNoHyphenation(string language)
Parameters
languagestring
TryHyphenate(string, ReadOnlySpan<char>, out int[], int, int)
Find the hyphenation break positions for word in language.
A break position k means "a soft break may go between word[k-1] and word[k]".
Returns false (and an empty array) when the language isn't registered.
public static bool TryHyphenate(string language, ReadOnlySpan<char> word, out int[] breaks, int leftMin = 2, int rightMin = 3)