From 1b90107f9c39ab62d67ca4df520edb2f4b107b3c Mon Sep 17 00:00:00 2001 From: LagTag Date: Sat, 27 Oct 2018 18:21:01 -0400 Subject: [PATCH 1/2] remove hard coded attributes --- lib/zebra/zpl/text.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index e1680c0..62e6805 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -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, :max_lines, :line_spacing, :hanging_indent def font_size=(f) FontSize.validate_font_size f @@ -20,6 +22,19 @@ def width=(width) end end + def max_lines=(value) + raise InvalidMaxLinesError unless value.to_i >= 1 + @max_lines = value || 4 + 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 @@ -66,7 +81,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 From 3bd8897c0751f27396af37c3898b85b1f6ef88c0 Mon Sep 17 00:00:00 2001 From: LagTag Date: Mon, 29 Oct 2018 12:52:45 -0400 Subject: [PATCH 2/2] Default to 4 --- lib/zebra/zpl/text.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index 62e6805..3d6e651 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -7,7 +7,7 @@ class Text class InvalidMaxLinesError < StandardError; end - attr_reader :font_size, :font_type, :width, :max_lines, :line_spacing, :hanging_indent + attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent def font_size=(f) FontSize.validate_font_size f @@ -24,7 +24,7 @@ def width=(width) def max_lines=(value) raise InvalidMaxLinesError unless value.to_i >= 1 - @max_lines = value || 4 + @max_lines = value end def line_spacing=(value) @@ -65,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