Module: Pdfrb::Layout::TextShaper

Defined in:
lib/pdfrb/layout/text_shaper.rb

Overview

Text shaping interface. Pure-Ruby shapers don't exist for the complexity of OpenType GSUB/GPOS — this module defines the contract that a real shaper (HarfBuzz, fribidi, etc.) must satisfy. Callers can plug in a shaper implementation via Pdfrb::Layout::TextShaper.implementation = MyShaper.

The default implementation is grapheme-cluster-aware: it keeps each user-perceived character (a base + combining marks, a Hangul syllable, an emoji-ZWJ sequence, etc.) together as one cluster so the TextLayouter measures and breaks at cluster boundaries, never inside one.

Defined Under Namespace

Classes: ShapedRun

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.implementationObject

Returns the value of attribute implementation.



23
24
25
# File 'lib/pdfrb/layout/text_shaper.rb', line 23

def implementation
  @implementation
end

Class Method Details

.shape(text, font: nil, size: 12, direction: :ltr) ⇒ Object

Shape text for font at size. Returns a ShapedRun.

When an implementation is registered, delegates to it. Otherwise runs the default grapheme-cluster shaper.



29
30
31
32
33
34
35
36
# File 'lib/pdfrb/layout/text_shaper.rb', line 29

def shape(text, font: nil, size: 12, direction: :ltr)
  if implementation
    return implementation.shape(text, font: font, size: size,
                                      direction: direction)
  end

  default_shape(text, size, direction)
end