Class: Arrolio::InlineRun

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/inline_run.rb

Overview

One inline run within a paragraph: a contiguous span of text sharing a single Style. A paragraph is laid out as a list of InlineRun instances. Lives at the Layout level so that other Layout modules (InlineBuilder, TextLayout, FO::Compiler) all share the same type.

Carries optional baseline_shift (:sub / :sup / nil) and font_size_scale for subscript/superscript rendering, plus optional href for hyperlink annotations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, style: Style.new, baseline_shift: nil, font_size_scale: 1.0, href: nil) ⇒ InlineRun

Returns a new instance of InlineRun.



16
17
18
19
20
21
22
23
# File 'lib/arrolio/inline_run.rb', line 16

def initialize(text, style: Style.new, baseline_shift: nil,
               font_size_scale: 1.0, href: nil)
  @text = text.to_s
  @style = style
  @baseline_shift = baseline_shift
  @font_size_scale = font_size_scale.to_f
  @href = href
end

Instance Attribute Details

#baseline_shiftObject (readonly)

Returns the value of attribute baseline_shift.



14
15
16
# File 'lib/arrolio/inline_run.rb', line 14

def baseline_shift
  @baseline_shift
end

#font_size_scaleObject (readonly)

Returns the value of attribute font_size_scale.



14
15
16
# File 'lib/arrolio/inline_run.rb', line 14

def font_size_scale
  @font_size_scale
end

#hrefObject (readonly)

Returns the value of attribute href.



14
15
16
# File 'lib/arrolio/inline_run.rb', line 14

def href
  @href
end

#styleObject (readonly)

Returns the value of attribute style.



14
15
16
# File 'lib/arrolio/inline_run.rb', line 14

def style
  @style
end

#textObject (readonly)

Returns the value of attribute text.



14
15
16
# File 'lib/arrolio/inline_run.rb', line 14

def text
  @text
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/arrolio/inline_run.rb', line 46

def ==(other)
  other.is_a?(self.class) &&
    text == other.text &&
    style == other.style &&
    baseline_shift == other.baseline_shift &&
    font_size_scale == other.font_size_scale &&
    href == other.href
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/arrolio/inline_run.rb', line 25

def empty?
  @text.empty?
end

#hashObject



55
56
57
# File 'lib/arrolio/inline_run.rb', line 55

def hash
  [text, style, baseline_shift, font_size_scale, href].hash
end

#hyperlink?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/arrolio/inline_run.rb', line 42

def hyperlink?
  !@href.nil? && !@href.empty?
end

#lengthObject



29
30
31
# File 'lib/arrolio/inline_run.rb', line 29

def length
  @text.length
end

#width(measurer, font_size: style.font_size) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/arrolio/inline_run.rb', line 33

def width(measurer, font_size: style.font_size)
  measurer.width_of_run(
    @text,
    font_size: font_size * @font_size_scale,
    character_spacing: style.character_spacing,
    word_spacing: style.word_spacing
  )
end