syncsign 0.2.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/lib/syncsign/hub.rb +39 -2
- data/lib/syncsign/node-display.rb +4 -2
- data/lib/syncsign/node.rb +10 -2
- data/lib/syncsign/service.rb +19 -4
- data/lib/syncsign/template.rb +15 -5
- data/lib/syncsign/version.rb +1 -1
- data/lib/syncsign/widget-core.rb +76 -0
- data/lib/syncsign/widgets/buttonlabels.rb +46 -0
- data/lib/syncsign/widgets/circle.rb +63 -0
- data/lib/syncsign/widgets/line.rb +56 -0
- data/lib/syncsign/widgets/qrcode.rb +62 -0
- data/lib/syncsign/widgets/rectangle.rb +57 -0
- data/lib/syncsign/widgets/symbolbox-symbols.rb +1630 -0
- data/lib/syncsign/widgets/symbolbox.rb +79 -0
- data/lib/syncsign/widgets/textbox.rb +100 -0
- data/lib/syncsign.rb +9 -1
- metadata +11 -3
- data/lib/syncsign/widgets.rb +0 -323
@@ -0,0 +1,79 @@
|
|
1
|
+
module SyncSign
|
2
|
+
class Widget
|
3
|
+
##
|
4
|
+
# A widget that draws a box of symbols.
|
5
|
+
class Symbolbox < Box
|
6
|
+
attr_accessor :type, :symbols, :id
|
7
|
+
|
8
|
+
##
|
9
|
+
# Initialize a new symbol box widget.
|
10
|
+
# @param x [Integer] horizontal position of the left side of the symbol box.
|
11
|
+
# @param y [Integer] vertical position of the top of the symbol box.
|
12
|
+
# @param width [Integer] how wide the symbl box should be.
|
13
|
+
# @param height [Integer] how tall the symbol box should be.
|
14
|
+
# @param colour [Symbol] The symbol colour used for the box.
|
15
|
+
# @param bgcolour [Symbol] The background colour used for the symbol box.
|
16
|
+
# @param type [Symbol] The type of symbols for this box (:weather, :solid, or :brands).
|
17
|
+
# @param symbols [Array] The list of symbols to include in the box.
|
18
|
+
# @param id [String] An ID value to attach to the symbol box.
|
19
|
+
def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, type: nil, id: nil, symbols: [])
|
20
|
+
raise(AlignmentException, "Symbolbox: either y or height must be a multiple of 8") if y % 8 != 0 and height % 8 != 0
|
21
|
+
raise(AlignmentException, "Symbolbox: width must be a multiple of 8") if width % 8 != 0
|
22
|
+
@type = type
|
23
|
+
raise(ArgumentError, "Symbolbox: Available types are :weather, :solid, or :brands.") unless [:weather, :solid, :brands].include? type
|
24
|
+
@id = id
|
25
|
+
@symbols = symbols
|
26
|
+
super(x: x, y: y, width: width, height: height, colour: colour, bgcolour: bgcolour)
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Convert the widget into an array for sending to the SyncSign service.
|
31
|
+
def to_a
|
32
|
+
symbol_type = nil
|
33
|
+
case @type
|
34
|
+
when :weather
|
35
|
+
symbol_type = "ICON_WEATHER"
|
36
|
+
when :solid
|
37
|
+
symbol_type = "ICON_FA_SOLID"
|
38
|
+
when :brands
|
39
|
+
symbol_type = "ICON_FA_BRANDS"
|
40
|
+
end
|
41
|
+
|
42
|
+
text = decode_symbols(@symbols)
|
43
|
+
{
|
44
|
+
'type': 'TEXT',
|
45
|
+
'data': {
|
46
|
+
'block': {x: @x, y: @y, w: @width, h: @height},
|
47
|
+
'textColor': @colour.to_s.upcase,
|
48
|
+
'font': symbol_type,
|
49
|
+
'text': text
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def decode_symbols(symbol_arr)
|
57
|
+
symbol_str = ""
|
58
|
+
symbol_arr.each do |symbol|
|
59
|
+
raise ArgumentError, "No such symbol :#{symbol.to_s} in type '#{@type}'!" unless SyncSign::Widget::Symbols::SYMBOL_LIBRARY[@type][symbol]
|
60
|
+
symbol_str += [SyncSign::Widget::Symbols::SYMBOL_LIBRARY[type][symbol]].pack('U*')
|
61
|
+
end
|
62
|
+
|
63
|
+
symbol_str
|
64
|
+
end
|
65
|
+
|
66
|
+
def ==(other)
|
67
|
+
@x == other.x &&
|
68
|
+
@y == other.y &&
|
69
|
+
@width == other.width &&
|
70
|
+
@height == other.height &&
|
71
|
+
@colour == other.colour &&
|
72
|
+
@bgcolour == other.bgcolour &&
|
73
|
+
@type == other.type &&
|
74
|
+
@id == other.id &&
|
75
|
+
@symbols == other.symbols
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module SyncSign
|
2
|
+
class Widget
|
3
|
+
##
|
4
|
+
# A widget that draws a text box.
|
5
|
+
class Textbox < Box
|
6
|
+
attr_accessor :font, :size, :id, :align, :text, :linespacing
|
7
|
+
|
8
|
+
##
|
9
|
+
# Initialize a new text box widget.
|
10
|
+
# @param x [Integer] horizontal position of the left side of the text box.
|
11
|
+
# @param y [Integer] vertical position of the top of the text box.
|
12
|
+
# @param width [Integer] how wide the text box should be.
|
13
|
+
# @param height [Integer] how tall the text box should be.
|
14
|
+
# @param colour [Symbol] The text colour used for the text.
|
15
|
+
# @param bgcolour [Symbol] The background colour used for the text box.
|
16
|
+
# @param font [Symbol] The font to use when drawing the text.
|
17
|
+
# @param size [Integer] The point size to use when drawing the text.
|
18
|
+
# @param align [Symbol] Whether to align the text left, center, or right.
|
19
|
+
# @param linespacing [Integer] How much space to leave between each line.
|
20
|
+
# @param text [String] The text to draw in the box.
|
21
|
+
# @param id [String] An ID value to attach to the text box.
|
22
|
+
def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, font: nil, size: nil, id: nil, align: :left, linespacing: 2, text: nil)
|
23
|
+
check_font(font: font, size: size)
|
24
|
+
raise(AlignmentException, "Textbox: either y or height must be a multiple of 8") if y % 8 != 0 and height % 8 != 0
|
25
|
+
raise(AlignmentException, "Textbox: width must be a multiple of 8") if width % 8 != 0
|
26
|
+
@font = font.upcase
|
27
|
+
@size = size
|
28
|
+
@id = id
|
29
|
+
@align = align
|
30
|
+
@linespacing = linespacing
|
31
|
+
@text = text
|
32
|
+
super(x: x, y: y, width: width, height: height, colour: colour, bgcolour: bgcolour)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Convert the widget into an array for sending to the SyncSign service.
|
37
|
+
def to_a
|
38
|
+
font_string = "#{@font}_#{@size.to_s}"
|
39
|
+
# this one font has to be specified in a different way
|
40
|
+
font_string += "_B" if @font.to_s.upcase == "YANONE_KAFFEESATZ"
|
41
|
+
{
|
42
|
+
'type': 'TEXT',
|
43
|
+
'data': {
|
44
|
+
'block': {x: @x, y: @y, w: @width, h: @height},
|
45
|
+
'textColor': @colour.to_s.upcase,
|
46
|
+
'textAlign': @align.to_s.upcase,
|
47
|
+
'font': font_string,
|
48
|
+
'lineSpace': @linespacing,
|
49
|
+
'text': @text
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# Check a font/size combination to make sure it's valid.
|
55
|
+
# Will raise ArgumentError if the font, size, or combination isn't supported..
|
56
|
+
# @param font [Symbol] A symbol to check, representing a font.
|
57
|
+
# @param size [Integer] A font size to check.
|
58
|
+
def check_font(font: nil, size: nil)
|
59
|
+
available_sizes = {
|
60
|
+
:ddin => [16, 24, 32, 48, 64, 128],
|
61
|
+
:ddin_condensed => [16, 24, 32, 48, 64],
|
62
|
+
:charriot => [10],
|
63
|
+
:aprilsans => [10, 16, 24],
|
64
|
+
:roboto_condensed => [24, 48],
|
65
|
+
:roboto_slab => [24, 48],
|
66
|
+
:yanone_kaffeesatz => [24, 44],
|
67
|
+
:kaushan_script => [20, 32],
|
68
|
+
:sriracha => [24],
|
69
|
+
:dorsa => [32],
|
70
|
+
:londrina_outline => [36],
|
71
|
+
:bungee_shade => [36],
|
72
|
+
:noto_serif => [16],
|
73
|
+
:noto_sans => [24, 40]
|
74
|
+
}
|
75
|
+
|
76
|
+
if(!available_sizes.keys.include? font) then
|
77
|
+
raise ArgumentError, "#{font} is not a valid font. Available fonts: #{available_sizes.keys}"
|
78
|
+
end
|
79
|
+
if(!available_sizes[font].include? size) then
|
80
|
+
raise ArgumentError, "#{font} is not available in size #{size}. Available sizes for this font: #{available_sizes[font].join(", ")}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def ==(other)
|
85
|
+
@x == other.x &&
|
86
|
+
@y == other.y &&
|
87
|
+
@width == other.width &&
|
88
|
+
@height == other.height &&
|
89
|
+
@colour == other.colour &&
|
90
|
+
@bgcolour == other.bgcolour &&
|
91
|
+
@font == other.font &&
|
92
|
+
@size == other.size &&
|
93
|
+
@id == other.id &&
|
94
|
+
@linespacing == other.linespacing &&
|
95
|
+
@align == other.align &&
|
96
|
+
@text == other.text
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/syncsign.rb
CHANGED
@@ -6,4 +6,12 @@ require 'syncsign/hub.rb'
|
|
6
6
|
require 'syncsign/node.rb'
|
7
7
|
require 'syncsign/node-display.rb'
|
8
8
|
require 'syncsign/template.rb'
|
9
|
-
require 'syncsign/
|
9
|
+
require 'syncsign/widget-core.rb'
|
10
|
+
require 'syncsign/widgets/symbolbox-symbols.rb'
|
11
|
+
require 'syncsign/widgets/buttonlabels.rb'
|
12
|
+
require 'syncsign/widgets/circle.rb'
|
13
|
+
require 'syncsign/widgets/line.rb'
|
14
|
+
require 'syncsign/widgets/qrcode.rb'
|
15
|
+
require 'syncsign/widgets/rectangle.rb'
|
16
|
+
require 'syncsign/widgets/symbolbox.rb'
|
17
|
+
require 'syncsign/widgets/textbox.rb'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syncsign
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sarahemm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Interface library for SyncSign e-paper displays
|
14
14
|
email: github@sen.cx
|
@@ -25,7 +25,15 @@ files:
|
|
25
25
|
- lib/syncsign/service.rb
|
26
26
|
- lib/syncsign/template.rb
|
27
27
|
- lib/syncsign/version.rb
|
28
|
-
- lib/syncsign/
|
28
|
+
- lib/syncsign/widget-core.rb
|
29
|
+
- lib/syncsign/widgets/buttonlabels.rb
|
30
|
+
- lib/syncsign/widgets/circle.rb
|
31
|
+
- lib/syncsign/widgets/line.rb
|
32
|
+
- lib/syncsign/widgets/qrcode.rb
|
33
|
+
- lib/syncsign/widgets/rectangle.rb
|
34
|
+
- lib/syncsign/widgets/symbolbox-symbols.rb
|
35
|
+
- lib/syncsign/widgets/symbolbox.rb
|
36
|
+
- lib/syncsign/widgets/textbox.rb
|
29
37
|
homepage: http://github.com/sarahemm/ruby-syncsign
|
30
38
|
licenses:
|
31
39
|
- MIT
|
data/lib/syncsign/widgets.rb
DELETED
@@ -1,323 +0,0 @@
|
|
1
|
-
module SyncSign
|
2
|
-
##
|
3
|
-
# Raised when UI elements are not properly aligned.
|
4
|
-
# Several UI elements must be aligned to a multiple of 8 or corruption will
|
5
|
-
# occur on the display.
|
6
|
-
class AlignmentException < StandardError
|
7
|
-
end
|
8
|
-
|
9
|
-
##
|
10
|
-
# Widgets are UI elements that are placed onto a +Template+ for rendering.
|
11
|
-
class Widget
|
12
|
-
##
|
13
|
-
# An item that contains only x/y coordinates. This can't be used on its own, only its
|
14
|
-
# superclasses can be added to templates.
|
15
|
-
class Item
|
16
|
-
# @return [Integer] horizontal position of the item.
|
17
|
-
attr_accessor :x
|
18
|
-
# @return [Integer] vertical position of the item.
|
19
|
-
attr_accessor :y
|
20
|
-
|
21
|
-
##
|
22
|
-
# Initialize a new Item widget.
|
23
|
-
# @param x [Integer] The horizontal position of the item.
|
24
|
-
# @param y [Integer] The vertical position of the item.
|
25
|
-
def initialize(x: nil, y: nil)
|
26
|
-
@x = x
|
27
|
-
@y = y
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# A box that contains x/y coordinates, width and height, and colour information.
|
33
|
-
# This can't be used on its own, only its superclasses can be added to templates.
|
34
|
-
# You may be looking for +Rectangle+ if you want to draw rectangles.
|
35
|
-
class Box < Item
|
36
|
-
# @return [Integer] the width of the box.
|
37
|
-
attr_accessor :width
|
38
|
-
# @return [Integer] the height of the box.
|
39
|
-
attr_accessor :height
|
40
|
-
# @return [Symbol] the stroke or foreground colour of the box.
|
41
|
-
attr_accessor :colour
|
42
|
-
# @return [Symbol] the background colour of the box.
|
43
|
-
attr_accessor :bgcolour
|
44
|
-
|
45
|
-
def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white)
|
46
|
-
Widget::check_colours [colour, bgcolour]
|
47
|
-
@colour = colour
|
48
|
-
@bgcolour = bgcolour
|
49
|
-
@width = width
|
50
|
-
@height = height
|
51
|
-
super(x: x, y: y)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
# A widget that draws a rectangle.
|
57
|
-
class Rectangle < Box
|
58
|
-
attr_accessor :pen_width
|
59
|
-
|
60
|
-
##
|
61
|
-
# Initialize a new rectangle widget.
|
62
|
-
# @param x [Integer] horizontal position of the left side of the rectangle.
|
63
|
-
# @param y [Integer] vertical position of the top of the rectangle.
|
64
|
-
# @param width [Integer] how wide the rectangle should be.
|
65
|
-
# @param height [Integer] how tall the rectangle should be.
|
66
|
-
# @param colour [Symbol] The stroke colour used for the rectangle
|
67
|
-
# (either black, white, or red).
|
68
|
-
# @param bgcolour [Symbol] The fill colour used for the rectangle
|
69
|
-
# (either black, white, or red).
|
70
|
-
# @param pen_width [Integer] The width in pixels of the stroke.
|
71
|
-
def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, pen_width: 1, fillpattern: :none, strokepattern: :solid)
|
72
|
-
Widget::check_patterns [fillpattern, strokepattern]
|
73
|
-
raise(AlignmentException, "Rect: x and width must both be a multiple of 8") if x % 8 != 0 or width % 8 != 0
|
74
|
-
@pen_width = pen_width
|
75
|
-
@fillpattern = fillpattern
|
76
|
-
@strokepattern = strokepattern
|
77
|
-
super(x: x, y: y, width: width, height: height, colour: colour, bgcolour: bgcolour)
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Convert the widget into an array for sending to the SyncSign service.
|
82
|
-
def to_a
|
83
|
-
{
|
84
|
-
'type': 'RECTANGLE',
|
85
|
-
'data': {
|
86
|
-
'block': {x: @x, y: @y, w: @width, h: @height},
|
87
|
-
'fillColor': @bgcolour.to_s.upcase,
|
88
|
-
'fillPattern': @fillpattern.to_s.upcase,
|
89
|
-
'strokeColor': @colour.to_s.upcase,
|
90
|
-
'strokePattern': @strokepattern.to_s.upcase,
|
91
|
-
'strokeThickness': @pen_width
|
92
|
-
}
|
93
|
-
}
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
##
|
98
|
-
# A widget that draws a line.
|
99
|
-
class Line
|
100
|
-
attr_accessor :x0, :y0, :x1, :y1, :bgcolour, :colour, :pattern
|
101
|
-
|
102
|
-
##
|
103
|
-
# Initialize a new line widget.
|
104
|
-
# @param x0 [Integer] horizontal position of the starting point of the line.
|
105
|
-
# @param y0 [Integer] vertical position of the starting point of the line.
|
106
|
-
# @param x1 [Integer] horizontal position of the ending point of the line.
|
107
|
-
# @param y1 [Integer] vertical position of the ending point of the line.
|
108
|
-
# @param colour [Symbol] The stroke colour used for the rectangle
|
109
|
-
# (either black, white, or red).
|
110
|
-
# @param bgcolour [Symbol] The fill colour used for the rectangle
|
111
|
-
# (either black, white, or red).
|
112
|
-
# @param pattern [Symbol] The linestyle to use when drawing the line, one of solid, interleave, dash_tiny, dash_mid, or dash_wide.
|
113
|
-
def initialize(x0: nil, y0: nil, x1: nil, y1: nil, bgcolour: :white, colour: :black, pattern: :solid)
|
114
|
-
Widget::check_colours [colour, bgcolour]
|
115
|
-
Widget::check_patterns [pattern]
|
116
|
-
@x0 = x0
|
117
|
-
@y0 = y0
|
118
|
-
@x1 = x1
|
119
|
-
@y1 = y1
|
120
|
-
@colour = colour
|
121
|
-
@bgcolour = bgcolour
|
122
|
-
@pattern = pattern
|
123
|
-
end
|
124
|
-
|
125
|
-
##
|
126
|
-
# Convert the widget into an array for sending to the SyncSign service.
|
127
|
-
def to_a
|
128
|
-
{
|
129
|
-
'type': 'LINE',
|
130
|
-
'data': {
|
131
|
-
'block': {x0: @x0, y0: @y0, x1: @x1, y1: @y1},
|
132
|
-
'backgroundColor': @bgcolour.to_s.upcase,
|
133
|
-
'lineColor': @colour.to_s.upcase,
|
134
|
-
'linePattern': @pattern.to_s.upcase
|
135
|
-
}
|
136
|
-
}
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
##
|
141
|
-
# A widget that draws a circle.
|
142
|
-
class Circle < Item
|
143
|
-
attr_accessor :radius, :bgcolour, :colour, :fillpattern, :strokepattern
|
144
|
-
|
145
|
-
##
|
146
|
-
# Initialize a new circle widget.
|
147
|
-
# @param x [Integer] horizontal position of the centre of the circle.
|
148
|
-
# @param y [Integer] vertical position of the centre of the circle
|
149
|
-
# @param radius [Integer] The radius of the circle in pixels.
|
150
|
-
# @param colour [Symbol] The stroke colour used for the circle
|
151
|
-
# (either black, white, or red).
|
152
|
-
# @param bgcolour [Symbol] The fill colour used for the circle
|
153
|
-
# (either black, white, or red).
|
154
|
-
# @param fillpattern [Symbol] The fill pattern to use when filling the circle.
|
155
|
-
# @param strokepattern [Symbol] The stroke pattern to use when drawing the circle.
|
156
|
-
# @param pen_width [Integer] The thickness in pixels of the stroke.
|
157
|
-
def initialize(x: nil, y: nil, radius: nil, bgcolour: :white, colour: :black, fillpattern: :none, strokepattern: :solid, pen_width: 1)
|
158
|
-
Widget::check_colours [colour, bgcolour]
|
159
|
-
Widget::check_patterns [fillpattern, strokepattern]
|
160
|
-
@radius = radius
|
161
|
-
@colour = colour
|
162
|
-
@bgcolour = bgcolour
|
163
|
-
@fillpattern = fillpattern
|
164
|
-
@strokepattern = strokepattern
|
165
|
-
@pen_width = pen_width
|
166
|
-
super(x: x, y:y)
|
167
|
-
end
|
168
|
-
|
169
|
-
##
|
170
|
-
# Convert the widget into an array for sending to the SyncSign service.
|
171
|
-
def to_a
|
172
|
-
{
|
173
|
-
'type': 'CIRCLE',
|
174
|
-
'data': {
|
175
|
-
'center': {x: @x, y: @y},
|
176
|
-
'fillColor': @bgcolour.to_s.upcase,
|
177
|
-
'fillPattern': @fillpattern.to_s.upcase,
|
178
|
-
'strokeColor': @colour.to_s.upcase,
|
179
|
-
'strokePattern': @strokepattern.to_s.upcase,
|
180
|
-
'strokeThickness': @pen_width
|
181
|
-
}
|
182
|
-
}
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
##
|
187
|
-
# A widget that draws a text box.
|
188
|
-
class Textbox < Box
|
189
|
-
attr_accessor :font, :size, :id, :align, :text
|
190
|
-
|
191
|
-
##
|
192
|
-
# Initialize a new text box widget.
|
193
|
-
# @param x [Integer] horizontal position of the left side of the text box.
|
194
|
-
# @param y [Integer] vertical position of the top of the text box.
|
195
|
-
# @param width [Integer] how wide the text box should be.
|
196
|
-
# @param height [Integer] how tall the text box should be.
|
197
|
-
# @param colour [Symbol] The text colour used for the text.
|
198
|
-
# @param bgcolour [Symbol] The background colour used for the text box.
|
199
|
-
# @param font [Symbol] The font to use when drawing the text.
|
200
|
-
# @param size [Integer] The point size to use when drawing the text.
|
201
|
-
# @param align [Symbol] Whether to align the text left, center, or right.
|
202
|
-
# @param text [String] The text to draw in the box.
|
203
|
-
# @param id [String] An ID value to attach to the text box.
|
204
|
-
def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, font: nil, size: nil, id: nil, align: :left, text: nil)
|
205
|
-
check_font(font: font, size: size)
|
206
|
-
raise(AlignmentException, "Textbox: either y or height must be a multiple of 8") if y % 8 != 0 and height % 8 != 0
|
207
|
-
raise(AlignmentException, "Textbox: width must be a multiple of 8") if width % 8 != 0
|
208
|
-
@font = font.upcase
|
209
|
-
@size = size
|
210
|
-
@id = id
|
211
|
-
@align = align
|
212
|
-
@text = text
|
213
|
-
super(x: x, y: y, width: width, height: height, colour: colour, bgcolour: bgcolour)
|
214
|
-
end
|
215
|
-
|
216
|
-
##
|
217
|
-
# Convert the widget into an array for sending to the SyncSign service.
|
218
|
-
def to_a
|
219
|
-
{
|
220
|
-
'type': 'TEXT',
|
221
|
-
'data': {
|
222
|
-
'block': {x: @x, y: @y, w: @width, h: @height},
|
223
|
-
'textColor': @colour.to_s.upcase,
|
224
|
-
'textAlign': @align.to_s.upcase,
|
225
|
-
'font': "#{@font}_#{@size.to_s}",
|
226
|
-
'text': @text
|
227
|
-
}
|
228
|
-
}
|
229
|
-
end
|
230
|
-
|
231
|
-
def check_font(font: nil, size: nil)
|
232
|
-
available_sizes = {
|
233
|
-
:ddin => [16, 24, 32, 48, 64, 128],
|
234
|
-
:ddin_condensed => [16, 24, 32, 48, 64],
|
235
|
-
:charriot => [10],
|
236
|
-
:aprilsans => [10, 16, 24],
|
237
|
-
:roboto_condensed => [24, 48],
|
238
|
-
:roboto_slab => [24, 48],
|
239
|
-
:yanone_kaffeesatz => [24, 44],
|
240
|
-
:kaushan_script => [20, 32],
|
241
|
-
:sriracha => [24],
|
242
|
-
:dorsa => [32],
|
243
|
-
:londrina_outline => [36],
|
244
|
-
:bungee_shade => [36],
|
245
|
-
:noto_serif => [16],
|
246
|
-
:noto_sans => [24, 40]
|
247
|
-
}
|
248
|
-
|
249
|
-
if(!available_sizes.keys.include? font) then
|
250
|
-
raise ArgumentError, "#{font} is not a valid font. Available fonts: #{available_sizes.keys}"
|
251
|
-
end
|
252
|
-
if(!available_sizes[font].include? size) then
|
253
|
-
raise ArgumentError, "#{font} is not available in size #{size}. Available sizes for this font: #{available_sizes[font].join(", ")}"
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
##
|
259
|
-
# A widget that draws a QR code.
|
260
|
-
class QRCode < Item
|
261
|
-
# @return [Integer] scale of the QR code (how many pixels to use to
|
262
|
-
# represent each base pixel).
|
263
|
-
attr_accessor :scale
|
264
|
-
# @return [Integer] the version (which is actually size, in QR-speak)
|
265
|
-
# of this QR code.
|
266
|
-
attr_accessor :version
|
267
|
-
# @return [Symbol] the level of error checking code for this QR code,
|
268
|
-
# either :low, :medium, :quartile, or :high.
|
269
|
-
attr_accessor :ecclevel
|
270
|
-
# @return [String] the text to encode in this QR code.
|
271
|
-
attr_accessor :text
|
272
|
-
|
273
|
-
##
|
274
|
-
# Initialize a new QR code widget.
|
275
|
-
# @param x [Integer] horizontal position of the left side of the QR code.
|
276
|
-
# @param y [Integer] vertical position of the top of the QR code.
|
277
|
-
# @param scale [Integer] scale of the QR code (how many pixels to use to
|
278
|
-
# represent each base pixel).
|
279
|
-
# @param version [Integer] the version (which is actually size, in QR-speak)
|
280
|
-
# of this QR code.
|
281
|
-
# @param ecclevel [Symbol] the level of error checking code for this QR code,
|
282
|
-
# either :low, :medium, :quartile, or :high.
|
283
|
-
# @param text [String] the text to encode in this QR code.
|
284
|
-
def initialize(x: nil, y: nil, scale: 4, version: 2, ecclevel: :medium, text: nil)
|
285
|
-
@scale = scale
|
286
|
-
@version = version
|
287
|
-
@ecclevel = ecclevel
|
288
|
-
@text = text
|
289
|
-
|
290
|
-
super(x: x, y: y)
|
291
|
-
end
|
292
|
-
|
293
|
-
##
|
294
|
-
# Convert the widget into an array for sending to the SyncSign service.
|
295
|
-
def to_a
|
296
|
-
{
|
297
|
-
'type': 'QRCODE',
|
298
|
-
'data': {
|
299
|
-
'scale': @scale,
|
300
|
-
'eccLevel': @ecclevel.to_s.upcase,
|
301
|
-
'version': @version,
|
302
|
-
'position': {x: @x, y: @y},
|
303
|
-
'text': @text
|
304
|
-
}
|
305
|
-
}
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
def self.check_colours(colours)
|
310
|
-
colours.each do |colour|
|
311
|
-
next if [:white, :black, :red].include? colour
|
312
|
-
raise ArgumentError, "Colour must be :white, :black, or :red."
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
def self.check_patterns(patterns)
|
317
|
-
patterns.each do |pattern|
|
318
|
-
next if [:solid, :interleave, :dash_tiny, :dash_medium, :dash_wide, :none].include? pattern
|
319
|
-
raise ArgumentError, "Pattern must be :solid, :interleave, :dash_tiny, :dash_medium, :dash_wide, or :none."
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|