Class: Arrolio::InlineRun
- Inherits:
-
Object
- Object
- Arrolio::InlineRun
- 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
-
#baseline_shift ⇒ Object
readonly
Returns the value of attribute baseline_shift.
-
#font_size_scale ⇒ Object
readonly
Returns the value of attribute font_size_scale.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Object
- #hyperlink? ⇒ Boolean
-
#initialize(text, style: Style.new, baseline_shift: nil, font_size_scale: 1.0, href: nil) ⇒ InlineRun
constructor
A new instance of InlineRun.
- #length ⇒ Object
- #width(measurer, font_size: style.font_size) ⇒ Object
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_shift ⇒ Object (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_scale ⇒ Object (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 |
#href ⇒ Object (readonly)
Returns the value of attribute href.
14 15 16 |
# File 'lib/arrolio/inline_run.rb', line 14 def href @href end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
14 15 16 |
# File 'lib/arrolio/inline_run.rb', line 14 def style @style end |
#text ⇒ Object (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
25 26 27 |
# File 'lib/arrolio/inline_run.rb', line 25 def empty? @text.empty? end |
#hash ⇒ Object
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
42 43 44 |
# File 'lib/arrolio/inline_run.rb', line 42 def hyperlink? !@href.nil? && !@href.empty? end |
#length ⇒ Object
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 |