10
10
11
11
namespace chillerlan \QRCode \Output ;
12
12
13
- use function count , date , implode , is_array , is_numeric , max , min , round , sprintf ;
13
+ use function array_values , count , date , implode , is_array , is_numeric , max , min , round , sprintf ;
14
14
15
15
/**
16
16
* Encapsulated Postscript (EPS) output
@@ -31,28 +31,41 @@ public static function moduleValueIsValid($value):bool{
31
31
return false ;
32
32
}
33
33
34
- // check the first 3 values of the array
35
- for ($ i = 0 ; $ i < 3 ; $ i ++){
36
- if (!is_numeric ($ value [$ i ])){
34
+ // check the first values of the array
35
+ foreach ($ value as $ i => $ val ){
36
+
37
+ if ($ i > 3 ){
38
+ break ;
39
+ }
40
+
41
+ if (!is_numeric ($ val )){
37
42
return false ;
38
43
}
44
+
39
45
}
40
46
41
47
return true ;
42
48
}
43
49
44
50
/**
51
+ * @param array $value
52
+ *
45
53
* @inheritDoc
46
54
*/
47
55
protected function getModuleValue ($ value ):array {
48
- $ val = [];
56
+ $ values = [];
57
+
58
+ foreach (array_values ($ value ) as $ i => $ val ){
59
+
60
+ if ($ i > 3 ){
61
+ break ;
62
+ }
49
63
50
- for ($ i = 0 ; $ i < 3 ; $ i ++){
51
- // clamp value and convert from 0-255 to 0-1 RGB range
52
- $ val [] = round ((max (0 , min (255 , $ value [$ i ])) / 255 ), 6 );
64
+ // clamp value and convert from 0-255 to 0-1 RGB/CMYK range
65
+ $ values [] = round ((max (0 , min (255 , $ val )) / 255 ), 6 );
53
66
}
54
67
55
- return $ val ;
68
+ return $ values ;
56
69
}
57
70
58
71
/**
@@ -80,7 +93,8 @@ public function dump(string $file = null):string{
80
93
// function definitions
81
94
'%%BeginProlog ' ,
82
95
'/F { rectfill } def ' ,
83
- '/S { setrgbcolor } def ' ,
96
+ '/R { setrgbcolor } def ' ,
97
+ '/C { setcmykcolor } def ' ,
84
98
'%%EndProlog ' ,
85
99
];
86
100
@@ -93,7 +107,9 @@ public function dump(string $file = null):string{
93
107
continue ;
94
108
}
95
109
96
- $ eps [] = sprintf ('%f %f %f S ' , ...$ this ->moduleValues [$ M_TYPE ]);
110
+ // 4 values will be interpreted as CMYK, 3 as RGB
111
+ $ format = (count ($ this ->moduleValues [$ M_TYPE ]) === 4 ) ? '%f %f %f %f C ' : '%f %f %f R ' ;
112
+ $ eps [] = sprintf ($ format , ...$ this ->moduleValues [$ M_TYPE ]);
97
113
$ eps [] = implode ("\n" , $ path );
98
114
}
99
115
0 commit comments