Issues (331)

examples/clip-operator.php (6 issues)

Labels
Severity
1
<?php
2
3
use Cairo\Context;
0 ignored issues
show
The type Cairo\Context was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use Cairo\Operator;
0 ignored issues
show
The type Cairo\Operator was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Cairo\Pattern\Gradient\Linear;
0 ignored issues
show
The type Cairo\Pattern\Gradient\Linear was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Cairo\Surface\Content;
0 ignored issues
show
The type Cairo\Surface\Content was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Cairo\Surface\Image;
0 ignored issues
show
The type Cairo\Surface\Image was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Cairo\Surface\ImageFormat;
0 ignored issues
show
The type Cairo\Surface\ImageFormat was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
$width = 16;
11
$height = 16;
12
$pad = 2;
13
$noperator = 1 + Operator::SATURATE - Operator::CLEAR;
14
$imagewidth = $noperator * ($width + $pad) + $pad;
15
$imageheight = 4 * ($height + $pad) + $pad;
16
$surface = new Image(ImageFormat::ARGB32, $imagewidth, $imageheight);
17
$context = new Context($surface);
18
$context->selectFontFace('Bitstream Vera Sans');
19
$context->setFontSize(0.9 * $height);
20
21
for ($i = 0; $i < 4; $i++)
22
{
23
	for ($op = Operator::CLEAR; $op < $noperator; $op++)
24
	{
25
		$x = $op * ($width + $pad) + $pad;
26
		$y = $i * ($height + $pad) + $pad;
27
		
28
		$context->save();
29
		$pat = new Linear($x + $width, $y, $x, $y + $height);
30
		$pat->addColorStopRgba(0.2, 0, 0, 1, 1);
31
		$pat->addColorStopRgba(0.8, 0, 0, 1, 0);
32
		
33
		$context->setPattern($pat);
34
		$context->rectangle($x, $y, $width, $height);
35
		$context->fill();
36
		$context->setOperator($op);
37
		$context->setSourceRgb(1, 0, 0);
38
		$context->moveTo($x, $y);
39
		$context->lineTo($x + $width, $y);
40
		$context->lineTo($x, $y + $height);
41
		$context->clip();
42
		
43
		switch ($i)
44
		{
45
			case 0:
46
				$wi = floor($width * 0.9);
47
				$he = floor($height * 0.9);
48
				$x += 0.05 * $width;
49
				$y += 0.05 * $height;
50
				
51
				$msur = $surface->createSimilar(Content::ALPHA, $wi, $he);
52
				
53
				$c2 = new Context($msur);
54
				$c2->save();
55
				$c2->setSourceRgba(0, 0, 0, 0);
56
				$c2->setOperator(Operator::SOURCE);
57
				$c2->paint();
58
				$c2->restore();
59
				
60
				$c2->setSourceRgb(1, 1, 1);
61
				$c2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI);
62
				$c2->fill();
63
				
64
				$context->maskSurface($msur, $x, $y);
65
				
66
				break;
67
			
68
			case 1:
69
				$context->setFontSize(0.9 * $height);
70
				$ext = $context->getTextExtents('FG');
71
				$context->moveTo($x + floor(($width - $ext['width']) / 2 + 0.5) - $ext['x_bearing'], $y + floor(($height - $ext['height']) / 2 + 0.5) - $ext['y_bearing']);
72
				$context->showText('FG');
73
				
74
				break;
75
			
76
			case 2:
77
				$wi = floor($width * 9 / 10);
78
				$he = floor($height * 9 / 10);
79
				$x += 0.05 * $width;
80
				$y += 0.05 * $height;
81
				$context->newPath();
82
				$context->moveTo($x, $y);
83
				$context->lineTo($x, $y + $he);
84
				$context->lineTo($x + $wi / 2, $y + 3 * $he / 4);
85
				$context->lineTo($x + $wi, $y + $he);
86
				$context->lineTo($x + $wi, $y);
87
				$context->lineTo($x + $wi / 2, $y + $he / 4);
88
				$context->closePath();
89
				$context->fill();
90
				
91
				break;
92
			
93
			case 3:
94
				$bw = floor(0.33 * $width + 0.5);
95
				$bh = floor(0.33 * $height + 0.5);
96
				
97
				for ($t1 = 0; $t1 < 3; $t1++)
98
				{
99
					for ($t2 = 0; $t2 < 3; $t2++)
100
					{
101
						if (($t1 + $t2) % 2 == 0)
102
						{
103
							$context->rectangle($x + $bw * $t1, $y + $bh * $t2, $bw, $bh);
104
						}
105
					}
106
					
107
					$context->fill();
108
				}
109
				
110
				break;
111
		}
112
		
113
		$context->restore();
114
	}
115
}
116
117
$surface->writeToPng(dirname(__FILE__).'/clip-operator-php.png');
118