Class: RGhost::Barcode::Base

Inherits:
Parameter
  • Object
show all
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.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 165

def initialize(barcode_string,options={})
  options||={}
  
  @options=options.dup
  @options[:x]||= :limit_left
  @options[:y]||= :current_row
  @barcode=barcode_string
  @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
  # RGhost::Config::GS[:preload] << @self_name
end

Instance Attribute Details

#borderObject (readonly)

Returns the value of attribute border.



163
164
165
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 163

def border
  @border
end

#guardObject (readonly)

Returns the value of attribute guard.



163
164
165
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 163

def guard
  @guard
end

#pointObject (readonly)

Returns the value of attribute point.



163
164
165
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 163

def point
  @point
end

#textObject (readonly)

Returns the value of attribute text.



163
164
165
# File 'lib/rghost_barcode/rghost_barcode_base.rb', line 163

def text
  @text
end

Instance Method Details

#makeObject



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

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   add(key,value)
    end
  end
  
end

#psObject



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

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} closepath grestore"
end