Class PatternHyphenator
Liang's hyphenation algorithm (as used by TeX) with pattern files from the hyph-utf8 project, e.g.
hyph-de-1996.tex (German), hyph-de-ch-1901.tex (Swiss German) or hyph-en-us.tex.
Load patterns with FromTex(string, int, int); the pattern files are not bundled.
public sealed class PatternHyphenator : IHyphenator
- Inheritance
-
PatternHyphenator
- Implements
- Inherited Members
Examples
var german = PatternHyphenator.FromTex(File.ReadAllText("hyph-de-1996.tex"));
TextLayout.DefaultHyphenator = german; // or per paragraph: paragraph.Hyphenator = german
Constructors
PatternHyphenator(IEnumerable<string>, IEnumerable<string>?, int, int)
public PatternHyphenator(IEnumerable<string> patterns, IEnumerable<string>? exceptions = null, int leftMin = 2, int rightMin = 2)
Parameters
patternsIEnumerable<string>Patterns such as "hy3ph" or ".ab1c" (digits mark break priorities).
exceptionsIEnumerable<string>Exception words with explicit hyphens, e.g. "ta-ble".
leftMinintMinimum number of characters before a break.
rightMinintMinimum number of characters after a break.
Properties
LeftMin
Minimum number of characters before a break.
public int LeftMin { get; }
Property Value
RightMin
Minimum number of characters after a break.
public int RightMin { get; }
Property Value
Methods
FromTex(string, int, int)
Loads a TeX pattern file (\patterns{...} and optional \hyphenation{...}).
public static PatternHyphenator FromTex(string tex, int leftMin = 2, int rightMin = 2)
Parameters
Returns
GetBreakPoints(string)
Returns the indexes i where a hyphen may be inserted before word[i], honoring LeftMin
and RightMin. Exception words return their explicit hyphen positions. Matching is case-insensitive.
public IReadOnlyList<int> GetBreakPoints(string word)
Parameters
wordstring