File: font.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 (37 lines) | stat: -rw-r--r-- 1,101 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
# encoding: utf-8
# 
# The <code>font</code> method can be used in three different ways.
#
# If we don't pass it any arguments it will return the current font being used
# to render text.
#
# If we just pass it a font name it will use that font for rendering text
# through the rest of the document.
#
# It can also be used by passing a font name and a block. In this case the
# specified font will only be used to render text 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 "Let's see which font we are using: #{font.inspect}"
  
  move_down 20
  font "Times-Roman"
  text "Written in Times."
  
  move_down 20
  font("Courier") do
    text "Written in Courier because we are inside the block."
  end
  
  move_down 20
  text "Written in Times again as we left the previous block."
  
  move_down 20
  text "Let's see which font we are using again: #{font.inspect}"
  
  font "Helvetica"  # back to normal
end