Class: Krill::Fragment
- Inherits:
-
Object
- Object
- Krill::Fragment
- Defined in:
- lib/krill/fragment.rb
Instance Attribute Summary collapse
-
#ascender ⇒ Object
Returns the value of attribute ascender.
-
#baseline ⇒ Object
Returns the value of attribute baseline.
-
#descender ⇒ Object
Returns the value of attribute descender.
-
#font ⇒ Object
(also: #formatter)
readonly
Returns the value of attribute font.
-
#format_state ⇒ Object
readonly
Returns the value of attribute format_state.
-
#left ⇒ Object
Returns the value of attribute left.
-
#line_height ⇒ Object
Returns the value of attribute line_height.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
- #width ⇒ Object
-
#word_spacing ⇒ Object
Returns the value of attribute word_spacing.
Instance Method Summary collapse
- #bottom ⇒ Object
- #character_spacing ⇒ Object
- #default_direction=(direction) ⇒ Object
- #direction ⇒ Object
- #height ⇒ Object
- #include_trailing_white_space! ⇒ Object
-
#initialize(text, format_state) ⇒ Fragment
constructor
A new instance of Fragment.
- #right ⇒ Object
- #space_count ⇒ Object
- #strikethrough_points ⇒ Object
- #subscript? ⇒ Boolean
- #superscript? ⇒ Boolean
- #top ⇒ Object
- #underline_points ⇒ Object
- #y_offset ⇒ Object
Constructor Details
#initialize(text, format_state) ⇒ Fragment
Returns a new instance of Fragment.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/krill/fragment.rb', line 11 def initialize(text, format_state) @format_state = format_state @font = format_state.fetch(:font) @word_spacing = 0 # keep the original value of "text", so we can reinitialize @text if formatting parameters # like text direction are changed @original_text = text @text = process_text(@original_text) end |
Instance Attribute Details
#ascender ⇒ Object
Returns the value of attribute ascender.
5 6 7 |
# File 'lib/krill/fragment.rb', line 5 def ascender @ascender end |
#baseline ⇒ Object
Returns the value of attribute baseline.
6 7 8 |
# File 'lib/krill/fragment.rb', line 6 def baseline @baseline end |
#descender ⇒ Object
Returns the value of attribute descender.
5 6 7 |
# File 'lib/krill/fragment.rb', line 5 def descender @descender end |
#font ⇒ Object (readonly) Also known as: formatter
Returns the value of attribute font.
8 9 10 |
# File 'lib/krill/fragment.rb', line 8 def font @font end |
#format_state ⇒ Object (readonly)
Returns the value of attribute format_state.
3 4 5 |
# File 'lib/krill/fragment.rb', line 3 def format_state @format_state end |
#left ⇒ Object
Returns the value of attribute left.
6 7 8 |
# File 'lib/krill/fragment.rb', line 6 def left @left end |
#line_height ⇒ Object
Returns the value of attribute line_height.
5 6 7 |
# File 'lib/krill/fragment.rb', line 5 def line_height @line_height end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/krill/fragment.rb', line 3 def text @text end |
#width ⇒ Object
22 23 24 25 |
# File 'lib/krill/fragment.rb', line 22 def width return @width if @word_spacing.zero? @width + @word_spacing * space_count end |
#word_spacing ⇒ Object
Returns the value of attribute word_spacing.
6 7 8 |
# File 'lib/krill/fragment.rb', line 6 def word_spacing @word_spacing end |
Instance Method Details
#bottom ⇒ Object
88 89 90 |
# File 'lib/krill/fragment.rb', line 88 def bottom baseline - descender end |
#character_spacing ⇒ Object
39 40 41 |
# File 'lib/krill/fragment.rb', line 39 def character_spacing formatter.character_spacing end |
#default_direction=(direction) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/krill/fragment.rb', line 64 def default_direction=(direction) unless @format_state[:direction] @format_state[:direction] = direction @text = process_text(@original_text) end end |
#direction ⇒ Object
60 61 62 |
# File 'lib/krill/fragment.rb', line 60 def direction @format_state[:direction] end |
#height ⇒ Object
27 28 29 |
# File 'lib/krill/fragment.rb', line 27 def height top - bottom end |
#include_trailing_white_space! ⇒ Object
71 72 73 74 |
# File 'lib/krill/fragment.rb', line 71 def include_trailing_white_space! @format_state.delete(:exclude_trailing_white_space) @text = process_text(@original_text) end |
#right ⇒ Object
80 81 82 |
# File 'lib/krill/fragment.rb', line 80 def right left + width end |
#space_count ⇒ Object
76 77 78 |
# File 'lib/krill/fragment.rb', line 76 def space_count @text.count(" ") end |
#strikethrough_points ⇒ Object
55 56 57 58 |
# File 'lib/krill/fragment.rb', line 55 def strikethrough_points y = baseline + ascender * 0.3 [[left, y], [right, y]] end |
#subscript? ⇒ Boolean
35 36 37 |
# File 'lib/krill/fragment.rb', line 35 def subscript? formatter.subscript? end |
#superscript? ⇒ Boolean
31 32 33 |
# File 'lib/krill/fragment.rb', line 31 def superscript? formatter.superscript? end |
#top ⇒ Object
84 85 86 |
# File 'lib/krill/fragment.rb', line 84 def top baseline + ascender end |
#underline_points ⇒ Object
50 51 52 53 |
# File 'lib/krill/fragment.rb', line 50 def underline_points y = baseline - 1.25 [[left, y], [right, y]] end |
#y_offset ⇒ Object
43 44 45 46 47 48 |
# File 'lib/krill/fragment.rb', line 43 def y_offset if subscript? then -descender elsif superscript? then 0.85 * ascender else 0 end end |