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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Carlo Machado committed May 17, 2014
161 parents fff768a + 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 + 4b7efd6 + 8afd3ba + a8d8f8c + 71da426 + 779db49 + d043430 commit 394fee8
Show file tree
Hide file tree
Showing 45 changed files with 346 additions and 110 deletions.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@
}
},
"require": {
"php": ">=5.3.3",
"php": ">=5.3.23",
"zendframework/zend-stdlib": "self.version",
"zendframework/zend-validator": "self.version"
},
"require-dev": {
"zendframework/zend-servicemanager": "self.version",
"zendframework/zendpdf": "*",
"zendframework/zend-validator": "self.version",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
},
"suggest": {
"zendframework/zend-servicemanager": "Zend\\ServiceManager component, required when using the factory methods of Zend\\Barcode.",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component",
"zendframework/zendpdf": "ZendPdf component",
"zendframework/zend-validator": "Zend\\Validator component"
},
"extra": {
"branch-alias": {
"dev-master": "2.2-dev",
"dev-develop": "2.3-dev"
"dev-master": "2.3-dev",
"dev-develop": "2.4-dev"
}
},
"autoload-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static function makeBarcode($barcode, $barcodeConfig = array())
}

/*
* Verify that an barcode name has been specified.
* Verify that a barcode name has been specified.
*/
if (!is_string($barcode) || empty($barcode)) {
throw new Exception\InvalidArgumentException(
Expand Down Expand Up @@ -234,7 +234,7 @@ public static function makeRenderer($renderer = 'image', $rendererConfig = array
}

/*
* Verify that an barcode name has been specified.
* Verify that a barcode name has been specified.
*/
if (!is_string($renderer) || empty($renderer)) {
throw new Exception\RendererCreationException(
Expand Down
5 changes: 3 additions & 2 deletions src/Object/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ protected function addPolygon(array $points, $color = null, $filled = true)
* Add a text drawing instruction in the set of instructions
* @param string $text
* @param float $size
* @param array $position
* @param int[] $position
* @param string $font
* @param int $color
* @param string $alignment
Expand Down Expand Up @@ -844,6 +844,7 @@ public function checkParams()

/**
* Check if a text is really provided to barcode
* @param string|null $value
* @return void
* @throws \Zend\Barcode\Object\Exception\ExceptionInterface
*/
Expand Down Expand Up @@ -1026,7 +1027,7 @@ public function getOffsetTop($recalculate = false)
* Apply rotation on a point in X/Y dimensions
* @param float $x1 x-position before rotation
* @param float $y1 y-position before rotation
* @return array Array of two elements corresponding to the new XY point
* @return int[] Array of two elements corresponding to the new XY point
*/
protected function rotate($x1, $y1)
{
Expand Down
1 change: 1 addition & 0 deletions src/Object/Codabar.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected function checkSpecificParams()
protected function prepareBarcode()
{
$text = str_split($this->getText());
$barcodeTable = array();
foreach ($text as $char) {
$barcodeChar = str_split($this->codingMap[$char]);
foreach ($barcodeChar as $c) {
Expand Down
6 changes: 3 additions & 3 deletions src/Object/Code128.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ protected function convertToBarcodeChars($string)
$currentCharset = null;
$result = array();

for ($pos = 0; $pos < strlen($string); $pos++) {
$strlen = strlen($string);
for ($pos = 0; $pos < $strlen; $pos++) {
$char = $string[$pos];
$code = null;

if (static::_isDigit($string, $pos, 4) && $currentCharset != 'C'
|| static::_isDigit($string, $pos, 2) && $currentCharset == 'C') {
Expand Down Expand Up @@ -247,7 +247,7 @@ protected function convertToBarcodeChars($string)
if ($pos == 0) {
$code = array_search("START A", $this->charSets['A']);
} else {
$code =array_search("Code A", $this->charSets[$currentCharset]);
$code = array_search("Code A", $this->charSets[$currentCharset]);
}
$result[] = $code;
$currentCharset = 'A';
Expand Down
2 changes: 2 additions & 0 deletions src/Object/Code25interleaved.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ protected function prepareBarcode()
$this->withBorder = false;
}

$barcodeTable = array();

// Start character (0000)
$barcodeTable[] = array(1, $this->barThinWidth, 0, 1);
$barcodeTable[] = array(0, $this->barThinWidth, 0, 1);
Expand Down
4 changes: 4 additions & 0 deletions src/Object/Ean5.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public function getChecksum($text)
return ($checksum % 10);
}

/**
* @param int $i
* @return string
*/
protected function getParity($i)
{
$checksum = $this->getChecksum($this->getText());
Expand Down
2 changes: 1 addition & 1 deletion src/Object/Identcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getTextToDisplay()
* Check allowed characters
* @param string $value
* @return string
* @throws Exception
* @throws Exception\BarcodeValidationException
*/
public function validateText($value)
{
Expand Down
28 changes: 28 additions & 0 deletions src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ abstract class AbstractRenderer implements RendererInterface
*/
protected $resource;

/**
* Show a transparent background
* @var Boolean
*/
protected $transparentBackground = false;

/**
* Constructor
* @param array|Traversable $options
Expand Down Expand Up @@ -135,6 +141,28 @@ public function getRendererNamespace()
return $this->rendererNamespace;
}

/**
* Set whether background should be transparent
* Will work for SVG and Image (png and gif only)
*
* @param $bool
* @return $this
*/
public function setTransparentBackground($bool)
{
$this->transparentBackground = $bool;

return $this;
}

/**
* @return bool
*/
public function getTransparentBackground()
{
return $this->transparentBackground;
}

/**
* Retrieve renderer type
* @return string
Expand Down
113 changes: 55 additions & 58 deletions src/Renderer/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Image extends AbstractRenderer
* @var array
*/
protected $allowedImageType = array('png',
'jpeg',
'gif' );
'jpeg',
'gif' );

/**
* Image format
Expand Down Expand Up @@ -194,22 +194,7 @@ protected function initRenderer()
$barcodeWidth = $this->barcode->getWidth(true);
$barcodeHeight = $this->barcode->getHeight(true);

if ($this->resource !== null) {
$foreColor = $this->barcode->getForeColor();
$backgroundColor = $this->barcode->getBackgroundColor();
$this->imageBackgroundColor = imagecolorallocate(
$this->resource,
($backgroundColor & 0xFF0000) >> 16,
($backgroundColor & 0x00FF00) >> 8,
$backgroundColor & 0x0000FF
);
$this->imageForeColor = imagecolorallocate(
$this->resource,
($foreColor & 0xFF0000) >> 16,
($foreColor & 0x00FF00) >> 8,
$foreColor & 0x0000FF
);
} else {
if (null === $this->resource) {
$width = $barcodeWidth;
$height = $barcodeHeight;
if ($this->userWidth && $this->barcode->getType() != 'error') {
Expand All @@ -219,32 +204,44 @@ protected function initRenderer()
$height = $this->userHeight;
}

$foreColor = $this->barcode->getForeColor();
$backgroundColor = $this->barcode->getBackgroundColor();
$this->resource = imagecreatetruecolor($width, $height);

$this->imageBackgroundColor = imagecolorallocate(
$this->resource,
($backgroundColor & 0xFF0000) >> 16,
($backgroundColor & 0x00FF00) >> 8,
$backgroundColor & 0x0000FF
);
$this->imageForeColor = imagecolorallocate(
$this->resource,
($foreColor & 0xFF0000) >> 16,
($foreColor & 0x00FF00) >> 8,
$foreColor & 0x0000FF
);
$white = imagecolorallocate($this->resource, 255, 255, 255);
imagefilledrectangle($this->resource, 0, 0, $width - 1, $height - 1, $white);
}

$foreColor = $this->barcode->getForeColor();
$this->imageForeColor = imagecolorallocate(
$this->resource,
($foreColor & 0xFF0000) >> 16,
($foreColor & 0x00FF00) >> 8,
$foreColor & 0x0000FF
);

$backgroundColor = $this->barcode->getBackgroundColor();
$this->imageBackgroundColor = imagecolorallocate(
$this->resource,
($backgroundColor & 0xFF0000) >> 16,
($backgroundColor & 0x00FF00) >> 8,
$backgroundColor & 0x0000FF
);

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

$this->adjustPosition(imagesy($this->resource), imagesx($this->resource));
imagefilledrectangle($this->resource,
$this->leftOffset,
$this->topOffset,
$this->leftOffset + $barcodeWidth - 1,
$this->topOffset + $barcodeHeight - 1,
$this->imageBackgroundColor);

imagefilledrectangle(
$this->resource,
$this->leftOffset,
$this->topOffset,
$this->leftOffset + $barcodeWidth - 1,
$this->topOffset + $barcodeHeight - 1,
$this->imageBackgroundColor
);
}

/**
Expand Down Expand Up @@ -330,18 +327,18 @@ public function render()
protected function drawPolygon($points, $color, $filled = true)
{
$newPoints = array($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[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, );

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

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

if ($font == null) {
$font = 3;
Expand Down Expand Up @@ -422,13 +419,13 @@ protected function drawText($text, $size, $position, $font, $color, $alignment =
break;
}
imagettftext($this->resource,
$size,
$orientation,
$position[0] - ($width * cos(pi() * $orientation / 180)),
$position[1] + ($width * sin(pi() * $orientation / 180)),
$allocatedColor,
$font,
$text);
$size,
$orientation,
$position[0] - ($width * cos(pi() * $orientation / 180)),
$position[1] + ($width * sin(pi() * $orientation / 180)),
$allocatedColor,
$font,
$text);
}
}
}
2 changes: 2 additions & 0 deletions src/Renderer/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ protected function initRenderer()
protected function drawPolygon($points, $color, $filled = true)
{
$page = $this->resource->pages[$this->page];
$x = array();
$y = array();
foreach ($points as $point) {
$x[] = $point[0] * $this->moduleSize + $this->leftOffset;
$y[] = $page->getHeight() - $point[1] * $this->moduleSize - $this->topOffset;
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function getLeftOffset();
/**
* Activate/Deactivate the automatic rendering of exception
* @param bool $value
* @return self
*/
public function setAutomaticRenderError($value);

Expand Down
Loading

0 comments on commit 394fee8

Please sign in to comment.