Class: RGhost::Barcode::Base

Inherits:
Parameter
  • Object
show all
Includes:
RubyToPs
Defined in:
lib/rghost_barcode/rghost_barcode_base.rb

Overview

Base of all kinds of barcodes. It’s used to creates barcode. For more details about options see groups.google.com/group/postscriptbarcode/web/Options

Options

Facades

  • :text RGhost::Barcode::Text

  • :guard RGhost::Barcode::Guard

  • :border RGhost::Barcode::Border

Options. Between parenthesis the original parameter.

  • :scale Scale in Array(). Example for twice the original size, :scale => [2,2]

  • :rotate Rotate angle.

  • :color(barcolor) Foreground color.

  • :background(backgroundcolor)

  • :x and :y Position. RGhost::Config::GS will be used. Default :current_row and :limit_left

  • :width and :height(width and height). Width and height of barcode, RGhost::Config::GS will be used.

Example: doc=Document.new doc.barcode_interleaved2of5(‘0123456789’,

  :text => {:size => 10, :offset => [0,-10], :enable => [:text, :check, :checkintext] }, 
  :border => {:width => 4, :left => 15, :right => 15, :show => true}, 
  :height => 2
)

Without options doc=Document.new doc.barcode_code39(‘0123456789’)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(barcode_string, options = {}) ⇒ Base

Returns a new instance of Base.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 160

def initialize(barcode_string,options={})
  options||={}
  
  @options=options.dup
  @options[:x]||= :limit_left
  @options[:y]||= :current_row
  
  @barcode=(barcode_string.to_s == '') ? "Data Missing" : barcode_string
  #@barcode =to_string(@barcode)
  @text   = RGhost::Barcode::Text.new(@options[:text])
  
  @guard  = RGhost::Barcode::Guard.new(@options[:guard])
  @border = RGhost::Barcode::Border.new(@options[:border])
  @point=RGhost::Cursor.translate(@options)
  @rotate=RGhost::Cursor.rotate @options[:rotate]
  @scale=RGhost::Scale.new @options[:scale][0],@options[:scale][1] if @options[:scale]
  [:scale, :enable, :text,:guard,:border, :x, :y, :rotate].each{|v| @options.delete v}
  super(@options)
  @self_name=self.class.to_s.downcase.split(/::/).last.gsub(/_/,'-')
end

Instance Attribute Details

#borderObject (readonly)

Returns the value of attribute border.



158
159
160
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 158

def border
  @border
end

#guardObject (readonly)

Returns the value of attribute guard.



158
159
160
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 158

def guard
  @guard
end

#pointObject (readonly)

Returns the value of attribute point.



158
159
160
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 158

def point
  @point
end

#textObject (readonly)

Returns the value of attribute text.



158
159
160
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 158

def text
  @text
end

Instance Method Details

#makeObject



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 181

def make
  
  [:x,:y].each{|v| @options.delete v}
  
  @options.each do |key,value| 
    case key
    when :color then add_color("barcolor", value) 
    when :background then add_color("backgroundcolor", value) 
    when :width, :height then add_with_unit(key,value)
      #when :inkspread then  add(key,value)
    else   
      if (value == true)
        add_single(key)
        next
      end
      add(key,value)
    end
  end
  
end

#psObject



202
203
204
205
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 202

def ps
  formated_params=[ @text.map, @border.map, @guard.map, self.map].join(" ")
  "gsave newpath #{@point.ps} #{@rotate} #{@scale} 0 0 moveto (#{@barcode}) (#{formated_params}) /#{@self_name} /uk.co.terryburton.bwipp findresource exec closepath grestore"
end