Sha256: 5854708ad60b30b0d8dcc5639294767e165d7dc28c60ea90f440d83a9e393d5a

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require "zebra/zpl/printable"

module Zebra
  module Zpl
    class Text
      include Printable

      attr_reader   :font_size, :font_type, :width

      def font_size=(f)
        FontSize.validate_font_size f
        @font_size = f
      end

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

      def font_type=(type)
        FontType.validate_font_type type
        @font_type = type
      end

      def font_type
        @font_type || FontType::TYPE_0
      end

      def print_mode=(mode)
        PrintMode.validate_mode mode
        @print_mode = mode
      end

      def print_mode
        @print_mode || PrintMode::NORMAL
      end

      def h_multiplier
        @h_multiplier || HorizontalMultiplier::VALUE_1
      end

      def v_multiplier
        @v_multiplier || VerticalMultiplier::VALUE_1
      end

      def print_mode
        @print_mode || PrintMode::NORMAL
      end

      def h_multiplier=(multiplier)
        HorizontalMultiplier.validate_multiplier multiplier
        @h_multiplier = multiplier
      end

      def v_multiplier=(multiplier)
        VerticalMultiplier.validate_multiplier multiplier
        @v_multiplier = multiplier
      end

      def to_zpl
        check_attributes
        # ["A#{x}", y, rotation, font_size, h_multiplier, v_multiplier, print_mode, "\"#{data}\""].join(",")
        # "^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"
      end

      private

      def check_attributes
        super
        raise MissingAttributeError.new("the font_size to be used is not given") unless @font_size
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zebra-zpl-1.0.2 lib/zebra/zpl/text.rb
zebra-zpl-1.0.1 lib/zebra/zpl/text.rb
zebra-zpl-1.0.0 lib/zebra/zpl/text.rb