Permalink
Browse files

Merge branch 'text-field-appearance-streams' of git://github.com/brad…

…ediger/prawn-forms
  • Loading branch information...
2 parents e7f40bb + dd6ee1e commit 076e37a682a3295d5db82b7521a9bf9e74e61791 Wes Garrison committed Dec 19, 2011
Showing with 21 additions and 4 deletions.
  1. +21 −4 lib/prawn/forms.rb
View
@@ -21,6 +21,7 @@ def button(text)
def text_field(name, x, y, w, h, opts = {})
x, y = map_to_absolute(x, y)
+ border = opts.fetch(:border, true)
field_dict = {:T => Prawn::Core::LiteralString.new(name),
:DA => Prawn::Core::LiteralString.new(
@@ -31,7 +32,7 @@ def text_field(name, x, y, w, h, opts = {})
:MK => {:BC => [0, 0, 0]},
:Rect => [x, y, x + w, y - h]}
- if opts.fetch(:border, true)
+ if border
field_dict[:MK] = {:BC => [0, 0, 0]}
end
@@ -48,7 +49,7 @@ def text_field(name, x, y, w, h, opts = {})
field_dict.merge!(
:Type => :Annot,
:Subtype => :Widget,
- :AP => text_field_appearance_stream(opts[:default], w, h),
+ :AP => text_field_appearance_stream(opts[:default], w, h, border),
:P => state.page.dictionary)
end
@@ -88,7 +89,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)
+ def text_field_appearance_stream(default_text, w, h, border)
# 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).
@@ -99,7 +100,23 @@ def text_field_appearance_stream(default_text, w, h)
# the font resources and stream are embedded in the form XObject, not
# the page's content stream.
#
- stream = "/Tx BMC q BT\n"
+ stream = "/Tx BMC q\n"
+
+ # If there is a border, we must include it in the appearance stream,
+ # otherwise it won't show up in the default state.
+ if border
+ # Fudge the borders so they stay inside the box. This appears to be
+ # necessary, from examining Acrobat's output.
+ # Example:
+ # /BBox[0.0 0.0 149.999 22.0]
+ # vs.
+ # 0.5 0.5 148.9995 21 re s
+ box = [0.5, 0.5, w-1, h-1]
+ stream << "#{box.map{ |x| Prawn::Core::PdfObject(x)}.join(" ")} re S\n"
+ end
+
+ stream << "BT\n"
+
font_refs = {}
x, y = pad_x, bounds.height - h + pad_y
text_box(default_text,

0 comments on commit 076e37a

Please sign in to comment.