prawn-svg 0.34.1 → 0.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +19 -0
- data/.github/workflows/test.yml +14 -27
- data/.gitignore +0 -1
- data/.rubocop.yml +86 -0
- data/.rubocop_todo.yml +51 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +81 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/prawn/svg/attributes/clip_path.rb +3 -3
- data/lib/prawn/svg/attributes/opacity.rb +3 -3
- data/lib/prawn/svg/attributes/stroke.rb +9 -9
- data/lib/prawn/svg/attributes/transform.rb +2 -2
- data/lib/prawn/svg/attributes.rb +1 -1
- data/lib/prawn/svg/calculators/arc_to_bezier_curve.rb +17 -15
- data/lib/prawn/svg/calculators/aspect_ratio.rb +16 -14
- data/lib/prawn/svg/calculators/document_sizing.rb +9 -10
- data/lib/prawn/svg/calculators/pixels.rb +8 -5
- data/lib/prawn/svg/color.rb +209 -212
- data/lib/prawn/svg/css/font_family_parser.rb +2 -2
- data/lib/prawn/svg/css/selector_parser.rb +39 -35
- data/lib/prawn/svg/css/stylesheets.rb +31 -24
- data/lib/prawn/svg/css/values_parser.rb +68 -0
- data/lib/prawn/svg/document.rb +6 -5
- data/lib/prawn/svg/elements/base.rb +39 -34
- data/lib/prawn/svg/elements/circle.rb +4 -4
- data/lib/prawn/svg/elements/clip_path.rb +0 -1
- data/lib/prawn/svg/elements/depth_first_base.rb +6 -6
- data/lib/prawn/svg/elements/ellipse.rb +3 -4
- data/lib/prawn/svg/elements/gradient.rb +49 -51
- data/lib/prawn/svg/elements/image.rb +5 -5
- data/lib/prawn/svg/elements/marker.rb +6 -7
- data/lib/prawn/svg/elements/path.rb +46 -47
- data/lib/prawn/svg/elements/polygon.rb +1 -1
- data/lib/prawn/svg/elements/polyline.rb +2 -2
- data/lib/prawn/svg/elements/rect.rb +3 -3
- data/lib/prawn/svg/elements/text.rb +1 -1
- data/lib/prawn/svg/elements/text_component.rb +22 -22
- data/lib/prawn/svg/elements/use.rb +4 -8
- data/lib/prawn/svg/elements/viewport.rb +5 -4
- data/lib/prawn/svg/elements.rb +30 -29
- data/lib/prawn/svg/extension.rb +2 -1
- data/lib/prawn/svg/font.rb +7 -7
- data/lib/prawn/svg/font_registry.rb +13 -13
- data/lib/prawn/svg/gradients.rb +3 -2
- data/lib/prawn/svg/interface.rb +4 -3
- data/lib/prawn/svg/loaders/data.rb +2 -2
- data/lib/prawn/svg/loaders/file.rb +12 -14
- data/lib/prawn/svg/loaders/web.rb +4 -8
- data/lib/prawn/svg/pathable.rb +41 -37
- data/lib/prawn/svg/properties.rb +34 -33
- data/lib/prawn/svg/renderer.rb +7 -7
- data/lib/prawn/svg/state.rb +1 -1
- data/lib/prawn/svg/transform_parser.rb +5 -5
- data/lib/prawn/svg/ttf.rb +21 -17
- data/lib/prawn/svg/url_loader.rb +1 -1
- data/lib/prawn/svg/version.rb +1 -1
- data/lib/prawn-svg.rb +1 -0
- data/prawn-svg.gemspec +4 -6
- data/spec/integration_spec.rb +77 -70
- data/spec/prawn/svg/attributes/opacity_spec.rb +11 -15
- data/spec/prawn/svg/attributes/transform_spec.rb +6 -6
- data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +50 -50
- data/spec/prawn/svg/calculators/document_sizing_spec.rb +35 -35
- data/spec/prawn/svg/calculators/pixels_spec.rb +31 -30
- data/spec/prawn/svg/color_spec.rb +31 -31
- data/spec/prawn/svg/css/font_family_parser_spec.rb +12 -12
- data/spec/prawn/svg/css/selector_parser_spec.rb +21 -21
- data/spec/prawn/svg/css/stylesheets_spec.rb +51 -43
- data/spec/prawn/svg/css/values_parser_spec.rb +16 -0
- data/spec/prawn/svg/document_spec.rb +15 -14
- data/spec/prawn/svg/elements/base_spec.rb +39 -34
- data/spec/prawn/svg/elements/gradient_spec.rb +39 -39
- data/spec/prawn/svg/elements/line_spec.rb +22 -22
- data/spec/prawn/svg/elements/marker_spec.rb +44 -47
- data/spec/prawn/svg/elements/path_spec.rb +134 -110
- data/spec/prawn/svg/elements/polygon_spec.rb +18 -18
- data/spec/prawn/svg/elements/polyline_spec.rb +16 -16
- data/spec/prawn/svg/elements/text_spec.rb +149 -127
- data/spec/prawn/svg/font_registry_spec.rb +34 -34
- data/spec/prawn/svg/font_spec.rb +4 -4
- data/spec/prawn/svg/interface_spec.rb +47 -39
- data/spec/prawn/svg/loaders/data_spec.rb +21 -21
- data/spec/prawn/svg/loaders/file_spec.rb +43 -40
- data/spec/prawn/svg/loaders/web_spec.rb +15 -15
- data/spec/prawn/svg/pathable_spec.rb +21 -21
- data/spec/prawn/svg/properties_spec.rb +51 -51
- data/spec/prawn/svg/transform_parser_spec.rb +12 -12
- data/spec/prawn/svg/ttf_spec.rb +5 -5
- data/spec/prawn/svg/url_loader_spec.rb +25 -23
- data/spec/spec_helper.rb +4 -4
- metadata +12 -143
@@ -4,7 +4,7 @@ module Prawn::SVG::Calculators::Pixels
|
|
4
4
|
|
5
5
|
def self.to_pixels(value, axis_length = nil, font_size: Prawn::SVG::Properties::EM)
|
6
6
|
if value.is_a?(String)
|
7
|
-
if match = value.match(/\d(em|ex|pc|cm|mm|in)$/)
|
7
|
+
if (match = value.match(/\d(em|ex|pc|cm|mm|in)$/))
|
8
8
|
case match[1]
|
9
9
|
when 'em'
|
10
10
|
value.to_f * font_size
|
@@ -15,7 +15,7 @@ module Prawn::SVG::Calculators::Pixels
|
|
15
15
|
else
|
16
16
|
send("#{match[1]}2pt", value.to_f)
|
17
17
|
end
|
18
|
-
elsif value[-1
|
18
|
+
elsif value[-1..] == '%'
|
19
19
|
value.to_f * axis_length / 100.0
|
20
20
|
else
|
21
21
|
value.to_f
|
@@ -39,14 +39,17 @@ module Prawn::SVG::Calculators::Pixels
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def pixels(value)
|
42
|
-
value && Measurement.to_pixels(value, state.viewport_sizing.viewport_diagonal,
|
42
|
+
value && Measurement.to_pixels(value, state.viewport_sizing.viewport_diagonal,
|
43
|
+
font_size: computed_properties.numerical_font_size)
|
43
44
|
end
|
44
45
|
|
45
46
|
def x_pixels(value)
|
46
|
-
value && Measurement.to_pixels(value, state.viewport_sizing.viewport_width,
|
47
|
+
value && Measurement.to_pixels(value, state.viewport_sizing.viewport_width,
|
48
|
+
font_size: computed_properties.numerical_font_size)
|
47
49
|
end
|
48
50
|
|
49
51
|
def y_pixels(value)
|
50
|
-
value && Measurement.to_pixels(value, state.viewport_sizing.viewport_height,
|
52
|
+
value && Measurement.to_pixels(value, state.viewport_sizing.viewport_height,
|
53
|
+
font_size: computed_properties.numerical_font_size)
|
51
54
|
end
|
52
55
|
end
|
data/lib/prawn/svg/color.rb
CHANGED
@@ -2,243 +2,240 @@ class Prawn::SVG::Color
|
|
2
2
|
RGB = Struct.new(:value)
|
3
3
|
CMYK = Struct.new(:value)
|
4
4
|
|
5
|
-
RGB_DEFAULT_COLOR = RGB.new(
|
5
|
+
RGB_DEFAULT_COLOR = RGB.new('000000')
|
6
6
|
CMYK_DEFAULT_COLOR = CMYK.new([0, 0, 0, 100])
|
7
7
|
|
8
8
|
HTML_COLORS = {
|
9
|
-
'aliceblue'
|
10
|
-
'antiquewhite'
|
11
|
-
'aqua'
|
12
|
-
'aquamarine'
|
13
|
-
'azure'
|
14
|
-
'beige'
|
15
|
-
'bisque'
|
16
|
-
'black'
|
17
|
-
'blanchedalmond'
|
18
|
-
'blue'
|
19
|
-
'blueviolet'
|
20
|
-
'brown'
|
21
|
-
'burlywood'
|
22
|
-
'cadetblue'
|
23
|
-
'chartreuse'
|
24
|
-
'chocolate'
|
25
|
-
'coral'
|
26
|
-
'cornflowerblue'
|
27
|
-
'cornsilk'
|
28
|
-
'crimson'
|
29
|
-
'cyan'
|
30
|
-
'darkblue'
|
31
|
-
'darkcyan'
|
32
|
-
'darkgoldenrod'
|
33
|
-
'darkgray'
|
34
|
-
'darkgreen'
|
35
|
-
'darkgrey'
|
36
|
-
'darkkhaki'
|
37
|
-
'darkmagenta'
|
38
|
-
'darkolivegreen'
|
39
|
-
'darkorange'
|
40
|
-
'darkorchid'
|
41
|
-
'darkred'
|
42
|
-
'darksalmon'
|
43
|
-
'darkseagreen'
|
44
|
-
'darkslateblue'
|
45
|
-
'darkslategray'
|
46
|
-
'darkslategrey'
|
47
|
-
'darkturquoise'
|
48
|
-
'darkviolet'
|
49
|
-
'deeppink'
|
50
|
-
'deepskyblue'
|
51
|
-
'dimgray'
|
52
|
-
'dimgrey'
|
53
|
-
'dodgerblue'
|
54
|
-
'firebrick'
|
55
|
-
'floralwhite'
|
56
|
-
'forestgreen'
|
57
|
-
'fuchsia'
|
58
|
-
'gainsboro'
|
59
|
-
'ghostwhite'
|
60
|
-
'gold'
|
61
|
-
'goldenrod'
|
62
|
-
'gray'
|
63
|
-
'grey'
|
64
|
-
'green'
|
65
|
-
'greenyellow'
|
66
|
-
'honeydew'
|
67
|
-
'hotpink'
|
68
|
-
'indianred'
|
69
|
-
'indigo'
|
70
|
-
'ivory'
|
71
|
-
'khaki'
|
72
|
-
'lavender'
|
73
|
-
'lavenderblush'
|
74
|
-
'lawngreen'
|
75
|
-
'lemonchiffon'
|
76
|
-
'lightblue'
|
77
|
-
'lightcoral'
|
78
|
-
'lightcyan'
|
9
|
+
'aliceblue' => 'f0f8ff',
|
10
|
+
'antiquewhite' => 'faebd7',
|
11
|
+
'aqua' => '00ffff',
|
12
|
+
'aquamarine' => '7fffd4',
|
13
|
+
'azure' => 'f0ffff',
|
14
|
+
'beige' => 'f5f5dc',
|
15
|
+
'bisque' => 'ffe4c4',
|
16
|
+
'black' => '000000',
|
17
|
+
'blanchedalmond' => 'ffebcd',
|
18
|
+
'blue' => '0000ff',
|
19
|
+
'blueviolet' => '8a2be2',
|
20
|
+
'brown' => 'a52a2a',
|
21
|
+
'burlywood' => 'deb887',
|
22
|
+
'cadetblue' => '5f9ea0',
|
23
|
+
'chartreuse' => '7fff00',
|
24
|
+
'chocolate' => 'd2691e',
|
25
|
+
'coral' => 'ff7f50',
|
26
|
+
'cornflowerblue' => '6495ed',
|
27
|
+
'cornsilk' => 'fff8dc',
|
28
|
+
'crimson' => 'dc143c',
|
29
|
+
'cyan' => '00ffff',
|
30
|
+
'darkblue' => '00008b',
|
31
|
+
'darkcyan' => '008b8b',
|
32
|
+
'darkgoldenrod' => 'b8860b',
|
33
|
+
'darkgray' => 'a9a9a9',
|
34
|
+
'darkgreen' => '006400',
|
35
|
+
'darkgrey' => 'a9a9a9',
|
36
|
+
'darkkhaki' => 'bdb76b',
|
37
|
+
'darkmagenta' => '8b008b',
|
38
|
+
'darkolivegreen' => '556b2f',
|
39
|
+
'darkorange' => 'ff8c00',
|
40
|
+
'darkorchid' => '9932cc',
|
41
|
+
'darkred' => '8b0000',
|
42
|
+
'darksalmon' => 'e9967a',
|
43
|
+
'darkseagreen' => '8fbc8f',
|
44
|
+
'darkslateblue' => '483d8b',
|
45
|
+
'darkslategray' => '2f4f4f',
|
46
|
+
'darkslategrey' => '2f4f4f',
|
47
|
+
'darkturquoise' => '00ced1',
|
48
|
+
'darkviolet' => '9400d3',
|
49
|
+
'deeppink' => 'ff1493',
|
50
|
+
'deepskyblue' => '00bfff',
|
51
|
+
'dimgray' => '696969',
|
52
|
+
'dimgrey' => '696969',
|
53
|
+
'dodgerblue' => '1e90ff',
|
54
|
+
'firebrick' => 'b22222',
|
55
|
+
'floralwhite' => 'fffaf0',
|
56
|
+
'forestgreen' => '228b22',
|
57
|
+
'fuchsia' => 'ff00ff',
|
58
|
+
'gainsboro' => 'dcdcdc',
|
59
|
+
'ghostwhite' => 'f8f8ff',
|
60
|
+
'gold' => 'ffd700',
|
61
|
+
'goldenrod' => 'daa520',
|
62
|
+
'gray' => '808080',
|
63
|
+
'grey' => '808080',
|
64
|
+
'green' => '008000',
|
65
|
+
'greenyellow' => 'adff2f',
|
66
|
+
'honeydew' => 'f0fff0',
|
67
|
+
'hotpink' => 'ff69b4',
|
68
|
+
'indianred' => 'cd5c5c',
|
69
|
+
'indigo' => '4b0082',
|
70
|
+
'ivory' => 'fffff0',
|
71
|
+
'khaki' => 'f0e68c',
|
72
|
+
'lavender' => 'e6e6fa',
|
73
|
+
'lavenderblush' => 'fff0f5',
|
74
|
+
'lawngreen' => '7cfc00',
|
75
|
+
'lemonchiffon' => 'fffacd',
|
76
|
+
'lightblue' => 'add8e6',
|
77
|
+
'lightcoral' => 'f08080',
|
78
|
+
'lightcyan' => 'e0ffff',
|
79
79
|
'lightgoldenrodyellow' => 'fafad2',
|
80
|
-
'lightgray'
|
81
|
-
'lightgreen'
|
82
|
-
'lightgrey'
|
83
|
-
'lightpink'
|
84
|
-
'lightsalmon'
|
85
|
-
'lightseagreen'
|
86
|
-
'lightskyblue'
|
87
|
-
'lightslategray'
|
88
|
-
'lightslategrey'
|
89
|
-
'lightsteelblue'
|
90
|
-
'lightyellow'
|
91
|
-
'lime'
|
92
|
-
'limegreen'
|
93
|
-
'linen'
|
94
|
-
'magenta'
|
95
|
-
'maroon'
|
96
|
-
'mediumaquamarine'
|
97
|
-
'mediumblue'
|
98
|
-
'mediumorchid'
|
99
|
-
'mediumpurple'
|
100
|
-
'mediumseagreen'
|
101
|
-
'mediumslateblue'
|
102
|
-
'mediumspringgreen'
|
103
|
-
'mediumturquoise'
|
104
|
-
'mediumvioletred'
|
105
|
-
'midnightblue'
|
106
|
-
'mintcream'
|
107
|
-
'mistyrose'
|
108
|
-
'moccasin'
|
109
|
-
'navajowhite'
|
110
|
-
'navy'
|
111
|
-
'oldlace'
|
112
|
-
'olive'
|
113
|
-
'olivedrab'
|
114
|
-
'orange'
|
115
|
-
'orangered'
|
116
|
-
'orchid'
|
117
|
-
'palegoldenrod'
|
118
|
-
'palegreen'
|
119
|
-
'paleturquoise'
|
120
|
-
'palevioletred'
|
121
|
-
'papayawhip'
|
122
|
-
'peachpuff'
|
123
|
-
'peru'
|
124
|
-
'pink'
|
125
|
-
'plum'
|
126
|
-
'powderblue'
|
127
|
-
'purple'
|
128
|
-
'red'
|
129
|
-
'rosybrown'
|
130
|
-
'royalblue'
|
131
|
-
'saddlebrown'
|
132
|
-
'salmon'
|
133
|
-
'sandybrown'
|
134
|
-
'seagreen'
|
135
|
-
'seashell'
|
136
|
-
'sienna'
|
137
|
-
'silver'
|
138
|
-
'skyblue'
|
139
|
-
'slateblue'
|
140
|
-
'slategray'
|
141
|
-
'slategrey'
|
142
|
-
'snow'
|
143
|
-
'springgreen'
|
144
|
-
'steelblue'
|
145
|
-
'tan'
|
146
|
-
'teal'
|
147
|
-
'thistle'
|
148
|
-
'tomato'
|
149
|
-
'turquoise'
|
150
|
-
'violet'
|
151
|
-
'wheat'
|
152
|
-
'white'
|
153
|
-
'whitesmoke'
|
154
|
-
'yellow'
|
155
|
-
'yellowgreen'
|
80
|
+
'lightgray' => 'd3d3d3',
|
81
|
+
'lightgreen' => '90ee90',
|
82
|
+
'lightgrey' => 'd3d3d3',
|
83
|
+
'lightpink' => 'ffb6c1',
|
84
|
+
'lightsalmon' => 'ffa07a',
|
85
|
+
'lightseagreen' => '20b2aa',
|
86
|
+
'lightskyblue' => '87cefa',
|
87
|
+
'lightslategray' => '778899',
|
88
|
+
'lightslategrey' => '778899',
|
89
|
+
'lightsteelblue' => 'b0c4de',
|
90
|
+
'lightyellow' => 'ffffe0',
|
91
|
+
'lime' => '00ff00',
|
92
|
+
'limegreen' => '32cd32',
|
93
|
+
'linen' => 'faf0e6',
|
94
|
+
'magenta' => 'ff00ff',
|
95
|
+
'maroon' => '800000',
|
96
|
+
'mediumaquamarine' => '66cdaa',
|
97
|
+
'mediumblue' => '0000cd',
|
98
|
+
'mediumorchid' => 'ba55d3',
|
99
|
+
'mediumpurple' => '9370db',
|
100
|
+
'mediumseagreen' => '3cb371',
|
101
|
+
'mediumslateblue' => '7b68ee',
|
102
|
+
'mediumspringgreen' => '00fa9a',
|
103
|
+
'mediumturquoise' => '48d1cc',
|
104
|
+
'mediumvioletred' => 'c71585',
|
105
|
+
'midnightblue' => '191970',
|
106
|
+
'mintcream' => 'f5fffa',
|
107
|
+
'mistyrose' => 'ffe4e1',
|
108
|
+
'moccasin' => 'ffe4b5',
|
109
|
+
'navajowhite' => 'ffdead',
|
110
|
+
'navy' => '000080',
|
111
|
+
'oldlace' => 'fdf5e6',
|
112
|
+
'olive' => '808000',
|
113
|
+
'olivedrab' => '6b8e23',
|
114
|
+
'orange' => 'ffa500',
|
115
|
+
'orangered' => 'ff4500',
|
116
|
+
'orchid' => 'da70d6',
|
117
|
+
'palegoldenrod' => 'eee8aa',
|
118
|
+
'palegreen' => '98fb98',
|
119
|
+
'paleturquoise' => 'afeeee',
|
120
|
+
'palevioletred' => 'db7093',
|
121
|
+
'papayawhip' => 'ffefd5',
|
122
|
+
'peachpuff' => 'ffdab9',
|
123
|
+
'peru' => 'cd853f',
|
124
|
+
'pink' => 'ffc0cb',
|
125
|
+
'plum' => 'dda0dd',
|
126
|
+
'powderblue' => 'b0e0e6',
|
127
|
+
'purple' => '800080',
|
128
|
+
'red' => 'ff0000',
|
129
|
+
'rosybrown' => 'bc8f8f',
|
130
|
+
'royalblue' => '4169e1',
|
131
|
+
'saddlebrown' => '8b4513',
|
132
|
+
'salmon' => 'fa8072',
|
133
|
+
'sandybrown' => 'f4a460',
|
134
|
+
'seagreen' => '2e8b57',
|
135
|
+
'seashell' => 'fff5ee',
|
136
|
+
'sienna' => 'a0522d',
|
137
|
+
'silver' => 'c0c0c0',
|
138
|
+
'skyblue' => '87ceeb',
|
139
|
+
'slateblue' => '6a5acd',
|
140
|
+
'slategray' => '708090',
|
141
|
+
'slategrey' => '708090',
|
142
|
+
'snow' => 'fffafa',
|
143
|
+
'springgreen' => '00ff7f',
|
144
|
+
'steelblue' => '4682b4',
|
145
|
+
'tan' => 'd2b48c',
|
146
|
+
'teal' => '008080',
|
147
|
+
'thistle' => 'd8bfd8',
|
148
|
+
'tomato' => 'ff6347',
|
149
|
+
'turquoise' => '40e0d0',
|
150
|
+
'violet' => 'ee82ee',
|
151
|
+
'wheat' => 'f5deb3',
|
152
|
+
'white' => 'ffffff',
|
153
|
+
'whitesmoke' => 'f5f5f5',
|
154
|
+
'yellow' => 'ffff00',
|
155
|
+
'yellowgreen' => '9acd32'
|
156
156
|
}.freeze
|
157
157
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
URL_REGEXP = /\Aurl\(([^)]*)\)\z/i
|
158
|
+
class << self
|
159
|
+
def parse(color_string, gradients = nil, color_mode = :rgb)
|
160
|
+
url_specified = false
|
162
161
|
|
163
|
-
|
164
|
-
url_specified = false
|
162
|
+
values = ::Prawn::SVG::CSS::ValuesParser.parse(color_string)
|
165
163
|
|
166
|
-
|
164
|
+
result = values.map do |value|
|
165
|
+
case value
|
166
|
+
in ['rgb', args]
|
167
|
+
hex = (0..2).collect do |n|
|
168
|
+
number = args[n].to_f
|
169
|
+
number *= 2.55 if args[n][-1..] == '%'
|
170
|
+
format('%02x', number.round.clamp(0, 255))
|
171
|
+
end.join
|
167
172
|
|
168
|
-
|
169
|
-
if m = color.match(/\A#([0-9a-f])([0-9a-f])([0-9a-f])\z/i)
|
170
|
-
RGB.new("#{m[1] * 2}#{m[2] * 2}#{m[3] * 2}")
|
173
|
+
RGB.new(hex)
|
171
174
|
|
172
|
-
|
173
|
-
|
175
|
+
in ['device-cmyk', args]
|
176
|
+
cmyk = (0..3).collect do |n|
|
177
|
+
number = args[n].to_f
|
178
|
+
number *= 100 unless args[n][-1..] == '%'
|
179
|
+
number.clamp(0, 100)
|
180
|
+
end
|
174
181
|
|
175
|
-
|
176
|
-
hex_color(hex, color_mode)
|
182
|
+
CMYK.new(cmyk)
|
177
183
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end.join
|
184
|
+
in ['url', [url]]
|
185
|
+
url_specified = true
|
186
|
+
if url[0] == '#' && gradients && (gradient = gradients[url[1..]])
|
187
|
+
gradient
|
188
|
+
end
|
184
189
|
|
185
|
-
|
190
|
+
in /\A#([0-9a-f])([0-9a-f])([0-9a-f])\z/i
|
191
|
+
RGB.new("#{$1 * 2}#{$2 * 2}#{$3 * 2}")
|
186
192
|
|
187
|
-
|
188
|
-
|
189
|
-
value = m[n].to_f
|
190
|
-
value *= 100 unless m[n][-1..-1] == '%'
|
191
|
-
clamp(value, 0, 100)
|
192
|
-
end
|
193
|
+
in /\A#[0-9a-f]{6}\z/i
|
194
|
+
RGB.new(value[1..])
|
193
195
|
|
194
|
-
|
196
|
+
in String => color
|
197
|
+
if (hex = HTML_COLORS[color.downcase])
|
198
|
+
hex_color(hex, color_mode)
|
199
|
+
end
|
195
200
|
|
196
|
-
|
197
|
-
|
198
|
-
url = matches[1]
|
199
|
-
if url[0] == "#" && gradients && gradient = gradients[url[1..-1]]
|
200
|
-
gradient
|
201
|
+
else
|
202
|
+
nil
|
201
203
|
end
|
202
204
|
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# Generally, we default to black if the colour was unparseable.
|
206
|
-
# http://www.w3.org/TR/SVG/painting.html section 11.2 says if a URL was
|
207
|
-
# supplied without a fallback, that's an error.
|
208
|
-
result << default_color(color_mode) unless url_specified
|
209
205
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
result = parse(color).detect {|result| result.is_a?(RGB) || result.is_a?(CMYK)}
|
215
|
-
result.value if result
|
216
|
-
end
|
206
|
+
# Generally, we default to black if the colour was unparseable.
|
207
|
+
# http://www.w3.org/TR/SVG/painting.html section 11.2 says if a URL was
|
208
|
+
# supplied without a fallback, that's an error.
|
209
|
+
result << default_color(color_mode) unless url_specified
|
217
210
|
|
218
|
-
|
211
|
+
result.compact
|
212
|
+
end
|
219
213
|
|
220
|
-
|
221
|
-
|
222
|
-
|
214
|
+
def css_color_to_prawn_color(color)
|
215
|
+
parse(color).detect { |value| value.is_a?(RGB) || value.is_a?(CMYK) }&.value
|
216
|
+
end
|
223
217
|
|
224
|
-
|
225
|
-
|
226
|
-
|
218
|
+
def default_color(color_mode)
|
219
|
+
color_mode == :cmyk ? CMYK_DEFAULT_COLOR : RGB_DEFAULT_COLOR
|
220
|
+
end
|
227
221
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
222
|
+
private
|
223
|
+
|
224
|
+
def hex_color(hex, color_mode)
|
225
|
+
if color_mode == :cmyk
|
226
|
+
r, g, b = [hex[0..1], hex[2..3], hex[4..5]].map { |h| h.to_i(16) / 255.0 }
|
227
|
+
k = 1 - [r, g, b].max
|
228
|
+
if k == 1
|
229
|
+
CMYK.new([0, 0, 0, 100])
|
230
|
+
else
|
231
|
+
c = (1 - r - k) / (1 - k)
|
232
|
+
m = (1 - g - k) / (1 - k)
|
233
|
+
y = (1 - b - k) / (1 - k)
|
234
|
+
CMYK.new([c, m, y, k].map { |v| (v * 100).round })
|
235
|
+
end
|
234
236
|
else
|
235
|
-
|
236
|
-
m = (1 - g - k) / (1 - k)
|
237
|
-
y = (1 - b - k) / (1 - k)
|
238
|
-
CMYK.new([c, m, y, k].map { |v| (v * 100).round })
|
237
|
+
RGB.new(hex)
|
239
238
|
end
|
240
|
-
else
|
241
|
-
RGB.new(hex)
|
242
239
|
end
|
243
240
|
end
|
244
241
|
end
|
@@ -6,7 +6,7 @@ module Prawn::SVG::CSS
|
|
6
6
|
current = nil
|
7
7
|
fonts = []
|
8
8
|
|
9
|
-
string.
|
9
|
+
string.each_char do |char|
|
10
10
|
if in_escape
|
11
11
|
in_escape = false
|
12
12
|
if current.nil?
|
@@ -19,7 +19,7 @@ module Prawn::SVG::CSS
|
|
19
19
|
current = nil
|
20
20
|
elsif char == in_quote
|
21
21
|
in_quote = nil
|
22
|
-
elsif in_quote.nil? &&
|
22
|
+
elsif in_quote.nil? && ['"', "'"].include?(char)
|
23
23
|
in_quote = char
|
24
24
|
elsif char == '\\'
|
25
25
|
in_escape = true
|