Skip to content

Commit

Permalink
Merge pull request #10 from bbulpett/add_side_margins
Browse files Browse the repository at this point in the history
Add side margins
  • Loading branch information
bbulpett authored Jul 11, 2016
2 parents b75a37d + 7af2f61 commit d8577c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/zebra/zpl/printable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ def initialize(message)
end
end

attr_reader :position, :x, :y
attr_reader :position, :x, :y, :margin
attr_accessor :data

def initialize(options = {})
options.each_pair { |attribute, value| self.__send__ "#{attribute}=", value }
end

def position=(coords)
@position, @x, @y = coords, coords[0], coords[1]
@position = coords
@x = (@margin.nil? || @margin == 0) ? coords[0] : @margin
@y = coords[1]
end

def justification=(just)
Expand All @@ -27,6 +29,10 @@ def justification
@justification || Justification::LEFT
end

def margin=(margin)
@margin = margin || 0
end

def rotation=(rot)
Rotation.validate_rotation rot
@rotation = rot
Expand Down
6 changes: 5 additions & 1 deletion lib/zebra/zpl/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def font_size=(f)
end

def width=(width)
@width = width || 0
unless (margin.nil? || margin < 1)
@width = (width - (margin*2))
else
@width = width || 0
end
end

def font_type=(type)
Expand Down

0 comments on commit d8577c4

Please sign in to comment.