Class: Prawn::Format::TextObject
- Inherits:
-
Object
- Object
- Prawn::Format::TextObject
- Includes:
- Graphics::Color
- Defined in:
- lib/prawn/format/text_object.rb
Constant Summary collapse
- RENDER_MODES =
{ :fill => 0, :stroke => 1, :fill_stroke => 2, :invisible => 3, :fill_clip => 4, :stroke_clip => 5, :fill_stroke_clip => 6, :clip => 7 }
Instance Method Summary collapse
- #add_content(string) ⇒ Object
- #character_space(dc) ⇒ Object
- #close ⇒ Object
- #font(identifier, size) ⇒ Object
-
#initialize ⇒ TextObject
constructor
A new instance of TextObject.
- #leading(dl) ⇒ Object
- #move_by(dx, dy) ⇒ Object
- #move_to(x, y) ⇒ Object
- #next_line(dy) ⇒ Object
- #open ⇒ Object
- #render(mode) ⇒ Object
- #rise(value) ⇒ Object
- #rotate(x, y, theta) ⇒ Object
- #show(argument) ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #word_space(dw) ⇒ Object
Constructor Details
#initialize ⇒ TextObject
Returns a new instance of TextObject.
21 22 23 24 |
# File 'lib/prawn/format/text_object.rb', line 21 def initialize @content = nil @last_x = @last_y = 0 end |
Instance Method Details
#add_content(string) ⇒ Object
102 103 104 |
# File 'lib/prawn/format/text_object.rb', line 102 def add_content(string) @content << string << "\n" end |
#character_space(dc) ⇒ Object
56 57 58 59 |
# File 'lib/prawn/format/text_object.rb', line 56 def character_space(dc) @content << "#{dc} Tc\n" self end |
#close ⇒ Object
31 32 33 34 |
# File 'lib/prawn/format/text_object.rb', line 31 def close @content << "ET" self end |
#font(identifier, size) ⇒ Object
71 72 73 74 |
# File 'lib/prawn/format/text_object.rb', line 71 def font(identifier, size) @content << "/#{identifier} #{size} Tf\n" self end |
#leading(dl) ⇒ Object
66 67 68 69 |
# File 'lib/prawn/format/text_object.rb', line 66 def leading(dl) @content << "#{dl} TL\n" self end |
#move_by(dx, dy) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/prawn/format/text_object.rb', line 40 def move_by(dx,dy) @last_x += dx @last_y += dy @content << "#{dx} #{dy} Td\n" self end |
#move_to(x, y) ⇒ Object
36 37 38 |
# File 'lib/prawn/format/text_object.rb', line 36 def move_to(x, y) move_by(x - @last_x, y - @last_y) end |
#next_line(dy) ⇒ Object
47 48 |
# File 'lib/prawn/format/text_object.rb', line 47 def next_line(dy) end |
#open ⇒ Object
26 27 28 29 |
# File 'lib/prawn/format/text_object.rb', line 26 def open @content = "BT\n" self end |
#render(mode) ⇒ Object
76 77 78 79 80 |
# File 'lib/prawn/format/text_object.rb', line 76 def render(mode) mode_value = RENDER_MODES[mode] || raise(ArgumentError, "unsupported render mode #{mode.inspect}, should be one of #{RENDER_MODES.keys.inspect}") @content << "#{mode_value} Tr\n" self end |
#rise(value) ⇒ Object
82 83 84 85 |
# File 'lib/prawn/format/text_object.rb', line 82 def rise(value) @content << "#{value} Ts\n" self end |
#rotate(x, y, theta) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/prawn/format/text_object.rb', line 87 def rotate(x, y, theta) radians = theta * Math::PI / 180 cos, sin = Math.cos(radians), Math.sin(radians) arr = [cos, sin, -sin, cos, x, y] add_content "%.3f %.3f %.3f %.3f %.3f %.3f Tm" % arr end |
#show(argument) ⇒ Object
50 51 52 53 54 |
# File 'lib/prawn/format/text_object.rb', line 50 def show(argument) instruction = argument.is_a?(Array) ? "TJ" : "Tj" @content << "#{Prawn::PdfObject(argument, true)} #{instruction}\n" self end |
#to_s ⇒ Object
94 95 96 |
# File 'lib/prawn/format/text_object.rb', line 94 def to_s @content end |
#to_str ⇒ Object
98 99 100 |
# File 'lib/prawn/format/text_object.rb', line 98 def to_str @content end |
#word_space(dw) ⇒ Object
61 62 63 64 |
# File 'lib/prawn/format/text_object.rb', line 61 def word_space(dw) @content << "#{dw} Tw\n" self end |