Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore barcode functionality #5

Merged
merged 14 commits into from
Jun 29, 2016
3 changes: 1 addition & 2 deletions lib/zebra/zpl/barcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def print_human_readable_code
def to_zpl
check_attributes
human_readable = print_human_readable_code ? "Y" : "N"
# ["B#{x}", y, rotation, type, narrow_bar_width, wide_bar_width, height, human_readable, "\"#{data}\""].join(",")
"^FO#{x},#{y}^FB800,4,0,C,0^B#{type}#{rotation},#{height},#{human_readable},N,N^FD#{data}"
"^FO#{x},#{y}^BY#{narrow_bar_width}^B#{type}#{rotation},#{height},#{human_readable}^FD#{data}^FS"
end

private
Expand Down
17 changes: 11 additions & 6 deletions lib/zebra/zpl/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ class Box

class InvalidLineThickness < StandardError; end

attr_reader :line_thickness, :end_position, :end_x, :end_y
attr_reader :line_thickness, :box_width, :box_height

def line_thickness=(thickness)
raise InvalidLineThickness unless thickness.nil? || thickness.to_i.to_s == thickness.to_s
@line_thickness = thickness
end

def end_position=(coords)
@end_position, @end_x, @end_y = coords, coords[0], coords[1]
def box_width=(width)
@box_width = width
end

def box_height=(height)
@box_height = height
end

def to_zpl
check_attributes
["X#{x}", y, line_thickness, end_x, end_y].join(",")
# "^FO#{x},#{y}^GB#{box_width},#{box_height},#{line_thickness}^FS"
"^FO#{x},#{y}^GB#{box_width},#{box_height},#{line_thickness}^FS"
end

private
Expand All @@ -32,8 +37,8 @@ def has_data?
def check_attributes
super
raise MissingAttributeError.new("the line thickness is not given") unless line_thickness
raise MissingAttributeError.new("the horizontal end position (X) is not given") unless end_x
raise MissingAttributeError.new("the vertical end position (Y) is not given") unless end_y
raise MissingAttributeError.new("the box_width is not given") unless box_width
raise MissingAttributeError.new("the box_height is not given") unless box_height
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/zebra/zpl/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def print_speed=(s)
end

def print_density=(d)
raise InvalidPrintDensityError unless (0..15).include?(d)
raise InvalidPrintDensityError unless (0..6).include?(d)
@print_density = d
end

Expand All @@ -52,7 +52,6 @@ def dump_contents(io = STDOUT)
io << "^PR#{print_speed}"
# Density (D command) "Carried over from EPL, does this exist in ZPL ????"
# io << "D#{print_density}\n" if print_density
# ZT = Printing from top of image buffer.

# TEST ZPL (comment everything else out)...
# io << "^XA^WD*:*.FNT*^XZ"
Expand All @@ -71,6 +70,7 @@ def dump_contents(io = STDOUT)
end

def persist
# debugger
tempfile = Tempfile.new "zebra_label"
dump_contents tempfile
tempfile.close
Expand Down