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

Remove hard coded attributes in Text Element #29

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/zebra/zpl/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module Zpl
class Text
include Printable

attr_reader :font_size, :font_type, :width
class InvalidMaxLinesError < StandardError; end

attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent

def font_size=(f)
FontSize.validate_font_size f
Expand All @@ -20,6 +22,19 @@ def width=(width)
end
end

def max_lines=(value)
raise InvalidMaxLinesError unless value.to_i >= 1
@max_lines = value
end

def line_spacing=(value)
@line_spacing = value || 0
end

def hanging_indent=(value)
@hanging_indent = value || 0
end

def font_type=(type)
FontType.validate_font_type type
@font_type = type
Expand Down Expand Up @@ -50,6 +65,10 @@ def print_mode
@print_mode || PrintMode::NORMAL
end

def max_lines
@max_lines || 4
end

def h_multiplier=(multiplier)
HorizontalMultiplier.validate_multiplier multiplier
@h_multiplier = multiplier
Expand All @@ -66,7 +85,7 @@ def to_zpl
# "^FO25,25^FB600,100,0,C,0^FDFoo^FS"

# "^CF#{font_type},#{font_size}^FO#{x},#{y}^FB609,4,0,#{justification},0^FD#{data}^FS"
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},4,0,#{justification},0^FD#{data}^FS"
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS"
end

private
Expand Down