Skip to content

Commit

Permalink
changed text_at to draw_text
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Nelson authored and Daniel Nelson committed Feb 11, 2010
1 parent db0535d commit 1f9f495
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion bench/afm_text_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Prawn::Document.new {
N.times do
(1..5).each do |i|
text_at "Hello Prawn", :at => [200, i * 100]
draw_text "Hello Prawn", :at => [200, i * 100]
end
start_new_page
end
Expand Down
2 changes: 1 addition & 1 deletion bench/ttf_text_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
N.times do
(1..5).each do |i|
text_at "Hello Prawn", :at => [200, i * 100]
draw_text "Hello Prawn", :at => [200, i * 100]
end
start_new_page
end
Expand Down
4 changes: 2 additions & 2 deletions examples/general/measurement_units.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
temp << "1#{unit} => #{one_unit_in_pt}pt\n" #puts converted unit in points

offset = offset_multiplier * unit_index
pdf.text_at units[unit_index], :at => [offset + 0.5.mm, pdf.bounds.top - 2.mm]
pdf.draw_text units[unit_index], :at => [offset + 0.5.mm, pdf.bounds.top - 2.mm]

pdf.stroke_line(offset, pdf.bounds.top, offset, pdf.bounds.bottom)

0.upto(((pdf.bounds.height - 5.mm) / one_unit_in_pt).to_i) do |i| # checks, how many strokes can be drawn
pdf.stroke_line(offset, i * one_unit_in_pt, (i % 5 == 0 ? 6.mm : 3.mm) + offset, i * one_unit_in_pt) # every fifth stroke is twice as large like on a real ruler
pdf.text_at "#{i}#{unit}", :at => [7.mm + offset, i * one_unit_in_pt] unless unit == "mm" && i % 5 != 0 || unit == "pt" && i % 10 != 0 # avoid text too close to each other
pdf.draw_text "#{i}#{unit}", :at => [7.mm + offset, i * one_unit_in_pt] unless unit == "mm" && i % 5 != 0 || unit == "pt" && i % 10 != 0 # avoid text too close to each other
end
end

Expand Down
14 changes: 7 additions & 7 deletions examples/general/repeaters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
Prawn::Document.generate("repeat.pdf", :skip_page_creation => true) do

repeat :all do
text_at "ALLLLLL", :at => bounds.top_left
draw_text "ALLLLLL", :at => bounds.top_left
end

repeat :odd do
text_at "ODD", :at => [0,0]
draw_text "ODD", :at => [0,0]
end

repeat :even do
text_at "EVEN", :at => [0,0]
draw_text "EVEN", :at => [0,0]
end

repeat [1,2] do
text_at "[1,2]", :at => [100,0]
draw_text "[1,2]", :at => [100,0]
end

repeat 2..4 do
text_at "2..4", :at => [200,0]
draw_text "2..4", :at => [200,0]
end

repeat(lambda { |pg| pg % 3 == 0 }) do
text_at "Every third", :at => [250, 20]
draw_text "Every third", :at => [250, 20]
end

10.times do
start_new_page
text_at "A wonderful page", :at => [400,400]
draw_text "A wonderful page", :at => [400,400]
end

end
Expand Down
8 changes: 4 additions & 4 deletions examples/general/stamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
Prawn::Document.generate("stamp.pdf", :skip_page_creation => true) do

create_stamp("odd_page_template") do
text_at "This is the odd page template",
draw_text "This is the odd page template",
:at => [0, bounds.top - font.height]
text_at "This is also in the odd page template", :at => [0, 0]
draw_text "This is also in the odd page template", :at => [0, 0]
end

create_stamp("even_page_template") do
text_at "This is the even page template",
draw_text "This is the even page template",
:at => [0, bounds.top - font.height]
text_at "This is also in the even page template", :at => [0, 0]
draw_text "This is also in the even page template", :at => [0, 0]
end

start_new_page
Expand Down
2 changes: 1 addition & 1 deletion examples/graphics/basic_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
stef = "#{Prawn::BASEDIR}/data/images/stef.jpg"
image stef, :at => [500, 400], :width => 200, :height => 200

text_at "Please enjoy the pigs", :size => 36, :at => [200,15]
draw_text "Please enjoy the pigs", :size => 36, :at => [200,15]

ruport = "#{Prawn::BASEDIR}/data/images/ruport.png"
image ruport, :at => [400,200], :width => 150
Expand Down
16 changes: 8 additions & 8 deletions examples/graphics/transformations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@
y = pdf.bounds.top - 50

pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("reference rectangle", :at => [x + width, y - height])
pdf.draw_text("reference rectangle", :at => [x + width, y - height])
pdf.rotate(30, :origin => [x, y]) do
pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("rectangle rotated around upper-left corner", :at => [x + width, y - height])
pdf.draw_text("rectangle rotated around upper-left corner", :at => [x + width, y - height])
end

x = 50
y = pdf.bounds.top - 200

pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("reference rectangle", :at => [x + width, y - height])
pdf.draw_text("reference rectangle", :at => [x + width, y - height])
pdf.rotate(30, :origin => [x + width / 2, y - height / 2]) do
pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("rectangle rotated around center", :at => [x + width, y - height])
pdf.draw_text("rectangle rotated around center", :at => [x + width, y - height])
end

# SCALE
x = 0
y = pdf.bounds.top - 500

pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("reference rectangle", :at => [x + width, y - height])
pdf.draw_text("reference rectangle", :at => [x + width, y - height])
pdf.scale(2, :origin => [x, y]) do
pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("rectangle scaled from upper-left corner", :at => [x + width, y - height])
pdf.draw_text("rectangle scaled from upper-left corner", :at => [x + width, y - height])
end

x = 150
y = pdf.bounds.top - 400

pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("reference rectangle", :at => [x + width, y - height])
pdf.draw_text("reference rectangle", :at => [x + width, y - height])
pdf.scale(2, :origin => [x + width / 2, y - height / 2]) do
pdf.stroke_rectangle([x, y], width, height)
pdf.text_at("rectangle scaled from center", :at => [x + width, y - height])
pdf.draw_text("rectangle scaled from center", :at => [x + width, y - height])
end
end
2 changes: 1 addition & 1 deletion examples/m17n/win_ansi_charset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
when :center then offset = (total_width - width)/2
end

text_at(field, :at => [dx + offset, y])
draw_text(field, :at => [dx + offset, y])
end

dx += total_width
Expand Down
6 changes: 3 additions & 3 deletions examples/text/font_calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def demonstration
bl = y - bounds.absolute_bottom

stroke_horizontal_rule
text_at "When using text positioned with :at, the baseline is used", :at => [0, bl]
draw_text "When using text positioned with :at, the baseline is used", :at => [0, bl]

text_at "(and the Y-cursor is not moved)", :at => [350, bl]
draw_text "(and the Y-cursor is not moved)", :at => [350, bl]

colors = { :ascender => "ff0000",
:descender => "00ff00",
Expand Down Expand Up @@ -57,7 +57,7 @@ def demonstration
move_down 40

bl = y - bounds.absolute_bottom
text_at "The quick brown fox jumps over the lazy dog.", :at => [0, bl]
draw_text "The quick brown fox jumps over the lazy dog.", :at => [0, bl]

stroke_color colors[:ascender]
stroke_line [0, bl], [0, bl + font.ascender]
Expand Down
8 changes: 4 additions & 4 deletions examples/text/kerning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
require "#{File.dirname(__FILE__)}/../example_helper.rb"

Prawn::Document.generate "kerning.pdf" do
text_at "To kern?", :at => [200,720], :size => 24, :kerning => true
text_at "To not kern?", :at => [200,690], :size => 24, :kerning => false
draw_text "To kern?", :at => [200,720], :size => 24, :kerning => true
draw_text "To not kern?", :at => [200,690], :size => 24, :kerning => false

move_down 100

Expand All @@ -18,8 +18,8 @@

font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"

text_at "To kern?", :at => [200,660], :size => 24, :kerning => true
text_at "To not kern?", :at => [200,630], :size => 24, :kerning => false
draw_text "To kern?", :at => [200,660], :size => 24, :kerning => true
draw_text "To not kern?", :at => [200,630], :size => 24, :kerning => false

pad(30) do
text "To kern and wrap. " * 5, :size => 24, :kerning => true
Expand Down
6 changes: 3 additions & 3 deletions examples/text/simple_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

Prawn::Document.generate "simple_text.pdf" do
fill_color "0000ff"
text_at "Hello World", :at => [200,420], :size => 32, :rotate => 45
draw_text "Hello World", :at => [200,420], :size => 32, :rotate => 45
font "Times-Roman"
fill_color "ff0000"
text_at "Using Another Font", :at => [5,5]
draw_text "Using Another Font", :at => [5,5]
start_new_page
font "Courier"
text_at "Goodbye World", :at => [288,50]
draw_text "Goodbye World", :at => [288,50]
end
2 changes: 1 addition & 1 deletion examples/text/simple_text_ttf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Prawn::Document.generate "simple_text_ttf.pdf" do
fill_color "0000ff"
font "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
text_at "Hello World", :at => [200,720], :size => 32
draw_text "Hello World", :at => [200,720], :size => 32

font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"

Expand Down
6 changes: 3 additions & 3 deletions lib/prawn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.inherited(base) #:nodoc:
# # self here is set to the newly instantiated Prawn::Document
# # and so any variables in the outside scope are unavailable
# font "Times-Roman"
# text_at "Hello World", :at => [200,720], :size => 32
# draw_text "Hello World", :at => [200,720], :size => 32
# end
#
# If you need to access your local and instance variables, use the explicit
Expand All @@ -124,7 +124,7 @@ def self.inherited(base) #:nodoc:
# Prawn::Document.generate "example.pdf" do |pdf|
# # self here is left alone
# pdf.font "Times-Roman"
# pdf.text_at content, :at => [200,720], :size => 32
# pdf.draw_text content, :at => [200,720], :size => 32
# end
#
def self.generate(filename,options={},&block)
Expand Down Expand Up @@ -552,7 +552,7 @@ def number_pages(string, position)
page_count.times do |i|
go_to_page(i+1)
str = string.gsub("<page>","#{i+1}").gsub("<total>","#{page_count}")
text_at str, :at => position
draw_text str, :at => position
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/prawn/document/bounding_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def anchor
#
# Example, position some text 3 pts from the left of the containing box:
#
# text_at('hello', :at => [(bounds.left + 3), 0])
# draw_text('hello', :at => [(bounds.left + 3), 0])
#
def left
0
Expand Down Expand Up @@ -248,7 +248,7 @@ def indent(left_padding, &block)
#
# Example, position some text 3 pts from the right of the containing box:
#
# text_at('hello', :at => [(bounds.right - 3), 0])
# draw_text('hello', :at => [(bounds.right - 3), 0])
#
def right
@width
Expand All @@ -258,7 +258,7 @@ def right
#
# Example, position some text 3 pts from the top of the containing box:
#
# text_at('hello', :at => [0, (bounds.top - 3)])
# draw_text('hello', :at => [0, (bounds.top - 3)])
#
def top
height
Expand All @@ -268,7 +268,7 @@ def top
#
# Example, position some text 3 pts from the bottom of the containing box:
#
# text_at('hello', :at => [0, (bounds.bottom + 3)])
# draw_text('hello', :at => [0, (bounds.bottom + 3)])
#
def bottom
0
Expand Down
14 changes: 7 additions & 7 deletions lib/prawn/repeater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,32 @@ def repeaters
# Prawn::Document.generate("repeat.pdf", :skip_page_creation => true) do
#
# repeat :all do
# text_at "ALLLLLL", :at => bounds.top_left
# draw_text "ALLLLLL", :at => bounds.top_left
# end
#
# repeat :odd do
# text_at "ODD", :at => [0,0]
# draw_text "ODD", :at => [0,0]
# end
#
# repeat :even do
# text_at "EVEN", :at => [0,0]
# draw_text "EVEN", :at => [0,0]
# end
#
# repeat [1,2] do
# text_at "[1,2]", :at => [100,0]
# draw_text "[1,2]", :at => [100,0]
# end
#
# repeat 2..4 do
# text_at "2..4", :at => [200,0]
# draw_text "2..4", :at => [200,0]
# end
#
# repeat(lambda { |pg| pg % 3 == 0 }) do
# text_at "Every third", :at => [250, 20]
# draw_text "Every third", :at => [250, 20]
# end
#
# 10.times do
# start_new_page
# text_at "A wonderful page", :at => [400,400]
# draw_text "A wonderful page", :at => [400,400]
# end
#
# end
Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/stamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Prawn
# Example:
# pdf.create_stamp("my_stamp") {
# pdf.fill_circle_at([10, 15], :radius => 5)
# pdf.text_at("hello world", :at => [20, 10])
# pdf.draw_text("hello world", :at => [20, 10])
# }
# pdf.stamp("my_stamp")
#
Expand Down Expand Up @@ -72,7 +72,7 @@ def stamp_at(name, point)
# Example:
# pdf.create_stamp("my_stamp") {
# pdf.fill_circle_at([10, 15], :radius => 5)
# pdf.text_at("hello world", :at => [20, 10])
# pdf.draw_text("hello world", :at => [20, 10])
# }
#
def create_stamp(name, &block)
Expand Down
16 changes: 8 additions & 8 deletions lib/prawn/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def text(text, options={})
# Draws text on the page, beginning at the point specified by the :at option
# the string is assumed to be pre-formatted to properly fit the page.
#
# pdf.text_at "Hello World", :at => [100,100]
# pdf.text_at "Goodbye World", :at => [50,50], :size => 16
# pdf.draw_text "Hello World", :at => [100,100]
# pdf.draw_text "Goodbye World", :at => [50,50], :size => 16
#
# If your font contains kerning pairs data that Prawn can parse, the
# text will be kerned by default. You can disable this feature by passing
Expand Down Expand Up @@ -158,10 +158,10 @@ def text(text, options={})
# Raises <tt>ArgumentError</tt> if <tt>:at</tt> option omitted
# Raises <tt>ArgumentError</tt> if <tt>:align</tt> option included
#
def text_at(text, options)
def draw_text(text, options)
# we modify the options. don't change the user's hash
options = options.dup
inspect_options_for_text_at(options)
inspect_options_for_draw_text(options)
# dup because normalize_encoding changes the string
text = text.to_s.dup
options = @text_options.merge(options)
Expand Down Expand Up @@ -193,11 +193,11 @@ def fill_text_box(text, options)
remaining_text
end

def inspect_options_for_text_at(options)
def inspect_options_for_draw_text(options)
if options[:at].nil?
raise ArgumentError, "The :at option is required for text_at"
raise ArgumentError, "The :at option is required for draw_text"
elsif options[:align]
raise ArgumentError, "The :align option does not work with text_at"
raise ArgumentError, "The :align option does not work with draw_text"
end
valid_options = VALID_TEXT_OPTIONS.dup.concat([:at, :rotate])
Prawn.verify_options(valid_options, options)
Expand All @@ -206,7 +206,7 @@ def inspect_options_for_text_at(options)
def inspect_options_for_text(options)
if options[:at]
raise ArgumentError, ":at is no longer a valid option with text." +
"use text_at or text_box instead"
"use draw_text or text_box instead"
end
options[:final_gap] = options[:final_gap].nil? || options[:final_gap]
options[:document] = self
Expand Down
Loading

0 comments on commit 1f9f495

Please sign in to comment.