Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/45'
Browse files Browse the repository at this point in the history
Close #45
Fix #27
  • Loading branch information
michalbundyra committed Sep 21, 2019
2 parents 70320ed + 5363fb2 commit 8f245d1
Show file tree
Hide file tree
Showing 9 changed files with 1,527 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ All notable changes to this project will be documented in this file, in reverse
curly braces in array and string offset access to square brackets
in order to prevent issues under the upcoming PHP 7.4 release.

- [#45](https://github.com/zendframework/zend-barcode/pull/45) fixes
rotation calculations.

- [#46](https://github.com/zendframework/zend-barcode/pull/46) fixes
generating checksum for EAN5 and Identcode/Leitcode. These barcodes
have fixed length and checksum generator must use also leading zeros.
Expand Down
8 changes: 4 additions & 4 deletions src/Object/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,11 +1103,11 @@ public function getOffsetTop($recalculate = false)
*/
protected function rotate($x1, $y1)
{
$x2 = $x1 * cos($this->orientation / 180 * pi())
- $y1 * sin($this->orientation / 180 * pi())
$x2 = $x1 * round(cos($this->orientation / 180 * pi()), 6)
- $y1 * round(sin($this->orientation / 180 * pi()), 6)
+ $this->getOffsetLeft();
$y2 = $y1 * cos($this->orientation / 180 * pi())
+ $x1 * sin($this->orientation / 180 * pi())
$y2 = $y1 * round(cos($this->orientation / 180 * pi()), 6)
+ $x1 * round(sin($this->orientation / 180 * pi()), 6)
+ $this->getOffsetTop();
return [intval($x2), intval($y2)];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract class AbstractRenderer implements RendererInterface

/**
* Barcode object
* @var Object\ObjectInterface
* @var ObjectInterface
*/
protected $barcode;

Expand Down
6 changes: 4 additions & 2 deletions src/Renderer/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,16 @@ public function render()
*/
protected function drawPolygon($points, $color, $filled = true)
{
$newPoints = [$points[0][0] + $this->leftOffset,
$newPoints = [
$points[0][0] + $this->leftOffset,
$points[0][1] + $this->topOffset,
$points[1][0] + $this->leftOffset,
$points[1][1] + $this->topOffset,
$points[2][0] + $this->leftOffset,
$points[2][1] + $this->topOffset,
$points[3][0] + $this->leftOffset,
$points[3][1] + $this->topOffset, ];
$points[3][1] + $this->topOffset,
];

$allocatedColor = imagecolorallocate(
$this->resource,
Expand Down
8 changes: 4 additions & 4 deletions src/Renderer/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ protected function drawPolygon($points, $color, $filled = true)
$points[0][1] + $this->topOffset,
$points[1][0] + $this->leftOffset,
$points[1][1] + $this->topOffset,
$points[2][0] + $this->leftOffset + cos(-$orientation),
$points[2][1] + $this->topOffset - sin($orientation),
$points[3][0] + $this->leftOffset + cos(-$orientation),
$points[3][1] + $this->topOffset - sin($orientation),
$points[2][0] + $this->leftOffset + cos(-$orientation / 180 * pi()),
$points[2][1] + $this->topOffset + sin($orientation / 180 * pi()),
$points[3][0] + $this->leftOffset + cos(-$orientation / 180 * pi()),
$points[3][1] + $this->topOffset + sin($orientation / 180 * pi()),
];
$newPoints = implode(' ', $newPoints);
$attributes = [];
Expand Down
12 changes: 12 additions & 0 deletions test/Object/Code39Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,16 @@ public function testCompleteGenerationWithBorderWithOrientation()
);
$this->assertEquals($instructions, $this->object->getInstructions());
}

public function testCompleteGenerationWithOrientation270()
{
$this->object->setText('0123456789');
$this->object->setOrientation(270);
$this->object->draw();
$instructions = $this->loadInstructionsFile(
'Code39_0123456789_oriented_270_instructions'
);

$this->assertEquals($instructions, $this->object->getInstructions());
}
}
Loading

0 comments on commit 8f245d1

Please sign in to comment.