Skip to content

Commit

Permalink
Merge remote-tracking branch 'bradediger/text-field-appearance-streams'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/prawn/forms.rb
  • Loading branch information
Wes Garrison committed Dec 30, 2011
2 parents 375cba1 + 79b6b21 commit 159e12e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/prawn/forms.rb
Expand Up @@ -49,10 +49,17 @@ def text_field(name, x, y, w, h, opts = {})
field_dict.merge!(
:Type => :Annot,
:Subtype => :Widget,
:AP => text_field_appearance_stream(opts[:default].gsub("NEWLINE", "\012"), w, h, border),
:AP => text_field_appearance_stream(opts[:default].gsub("NEWLINE", "\012"), w, h, border, opts[:align]),
:P => state.page.dictionary)
end

case opts[:align]
when :center
field_dict.merge!(:Q => 1)
when :right
field_dict.merge!(:Q => 2)
end

add_interactive_field(:Tx, field_dict)
end

Expand Down Expand Up @@ -89,7 +96,7 @@ def acroform_resources
# Return a ref to a Form XObject containing the appearance stream for
# a text field.
#
def text_field_appearance_stream(default_text, w, h, border)
def text_field_appearance_stream(default_text, w, h, border, align)
# Padding to make the appearance stream line up with the text box once
# activated. Determined through experiment (Adobe Acrobat Pro 10.1.1,
# OS X).
Expand Down Expand Up @@ -122,6 +129,7 @@ def text_field_appearance_stream(default_text, w, h, border)
text_box(default_text,
:width => w - 4, # account for padding
:height => h,
:align => align || :left,
:draw_text_callback => lambda { |text, options|
new_x, new_y = options[:at]
dx, dy = new_x - x, new_y - y
Expand Down

0 comments on commit 159e12e

Please sign in to comment.