Module: Ruport::Util::FormHelpers
- Defined in:
- lib/ruport/util/pdf/form.rb
Instance Method Summary collapse
- #checked_box(x, y, width = 12, height = 12) ⇒ Object
-
#draw_border(x, y, width, height, opts = {}) ⇒ Object
Draws a box at the specified x and y coordinates (top left corner), with the specified width and height.
- #draw_line(x1, y1, x2, y2, thickness) ⇒ Object
- #form_field(label, text, opts = {}) ⇒ Object
- #full_width(x = nil) ⇒ Object
-
#horizontal_line_at(y, x1, x2) ⇒ Object
draws a horizontal line at y from x1 to x2.
- #option_box(opt, choice, opts = {}) ⇒ Object
- #unchecked_box(x, y, width = 12, height = 12) ⇒ Object
Instance Method Details
#checked_box(x, y, width = 12, height = 12) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ruport/util/pdf/form.rb', line 60 def checked_box(x,y,width=12,height=12) draw_border(x,y,width,height) pdf_writer.line(x, y, x + width, y - height) pdf_writer.line(x + width, y, x, y - height) pdf_writer.stroke end |
#draw_border(x, y, width, height, opts = {}) ⇒ Object
Draws a box at the specified x and y coordinates (top left corner), with the specified width and height
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruport/util/pdf/form.rb', line 73 def draw_border(x,y,width,height,opts={}) border = Array(opts[:border] || 1) border_top = border[0] border_right = border[1] || border_top border_bottom = border[2] || border_top border_left = border[3] || border_right draw_line(x, y, x + width, y, border_top) if border_top > 0 draw_line(x + width, y, x + width, y - height, border_right) if border_right > 0 draw_line(x, y - height, x + width, y - height, border_bottom) if border_bottom > 0 draw_line(x, y, x, y - height, border_left) if border_left > 0 end |
#draw_line(x1, y1, x2, y2, thickness) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/ruport/util/pdf/form.rb', line 90 def draw_line(x1,y1,x2,y2,thickness) ss = PDF::Writer::StrokeStyle.new(thickness) pdf_writer.stroke_style(ss) pdf_writer.line(x1,y1,x2,y2) pdf_writer.stroke end |
#form_field(label, text, opts = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruport/util/pdf/form.rb', line 5 def form_field(label,text,opts={}) padding = Array(opts.delete(:padding) || 0) padding_top = padding[0] padding_right = padding[1] || padding_top padding_bottom = padding[2] || padding_top padding_left = padding[3] || padding_right x = opts.delete(:x) || left_boundary y = opts.delete(:y) || cursor width = opts.delete(:width) || full_width(x) height = opts.delete(:height) old_cursor = cursor old_font = pdf_writer.font_size move_cursor_to(y - 2 - padding_top) if opts[:style] == "vertical" draw_text "<b>#{label}</b>\n#{text}", :left => x + 10 + padding_left height ||= pdf_writer.font_height * (text.count("\n") + 2) + 10 + padding_top + padding_bottom else draw_text "<b>#{label}</b> #{text}", :left => x + 10 + padding_left height ||= pdf_writer.font_height + 10 + padding_top + padding_bottom end draw_border(x,y,width,height,opts) if opts[:maintain_cursor] move_cursor_to(old_cursor) else move_cursor(-8 - padding_bottom) end pdf_writer.font_size = old_font end |
#full_width(x = nil) ⇒ Object
103 104 105 |
# File 'lib/ruport/util/pdf/form.rb', line 103 def full_width(x=nil) x ? right_boundary - x : right_boundary - left_boundary end |
#horizontal_line_at(y, x1, x2) ⇒ Object
draws a horizontal line at y from x1 to x2
98 99 100 101 |
# File 'lib/ruport/util/pdf/form.rb', line 98 def horizontal_line_at(y,x1,x2) pdf_writer.line(x1,y,x2,y) pdf_writer.stroke end |
#option_box(opt, choice, opts = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruport/util/pdf/form.rb', line 39 def option_box(opt,choice,opts={}) x = opts[:x] || left_boundary y = opts[:y] || cursor width = opts[:width] || 12 height = opts[:height] || 12 old_cursor = cursor old_font = pdf_writer.font_size if opt.eql?(choice) checked_box(x + 10, y - 3, width, height) else unchecked_box(x + 10, y - 3, width, height) end draw_text opts[:label], :left => x + 10 + width + 8, :y => y if opts[:label] opts[:maintain_cursor] ? move_cursor_to(old_cursor) : move_cursor(-8) pdf_writer.font_size = old_font end |
#unchecked_box(x, y, width = 12, height = 12) ⇒ Object
67 68 69 |
# File 'lib/ruport/util/pdf/form.rb', line 67 def unchecked_box(x,y,width=12,height=12) draw_border(x,y,width,height) end |