1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Cairo\Context; |
|
|
|
|
4
|
|
|
use Cairo\FontSlant; |
|
|
|
|
5
|
|
|
use Cairo\FontWeight; |
|
|
|
|
6
|
|
|
use Cairo\Operator; |
|
|
|
|
7
|
|
|
use Cairo\Pattern\Gradient\Linear; |
|
|
|
|
8
|
|
|
use Cairo\Surface\Content; |
|
|
|
|
9
|
|
|
use Cairo\Surface\Image; |
|
|
|
|
10
|
|
|
use Cairo\Surface\ImageFormat; |
|
|
|
|
11
|
|
|
|
12
|
|
|
function setSolidPattern($context, $x, $y) |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$context->setSourceRgb(1.0, 0, 0.0); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
function setGradientPttern($context, $width, $height, $x, $y) |
18
|
|
|
{ |
19
|
|
|
$pat = new Linear($x, $y, $x + $width, $y + $height); |
20
|
|
|
$pat->addColorStopRgba(0.2, 1, 0, 0, 1); |
21
|
|
|
$pat->addColorStopRgba(0.8, 1, 0, 0, 0.0); |
22
|
|
|
$context->setPattern($pat); |
23
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function drawMask($surface, $context, $width, $height, $x, $y) |
27
|
|
|
{ |
28
|
|
|
$wi = floor(0.9 * $width); |
29
|
|
|
$he = floor(0.9 * $height); |
30
|
|
|
$x += 0.05 * $width; |
31
|
|
|
$y += 0.05 * $height; |
32
|
|
|
|
33
|
|
|
$s = $surface->createSimilar(Content::ALPHA, $wi, $he); |
34
|
|
|
$con2 = new Context($s); |
35
|
|
|
$con2->setSourceRgb(1, 1, 1); /* white */ |
36
|
|
|
$con2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI); |
37
|
|
|
$con2->fill(); |
38
|
|
|
|
39
|
|
|
$context->maskSurface($s, $x, $y); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function drawGlyphs($context, $width, $height, $x, $y) |
43
|
|
|
{ |
44
|
|
|
$context->setFontSize(0.8 * $height); |
45
|
|
|
$extents = $context->textExtents('FG'); |
46
|
|
|
|
47
|
|
|
$moveX = $x + floor(($width - $extents['width']) / 2 + 0.5) - $extents['x_bearing']; |
48
|
|
|
$moveY = $y + floor(($height - $extents['height']) / 2 + 0.5) - $extents['y_bearing']; |
49
|
|
|
|
50
|
|
|
$context->moveTo($moveX, $moveY); |
51
|
|
|
$context->showText('FG'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function drawPolygon($context, $width, $height, $x, $y) |
55
|
|
|
{ |
56
|
|
|
$wi = floor(0.9 * $width); |
57
|
|
|
$he = floor(0.9 * $height); |
58
|
|
|
$x += 0.05 * $width; |
59
|
|
|
$y += 0.05 * $height; |
60
|
|
|
|
61
|
|
|
$context->newPath(); |
62
|
|
|
$context->moveTo($x, $y); |
63
|
|
|
$context->lineTo($x, $y + $he); |
64
|
|
|
$context->lineTo($x + $wi / 2, $y + 3 * $he / 4); |
65
|
|
|
$context->lineTo($x + $wi, $y + $he); |
66
|
|
|
$context->lineTo($x + $wi, $y); |
67
|
|
|
$context->lineTo($x + $wi / 2, $y + $he / 4); |
68
|
|
|
$context->closePath(); |
69
|
|
|
$context->fill(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function drawRects($context, $width, $height, $x, $y) |
73
|
|
|
{ |
74
|
|
|
$blockWidth = floor(0.33 * $width + 0.5); |
75
|
|
|
$blockHeight = floor(0.33 * $height + 0.5); |
76
|
|
|
|
77
|
|
|
for ($i = 0; $i < 3; $i++) |
78
|
|
|
{ |
79
|
|
|
for ($j = 0; $j < 3; $j++) |
80
|
|
|
{ |
81
|
|
|
if (($i + $j) % 2 == 0) |
82
|
|
|
{ |
83
|
|
|
$context->rectangle($x + $blockWidth * $i, $y + $blockHeight * $j, $blockWidth, $blockHeight); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$context->fill(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$width = 16; |
92
|
|
|
$height = 16; |
93
|
|
|
$pad = 2; |
94
|
|
|
|
95
|
|
|
$imageWidth = 2 * ($width + $pad) + $pad; |
96
|
|
|
$imageHeight = 4 * ($height + $pad) + $pad; |
97
|
|
|
|
98
|
|
|
$surface = new Image(ImageFormat::ARGB32, $imageWidth, $imageHeight); |
99
|
|
|
$context = new Context($surface); |
100
|
|
|
$context->selectFontFace('Bitstream Vera Sans', FontSlant::NORMAL, FontWeight::NORMAL); |
101
|
|
|
|
102
|
|
|
for ($j = 0; $j < 4; $j++) |
103
|
|
|
{ |
104
|
|
|
for ($i = 0; $i < 2; $i++) |
105
|
|
|
{ |
106
|
|
|
$x = $i * ($width + $pad) + $pad; |
107
|
|
|
$y = $j * ($height + $pad) + $pad; |
108
|
|
|
|
109
|
|
|
$context->save(); |
110
|
|
|
|
111
|
|
|
$pat = new Linear($x + $width, $y, $x, $y + $height); |
112
|
|
|
$pat->addColorStopRgba(0.2, 0.0, 0.0, 1.0, 1.0); /* Solid blue */ |
113
|
|
|
$pat->addColorStopRgba(0.8, 0.0, 0.0, 1.0, 0.0); /* Transparent blue */ |
114
|
|
|
$context->setPattern($pat); |
115
|
|
|
|
116
|
|
|
$context->rectangle($x, $y, $width, $height); |
117
|
|
|
$context->fillPreserve(); |
118
|
|
|
$context->clip(); |
119
|
|
|
|
120
|
|
|
$context->setOperator(Operator::CLEAR); |
121
|
|
|
|
122
|
|
|
switch ($i) |
123
|
|
|
{ |
124
|
|
|
case 0: |
125
|
|
|
setSolidPattern($context, $x, $y); |
126
|
|
|
break; |
127
|
|
|
case 1: |
128
|
|
|
setGradientPttern($context, $width, $height, $x, $y); |
129
|
|
|
break; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
switch ($j) |
133
|
|
|
{ |
134
|
|
|
case 0: |
135
|
|
|
drawMask($surface, $context, $width, $height, $x, $y); |
136
|
|
|
break; |
137
|
|
|
case 1: |
138
|
|
|
drawGlyphs($context, $width, $height, $x, $y); |
139
|
|
|
break; |
140
|
|
|
case 2: |
141
|
|
|
drawPolygon($context, $width, $height, $x, $y); |
142
|
|
|
break; |
143
|
|
|
case 3: |
144
|
|
|
drawRects($context, $width, $height, $x, $y); |
145
|
|
|
break; |
146
|
|
|
} |
147
|
|
|
$context->restore(); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$surface->writeToPng(dirname(__FILE__).'/operator-clear-php.png'); |
152
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths