GlyphLayoutManager for correct glyph layout per document#1519
Open
vk-github18 wants to merge 31 commits intoLibrePDF:masterfrom
Open
GlyphLayoutManager for correct glyph layout per document#1519vk-github18 wants to merge 31 commits intoLibrePDF:masterfrom
vk-github18 wants to merge 31 commits intoLibrePDF:masterfrom
Conversation
# Conflicts: # openpdf-core/src/main/java/org/openpdf/text/pdf/GlyphLayoutFontManager.java
Exception handling, formatting
Corrections
…t, rename variables, formatting
…es for multithreading example
…n file path or URL
… load a font from the Web
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description of the new Feature/Bugfix
New classes GlyphLayoutManager, GlyphLayoutFontManager for correct glyph layout per document.
These classes should also work in multi-threading environments like in Eclipse BIRT.
Related Issue: #1307
See also eclipse-birt/birt#2144
Unit-Tests for the new Feature/Bugfix
Example classes in pdf-toolbox/src/test/java/org/openpdf/examples/glyphlayout
Compatibilities Issues
New classes that can be used, otherwise no change.
Your real name
Volker Kunert
Testing details
See example classes in pdf-toolbox/src/test/java/org/openpdf/examples/glyphlayout
check the resulting pdf files
Description for Wiki
Correct positioning of accents
To process text containing letters composed of multiple Unicode glyphs e.g. letters with accents,
it is necessary to compute the correct positioning of the glyphs and code this positions into the resulting
PDF file. For complex scripts glyph substitution and reordering is necessary.
OpenPDF can process such texts starting with release 1.3.24.
This page describes the usage for release 3.0.4 or newer with
GlyphLayoutManager.For release 3.0.3 using (the now deprecated)
LayoutProcessorsee Accents, DIN 91379, non Latin scripts (2025-09-21),for older releases see Accents, DIN 91379, non Latin scripts (2025-06-06).
Internally OpenPDF uses
Java2Dbuiltin routines for glyph layout, reordering and substitution.Since
Java 9these routines rely on theHarfBuzzshaping library.DIN 91379
We tested this approach with letters conforming to "DIN 91379: Characters and defined character sequences in Unicode for the electronic processing of names and data exchange in Europe, with CD-ROM" (and the predecessor DIN SPEC 91379) which describes a subset of Unicode consisting mainly of
Latin letters and diacritic signs. This standard is mandatory for the data exchange of the German administration with citizens and businesses since Nov. 2024.
Non-Latin scripts
The processing of text in other languages and scripts using this approach should be possible, you are invited
to try it and share the results.
Multithreading
GlyphLayoutManageris enabled perDocument, and has no static state, so it is designed to work in amultithreading environment processing multiple documents in separate threads.
Usage
1. Step: Provide an OpenType font
Provide an OpenType font containing the necessary characters and positioning information, see below
for some open source fonts.
If no OpenType font is provided, GlyphLayoutManager will throw an exception.
You can also load the font from an input source. You have to supply a name for loading the font that ends
with ".ttf" or ".otf".
If an error occurs while loading a font, a
GlyphLayoutFontManager.FontLoadExceptionis thrown.2. Step: Enable advanced glyph layout
You enable advanced glyph layout by registering the glyphLayoutManager with the Document.
You can also use the following form:
Set Options
Default Options
Optionally you can set the default
GlyphLayoutManagerfont options before loading the fonts.These options are used for all fonts loaded with this
GlyphLayoutManager.Options per font
If you want to use different options, you can set the font options per font while loading the font.
Exceptions
Checked Exceptions
GlyphLayoutManager.loadFontthrowsGlyphLayoutFontManager.FontLoadExceptionif the font can not be loadedor it is not an OpenType font.
Unchecked Exceptions
The constructor of
GlyphLayoutManagerthrows anIllegalStateExceptionif
LayoutProcessoris enabled. Don't use the deprecatedLayoutProcessor!If a font is used that has not been loaded
GlyphLayoutManager.loadFontthrows anUnsupportedOperationExceptionis thrown. All fonts have to be loaded with
GlyphLayoutManager.loadFont.LayoutProcessor
LayoutProcessoris the predecessor ofGlyphLayoutManagerand is deprecated now, useGlyphLayoutManager.FopGlyphProcessor
GlyphLayoutManager and
FopGlyphProcessorcan't be used together, you have to decide for one of them.If you use GlyphLayoutProcessor, FopGlyphProcessor is switched off using document.setGlyphSubstitutionEnabled().
This call disables FopGlyphProcessor, and its functionality like glyph substitution and more will be provided by GlyphLayoutManager.
Examples
Producing a document
This example shows the correct rendering for all letters from DIN 91379.
Code: GlyphLayoutDin91379.java
Result: GlyphLayoutDin91379.pdf
Processing a form
GlyphLayoutFormDin91379.java
GlyphLayoutFormDin91379.pdf
Producing a document with bidirectional text
Java's
Bidi-class is used to deduce the text direction for each chunk of text,it should not be necessary to specify the text direction per font explicitly.
GlyphLayoutBidi.java
GlyphLayoutBidi.pdf
GlyphLayoutBidiRotated.java
GlyphLayoutBidiRotated.pdf
Specify direction per font
It is possible to set the direction per font, but this should not be necessary.
GlyphLayoutBidiPerFont.java
GlyphLayoutBidiPerFont.pdf
Load the font from an input source
You can load the font from an input source.
GlyphLayoutInputSource.java
GlyphLayoutInputStream.pdf
Specify kerning and ligatures per document
Optionally you can specify kerning and ligatures per document.
GlyphLayoutKernLigaPerFont.java
GlyphLayoutKernLiga.pdf
Specify kerning and ligatures per font
Optionally you can specify kerning and ligatures per font.
GlyphLayoutKernLigaPerFont.java
GlyphLayoutKernLigaPerFont.pdf
Use GlyphLayoutManager for Letters from the Unicode Supplementary Multilingual Plane
Show letters and symbols from the Unicode Supplementary Multilingual Plane,
GlyphLayoutSMP
GlyphLayoutSMP.pdf
Use GlyphLayoutManager with an image
GlyphLayoutWithImage
GlyphLayoutWithImage.pdf
Open source OpenType fonts
References
Correct positioning of accents
To process text containing letters composed of multiple Unicode glyphs e.g. letters with accents,
it is necessary to compute the correct positioning of the glyphs and code this positions into the resulting
PDF file. For complex scripts glyph substitution and reordering is necessary.
OpenPDF can process such texts starting with release 1.3.24.
This page describes the usage for release 3.0.4 or newer with
GlyphLayoutManager.For release 3.0.3 using (the now deprecated)
LayoutProcessorsee Accents, DIN 91379, non Latin scripts (2025-09-21),for older releases see Accents, DIN 91379, non Latin scripts (2025-06-06).
Internally OpenPDF uses
Java2Dbuiltin routines for glyph layout, reordering and substitution.Since
Java 9these routines rely on theHarfBuzzshaping library.DIN 91379
We tested this approach with letters conforming to "DIN 91379: Characters and defined character sequences in Unicode for the electronic processing of names and data exchange in Europe, with CD-ROM" (and the predecessor DIN SPEC 91379) which describes a subset of Unicode consisting mainly of
Latin letters and diacritic signs. This standard is mandatory for the data exchange of the German administration with citizens and businesses since Nov. 2024.
Non-Latin scripts
The processing of text in other languages and scripts using this approach should be possible, you are invited
to try it and share the results.
Multithreading
GlyphLayoutManageris enabled perDocument, and has no static state, so it is designed to work in amultithreading environment processing multiple documents in separate threads.
Usage
1. Step: Provide an OpenType font
Provide an OpenType font containing the necessary characters and positioning information, see below
for some open source fonts.
If no OpenType font is provided, GlyphLayoutManager will throw an exception.
You can also load the font from an input source. You have to supply a name for loading the font that ends
with ".ttf" or ".otf".
If an error occurs while loading a font, a
GlyphLayoutFontManager.FontLoadExceptionis thrown.2. Step: Enable advanced glyph layout
You enable advanced glyph layout by registering the glyphLayoutManager with the Document.
You can also use the following form:
Set Options
Default Options
Optionally you can set the default
GlyphLayoutManagerfont options before loading the fonts.These options are used for all fonts loaded with this
GlyphLayoutManager.Options per font
If you want to use different options, you can set the font options per font while loading the font.
Exceptions
Checked Exceptions
GlyphLayoutManager.loadFontthrowsGlyphLayoutFontManager.FontLoadExceptionif the font can not be loadedor it is not an OpenType font.
Unchecked Exceptions
The constructor of
GlyphLayoutManagerthrows anIllegalStateExceptionif
LayoutProcessoris enabled. Don't use the deprecatedLayoutProcessor!If a font is used that has not been loaded
GlyphLayoutManager.loadFontthrows anUnsupportedOperationExceptionis thrown. All fonts have to be loaded with
GlyphLayoutManager.loadFont.LayoutProcessor
LayoutProcessoris the predecessor ofGlyphLayoutManagerand is deprecated now, useGlyphLayoutManager.FopGlyphProcessor
GlyphLayoutManager and
FopGlyphProcessorcan't be used together, you have to decide for one of them.If you use GlyphLayoutProcessor, FopGlyphProcessor is switched off using document.setGlyphSubstitutionEnabled().
This call disables FopGlyphProcessor, and its functionality like glyph substitution and more will be provided by GlyphLayoutManager.
Examples
Producing a document
This example shows the correct rendering for all letters from DIN 91379.
Code: GlyphLayoutDin91379.java
Result: GlyphLayoutDin91379.pdf
Processing a form
GlyphLayoutFormDin91379.java
GlyphLayoutFormDin91379.pdf
Producing a document with bidirectional text
Java's
Bidi-class is used to deduce the text direction for each chunk of text,it should not be necessary to specify the text direction per font explicitly.
GlyphLayoutBidi.java
GlyphLayoutBidi.pdf
GlyphLayoutBidiRotated.java
GlyphLayoutBidiRotated.pdf
Specify direction per font
It is possible to set the direction per font, but this should not be necessary.
GlyphLayoutBidiPerFont.java
GlyphLayoutBidiPerFont.pdf
Load the font from an input stream
You can load the font from an input stream.
GlyphLayoutInputStream.java
GlyphLayoutInputStream.pdf
Specify kerning and ligatures per document
Optionally you can specify kerning and ligatures per document.
GlyphLayoutKernLiga.java
GlyphLayoutKernLiga.pdf
Specify kerning and ligatures per font
Optionally you can specify kerning and ligatures per font.
GlyphLayoutKernLigaPerFont.java
GlyphLayoutKernLigaPerFont.pdf
Use GlyphLayoutManager for Letters from the Unicode Supplementary Multilingual Plane
Show letters and symbols from the Unicode Supplementary Multilingual Plane,
GlyphLayoutSMP
GlyphLayoutSMP.pdf
Use GlyphLayoutManager with an image
GlyphLayoutWithImage
GlyphLayoutWithImage.pdf
Open source OpenType fonts
References