class Prawn::SVG::Elements::Text

Public Instance Methods

apply() click to toggle source
# File lib/prawn/svg/elements/text.rb, line 11
def apply
  add_call_and_enter "text_group"
  @text_root.apply_step(calls)
end
parse() click to toggle source
# File lib/prawn/svg/elements/text.rb, line 2
def parse
  state.text = Prawn::SVG::Elements::TextComponent::PositionsList.new([], [], [], [], [], nil)

  @text_root = Prawn::SVG::Elements::TextComponent.new(document, source, nil, state.dup)
  @text_root.parse_step

  reintroduce_trailing_and_leading_whitespace
end

Private Instance Methods

apply_calls_from_standard_attributes() click to toggle source
# File lib/prawn/svg/elements/text.rb, line 22
def apply_calls_from_standard_attributes
  # overridden because we want the attributes to be applied in the TextComponent root,
  # which is a duplicate of this element.
end
apportion_leading_and_trailing_spaces(printables) click to toggle source
# File lib/prawn/svg/elements/text.rb, line 58
def apportion_leading_and_trailing_spaces(printables)
  printables.each_cons(2) do |a, b|
    if a.text.empty?
      # Empty strings can only get a leading space from the previous non-empty text,
      # and never get a trailing space
    elsif a.trailing_space?
      a.text += ' '
    elsif b.leading_space?
      b.text = " #{b.text}"
    end
  end
end
built_printable_queue(queue, component) click to toggle source
# File lib/prawn/svg/elements/text.rb, line 36
def built_printable_queue(queue, component)
  component.commands.each do |command|
    case command
    when Prawn::SVG::Elements::TextComponent::Printable
      queue << command
    else
      built_printable_queue(queue, command)
    end
  end
end
drawable?() click to toggle source
# File lib/prawn/svg/elements/text.rb, line 18
def drawable?
  false
end
reintroduce_trailing_and_leading_whitespace() click to toggle source
# File lib/prawn/svg/elements/text.rb, line 27
def reintroduce_trailing_and_leading_whitespace
  printables = []
  built_printable_queue(printables, @text_root)

  remove_whitespace_only_printables_and_start_and_end(printables)
  remove_printables_that_are_completely_empty(printables)
  apportion_leading_and_trailing_spaces(printables)
end
remove_printables_that_are_completely_empty(printables) click to toggle source
# File lib/prawn/svg/elements/text.rb, line 52
def remove_printables_that_are_completely_empty(printables)
  printables.reject! do |printable|
    printable.text.empty? && !printable.trailing_space? && !printable.leading_space?
  end
end
remove_whitespace_only_printables_and_start_and_end(printables) click to toggle source
# File lib/prawn/svg/elements/text.rb, line 47
def remove_whitespace_only_printables_and_start_and_end(printables)
  printables.pop   while printables.last  && printables.last.text.empty?
  printables.shift while printables.first && printables.first.text.empty?
end