swen100 /
cairo
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | use Cairo\Context; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 4 | use Cairo\FontSlant; |
||||||
|
0 ignored issues
–
show
The type
Cairo\FontSlant 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. 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\FontWeight; |
||||||
|
0 ignored issues
–
show
The type
Cairo\FontWeight 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. 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\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. 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\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. 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\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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 9 | 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 10 | 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 11 | |||||||
| 12 | function setSolidPattern($context, $x, $y) |
||||||
|
0 ignored issues
–
show
The parameter
$y is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$x is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 13 | { |
||||||
| 14 | $context->setSourceRgb(1.0, 0, 0.0); |
||||||
| 15 | } |
||||||
| 16 | |||||||
| 17 | function setTranslucentPattern($context, $x, $y) |
||||||
|
0 ignored issues
–
show
The parameter
$y is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$x is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 18 | { |
||||||
| 19 | $context->setSourceRgba(1, 0, 0, 0.5); |
||||||
| 20 | } |
||||||
| 21 | |||||||
| 22 | function setGradientPattern($context, $width, $height, $x, $y) |
||||||
| 23 | { |
||||||
| 24 | $pat = new Linear($x, $y, $x + $width, $y + $height); |
||||||
| 25 | $pat->addColorStopRgba(0.2, 1, 0, 0, 1); |
||||||
| 26 | $pat->addColorStopRgba(0.8, 1, 0, 0, 0.0); |
||||||
| 27 | $context->setPattern($pat); |
||||||
| 28 | } |
||||||
| 29 | |||||||
| 30 | function setSurfacePattern($surface, $context, $width, $height, $x, $y) |
||||||
| 31 | { |
||||||
| 32 | $wi = floor(0.6 * $width); |
||||||
| 33 | $he = floor(0.6 * $height); |
||||||
| 34 | $x += 0.2 * $width; |
||||||
| 35 | $y += 0.2 * $height; |
||||||
| 36 | $s = $surface->createSimilar(Content::COLOR_ALPHA, $wi, $he); |
||||||
| 37 | $con2 = new Context($s); |
||||||
| 38 | $con2->setSourceRgb(1, 0, 0); |
||||||
| 39 | $con2->paint(); |
||||||
| 40 | $con2->setSourceRgb(1, 1, 1); |
||||||
| 41 | $con2->arc(0.5 * $wi, 0.5 * $he, 0.5 * $he, 0, 2 * M_PI); |
||||||
| 42 | $con2->fill(); |
||||||
| 43 | $s->writeToPng(dirname(__FILE__).'/temp.png'); |
||||||
| 44 | $context->setSurface($s, $x, $y); |
||||||
| 45 | unset($s); |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | function drawMask($surface, $context, $width, $height, $x, $y) |
||||||
| 49 | { |
||||||
| 50 | $wi = floor(0.9 * $width); |
||||||
| 51 | $he = floor(0.9 * $height); |
||||||
| 52 | $x += 0.05 * $width; |
||||||
| 53 | $y += 0.05 * $height; |
||||||
| 54 | $s = $surface->createSimilar(Content::ALPHA, $wi, $he); |
||||||
| 55 | $con2 = new Context($s); |
||||||
| 56 | $con2->setSourceRgb(1, 1, 1); /* white */ |
||||||
| 57 | $con2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI); |
||||||
| 58 | $con2->fill(); |
||||||
| 59 | $context->maskSurface($s, $x, $y); |
||||||
| 60 | unset($s); |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | function drawGlyphs($context, $width, $height, $x, $y) |
||||||
| 64 | { |
||||||
| 65 | $context->setFontSize(0.8 * $height); |
||||||
| 66 | $extents = $context->textExtents('FG'); |
||||||
| 67 | |||||||
| 68 | $moveX = $x + floor(($width - $extents['width']) / 2 + 0.5) - $extents['x_bearing']; |
||||||
| 69 | $moveY = $y + floor(($height - $extents['height']) / 2 + 0.5) - $extents['y_bearing']; |
||||||
| 70 | |||||||
| 71 | $context->moveTo($moveX, $moveY); |
||||||
| 72 | $context->showText('FG'); |
||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | function drawPolygon($context, $width, $height, $x, $y) |
||||||
| 76 | { |
||||||
| 77 | $wi = floor(0.9 * $width); |
||||||
| 78 | $he = floor(0.9 * $height); |
||||||
| 79 | $x += 0.05 * $width; |
||||||
| 80 | $y += 0.05 * $height; |
||||||
| 81 | |||||||
| 82 | $context->newPath(); |
||||||
| 83 | $context->moveTo($x, $y); |
||||||
| 84 | $context->lineTo($x, $y + $he); |
||||||
| 85 | $context->lineTo($x + $wi / 2, $y + 3 * $he / 4); |
||||||
| 86 | $context->lineTo($x + $wi, $y + $he); |
||||||
| 87 | $context->lineTo($x + $wi, $y); |
||||||
| 88 | $context->lineTo($x + $wi / 2, $y + $he / 4); |
||||||
| 89 | $context->closePath(); |
||||||
| 90 | $context->fill(); |
||||||
| 91 | } |
||||||
| 92 | |||||||
| 93 | function drawRects($context, $width, $height, $x, $y) |
||||||
| 94 | { |
||||||
| 95 | $blockWidth = floor(0.33 * $width + 0.5); |
||||||
| 96 | $blockHeight = floor(0.33 * $height + 0.5); |
||||||
| 97 | |||||||
| 98 | for ($i = 0; $i < 3; $i++) |
||||||
| 99 | { |
||||||
| 100 | for ($j = 0; $j < 3; $j++) |
||||||
| 101 | { |
||||||
| 102 | if (($i + $j) % 2 == 0) |
||||||
| 103 | { |
||||||
| 104 | $context->rectangle($x + $blockWidth * $i, $y + $blockHeight * $j, $blockWidth, $blockHeight); |
||||||
| 105 | } |
||||||
| 106 | } |
||||||
| 107 | } |
||||||
| 108 | |||||||
| 109 | $context->fill(); |
||||||
| 110 | } |
||||||
| 111 | |||||||
| 112 | $width = 16; |
||||||
| 113 | $height = 16; |
||||||
| 114 | $pad = 2; |
||||||
| 115 | |||||||
| 116 | $imageWidth = 4 * ($width + $pad) + $pad; |
||||||
| 117 | $imageHeight = 4 * ($height + $pad) + $pad; |
||||||
| 118 | |||||||
| 119 | $surface = new Image(ImageFormat::ARGB32, $imageWidth, $imageHeight); |
||||||
| 120 | $context = new Context($surface); |
||||||
| 121 | |||||||
| 122 | $context->selectFontFace('Bitstream Vera Sans', FontSlant::NORMAL, FontWeight::NORMAL); |
||||||
| 123 | |||||||
| 124 | for ($j = 0; $j < 4; $j++) |
||||||
| 125 | { |
||||||
| 126 | for ($i = 0; $i < 4; $i++) |
||||||
| 127 | { |
||||||
| 128 | $x = $i * ($width + $pad) + $pad; |
||||||
| 129 | $y = $j * ($height + $pad) + $pad; |
||||||
| 130 | |||||||
| 131 | $context->save(); |
||||||
| 132 | |||||||
| 133 | $pat = new Linear($x + $width, $y, $x, $y + $height); |
||||||
| 134 | $pat->addColorStopRgba(0.2, 0.0, 0.0, 1.0, 1.0); /* Solid blue */ |
||||||
| 135 | $pat->addColorStopRgba(0.8, 0.0, 0.0, 1.0, 0.0); /* Transparent blue */ |
||||||
| 136 | $context->setPattern($pat); |
||||||
| 137 | $context->rectangle($x, $y, $width, $height); |
||||||
| 138 | $context->fillPreserve(); |
||||||
| 139 | $context->clip(); |
||||||
| 140 | $context->setOperator(Operator::SOURCE); |
||||||
| 141 | |||||||
| 142 | switch ($i) |
||||||
| 143 | { |
||||||
| 144 | case 0: |
||||||
| 145 | setSolidPattern($context, $x, $y); |
||||||
| 146 | break; |
||||||
| 147 | case 1: |
||||||
| 148 | setTranslucentPattern($context, $x, $y); |
||||||
| 149 | break; |
||||||
| 150 | case 2: |
||||||
| 151 | setGradientPattern($context, $width, $height, $x, $y); |
||||||
| 152 | break; |
||||||
| 153 | case 3: |
||||||
| 154 | //setSurfacePattern($surface, $context, $width, $height, $x,$y); |
||||||
| 155 | break; |
||||||
| 156 | } |
||||||
| 157 | |||||||
| 158 | switch ($j) |
||||||
| 159 | { |
||||||
| 160 | case 0: |
||||||
| 161 | drawMask($surface, $context, $width, $height, $x, $y); |
||||||
| 162 | break; |
||||||
| 163 | case 1: |
||||||
| 164 | drawGlyphs($context, $width, $height, $x, $y); |
||||||
| 165 | break; |
||||||
| 166 | case 2: |
||||||
| 167 | drawPolygon($context, $width, $height, $x, $y); |
||||||
| 168 | break; |
||||||
| 169 | case 3: |
||||||
| 170 | drawRects($context, $width, $height, $x, $y); |
||||||
| 171 | break; |
||||||
| 172 | } |
||||||
| 173 | |||||||
| 174 | $context->restore(); |
||||||
| 175 | } |
||||||
| 176 | } |
||||||
| 177 | |||||||
| 178 | $surface->writeToPng(dirname(__FILE__).'/operator-source-php.png'); |
||||||
| 179 |
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