Skip to content

Commit

Permalink
Merge pull request #10 from genuitytech/4e13c8f3455203f43739e01aa46c3…
Browse files Browse the repository at this point in the history
…ae53db4135c

Implement checkboxes
  • Loading branch information
moessimple committed May 21, 2013
2 parents e3c04ba + 4e13c8f commit 74a53e9
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions lib/prawn-fillform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ def type
end
end

class Checkbox < Field
YES = "\u2713".freeze
NO = "".freeze

def type
:checkbox
end

def font_style
:normal
end

def font_size
12.0
end
end

class References
include Prawn::Document::Internals
def initialize(state)
Expand Down Expand Up @@ -206,7 +223,11 @@ def acroform_fields
when :Tx
acroform[page_number] << Text.new(dictionary)
when :Btn
acroform[page_number] << Button.new(dictionary)
if deref(dictionary[:AP]).has_key? :D
acroform[page_number] << Checkbox.new(dictionary)
else
acroform[page_number] << Button.new(dictionary)
end
end
end
end
Expand Down Expand Up @@ -245,8 +266,19 @@ def fill_form_with(data={})
# Default to the document font size if the field size is 0
:size => options[:font_size] || ((size = field.font_size) > 0.0 ? size : font_size),
:style => options[:font_style] || field.font_style
elsif field.type == :checkbox
is_yes = (v = value.downcase) == "yes" || v == "1" || v == "true"

formatted_text_box [{
text: is_yes ? Checkbox::YES : Checkbox::NO,
font: "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf",
size: field.font_size,
styles: [field.font_style]
}],
:at => [field.x + x_offset, field.y + y_offset],
:width => options[:width] || field.width,
:height => options[:height] || field.height
elsif field.type == :button

bounding_box([field.x + x_offset, field.y + y_offset], :width => field.width, :height => field.height) do
if value =~ /http/
image open(value), :position => options[:position] || :center,
Expand Down

0 comments on commit 74a53e9

Please sign in to comment.