Class: Mork::GridPDF

Inherits:
Grid
  • Object
show all
Defined in:
lib/mork/grid_pdf.rb

Overview

GridPDF gets coordinates and measurements from a Grid and provides SheetPDF with the properly computed values

Instance Method Summary collapse

Methods inherited from Grid

#barcode_bits, #max_choices_per_question, #max_questions, #options, #rm_blur, #rm_dilate, #show

Constructor Details

#initialize(options = nil) ⇒ GridPDF

Returns a new instance of GridPDF.



7
8
9
# File 'lib/mork/grid_pdf.rb', line 7

def initialize(options=nil)
  super options
end

Instance Method Details

#barcode_heightObject



25
26
27
# File 'lib/mork/grid_pdf.rb', line 25

def barcode_height
  super.mm
end

#barcode_widthObject



21
22
23
# File 'lib/mork/grid_pdf.rb', line 21

def barcode_width
  super.mm
end

#barcode_xy_for(code) ⇒ Object



29
30
31
32
# File 'lib/mork/grid_pdf.rb', line 29

def barcode_xy_for(code)
  black = barcode_bits.times.reject { |x| (code>>x)[0]==0 }
  black.collect { |x| barcode_xy x+1 }
end

#calibration_cells_xyObject



38
39
40
41
42
# File 'lib/mork/grid_pdf.rb', line 38

def calibration_cells_xy
  rows.times.collect do |q|
    [(reg_frame_width-cell_spacing).mm, item_y(q).mm]
  end
end

#choice_spacingObject



60
61
62
# File 'lib/mork/grid_pdf.rb', line 60

def choice_spacing
  cell_spacing.mm
end

#croundObject



68
69
70
# File 'lib/mork/grid_pdf.rb', line 68

def cround
  @cround ||= [width_of_cell, height_of_cell].min / 2
end

#header_align(k) ⇒ Object



80
# File 'lib/mork/grid_pdf.rb', line 80

def header_align(k)  @params[:header][k][:align]             end

#header_boxed?(k) ⇒ Boolean

Returns:

  • (Boolean)


81
# File 'lib/mork/grid_pdf.rb', line 81

def header_boxed?(k) @params[:header][k][:box] == true       end

#header_height(k) ⇒ Object



78
# File 'lib/mork/grid_pdf.rb', line 78

def header_height(k) @params[:header][k][:height].to_f.mm    end

#header_padding(k) ⇒ Object



90
91
92
93
94
95
# File 'lib/mork/grid_pdf.rb', line 90

def header_padding(k)
  [
    1.mm,
    header_height(k) - 1.mm
  ]
end

#header_size(k) ⇒ Object



79
# File 'lib/mork/grid_pdf.rb', line 79

def header_size(k)   @params[:header][k][:size].to_f         end

#header_width(k) ⇒ Object



77
# File 'lib/mork/grid_pdf.rb', line 77

def header_width(k)  @params[:header][k][:width].to_f.mm     end

#header_xy(k) ⇒ Object



83
84
85
86
87
88
# File 'lib/mork/grid_pdf.rb', line 83

def header_xy(k)
  [
    @params[:header][k][:left].to_f.mm,
    (reg_frame_height - @params[:header][k][:top].to_f).mm
  ]
end

#height_of_cellObject



56
57
58
# File 'lib/mork/grid_pdf.rb', line 56

def height_of_cell
  cell_height.mm
end

#ink_black_xyObject



34
35
36
# File 'lib/mork/grid_pdf.rb', line 34

def ink_black_xy
  barcode_xy 0
end

#item_font_sizeObject



76
# File 'lib/mork/grid_pdf.rb', line 76

def item_font_size() @params[:items][:font_size].to_f        end

#item_xy(q) ⇒ Object



64
65
66
# File 'lib/mork/grid_pdf.rb', line 64

def item_xy(q)
  [item_x(q).mm, item_y(q).mm]
end

#marginsObject



73
# File 'lib/mork/grid_pdf.rb', line 73

def margins()        reg_margin.mm                           end

#page_sizeObject



72
# File 'lib/mork/grid_pdf.rb', line 72

def page_size()      [page_width.mm, page_height.mm]         end

#qnum_marginObject



74
# File 'lib/mork/grid_pdf.rb', line 74

def qnum_margin()    @params[:items][:number_margin].to_f.mm end

#qnum_widthObject



75
# File 'lib/mork/grid_pdf.rb', line 75

def qnum_width()     @params[:items][:number_width].to_f.mm  end

#qnum_xy(q) ⇒ Object

Coordinates at which to place item numbers



45
46
47
48
49
50
# File 'lib/mork/grid_pdf.rb', line 45

def qnum_xy(q)
  [
    item_x(q).mm - qnum_width - qnum_margin,
    item_y(q).mm
  ]
end

#reg_marksObject



11
12
13
14
15
16
17
18
19
# File 'lib/mork/grid_pdf.rb', line 11

def reg_marks
  r = reg_radius.mm
  [
    { p: [0,                  0                  ], r: r },
    { p: [0,                  reg_frame_height.mm], r: r },
    { p: [reg_frame_width.mm, reg_frame_height.mm], r: r },
    { p: [reg_frame_width.mm, 0                  ], r: r }
  ]
end

#width_of_cellObject



52
53
54
# File 'lib/mork/grid_pdf.rb', line 52

def width_of_cell
  cell_width.mm
end