prawn-fillform 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/prawn-fillform.rb +38 -14
- data/lib/prawn-fillform/version.rb +1 -1
- metadata +1 -1
data/lib/prawn-fillform.rb
CHANGED
@@ -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.
|
146
|
-
|
147
|
-
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
:
|
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
|