Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require-dev": {
"zendframework/zend-barcode": ">=2.0.0,<2.4",
"zendframework/zend-validator": ">=2.0.0,<2.4",
"imagine/Imagine": ">=0.2.0,<0.6.0"
"imagine/Imagine": "~0.6"
},
"suggest": {
"zendframework/zend-barcode": "If you want to use barcodes",
Expand All @@ -29,4 +29,4 @@
"autoload": {
"psr-0": { "PHPPdf": "lib/", "Imagine": "lib/" }
}
}
}
10 changes: 6 additions & 4 deletions lib/PHPPdf/Core/Engine/Imagine/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

use Imagine\Image\ImagineInterface;
use PHPPdf\Core\Engine\AbstractFont;
use Imagine\Image\Color as ImagineColor;
use Imagine\Image\Palette\Color\RGB as Color;
use Imagine\Image\Palette\RGB as ColorPalette;

/**
* @author Piotr Śliwa <peter.pl7@gmail.com>
Expand Down Expand Up @@ -49,9 +50,10 @@ public function getWidthOfText($text, $fontSize)

private function createColor($color)
{
if(!$color instanceof ImagineColor)
if(!$color instanceof Color)
{
$color = new ImagineColor($color);
$palette = new ColorPalette();
$color = $palette->color($color);
}

return $color;
Expand All @@ -70,4 +72,4 @@ public function getCurrentResourceIdentifier()
{
return $this->fontResources[$this->currentStyle];
}
}
}
15 changes: 9 additions & 6 deletions lib/PHPPdf/Core/Engine/Imagine/GraphicsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
use Imagine\Image\ImageInterface;
use Imagine\Image\ImagineInterface;
use PHPPdf\Core\Engine\AbstractGraphicsContext;
use PHPPdf\Core\Engine\GraphicsContext as BaseGraphicsContext;
use PHPPdf\Core\Engine\Image as BaseImage;
use PHPPdf\Core\Engine\GraphicsContext as BaseGraphicsContext;
use PHPPdf\Core\Engine\Image as BaseImage;
use PHPPdf\Core\Engine\Font as BaseFont;
use Imagine\Image\Color as ImagineColor;

use Imagine\Image\Palette\RGB as ImagineColorPalette;

use Imagine\Image\FontInterface as ImagineFont;
use Zend\Barcode\Object\ObjectInterface as Barcode;
use Zend\Barcode\Object\ObjectInterface as Barcode;

/**
* Graphics context for Imagine
Expand Down Expand Up @@ -279,7 +281,8 @@ private function createColor($color)
{
$alpha = (int) (100 - $this->state['alpha'] * 100);

return new ImagineColor($color, $alpha);
$palette = new ImagineColorPalette();
return $palette->color($color); //, $alpha
}

protected function doSetFillColor($colorData)
Expand Down Expand Up @@ -605,4 +608,4 @@ protected function doDrawArc($x, $y, $width, $height, $start, $end, $fillType)
$image->draw()->pieSlice($point, $box, $start, $end, $color, false);
}
}
}
}
34 changes: 22 additions & 12 deletions tests/PHPPdf/Test/Core/Engine/Imagine/GraphicsContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace PHPPdf\Test\Core\Engine\Imagine;

use PHPPdf\Core\Engine\Imagine\Font;
use PHPPdf\Core\Engine\Imagine\Font;

use PHPPdf\Core\Engine\EmptyImage;
use PHPPdf\Core\Engine\EmptyImage;

use PHPPdf\Core\Engine\Imagine\Image;
use Imagine\Image\Palette\RGB as ColorPalette;
use PHPPdf\Bridge\Imagine\Image\Point;
use Imagine\Image\Box;
use PHPPdf\Core\Engine\Imagine\GraphicsContext;
use PHPPdf\PHPUnit\Framework\TestCase;

use PHPPdf\Core\Engine\Imagine\Image;
use Imagine\Image\Color;
use PHPPdf\Bridge\Imagine\Image\Point;
use Imagine\Image\Box;
use PHPPdf\Core\Engine\Imagine\GraphicsContext;
use PHPPdf\PHPUnit\Framework\TestCase;

class GraphicsContextTest extends TestCase
{
Expand All @@ -28,6 +29,15 @@ public function setUp()
$this->gc = new GraphicsContext($this->imagine, $this->image);
}

/**
* Create Imagine Color Interface
*/
private function createColor($color)
{
$palette = new ColorPalette();
return $palette->color($color);
}

/**
* @test
*/
Expand Down Expand Up @@ -139,7 +149,7 @@ public function drawLine()

$this->drawer->expects($this->once())
->method('line')
->with(new Point($x1, $height - $y1), new Point($x2, $height - $y2), new Color($color))
->with(new Point($x1, $height - $y1), new Point($x2, $height - $y2), $this->createColor($color))
->will($this->returnValue($this->drawer));

$this->gc->drawLine($x1, $y1, $x2, $y2);
Expand Down Expand Up @@ -241,7 +251,7 @@ public function drawPolygon(array $x, array $y, $fillType)
list($expectedColor, $expectedFill) = $polygon;
$this->drawer->expects($this->at($at))
->method('polygon')
->with($expectedCoords, new Color($expectedColor), $expectedFill)
->with($expectedCoords, $this->createColor($expectedColor), $expectedFill)
->will($this->returnValue($this->drawer));
}

Expand Down Expand Up @@ -300,7 +310,7 @@ public function drawText($alpha, $expectedImagineAlpha)

$font->expects($this->once())
->method('getWrappedFont')
->with(new Color($color, $expectedImagineAlpha), $fontSize)
->with($this->createColor($color, $expectedImagineAlpha), $fontSize)
->will($this->returnValue($imagineFont));

$this->image->expects($this->once())
Expand Down Expand Up @@ -433,4 +443,4 @@ public function ignoreEmptyImage()
$this->gc->drawImage($image, 50, 50, 100, 10);
$this->gc->commit();
}
}
}