Class: Zpl::Font
- Inherits:
-
Object
- Object
- Zpl::Font
- Defined in:
- lib/zpl-transformer/font.rb
Constant Summary collapse
- AVAILABLE_FONTS =
Font matrix
FONT HxW (dots) TYPE
Bitmap fonts A 9 X 5 U-L-D B 11 X 7 U C, D 18 X 10 U-L-D E 42 x 20 OCR-B F 26 x 13 U-L-D G 60 x 40 U-L-D H 34 x 22 OCR-A P 20 x 18 U-L-D Q 28 x 24 U-L-D R 35 x 31 U-L-D S 40 x 35 U-L-D T 48 x 42 U-L-D U 59 x 53 U-L-D V 80 x 71 U-L-D
Scalable font 0 Default: 15 x 12 U-L-D
{ "A" => Font.new(name: "A", base_height: 9, base_width: 5, type: :u_l_d), "B" => Font.new(name: "B", base_height: 11, base_width: 7, type: :u), "C" => Font.new(name: "C", base_height: 18, base_width: 10, type: :u_l_d), "D" => Font.new(name: "D", base_height: 18, base_width: 10, type: :u_l_d), "E" => Font.new(name: "E", base_height: 42, base_width: 20, type: :ocr_b), "F" => Font.new(name: "F", base_height: 26, base_width: 13, type: :u_l_d), "G" => Font.new(name: "G", base_height: 60, base_width: 40, type: :u_l_d), "H" => Font.new(name: "H", base_height: 34, base_width: 22, type: :ocr_a), "P" => Font.new(name: "P", base_height: 20, base_width: 18, type: :u_l_d), "Q" => Font.new(name: "Q", base_height: 28, base_width: 24, type: :u_l_d), "R" => Font.new(name: "R", base_height: 35, base_width: 31, type: :u_l_d), "S" => Font.new(name: "S", base_height: 40, base_width: 35, type: :u_l_d), "T" => Font.new(name: "T", base_height: 48, base_width: 42, type: :u_l_d), "U" => Font.new(name: "U", base_height: 59, base_width: 53, type: :u_l_d), "V" => Font.new(name: "V", base_height: 80, base_width: 71, type: :u_l_d), "0" => Font.new(name: "0", base_height: 15, base_width: 12, type: :u_l_d, scalable: true), }
Instance Attribute Summary collapse
-
#base_height ⇒ Object
Returns the value of attribute base_height.
-
#base_width ⇒ Object
Returns the value of attribute base_width.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #base_size ⇒ Object
-
#initialize(name:, base_height:, base_width:, type:, scalable: false) ⇒ Font
constructor
A new instance of Font.
-
#normalize_single_size(input_size, ref_size:) ⇒ Object
Normalize input_size to be a multiple of ref_size.
-
#normalize_size(height:, width:) ⇒ Object
Normalize height and width to the font’s height and width.
- #scalable? ⇒ Boolean
Constructor Details
#initialize(name:, base_height:, base_width:, type:, scalable: false) ⇒ Font
Returns a new instance of Font.
7 8 9 10 11 12 13 |
# File 'lib/zpl-transformer/font.rb', line 7 def initialize(name:, base_height:, base_width:, type:, scalable: false) @name = name @base_height = base_height @base_width = base_width @type = type @scalable = scalable end |
Instance Attribute Details
#base_height ⇒ Object
Returns the value of attribute base_height.
5 6 7 |
# File 'lib/zpl-transformer/font.rb', line 5 def base_height @base_height end |
#base_width ⇒ Object
Returns the value of attribute base_width.
5 6 7 |
# File 'lib/zpl-transformer/font.rb', line 5 def base_width @base_width end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/zpl-transformer/font.rb', line 5 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/zpl-transformer/font.rb', line 5 def type @type end |
Class Method Details
.all ⇒ Object
65 66 67 |
# File 'lib/zpl-transformer/font.rb', line 65 def self.all AVAILABLE_FONTS.values end |
.from_name?(font_name) ⇒ Boolean
69 70 71 |
# File 'lib/zpl-transformer/font.rb', line 69 def self.from_name?(font_name) AVAILABLE_FONTS[font_name] end |
Instance Method Details
#base_size ⇒ Object
15 16 17 |
# File 'lib/zpl-transformer/font.rb', line 15 def base_size [@base_height, @base_width] end |
#normalize_single_size(input_size, ref_size:) ⇒ Object
Normalize input_size to be a multiple of ref_size.
Example: (with ref_size = 10)
input_size normalized
0 10
7 10
10 10
11 20
89 90 91 92 93 94 95 |
# File 'lib/zpl-transformer/font.rb', line 89 def normalize_single_size(input_size, ref_size:) if input_size % ref_size == 0 input_size else ((input_size / ref_size) + 1) * ref_size end end |
#normalize_size(height:, width:) ⇒ Object
Normalize height and width to the font’s height and width.
74 75 76 77 78 79 |
# File 'lib/zpl-transformer/font.rb', line 74 def normalize_size(height:, width:) [ normalize_single_size(height, ref_size: base_height), normalize_single_size(width, ref_size: base_width), ] end |
#scalable? ⇒ Boolean
19 20 21 |
# File 'lib/zpl-transformer/font.rb', line 19 def scalable? @scalable end |