Hyphenation
Hyphenation is a way to arrange text in a document more compactly. However, it is important to remember that hyphenation rules may vary depending on the language.
Hyphenation is not used as often today as it used to be. However, enabling hyphenation can significantly affect the layout and therefore the appearance of output documents in fixed page formats, such as PDF or XPS.
To ensure correct word hyphenation, language-specific hyphenation dictionaries are used.
Hyphenation Dictionaries
As mentioned, different languages have different hyphenation rules and norms. In this case, the best solution for proper hyphenation is to use special dictionaries.
Hyphenation dictionaries are language-specific rule sets that define valid hyphenation points in words. Wordize uses OpenOffice dictionaries and advanced algorithms to work with these dictionaries – this provides hyphenation results that are as close as possible to those of Microsoft Word.
OpenOffice uses the Hunspell engine for spell checking, hyphenation, and thesaurus functions. When you enable hyphenation, OpenOffice dictionaries consult the corresponding dictionary to decide where to insert hyphens in long words at line breaks. For example, the word “information” might be hyphenated as “in-for-ma-tion”, depending on the dictionary rules.
Loading Hyphenation Dictionaries
To use the hyphenation feature, first register a hyphenation dictionary.
The following code example shows how to load hyphenation dictionaries for the specified languages from a file:
Wordize.Settings.Hyphenation.RegisterDictionary("en-US", "hyph_en_US.dic");
Wordize.Settings.Hyphenation.RegisterDictionary("de-CH", "hyph_de_CH.dic");
The following code example shows how to load hyphenation dictionaries for the specified language from a stream:
using var stream = File.OpenRead("hyph_de_CH.dic");
Wordize.Settings.Hyphenation.RegisterDictionary("de-CH", stream);
In addition to pre-registering hyphenation dictionaries, you can register the required hyphenation dictionaries “by request”. Use the IHyphenationCallback interface to get requested languages:
Wordize.Settings.Hyphenation.Callback = new HyphenationRequestsCollector();
Converter.Create()
.From("DocumentIn.docx")
.To("DocumentOut.pdf")
.Execute();
private class HyphenationRequestsCollector : IHyphenationCallback
{
public void RequestDictionary(string language)
{
Console.WriteLine(language);
}
}
Hyphenation Dictionaries Examples
To see how words can be broken into syllables differently by the different OpenOffice hyphenation dictionaries for different languages, let’s take the word “International” as an example.
The following table shows the hyphenation options for a few languages:
Language | Word | OpenOffice Hyphenation |
---|---|---|
English | International | In-ter-na-tion-al |
Spanish | Internacional | In-ter-na-cio-nal |
French | Internationale | In-ter-na-tio-nale |
German | International | In-ter-na-tio-nal |
Italian | Internazionale | In-ter-na-zio-na-le |