Class: Barby::Pdf417

Inherits:
Barcode2D show all
Defined in:
lib/barby/barcode/pdf_417.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :options       => 0,
  :y_height      => 3,
  :aspect_ratio  => 0.5, 
  :error_level   => 0,
  :len_codewords => 0,
  :code_rows     => 0,
  :code_columns  => 0
}

Instance Method Summary collapse

Methods inherited from Barcode

#method_missing, #outputter_class_for, #outputter_for, outputters, register_outputter, #to_s, #two_dimensional?, #valid?

Constructor Details

#initialize(data, options = {}) ⇒ Pdf417

Creates a new Pdf417 barcode. The options argument can use the same keys as DEFAULT_OPTIONS. Please consult the source code of Pdf417lib.java for details about values that can be used.



22
23
24
25
26
# File 'lib/barby/barcode/pdf_417.rb', line 22

def initialize(data, options={})
  @pdf417 = Java::Pdf417lib.new
  self.data = data
  DEFAULT_OPTIONS.merge(options).each{|k,v| send("#{k}=", v) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Barby::Barcode

Instance Method Details

#aspect_ratio=(aspect_ratio) ⇒ Object



36
37
38
# File 'lib/barby/barcode/pdf_417.rb', line 36

def aspect_ratio=(aspect_ratio)
  @pdf417.setAspectRatio(aspect_ratio)
end

#code_columns=(code_columns) ⇒ Object



52
53
54
# File 'lib/barby/barcode/pdf_417.rb', line 52

def code_columns=(code_columns)
  @pdf417.setCodeColumns(code_columns)
end

#code_rows=(code_rows) ⇒ Object



48
49
50
# File 'lib/barby/barcode/pdf_417.rb', line 48

def code_rows=(code_rows)
  @pdf417.setCodeRows(code_rows)
end

#data=(data) ⇒ Object



56
57
58
# File 'lib/barby/barcode/pdf_417.rb', line 56

def data=(data)
  @pdf417.setText(data)
end

#encodingObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/barby/barcode/pdf_417.rb', line 60

def encoding
  @pdf417.paintCode()

  cols = (@pdf417.getBitColumns() - 1) / 8 + 1
  enc = []
  row = nil
  @pdf417.getOutBits.each_with_index do |byte, n|
    if n%cols == 0
      row = ""
      enc << row
    end
    row << sprintf("%08b", (byte & 0xff) | 0x100)
  end
  enc
end

#error_level=(error_level) ⇒ Object



40
41
42
# File 'lib/barby/barcode/pdf_417.rb', line 40

def error_level=(error_level)
  @pdf417.setErrorLevel(error_level)
end

#len_codewords=(len_codewords) ⇒ Object



44
45
46
# File 'lib/barby/barcode/pdf_417.rb', line 44

def len_codewords=(len_codewords)
  @pdf417.setLenCodewords(len_codewords)
end

#options=(options) ⇒ Object



28
29
30
# File 'lib/barby/barcode/pdf_417.rb', line 28

def options=(options)
  @options = options
end

#y_height=(y_height) ⇒ Object



32
33
34
# File 'lib/barby/barcode/pdf_417.rb', line 32

def y_height=(y_height)
  @pdf417.setYHeight(y_height)
end