File: indentation.rb

package info (click to toggle)
ruby-prawn 1.0.0~rc1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: ruby: 17,499; sh: 44; makefile: 17
file content (46 lines) | stat: -rw-r--r-- 1,319 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# encoding: utf-8
# 
# Sometimes you just need to indent a portion of the contents of a bounding box, and
# using a nested bounding box is just pure overkill. The <code>indent</code>
# method is what you might need.
#
# Just provide a number for it to indent all content generated inside the
# block. 
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Example.generate(filename) do
  text "No indentation on the margin box."
  indent(20) do
    text "Some indentation inside an indent block."
  end
  move_down 20
  
  bounding_box([50, cursor], :width => 400, :height => cursor) do
    transparent(0.5) { stroke_bounds }
    
    move_down 10
    text "No indentation inside this bounding box."
    indent(40) do
      text "Inside an indent block. And so is the following line:"
      
      stroke_horizontal_rule
    end
    move_down 10
    text "No indentation"
    
    move_down 20
    indent(60) do
      text "Another indent block."
      
      bounding_box([0, cursor], :width => 200) do
        text "Note that this bounding box coordinates are relative to the " +
             "indent block"
        
        transparent(0.5) { stroke_bounds }
      end
    end
  end
end