Class: HexaPDF::Layout::TextShaper
- Inherits:
-
Object
- Object
- HexaPDF::Layout::TextShaper
- Defined in:
- lib/hexapdf/layout/text_shaper.rb
Overview
This class is used to perform text shaping, i.e. changing the position of glyphs (e.g. for kerning) or substituting one or more glyphs for other glyphs (e.g. for ligatures).
Status of the implementation:
-
All text shaping functionality possible for Type1 fonts is implemented, i.e. kerning and ligature substitution.
-
For TrueType fonts only kerning via the ‘kern’ table is implemented.
Instance Method Summary collapse
-
#shape_text(text_fragment) ⇒ Object
Shapes the given text fragment in-place.
Instance Method Details
#shape_text(text_fragment) ⇒ Object
Shapes the given text fragment in-place.
The following shaping options, retrieved from the text fragment’s Style#font_features, are supported:
- :kern
-
Pair-wise kerning.
- :liga
-
Ligature substitution.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hexapdf/layout/text_shaper.rb', line 62 def shape_text(text_fragment) font = text_fragment.style.font if text_fragment.style.font_features[:liga] && font.wrapped_font.features.include?(:liga) if font.font_type == :Type1 process_type1_ligatures(text_fragment) end text_fragment.clear_cache end if text_fragment.style.font_features[:kern] && font.wrapped_font.features.include?(:kern) case font.font_type when :TrueType process_true_type_kerning(text_fragment) when :Type1 process_type1_kerning(text_fragment) end text_fragment.clear_cache end text_fragment end |