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

Commit

Permalink
Merge branch 'cs/zendframework/zendframework#6500-zend-barcode-psr2-c…
Browse files Browse the repository at this point in the history
…ompliance' into develop

Forward port zendframework/zendframework#6500
  • Loading branch information
Ocramius committed Aug 6, 2014
167 parents 0bfcebc + ec89c2d + 5e5d76b + 4b7efd6 + 8afd3ba + 2d33c4d + 4aebbda + a47e3ed + ddb35c9 + 8a05e9b + a92be28 + 5d9546f + 644a1db + 1008053 + c0d0bfc + ab83210 + 88be4ef + e672b58 + c5c6433 + a6b0c4e + 28d72f0 + 48c143c + acee230 + 9a49788 + efd47ef + 8dad02c + 9be7abf + bf9e60b + a03898c + 025fb19 + 6551ff4 + e5066db + 30065eb + cd23bdb + f518ed9 + 54153cf + e4984e8 + cc9c920 + b3042ce + e57fd9d + d07707d + 60d87e0 + dea915e + 4f2f391 + e61f957 + a301eb4 + 86ee99c + 4f18442 + 0560233 + 803be33 + b3b44b2 + 747588e + ff0efd2 + 5651d65 + a3fbf6b + 2a0a9d7 + e987caa + f6cf6f8 + a97175a + 18ecd64 + f00b78e + 18be569 + af6e96a + a62b890 + 369a5ce + 2f4d803 + 045137d + 2fdcee4 + 147c99e + d95685a + 9fceeb6 + 4682ed8 + 58e6c7d + f9a818b + b470c79 + ce259b2 + 47e8c8b + 62bd37a + f6216bb + 01cd418 + 1d5008a + f7d1866 + 339c91f + 105863b + d697919 + a07d04f + ab69e95 + a01fec1 + 79aa858 + e6c1f7b + caa3725 + 42e5478 + 2d5d2cd + 80ddcc5 + e2d6bae + 4d230a7 + eb81fcd + d11d08b + 260e6bd + 7ad155b + 5fc070f + c78a364 + 4941bab + c4245dd + b4f05cd + a274d7e + 9ddc5d3 + b327453 + 4fb6bdc + 589d10e + 1190c26 + 7a8c4e6 + 34dd90e + 181ab3e + 67215df + 3722470 + 760ae55 + 71ba5e4 + 0e69738 + 5fee79a + edb69b7 + affa8ee + b842366 + 8bcb41c + 2d61aeb + 3e577bd + 2912cc2 + 480b09d + 9ef4bbd + a9fbb32 + a3442c5 + 3ba9ec5 + 249bcf9 + 17f4e58 + f5df8ff + 09c6fb7 + 244cca2 + e70f1f7 + c0ba5d9 + af32048 + e486343 + 2925378 + 7987d36 + f33a6b9 + ccec312 + c6e5159 + 5686261 + 032f44f + c050df1 + c5316e9 + e3aa8e4 + c5faeb8 + 8cb76ea + d3e8682 + ebc5f97 + fee3d00 + 89b4efe + aabf76f + d2e2f88 + fff768a + a8d8f8c + 71da426 + 779db49 + d043430 + 640b9df + 2be966a + c29959d commit 8f664d5
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 98 deletions.
35 changes: 19 additions & 16 deletions src/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ public static function getRendererPluginManager()
* @return Barcode
* @throws Exception\ExceptionInterface
*/
public static function factory($barcode,
$renderer = 'image',
$barcodeConfig = array(),
$rendererConfig = array(),
$automaticRenderError = true)
{
public static function factory(
$barcode,
$renderer = 'image',
$barcodeConfig = array(),
$rendererConfig = array(),
$automaticRenderError = true
) {
/*
* Convert Traversable argument to plain string
* barcode name and separate config object.
Expand Down Expand Up @@ -253,11 +254,12 @@ public static function makeRenderer($renderer = 'image', $rendererConfig = array
* @param array | Traversable $barcodeConfig
* @param array | Traversable $rendererConfig
*/
public static function render($barcode,
$renderer,
$barcodeConfig = array(),
$rendererConfig = array())
{
public static function render(
$barcode,
$renderer,
$barcodeConfig = array(),
$rendererConfig = array()
) {
static::factory($barcode, $renderer, $barcodeConfig, $rendererConfig)->render();
}

Expand All @@ -270,11 +272,12 @@ public static function render($barcode,
* @param array | Traversable $rendererConfig
* @return mixed
*/
public static function draw($barcode,
$renderer,
$barcodeConfig = array(),
$rendererConfig = array())
{
public static function draw(
$barcode,
$renderer,
$barcodeConfig = array(),
$rendererConfig = array()
) {
return static::factory($barcode, $renderer, $barcodeConfig, $rendererConfig)->draw();
}

Expand Down
4 changes: 1 addition & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
/**
* Exception for Zend\Barcode component.
*/
class InvalidArgumentException
extends \InvalidArgumentException
implements ExceptionInterface
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
4 changes: 1 addition & 3 deletions src/Exception/RendererCreationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
/**
* Exception for Zend\Barcode component.
*/
class RendererCreationException
extends \InvalidArgumentException
implements ExceptionInterface
class RendererCreationException extends \InvalidArgumentException implements ExceptionInterface
{
}
3 changes: 1 addition & 2 deletions src/Exception/UnexpectedValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/**
* Exception for Zend\Barcode component.
*/
class UnexpectedValueException extends \UnexpectedValueException implements
ExceptionInterface
class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface
{
}
50 changes: 18 additions & 32 deletions src/Object/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,20 +978,14 @@ public function getWidth($recalculate = false)
public function getOffsetLeft($recalculate = false)
{
if ($this->offsetLeft === null || $recalculate) {
$this->offsetLeft = - min(array(
0 * cos(
$this->orientation / 180 * pi()) - 0 * sin(
$this->orientation / 180 * pi()),
0 * cos(
$this->orientation / 180 * pi()) - $this->calculateBarcodeHeight() * sin(
$this->orientation / 180 * pi()),
$this->calculateBarcodeWidth() * cos(
$this->orientation / 180 * pi()) - $this->calculateBarcodeHeight() * sin(
$this->orientation / 180 * pi()),
$this->calculateBarcodeWidth() * cos(
$this->orientation / 180 * pi()) - 0 * sin(
$this->orientation / 180 * pi()),
));
$this->offsetLeft = - min(
array(
0 * cos($this->orientation / 180 * pi()) - 0 * sin($this->orientation / 180 * pi()),
0 * cos($this->orientation / 180 * pi()) - $this->calculateBarcodeHeight() * sin($this->orientation / 180 * pi()),
$this->calculateBarcodeWidth() * cos($this->orientation / 180 * pi()) - $this->calculateBarcodeHeight() * sin($this->orientation / 180 * pi()),
$this->calculateBarcodeWidth() * cos($this->orientation / 180 * pi()) - 0 * sin($this->orientation / 180 * pi()),
)
);
}
return $this->offsetLeft;
}
Expand All @@ -1005,20 +999,14 @@ public function getOffsetLeft($recalculate = false)
public function getOffsetTop($recalculate = false)
{
if ($this->offsetTop === null || $recalculate) {
$this->offsetTop = - min(array(
0 * cos(
$this->orientation / 180 * pi()) + 0 * sin(
$this->orientation / 180 * pi()),
$this->calculateBarcodeHeight() * cos(
$this->orientation / 180 * pi()) + 0 * sin(
$this->orientation / 180 * pi()),
$this->calculateBarcodeHeight() * cos(
$this->orientation / 180 * pi()) + $this->calculateBarcodeWidth() * sin(
$this->orientation / 180 * pi()),
0 * cos(
$this->orientation / 180 * pi()) + $this->calculateBarcodeWidth() * sin(
$this->orientation / 180 * pi()),
));
$this->offsetTop = - min(
array(
0 * cos($this->orientation / 180 * pi()) + 0 * sin($this->orientation / 180 * pi()),
$this->calculateBarcodeHeight() * cos($this->orientation / 180 * pi()) + 0 * sin($this->orientation / 180 * pi()),
$this->calculateBarcodeHeight() * cos($this->orientation / 180 * pi()) + $this->calculateBarcodeWidth() * sin($this->orientation / 180 * pi()),
0 * cos($this->orientation / 180 * pi()) + $this->calculateBarcodeWidth() * sin($this->orientation / 180 * pi()),
)
);
}
return $this->offsetTop;
}
Expand Down Expand Up @@ -1152,8 +1140,7 @@ protected function drawText()
$this->fontSize * $this->factor,
$this->rotate(
$leftPosition,
(int) $this->withBorder * 2
+ $this->factor * ($this->barHeight + $this->fontSize) + 1
(int) $this->withBorder * 2 + $this->factor * ($this->barHeight + $this->fontSize) + 1
),
$this->font,
$this->foreColor,
Expand All @@ -1167,8 +1154,7 @@ protected function drawText()
$this->fontSize * $this->factor,
$this->rotate(
$this->calculateWidth() / 2,
(int) $this->withBorder * 2
+ $this->factor * ($this->barHeight + $this->fontSize) + 1
(int) $this->withBorder * 2 + $this->factor * ($this->barHeight + $this->fontSize) + 1
),
$this->font,
$this->foreColor,
Expand Down
3 changes: 2 additions & 1 deletion src/Object/Codabar.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected function calculateBarcodeWidth()
* @return void
*/
protected function checkSpecificParams()
{}
{
}

/**
* Prepare array to draw barcode
Expand Down
8 changes: 4 additions & 4 deletions src/Object/Code128.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ protected function prepareBarcode()
protected static function _isDigit($string, $pos, $length = 2)
{
if ($pos + $length > strlen($string)) {
return false;
return false;
}

for ($i = $pos; $i < $pos + $length; $i++) {
if (!is_numeric($string[$i])) {
return false;
}
if (!is_numeric($string[$i])) {
return false;
}
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Object/Ean13.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ protected function calculateBarcodeWidth()
* @return void
*/
protected function checkSpecificParams()
{}
{
}

/**
* Prepare array to draw barcode
Expand Down Expand Up @@ -174,8 +175,7 @@ protected function drawEan13Text()
$this->fontSize * $this->factor,
$this->rotate(
$leftPosition,
(int) $this->withBorder * 2
+ $this->factor * ($this->barHeight + $this->fontSize) + 1
(int) $this->withBorder * 2 + $this->factor * ($this->barHeight + $this->fontSize) + 1
),
$this->font,
$this->foreColor,
Expand Down
3 changes: 1 addition & 2 deletions src/Object/Ean8.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ protected function drawText()
$this->fontSize * $this->factor,
$this->rotate(
$leftPosition,
(int) $this->withBorder * 2
+ $this->factor * ($this->barHeight + $this->fontSize) + 1
(int) $this->withBorder * 2 + $this->factor * ($this->barHeight + $this->fontSize) + 1
),
$this->font,
$this->foreColor,
Expand Down
4 changes: 1 addition & 3 deletions src/Object/Identcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ protected function getDefaultOptions()
*/
public function getTextToDisplay()
{
return preg_replace('/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})([0-9])/',
'$1.$2 $3.$4 $5',
$this->getText());
return preg_replace('/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})([0-9])/', '$1.$2 $3.$4 $5', $this->getText());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Object/Leitcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ protected function getDefaultOptions()
*/
public function getTextToDisplay()
{
return preg_replace('/([0-9]{5})([0-9]{3})([0-9]{3})([0-9]{2})([0-9])/',
'$1.$2.$3.$4 $5',
$this->getText());
return preg_replace('/([0-9]{5})([0-9]{3})([0-9]{3})([0-9]{2})([0-9])/', '$1.$2.$3.$4 $5', $this->getText());
}
}
3 changes: 2 additions & 1 deletion src/Object/Postnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected function calculateBarcodeWidth()
* @return void
*/
protected function checkSpecificParams()
{}
{
}

/**
* Prepare array to draw barcode
Expand Down
3 changes: 2 additions & 1 deletion src/Object/Royalmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ protected function calculateBarcodeWidth()
* @return void
*/
protected function checkSpecificParams()
{}
{
}

/**
* Prepare array to draw barcode
Expand Down
3 changes: 1 addition & 2 deletions src/Object/Upca.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ protected function drawText()
$fontSize * $this->factor,
$this->rotate(
$leftPosition,
(int) $this->withBorder * 2
+ $this->factor * ($this->barHeight + $fontSize) + 1
(int) $this->withBorder * 2 + $this->factor * ($this->barHeight + $fontSize) + 1
),
$this->font,
$this->foreColor,
Expand Down
3 changes: 1 addition & 2 deletions src/Object/Upce.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ protected function drawText()
$fontSize * $this->factor,
$this->rotate(
$leftPosition,
(int) $this->withBorder * 2
+ $this->factor * ($this->barHeight + $fontSize) + 1
(int) $this->withBorder * 2 + $this->factor * ($this->barHeight + $fontSize) + 1
),
$this->font,
$this->foreColor,
Expand Down
7 changes: 2 additions & 5 deletions src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ public function setModuleSize($value)
return $this;
}


/**
* Set the size of a module
* @return float
Expand Down Expand Up @@ -382,8 +381,7 @@ protected function adjustPosition($supportHeight, $supportWidth)
if ($barcodeHeight != $supportHeight && $this->topOffset == 0) {
switch ($this->verticalPosition) {
case 'middle':
$this->topOffset = floor(
($supportHeight - $barcodeHeight) / 2);
$this->topOffset = floor(($supportHeight - $barcodeHeight) / 2);
break;
case 'bottom':
$this->topOffset = $supportHeight - $barcodeHeight;
Expand All @@ -398,8 +396,7 @@ protected function adjustPosition($supportHeight, $supportWidth)
if ($barcodeWidth != $supportWidth && $this->leftOffset == 0) {
switch ($this->horizontalPosition) {
case 'center':
$this->leftOffset = floor(
($supportWidth - $barcodeWidth) / 2);
$this->leftOffset = floor(($supportWidth - $barcodeWidth) / 2);
break;
case 'right':
$this->leftOffset = $supportWidth - $barcodeWidth;
Expand Down
23 changes: 15 additions & 8 deletions src/Renderer/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function initRenderer()

// JPEG does not support transparency, if transparentBackground is true and
// image type is JPEG, ignore transparency
if($this->getImageType() != "jpeg" && $this->transparentBackground) {
if ($this->getImageType() != "jpeg" && $this->transparentBackground) {
imagecolortransparent($this->resource, $this->imageBackgroundColor);
}

Expand Down Expand Up @@ -335,10 +335,12 @@ protected function drawPolygon($points, $color, $filled = true)
$points[3][0] + $this->leftOffset,
$points[3][1] + $this->topOffset, );

$allocatedColor = imagecolorallocate($this->resource,
$allocatedColor = imagecolorallocate(
$this->resource,
($color & 0xFF0000) >> 16,
($color & 0x00FF00) >> 8,
$color & 0x0000FF );
$color & 0x0000FF
);

if ($filled) {
imagefilledpolygon($this->resource, $newPoints, 4, $allocatedColor);
Expand All @@ -361,10 +363,12 @@ protected function drawPolygon($points, $color, $filled = true)
*/
protected function drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
{
$allocatedColor = imagecolorallocate($this->resource,
$allocatedColor = imagecolorallocate(
$this->resource,
($color & 0xFF0000) >> 16,
($color & 0x00FF00) >> 8,
$color & 0x0000FF );
$color & 0x0000FF
);

if ($font == null) {
$font = 3;
Expand Down Expand Up @@ -403,7 +407,8 @@ protected function drawText($text, $size, $position, $font, $color, $alignment =

if (!function_exists('imagettfbbox')) {
throw new Exception\RuntimeException(
'A font was provided, but this instance of PHP does not have TTF (FreeType) support');
'A font was provided, but this instance of PHP does not have TTF (FreeType) support'
);
}

$box = imagettfbbox($size, 0, $font, $text);
Expand All @@ -418,14 +423,16 @@ protected function drawText($text, $size, $position, $font, $color, $alignment =
$width = ($box[2] - $box[0]);
break;
}
imagettftext($this->resource,
imagettftext(
$this->resource,
$size,
$orientation,
$position[0] - ($width * cos(pi() * $orientation / 180)),
$position[1] + ($width * sin(pi() * $orientation / 180)),
$allocatedColor,
$font,
$text);
$text
);
}
}
}
Loading

0 comments on commit 8f664d5

Please # to comment.