Class: Zpl::Transformer::FontScaler

Inherits:
BaseScaler show all
Defined in:
lib/zpl-transformer/transformer/font_scaler.rb

Overview

TODO: doc - Explain the algorithm used to scale bitmap font

NOTE: will ONLY scale font commands NOTE: doesn’t support partial font cmd (yet?)

e.g: font with height but not width

Defined Under Namespace

Classes: FontCommand

Instance Method Summary collapse

Methods inherited from Base

#apply

Constructor Details

#initialize(ratio, allow_font_change: true) ⇒ FontScaler

Supported font commands

^A - Scalable/Bitmapped Font

Param -1: font name (value: [A-Z0-9])

Note: This is part of the command name (second char), it will not appear in
the command's params

Param 0: field orientation (enum) Param 1: character height in dots Param 2: character width in dots

^CF - Change default Font

Param 0: font name (value: [A-Z0-9]) Param 1: character height in dots Param 2: character width in dots



31
32
33
34
# File 'lib/zpl-transformer/transformer/font_scaler.rb', line 31

def initialize(ratio, allow_font_change: true)
  super(ratio)
  @allow_font_change = allow_font_change
end

Instance Method Details

#map_cmd(raw_cmd) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zpl-transformer/transformer/font_scaler.rb', line 36

def map_cmd(raw_cmd)
  font, cmd_kind = font_and_kind_from_cmd?(raw_cmd)
  unless font
    # Unable to extract the font from the command, it is probably not
    # a font command, we don't touch it.
    return raw_cmd
  end

  given_height, given_width = extract_given_sizes(raw_cmd, cmd_kind)

  unless given_height && given_width
    # Either param *height* or *width* is not given, this is not supported.
    # Returning the same command.
    return raw_cmd
  end

  font_cmd = FontCommand.new(raw_cmd, cmd_kind, font, given_height, given_width)

  if font.scalable?
    scale_scalable_font(font_cmd)
  else
    scale_bitmap_font(font_cmd)
  end
end