Class: Prawn::SVG::Elements::Text

Inherits:
Elements::DirectRenderBase
  • Object
show all
Defined in:
lib/prawn/svg/elements/text.rb

Defined Under Namespace

Classes: Cursor

Instance Method Summary collapse

Instance Method Details

#parseObject



5
6
7
8
9
10
# File 'lib/prawn/svg/elements/text.rb', line 5

def parse
  @root_component = Elements::TextComponent.new(document, source, [], state.dup)
  @root_component.process

  reintroduce_trailing_and_leading_whitespace if @root_component.children
end

#render(prawn, renderer) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/prawn/svg/elements/text.rb', line 12

def render(prawn, renderer)
  return unless @root_component.children

  origin_x = @root_component.x_values.first
  origin_y = @root_component.y_values.first

  @root_component.lay_out(prawn)

  translate_x =
    case @root_component.computed_properties.text_anchor
    when 'middle'
      -@root_component.calculated_width / 2.0
    when 'end'
      -@root_component.calculated_width
    end

  cursor = Cursor.new(0, document.sizing.output_height)

  if vertical_writing_mode?
    render_vertical(prawn, renderer, cursor, translate_x, origin_x, origin_y)
  else
    @root_component.render_component(prawn, renderer, cursor, translate_x)
  end
end