1010
1111namespace chillerlan \QRCode \Output ;
1212
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 ;
1414
1515/**
1616 * Encapsulated Postscript (EPS) output
@@ -31,28 +31,41 @@ public static function moduleValueIsValid($value):bool{
3131 return false ;
3232 }
3333
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 )){
3742 return false ;
3843 }
44+
3945 }
4046
4147 return true ;
4248 }
4349
4450 /**
51+ * @param array $value
52+ *
4553 * @inheritDoc
4654 */
4755 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+ }
4963
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 );
5366 }
5467
55- return $ val ;
68+ return $ values ;
5669 }
5770
5871 /**
@@ -80,7 +93,8 @@ public function dump(string $file = null):string{
8093 // function definitions
8194 '%%BeginProlog ' ,
8295 '/F { rectfill } def ' ,
83- '/S { setrgbcolor } def ' ,
96+ '/R { setrgbcolor } def ' ,
97+ '/C { setcmykcolor } def ' ,
8498 '%%EndProlog ' ,
8599 ];
86100
@@ -93,7 +107,9 @@ public function dump(string $file = null):string{
93107 continue ;
94108 }
95109
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 ]);
97113 $ eps [] = implode ("\n" , $ path );
98114 }
99115
0 commit comments