Class: Barby::Pdf417

Inherits:
Barcode2D
  • Object
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

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.



26
27
28
29
30
31
32
33
34
35
# File 'lib/barby/barcode/pdf_417.rb', line 26

def initialize(data, options={})
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
    @pdf417 = Java::Pdf417lib.new
  else
    @pdf417 = ::Pdf417::Lib.new
  end
  
  self.data = data
  DEFAULT_OPTIONS.merge(options).each{|k,v| send("#{k}=", v) }
end

Instance Method Details

#aspect_ratio=(aspect_ratio) ⇒ Object



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

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

#code_columns=(code_columns) ⇒ Object



61
62
63
# File 'lib/barby/barcode/pdf_417.rb', line 61

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

#code_rows=(code_rows) ⇒ Object



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

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

#data=(data) ⇒ Object



65
66
67
# File 'lib/barby/barcode/pdf_417.rb', line 65

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

#encodingObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/barby/barcode/pdf_417.rb', line 69

def encoding
  @pdf417.paintCode()

  cols = (@pdf417.getBitColumns() - 1) / 8 + 1
  enc  = nil

  # Compute encoding
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
    enc = String.from_java_bytes(@pdf417.getOutBits)
  else
    enc = @pdf417.getOutBits
  end
  enc = enc.bytes.to_a.each_slice(cols).to_a[0..(@pdf417.getCodeRows-1)]

  return enc.collect do |row_of_bytes|
    row_of_bytes.collect { |byte| sprintf("%08b", byte) }.join[0..@pdf417.getBitColumns-1]
  end
end

#error_level=(error_level) ⇒ Object



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

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

#len_codewords=(len_codewords) ⇒ Object



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

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

#options=(options) ⇒ Object



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

def options=(options)
  @options = options
end

#y_height=(y_height) ⇒ Object



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

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