Class: Prawn::Text::Formatted::Fragment
- Inherits:
-
Object
- Object
- Prawn::Text::Formatted::Fragment
- Defined in:
- lib/prawn/text/formatted/fragment.rb
Overview
Prawn::Text::Formatted::Fragment is a state store for a formatted text fragment. It does not render anything.
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.
-
#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.
- #width ⇒ Object
-
#word_spacing ⇒ Object
Returns the value of attribute word_spacing.
Instance Method Summary collapse
- #absolute_bottom ⇒ Object
- #absolute_bottom_left ⇒ Object
- #absolute_bottom_right ⇒ Object
- #absolute_bounding_box ⇒ Object
- #absolute_left ⇒ Object
- #absolute_right ⇒ Object
- #absolute_top ⇒ Object
- #absolute_top_left ⇒ Object
- #absolute_top_right ⇒ Object
- #anchor ⇒ Object
- #bottom ⇒ Object
- #bottom_left ⇒ Object
- #bottom_right ⇒ Object
- #bounding_box ⇒ Object
- #callback_objects ⇒ Object
- #character_spacing ⇒ Object
- #color ⇒ Object
- #default_direction=(direction) ⇒ Object
- #direction ⇒ Object
- #font ⇒ Object
- #height ⇒ Object
- #include_trailing_white_space! ⇒ Object
-
#initialize(text, format_state, document) ⇒ Fragment
constructor
A new instance of Fragment.
- #link ⇒ Object
- #right ⇒ Object
- #size ⇒ Object
- #space_count ⇒ Object
- #strikethrough_points ⇒ Object
- #styles ⇒ Object
- #subscript? ⇒ Boolean
- #superscript? ⇒ Boolean
- #text ⇒ Object
- #top ⇒ Object
- #top_left ⇒ Object
- #top_right ⇒ Object
- #underline_points ⇒ Object
- #y_offset ⇒ Object
Constructor Details
#initialize(text, format_state, document) ⇒ Fragment
Returns a new instance of Fragment.
23 24 25 26 27 28 |
# File 'lib/prawn/text/formatted/fragment.rb', line 23 def initialize(text, format_state, document) @text = text @format_state = format_state @document = document @word_spacing = 0 end |
Instance Attribute Details
#ascender ⇒ Object
Returns the value of attribute ascender.
20 21 22 |
# File 'lib/prawn/text/formatted/fragment.rb', line 20 def ascender @ascender end |
#baseline ⇒ Object
Returns the value of attribute baseline.
21 22 23 |
# File 'lib/prawn/text/formatted/fragment.rb', line 21 def baseline @baseline end |
#descender ⇒ Object
Returns the value of attribute descender.
20 21 22 |
# File 'lib/prawn/text/formatted/fragment.rb', line 20 def descender @descender end |
#format_state ⇒ Object (readonly)
Returns the value of attribute format_state.
18 19 20 |
# File 'lib/prawn/text/formatted/fragment.rb', line 18 def format_state @format_state end |
#left ⇒ Object
Returns the value of attribute left.
21 22 23 |
# File 'lib/prawn/text/formatted/fragment.rb', line 21 def left @left end |
#line_height ⇒ Object
Returns the value of attribute line_height.
20 21 22 |
# File 'lib/prawn/text/formatted/fragment.rb', line 20 def line_height @line_height end |
#width ⇒ Object
48 49 50 51 52 |
# File 'lib/prawn/text/formatted/fragment.rb', line 48 def width if @word_spacing == 0 then @width else @width + @word_spacing * space_count end end |
#word_spacing ⇒ Object
Returns the value of attribute word_spacing.
21 22 23 |
# File 'lib/prawn/text/formatted/fragment.rb', line 21 def word_spacing @word_spacing end |
Instance Method Details
#absolute_bottom ⇒ Object
193 194 195 |
# File 'lib/prawn/text/formatted/fragment.rb', line 193 def absolute_bottom absolute_bounding_box[1] end |
#absolute_bottom_left ⇒ Object
205 206 207 |
# File 'lib/prawn/text/formatted/fragment.rb', line 205 def absolute_bottom_left [absolute_left, absolute_bottom] end |
#absolute_bottom_right ⇒ Object
209 210 211 |
# File 'lib/prawn/text/formatted/fragment.rb', line 209 def absolute_bottom_right [absolute_right, absolute_bottom] end |
#absolute_bounding_box ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/prawn/text/formatted/fragment.rb', line 77 def absolute_bounding_box box = bounding_box box[0] += @document.bounds.absolute_left box[2] += @document.bounds.absolute_left box[1] += @document.bounds.absolute_bottom box[3] += @document.bounds.absolute_bottom box end |
#absolute_left ⇒ Object
181 182 183 |
# File 'lib/prawn/text/formatted/fragment.rb', line 181 def absolute_left absolute_bounding_box[0] end |
#absolute_right ⇒ Object
185 186 187 |
# File 'lib/prawn/text/formatted/fragment.rb', line 185 def absolute_right absolute_bounding_box[2] end |
#absolute_top ⇒ Object
189 190 191 |
# File 'lib/prawn/text/formatted/fragment.rb', line 189 def absolute_top absolute_bounding_box[3] end |
#absolute_top_left ⇒ Object
197 198 199 |
# File 'lib/prawn/text/formatted/fragment.rb', line 197 def absolute_top_left [absolute_left, absolute_top] end |
#absolute_top_right ⇒ Object
201 202 203 |
# File 'lib/prawn/text/formatted/fragment.rb', line 201 def absolute_top_right [absolute_right, absolute_top] end |
#anchor ⇒ Object
104 105 106 |
# File 'lib/prawn/text/formatted/fragment.rb', line 104 def anchor @format_state[:anchor] end |
#bottom ⇒ Object
161 162 163 |
# File 'lib/prawn/text/formatted/fragment.rb', line 161 def bottom baseline - descender end |
#bottom_left ⇒ Object
177 178 179 |
# File 'lib/prawn/text/formatted/fragment.rb', line 177 def bottom_left [left, bottom] end |
#bottom_right ⇒ Object
173 174 175 |
# File 'lib/prawn/text/formatted/fragment.rb', line 173 def bottom_right [right, bottom] end |
#bounding_box ⇒ Object
73 74 75 |
# File 'lib/prawn/text/formatted/fragment.rb', line 73 def bounding_box [left, bottom, right, top] end |
#callback_objects ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/prawn/text/formatted/fragment.rb', line 142 def callback_objects callback = @format_state[:callback] if callback.nil? [] elsif callback.is_a?(Array) callback else [callback] end end |
#character_spacing ⇒ Object
120 121 122 123 |
# File 'lib/prawn/text/formatted/fragment.rb', line 120 def character_spacing @format_state[:character_spacing] || @document.character_spacing end |
#color ⇒ Object
108 109 110 |
# File 'lib/prawn/text/formatted/fragment.rb', line 108 def color @format_state[:color] end |
#default_direction=(direction) ⇒ Object
129 130 131 |
# File 'lib/prawn/text/formatted/fragment.rb', line 129 def default_direction=(direction) @format_state[:direction] = direction unless @format_state[:direction] end |
#direction ⇒ Object
125 126 127 |
# File 'lib/prawn/text/formatted/fragment.rb', line 125 def direction @format_state[:direction] end |
#font ⇒ Object
112 113 114 |
# File 'lib/prawn/text/formatted/fragment.rb', line 112 def font @format_state[:font] end |
#height ⇒ Object
54 55 56 |
# File 'lib/prawn/text/formatted/fragment.rb', line 54 def height top - bottom end |
#include_trailing_white_space! ⇒ Object
133 134 135 |
# File 'lib/prawn/text/formatted/fragment.rb', line 133 def include_trailing_white_space! @format_state.delete(:exclude_trailing_white_space) end |
#link ⇒ Object
100 101 102 |
# File 'lib/prawn/text/formatted/fragment.rb', line 100 def link @format_state[:link] end |
#right ⇒ Object
153 154 155 |
# File 'lib/prawn/text/formatted/fragment.rb', line 153 def right left + width end |
#size ⇒ Object
116 117 118 |
# File 'lib/prawn/text/formatted/fragment.rb', line 116 def size @format_state[:size] end |
#space_count ⇒ Object
137 138 139 140 |
# File 'lib/prawn/text/formatted/fragment.rb', line 137 def space_count string = exclude_trailing_white_space? ? @text.rstrip : @text string.count(" ") end |
#strikethrough_points ⇒ Object
91 92 93 94 |
# File 'lib/prawn/text/formatted/fragment.rb', line 91 def strikethrough_points y = baseline + ascender * 0.3 [[left, y], [right, y]] end |
#styles ⇒ Object
96 97 98 |
# File 'lib/prawn/text/formatted/fragment.rb', line 96 def styles @format_state[:styles] || [] end |
#subscript? ⇒ Boolean
58 59 60 |
# File 'lib/prawn/text/formatted/fragment.rb', line 58 def subscript? styles.include?(:subscript) end |
#superscript? ⇒ Boolean
62 63 64 |
# File 'lib/prawn/text/formatted/fragment.rb', line 62 def superscript? styles.include?(:superscript) end |
#text ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/prawn/text/formatted/fragment.rb', line 30 def text string = strip_zero_width_spaces(@text) if exclude_trailing_white_space? string = string.rstrip string = process_soft_hyphens(string) end case direction when :rtl if ruby_18 { true } string.scan(/./mu).reverse.join else string.reverse end else string end end |
#top ⇒ Object
157 158 159 |
# File 'lib/prawn/text/formatted/fragment.rb', line 157 def top baseline + ascender end |
#top_left ⇒ Object
165 166 167 |
# File 'lib/prawn/text/formatted/fragment.rb', line 165 def top_left [left, top] end |
#top_right ⇒ Object
169 170 171 |
# File 'lib/prawn/text/formatted/fragment.rb', line 169 def top_right [right, top] end |
#underline_points ⇒ Object
86 87 88 89 |
# File 'lib/prawn/text/formatted/fragment.rb', line 86 def underline_points y = baseline - 1.25 [[left, y], [right, y]] end |
#y_offset ⇒ Object
66 67 68 69 70 71 |
# File 'lib/prawn/text/formatted/fragment.rb', line 66 def y_offset if subscript? then -descender elsif superscript? then 0.85 * ascender else 0 end end |