prawn-fillform 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,23 +50,33 @@ module Prawn
50
50
  deref(@dictionary[:Ff])
51
51
  end
52
52
 
53
+ def font_size
54
+ deref(@dictionary[:DA]).split(" ")[1].to_f
55
+ end
56
+
57
+ def font_color
58
+ Prawn::Graphics::Color.rgb2hex(deref(@dictionary[:DA]).split(" ")[3..5].collect { |e| e.to_f * 255 }).to_s
59
+ end
60
+
53
61
  end
54
62
 
55
63
  class Text < Field
56
64
 
57
65
  def align
58
- case deref(@dictionary[:Q])
66
+ case deref(@dictionary[:Q]).to_i
59
67
  when 0
60
68
  :left
61
69
  when 1
62
70
  :center
63
71
  when 2
64
72
  :right
73
+ else
74
+ :left
65
75
  end
66
76
  end
67
77
 
68
78
  def max_length
69
- deref(@dictionary[:MaxLen])
79
+ deref(@dictionary[:MaxLen]).to_i
70
80
  end
71
81
 
72
82
  def type
@@ -108,6 +118,16 @@ module Prawn
108
118
  end
109
119
  end
110
120
 
121
+ def acroform_field_names
122
+ result = []
123
+ acroform_fields.each do |page, fields|
124
+ fields.each do |field|
125
+ result << field.name
126
+ end
127
+ end
128
+ result
129
+ end
130
+
111
131
  def acroform_fields
112
132
  acroform = {}
113
133
  state.pages.each_with_index do |page, i|
@@ -139,20 +159,24 @@ module Prawn
139
159
  fields.each do |field|
140
160
  number = page.to_s.split("_").last.to_i
141
161
  go_to_page(number)
142
- value = data[page][field.name] rescue nil
162
+ value = data[page][field.name].fetch(:value) rescue nil
163
+ options = data[page][field.name].fetch(:options) rescue nil
164
+ options ||= {}
143
165
 
144
166
  if value
145
- if field.instance_of? Prawn::Fillform::Text
146
- text_box value, :at => [field.x, field.y],
147
- :align => field.align,
148
- :width => field.width,
149
- :height => field.height,
150
- :valign => :center
151
- elsif field.instance_of? Prawn::Fillform::Button
152
- image value, :at => [field.x, field.y],
153
- :position => :center,
154
- :vposition => :center,
155
- :fit => [field.width, field.height]
167
+ if field.type == :text
168
+ fill_color options[:font_color] || field.font_color
169
+ text_box value, :at => [field.x + 2, field.y - 1],
170
+ :align => options[:align] || field.align,
171
+ :width => options[:width] || field.width,
172
+ :height => options[:height] || field.height,
173
+ :valign => options[:valign] || :center,
174
+ :size => options[:font_size] || field.font_size
175
+ elsif field.type == :button
176
+ image value, :at => [field.x + 2, field.y - 1],
177
+ :position => options[:position] || :center,
178
+ :vposition => options[:vposition] || :center,
179
+ :fit => options[:fit] || [field.width, field.height]
156
180
  end
157
181
  end
158
182
  end
@@ -1,6 +1,6 @@
1
1
  module Prawn
2
2
  module Fillform
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-fillform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: