Prawn::Text::Formatted::Fragment is a state store for a formatted text fragment. It does not render anything.
# File lib/prawn/text/formatted/fragment.rb, line 22 def initialize(text, format_state, document) @format_state = format_state @document = document @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
# File lib/prawn/text/formatted/fragment.rb, line 181 def absolute_bottom absolute_bounding_box[1] end
# File lib/prawn/text/formatted/fragment.rb, line 193 def absolute_bottom_left [absolute_left, absolute_bottom] end
# File lib/prawn/text/formatted/fragment.rb, line 197 def absolute_bottom_right [absolute_right, absolute_bottom] end
# File lib/prawn/text/formatted/fragment.rb, line 62 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
# File lib/prawn/text/formatted/fragment.rb, line 169 def absolute_left absolute_bounding_box[0] end
# File lib/prawn/text/formatted/fragment.rb, line 173 def absolute_right absolute_bounding_box[2] end
# File lib/prawn/text/formatted/fragment.rb, line 177 def absolute_top absolute_bounding_box[3] end
# File lib/prawn/text/formatted/fragment.rb, line 185 def absolute_top_left [absolute_left, absolute_top] end
# File lib/prawn/text/formatted/fragment.rb, line 189 def absolute_top_right [absolute_right, absolute_top] end
# File lib/prawn/text/formatted/fragment.rb, line 89 def anchor @format_state[:anchor] end
# File lib/prawn/text/formatted/fragment.rb, line 149 def bottom baseline - descender end
# File lib/prawn/text/formatted/fragment.rb, line 165 def bottom_left [left, bottom] end
# File lib/prawn/text/formatted/fragment.rb, line 161 def bottom_right [right, bottom] end
# File lib/prawn/text/formatted/fragment.rb, line 58 def bounding_box [left, bottom, right, top] end
# File lib/prawn/text/formatted/fragment.rb, line 130 def callback_objects callback = @format_state[:callback] if callback.nil? [] elsif callback.is_a?(Array) callback else [callback] end end
# File lib/prawn/text/formatted/fragment.rb, line 105 def character_spacing @format_state[:character_spacing] || @document.character_spacing end
# File lib/prawn/text/formatted/fragment.rb, line 93 def color @format_state[:color] end
# File lib/prawn/text/formatted/fragment.rb, line 114 def default_direction=(direction) unless @format_state[:direction] @format_state[:direction] = direction @text = process_text(@original_text) end end
# File lib/prawn/text/formatted/fragment.rb, line 110 def direction @format_state[:direction] end
# File lib/prawn/text/formatted/fragment.rb, line 97 def font @format_state[:font] end
# File lib/prawn/text/formatted/fragment.rb, line 39 def height top - bottom end
# File lib/prawn/text/formatted/fragment.rb, line 121 def include_trailing_white_space! @format_state.delete(:exclude_trailing_white_space) @text = process_text(@original_text) end
# File lib/prawn/text/formatted/fragment.rb, line 85 def link @format_state[:link] end
# File lib/prawn/text/formatted/fragment.rb, line 141 def right left + width end
# File lib/prawn/text/formatted/fragment.rb, line 101 def size @format_state[:size] end
# File lib/prawn/text/formatted/fragment.rb, line 126 def space_count @text.count(" ") end
# File lib/prawn/text/formatted/fragment.rb, line 76 def strikethrough_points y = baseline + ascender * 0.3 [[left, y], [right, y]] end
# File lib/prawn/text/formatted/fragment.rb, line 81 def styles @format_state[:styles] || [] end
# File lib/prawn/text/formatted/fragment.rb, line 43 def subscript? styles.include?(:subscript) end
# File lib/prawn/text/formatted/fragment.rb, line 47 def superscript? styles.include?(:superscript) end
# File lib/prawn/text/formatted/fragment.rb, line 145 def top baseline + ascender end
# File lib/prawn/text/formatted/fragment.rb, line 153 def top_left [left, top] end
# File lib/prawn/text/formatted/fragment.rb, line 157 def top_right [right, top] end
# File lib/prawn/text/formatted/fragment.rb, line 71 def underline_points y = baseline - 1.25 [[left, y], [right, y]] end
# File lib/prawn/text/formatted/fragment.rb, line 33 def width if @word_spacing == 0 then @width else @width + @word_spacing * space_count end end
# File lib/prawn/text/formatted/fragment.rb, line 51 def y_offset if subscript? then -descender elsif superscript? then 0.85 * ascender else 0 end end
# File lib/prawn/text/formatted/fragment.rb, line 220 def exclude_trailing_white_space? @format_state[:exclude_trailing_white_space] end
# File lib/prawn/text/formatted/fragment.rb, line 224 def normalized_soft_hyphen @format_state[:normalized_soft_hyphen] end
# File lib/prawn/text/formatted/fragment.rb, line 228 def process_soft_hyphens(string) if string.length > 0 && normalized_soft_hyphen ruby_19 { if string.encoding != normalized_soft_hyphen.encoding string.force_encoding(normalized_soft_hyphen.encoding) end } string[0..-2].gsub(normalized_soft_hyphen, "") + string[-1..-1] else string end end
# File lib/prawn/text/formatted/fragment.rb, line 203 def process_text(text) string = strip_zero_width_spaces(text) if exclude_trailing_white_space? string = process_soft_hyphens(string.rstrip) end case direction when :rtl if ruby_18 { true } string.scan(/./u).reverse.join else string.reverse end else string end end
# File lib/prawn/text/formatted/fragment.rb, line 241 def strip_zero_width_spaces(string) if !"".respond_to?(:encoding) || string.encoding.to_s == "UTF-8" string.gsub(Prawn::Text::ZWSP, "") else string end end