class Prawn::Text::Formatted::Fragment
Prawn::Text::Formatted::Fragment is a state store for a formatted text fragment. It does not render anything.
@private
Attributes
Public Class Methods
Source
# File lib/prawn/text/formatted/fragment.rb, line 24 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
@param text [String] @param format_state [Hash{Symbol => any}] @param document [Prawn::Documnt]
Public Instance Methods
Source
# File lib/prawn/text/formatted/fragment.rb, line 289 def absolute_bottom absolute_bounding_box[1] end
Absolute vertical coordinate of the bottom side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 310 def absolute_bottom_left [absolute_left, absolute_bottom] end
Absolute coordinates of the bottom left corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 317 def absolute_bottom_right [absolute_right, absolute_bottom] end
Absolute coordinates of the bottom right corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 87 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
Fragment bounding box, relative to the containing page.
@return [Array(Number, Number, Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 268 def absolute_left absolute_bounding_box[0] end
Absolute horizontal coordinate of the left side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 275 def absolute_right absolute_bounding_box[2] end
Absolute horizontal coordinate of the right side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 282 def absolute_top absolute_bounding_box[3] end
Absolute vertical coordinate of the top side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 296 def absolute_top_left [absolute_left, absolute_top] end
Absolute coordinates of the top left corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 303 def absolute_top_right [absolute_right, absolute_top] end
Absolute coordinates of the top right corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 129 def anchor @format_state[:anchor] end
Anchor.
@return [PDF::Core::Reference, Array, Hash]
Source
# File lib/prawn/text/formatted/fragment.rb, line 233 def bottom baseline - descender end
Vertical coordinate of the bottom side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 261 def bottom_left [left, bottom] end
Coordinates of the bottom left corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 254 def bottom_right [right, bottom] end
Coordinates of the bottom right corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 80 def bounding_box [left, bottom, right, top] end
Fragment bounding box, relative to the containing bounding box.
@return [Array(Number, Number, Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 205 def callback_objects callback = @format_state[:callback] if callback.nil? [] elsif callback.is_a?(Array) callback else [callback] end end
Callbacks.
@return [Array]
Source
# File lib/prawn/text/formatted/fragment.rb, line 164 def character_spacing @format_state[:character_spacing] || @document.character_spacing end
Character spacing.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 143 def color @format_state[:color] end
Fragment color.
@return [Color]
Source
# File lib/prawn/text/formatted/fragment.rb, line 180 def default_direction=(direction) unless @format_state[:direction] @format_state[:direction] = direction @text = process_text(@original_text) end end
Set default text direction.
@param direction [:ltr, :rtl] @return [void]
Source
# File lib/prawn/text/formatted/fragment.rb, line 172 def direction @format_state[:direction] end
Text direction.
@return [:ltr, :rtl]
Source
# File lib/prawn/text/formatted/fragment.rb, line 150 def font @format_state[:font] end
Fragment font name.
@return [String]
Source
# File lib/prawn/text/formatted/fragment.rb, line 48 def height top - bottom end
Height of fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 190 def include_trailing_white_space! @format_state.delete(:exclude_trailing_white_space) @text = process_text(@original_text) end
Keep trailing spaces.
@return [void]
Source
# File lib/prawn/text/formatted/fragment.rb, line 122 def link @format_state[:link] end
Fragment link.
@return [String, nil]
Source
# File lib/prawn/text/formatted/fragment.rb, line 136 def local @format_state[:local] end
Local destination.
@return [String]
Source
# File lib/prawn/text/formatted/fragment.rb, line 219 def right left + width end
Horizontal coordinate of the right side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 157 def size @format_state[:size] end
Font size.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 198 def space_count @text.count(' ') end
Number of spaces in the text.
@return [Integer]
Source
# File lib/prawn/text/formatted/fragment.rb, line 107 def strikethrough_points y = baseline + (ascender * 0.3) [[left, y], [right, y]] end
Strikethrough endpoints.
@return [Array(Array(Number, Number), Array(Number, Number))]
Source
# File lib/prawn/text/formatted/fragment.rb, line 115 def styles @format_state[:styles] || [] end
Fragment font styles.
@return [Array<Symbol>]
Source
# File lib/prawn/text/formatted/fragment.rb, line 55 def subscript? styles.include?(:subscript) end
Is this a subscript fragment?
@return [Boolean]
Source
# File lib/prawn/text/formatted/fragment.rb, line 62 def superscript? styles.include?(:superscript) end
Is this a superscript fragment?
@return [Boolean]
Source
# File lib/prawn/text/formatted/fragment.rb, line 226 def top baseline + ascender end
Vertical coordinate of the top side of the fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 240 def top_left [left, top] end
Coordinates of the top left corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 247 def top_right [right, top] end
Coordinates of the top right corner of the fragment.
@return [Array(Number, Number)]
Source
# File lib/prawn/text/formatted/fragment.rb, line 99 def underline_points y = baseline - 1.25 [[left, y], [right, y]] end
Underline endpoints.
@return [Array(Array(Number, Number), Array(Number, Number))]
Source
# File lib/prawn/text/formatted/fragment.rb, line 38 def width if @word_spacing.zero? then @width else @width + (@word_spacing * space_count) end end
Width of fragment.
@return [Number]
Source
# File lib/prawn/text/formatted/fragment.rb, line 69 def y_offset if subscript? then -descender elsif superscript? then 0.85 * ascender else 0 end end
Vertical offset of the fragment.
@return [Number]