Sha256: d45b8a26a65c80980fb7a63ae1e80ca067800560b4b141f4cc762a096a289964

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8
#
# Horizontal text alignment can be achieved by supplying the <code>:align</code>
# option to the text methods. Available options are <code>:left</code>
# (default), <code>:right</code>, <code>:center</code>, and
# <code>:justify</code>.
#
# Vertical text alignment can be achieved using the <code>:valign</code> option
# with the text methods. Available options are <code>:top</code> (default),
# <code>:center</code>, and <code>:bottom</code>.
#
# Both forms of alignment will be evaluated in the context of the current
# bounding_box.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  text "This text should be left aligned"
  text "This text should be centered",      :align => :center
  text "This text should be right aligned", :align => :right

  bounding_box([0, 220], :width => 250, :height => 220) do
    text "This text is flowing from the left. " * 4

    move_down 15
    text "This text is flowing from the center. " * 3, :align => :center

    move_down 15
    text "This text is flowing from the right. " * 4, :align => :right

    move_down 15
    text "This text is justified. " * 6, :align => :justify
    transparent(0.5) { stroke_bounds }
  end

  bounding_box([300, 220], :width => 250, :height => 220) do
    text "This text should be vertically top aligned"
    text "This text should be vertically centered",       :valign => :center
    text "This text should be vertically bottom aligned", :valign => :bottom
    transparent(0.5) { stroke_bounds }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prawn-2.1.0 manual/text/alignment.rb
prawn-2.0.2 manual/text/alignment.rb