Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Stable work to date #8

Merged
merged 30 commits into from

2 participants

@CloCkWeRX
Owner

Closes a number of issues, introduces adapter, introduces exceptions, & general tidyup

Gemorroj and others added some commits
@Gemorroj Gemorroj Fix documentation. Image_Barcode2::draw - static method. Deleted inco…
…rrect constructor from Code39.php
234d928
@Gemorroj Gemorroj code review 1c2cc9a
@Gemorroj Gemorroj code review b7c7ef2
@Gemorroj Gemorroj Merge branch 'master' of https://github.com/pear/Image_Barcode2
Conflicts:
	docs/examples/barcode_img.php
4f49d59
@CloCkWeRX CloCkWeRX Do readme file changes from 234d928 be135fb
@Gemorroj Gemorroj Merge branch 'master' of https://github.com/pear/Image_Barcode2
Conflicts:
	Image/Barcode2.php
	Image/Barcode2/Code39.php
	Image/Barcode2/code128.php
	Image/Barcode2/ean13.php
	Image/Barcode2/upca.php
8e71cee
@CloCkWeRX CloCkWeRX Merge branch 'master' of https://github.com/Gemorroj/Image_Barcode2
Conflicts:
	README
324b699
@CloCkWeRX CloCkWeRX Add quick-n-dirty adapter d038332
@CloCkWeRX CloCkWeRX Regenerate package fa8d2ec
@CloCkWeRX CloCkWeRX All drivers accept a writer for issue #2 0522043
@CloCkWeRX CloCkWeRX Add more methods to adapter for issue #3 3818e18
@CloCkWeRX CloCkWeRX #3 Have ean8 driver use writer 5f2dbf8
@CloCkWeRX CloCkWeRX #3 Have ean13 driver use writer f52f231
@CloCkWeRX CloCkWeRX #3 Add more methods bd5f366
@CloCkWeRX CloCkWeRX #3 Add TODO 9119fe0
@CloCkWeRX CloCkWeRX #3 Have other drivers use writer 4e25dcc
@CloCkWeRX CloCkWeRX #3 Have final driver use writer 12c507d
@CloCkWeRX CloCkWeRX Add interface for issue #5 04701dd
@CloCkWeRX CloCkWeRX Issue #5 - Make all drivers implement the interface 5665463
@CloCkWeRX CloCkWeRX Issue #5 - Refactor class to know about drivers 7958cf3
@CloCkWeRX CloCkWeRX Issue #4 Refactor slightly to a Common parent e650038
@CloCkWeRX CloCkWeRX Issue #4 Where valid, use accessors 3c6238d
@CloCkWeRX CloCkWeRX Issue #4 Where valid, use accessors a2901c0
@CloCkWeRX CloCkWeRX #4 - Actually commit common class 58bfa75
@CloCkWeRX CloCkWeRX #4 - Actually commit common class dd468b4
@CloCkWeRX CloCkWeRX #4 - Mark different kinds of classes with different interfaces even i…
…f most are capable of both via _Common
ca20686
@CloCkWeRX CloCkWeRX #4 - Mark different kinds of classes with different interfaces even i…
…f most are capable of both via _Common
61a36d4
@CloCkWeRX CloCkWeRX #6 Remove PEAR infavour of spl exceptions 35f8c35
@CloCkWeRX CloCkWeRX Merge branch 'master' of github.com:pear/Image_Barcode2
Conflicts:
	Image/Barcode2/Code39.php
	Image/Barcode2/Writer.php
	Image/Barcode2/code128.php
	Image/Barcode2/ean13.php
	Image/Barcode2/ean8.php
	Image/Barcode2/int25.php
	Image/Barcode2/postnet.php
	Image/Barcode2/upca.php
b19e50a
@CloCkWeRX CloCkWeRX Make CI suite less angry 0bd2d78
@CloCkWeRX CloCkWeRX merged commit ead0c4a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 11, 2011
  1. @Gemorroj

    Fix documentation. Image_Barcode2::draw - static method. Deleted inco…

    Gemorroj authored
    …rrect constructor from Code39.php
  2. @Gemorroj

    code review

    Gemorroj authored
  3. @Gemorroj

    code review

    Gemorroj authored
  4. @Gemorroj

    Merge branch 'master' of https://github.com/pear/Image_Barcode2

    Gemorroj authored
    Conflicts:
    	docs/examples/barcode_img.php
  5. @CloCkWeRX
  6. @Gemorroj

    Merge branch 'master' of https://github.com/pear/Image_Barcode2

    Gemorroj authored
    Conflicts:
    	Image/Barcode2.php
    	Image/Barcode2/Code39.php
    	Image/Barcode2/code128.php
    	Image/Barcode2/ean13.php
    	Image/Barcode2/upca.php
  7. @CloCkWeRX
  8. @CloCkWeRX

    Add quick-n-dirty adapter

    CloCkWeRX authored
  9. @CloCkWeRX

    Regenerate package

    CloCkWeRX authored
  10. @CloCkWeRX
  11. @CloCkWeRX
  12. @CloCkWeRX

    #3 Have ean8 driver use writer

    CloCkWeRX authored
  13. @CloCkWeRX

    #3 Have ean13 driver use writer

    CloCkWeRX authored
  14. @CloCkWeRX

    #3 Add more methods

    CloCkWeRX authored
  15. @CloCkWeRX

    #3 Add TODO

    CloCkWeRX authored
  16. @CloCkWeRX
  17. @CloCkWeRX

    #3 Have final driver use writer

    CloCkWeRX authored
  18. @CloCkWeRX

    Add interface for issue #5

    CloCkWeRX authored
  19. @CloCkWeRX
  20. @CloCkWeRX
  21. @CloCkWeRX
  22. @CloCkWeRX
  23. @CloCkWeRX
  24. @CloCkWeRX
  25. @CloCkWeRX
  26. @CloCkWeRX

    #4 - Mark different kinds of classes with different interfaces even i…

    CloCkWeRX authored
    …f most are capable of both via _Common
  27. @CloCkWeRX

    #4 - Mark different kinds of classes with different interfaces even i…

    CloCkWeRX authored
    …f most are capable of both via _Common
  28. @CloCkWeRX
  29. @CloCkWeRX

    Merge branch 'master' of github.com:pear/Image_Barcode2

    CloCkWeRX authored
    Conflicts:
    	Image/Barcode2/Code39.php
    	Image/Barcode2/Writer.php
    	Image/Barcode2/code128.php
    	Image/Barcode2/ean13.php
    	Image/Barcode2/ean8.php
    	Image/Barcode2/int25.php
    	Image/Barcode2/postnet.php
    	Image/Barcode2/upca.php
  30. @CloCkWeRX

    Make CI suite less angry

    CloCkWeRX authored
This page is out of date. Refresh to see the latest.
View
39 Image/Barcode2.php
@@ -23,7 +23,8 @@
* @link http://pear.php.net/package/Image_Barcode2
*/
-require_once 'PEAR.php';
+require_once 'Image/Barcode2/Writer.php';
+require_once 'Image/Barcode2/Driver.php';
/**
* Image_Barcode2 class
@@ -79,14 +80,14 @@ class Image_Barcode2
* @param integer $width The image width
*
* @return image The corresponding gd image object;
- * PEAR_Error on failure
- *
+ *
+ * @throws InvalidArgumentException
* @access public
*
* @author Marcelo Subtil Marcal <msmarcal@php.net>
* @since Image_Barcode2 0.3
*/
- public function draw($text,
+ public static function draw($text,
$type = Image_Barcode2::BARCODE_INT25,
$imgtype = Image_Barcode2::IMAGE_PNG,
$bSendToBrowser = true,
@@ -95,35 +96,35 @@ public function draw($text,
) {
//Make sure no bad files are included
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $type)) {
- return PEAR::raiseError('Invalid barcode type ' . $type);
+ throw new InvalidArgumentException('Invalid barcode type ' . $type);
}
+
if (!include_once 'Image/Barcode2/' . $type . '.php') {
- return PEAR::raiseError($type . ' barcode is not supported');
+ throw new InvalidArgumentException($type . ' barcode is not supported');
}
$classname = 'Image_Barcode2_' . $type;
- if (!in_array('draw', get_class_methods($classname))) {
- return PEAR::raiseError(
- "Unable to find draw method in '$classname' class"
+ $writer = new Image_Barcode2_Writer();
+
+ $obj = new $classname($writer);
+
+ if (!$obj instanceof Image_Barcode2_Driver) {
+ throw new InvalidArgumentException(
+ "'$classname' does not implement Image_Barcode2_Driver"
);
}
- $obj = new $classname();
-
- if (isset($obj->_barcodeheight)) {
- $obj->_barcodeheight = $height;
+ if (!$obj instanceof Image_Barcode2_DualWidth) {
+ $obj->setBarWidth($width);
}
- if (isset($obj->_barwidth)) {
- $obj->_barwidth = $width;
+ if (!$obj instanceof Image_Barcode2_DualHeight) {
+ $obj->setBarcodeHeight($height);
}
- $img = $obj->draw($text);
- if (@PEAR::isError($img)) {
- return $img;
- }
+ $img = $obj->draw($text);
if ($bSendToBrowser) {
// Send image to browser
View
94 Image/Barcode2/Code39.php
@@ -25,6 +25,8 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
+require_once 'Image/Barcode2/DualWidth.php';
/**
* Image_Barcode2_Code39 class
@@ -40,30 +42,9 @@
* @link http://pear.php.net/package/Image_Barcode2
* @since Image_Barcode2 0.5
*/
-class Image_Barcode2_Code39 implements Image_Barcode2_Driver
+class Image_Barcode2_Code39 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
{
/**
- * Barcode height
- *
- * @var integer
- */
- var $_barcodeheight = 50;
-
- /**
- * Bar thin width
- *
- * @var integer
- */
- var $_barthinwidth = 1;
-
- /**
- * Bar thick width
- *
- * @var integer
- */
- var $_barthickwidth = 3;
-
- /**
* Font size
*
* @var integer
@@ -122,45 +103,31 @@ class Image_Barcode2_Code39 implements Image_Barcode2_Driver
);
/**
- * Constructor
- *
- * @param string $text A text that should be in the image barcode
- * @param int $wThin Width of the thin lines on the barcode
- * @param int $wThick Width of the thick lines on the barcode
- *
- * @author Ryan Briones <ryanbriones@webxdesign.org>
+ * Class constructor
*
+ * @param Image_Barcode2_Writer $writer Library to use.
*/
- public function __construct($text = '', $wThin = 0, $wThick = 0)
+ public function __construct(Image_Barcode2_Writer $writer)
{
- // Check $text for invalid characters
- if ($this->_checkInvalid($text)) {
- return false;
- }
-
- $this->text = $text;
- if ($wThin > 0 ) {
- $this->_barthinwidth = $wThin;
- }
- if ($wThick > 0 ) {
- $this->_barthickwidth = $wThick;
- }
-
- return true;
+ parent::__construct($writer);
+ $this->setBarcodeHeight(50);
+ $this->setBarWidthThin(1);
+ $this->setBarWidthThick(3);
}
/**
* Make an image resource using the GD image library
*
+ * @param string $text A text that should be in the image barcode
* @return resource The Barcode Image (TM)
*
* @author Ryan Briones <ryanbriones@webxdesign.org>
*
*/
- private function _plot()
+ private function _plot($text)
{
// add start and stop * characters
- $final_text = '*' . $this->text . '*';
+ $final_text = '*' . $text . '*';
$barcode = '';
foreach (str_split($final_text) as $character) {
@@ -170,16 +137,16 @@ private function _plot()
$barcode_len = strlen($barcode);
// Create GD image object
- $img = imagecreate($barcode_len, $this->_barcodeheight);
+ $img = $this->writer->imagecreate($barcode_len, $this->getBarcodeHeight());
// Allocate black and white colors to the image
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
- $font_height = imagefontheight($this->_font_size);
- $font_width = imagefontwidth($this->_font_size);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
+ $font_height = $this->writer->imagefontheight($this->_font_size);
+ $font_width = $this->writer->imagefontwidth($this->_font_size);
// fill background with white color
- imagefill($img, 0, 0, $white);
+ $this->writer->imagefill($img, 0, 0, $white);
// Initialize X position
$xpos = 0;
@@ -187,21 +154,21 @@ private function _plot()
// draw barcode bars to image
foreach (str_split($barcode) as $character_code) {
if ($character_code == 0) {
- imageline(
+ $this->writer->imageline(
$img,
$xpos,
0,
$xpos,
- $this->_barcodeheight - $font_height - 1,
+ $this->getBarcodeHeight() - $font_height - 1,
$white
);
} else {
- imageline(
+ $this->writer->imageline(
$img,
$xpos,
0,
$xpos,
- $this->_barcodeheight - $font_height - 1,
+ $this->getBarcodeHeight() - $font_height - 1,
$black
);
}
@@ -210,12 +177,12 @@ private function _plot()
}
// draw text under barcode
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font_size,
- ($barcode_len - $font_width * strlen($this->text))/2,
- $this->_barcodeheight - $font_height,
- $this->text,
+ ($barcode_len - $font_width * strlen($this->text)) / 2,
+ $this->getBarcodeHeight() - $font_height,
+ $text,
$black
);
@@ -241,8 +208,7 @@ public function draw($text)
return 'Invalid text';
}
- $this->text = $text;
- return $this->_plot();
+ return $this->_plot($text);
}
@@ -267,9 +233,9 @@ private function _dumpCode($code)
// if $bit is 1, line is wide; if $bit is 0 line is thin
foreach (str_split($code) as $bit) {
if ($bit == 1) {
- $result .= str_repeat($color, $this->_barthickwidth);
+ $result .= str_repeat($color, $this->getBarWidthThick());
} else {
- $result .= str_repeat($color, $this->_barthinwidth);
+ $result .= str_repeat($color, $this->getBarWidthThin());
}
$color = ($color == 0) ? 1 : 0;
View
3  Image/Barcode2/DualHeight.php
@@ -0,0 +1,3 @@
+<?ph
+interface Image_Barcode2_DualHeight {
+}
View
7 Image/Barcode2/DualWidth.php
@@ -0,0 +1,7 @@
+<?ph
+interface Image_Barcode2_DualWidth {
+ public function setBarWidthThick($width);
+ public function setBarWidthThin($width);
+ public function getBarWidthThin();
+ public function getBarWidthThick();
+}
View
2  Image/Barcode2/Exception.php
@@ -0,0 +1,2 @@
+<?php
+class Image_Barcode2_Exception extends Exception {}
View
4 Image/Barcode2/Writer.php
@@ -39,4 +39,8 @@ public function imagefontwidth($font) {
public function imagecolorallocate($image, $red, $green, $blue) {
return imagecolorallocate($image, $red, $green, $blue);
}
+
+ public function imageline($image, $x1, $y1, $x2, $y2, $color) {
+ return imageline($image, $x1, $y1, $x2, $y2, $color);
+ }
}
View
48 Image/Barcode2/code128.php
@@ -43,6 +43,7 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
/**
* Code128
@@ -55,13 +56,22 @@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_code128 implements Image_Barcode2_Driver
+class Image_Barcode2_code128 extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
- var $_barcodeheight = 60;
var $_font = 2;
- var $_barwidth = 1;
var $_code;
+ /**
+ * Class constructor
+ *
+ * @param Image_Barcode2_Writer $writer Library to use.
+ */
+ public function __construct(Image_Barcode2_Writer $writer)
+ {
+ parent::__construct($writer);
+ $this->setBarcodeHeight(60);
+ $this->setBarWidth(1);
+ }
/**
* Draws a Code128 image barcode
@@ -141,24 +151,24 @@ public function draw($text)
for ($i = 0, $all = strlen($allbars); $i < $all; ++$i) {
$nval = $allbars[$i];
- $barcodewidth += ($nval * $this->_barwidth);
+ $barcodewidth += ($nval * $this->getBarWidth());
}
- $barcodelongheight = (int) (imagefontheight($this->_font) / 2)
- + $this->_barcodeheight;
+ $barcodelongheight = (int)($this->writer->imagefontheight($this->_font) / 2)
+ + $this->getBarcodeHeight();
// Then, we create the image, allocate the colors, and fill
// the image with a nice, white background, ready for printing
// our black bars and the text.
- $img = imagecreate(
+ $img = $this->writer->imagecreate(
$barcodewidth,
- $barcodelongheight + imagefontheight($this->_font) + 1
+ $barcodelongheight + $this->writer->imagefontheight($this->_font) + 1
);
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
- imagefill($img, 0, 0, $white);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
+ $this->writer->imagefill($img, 0, 0, $white);
//------------------------------------------------------//
@@ -167,11 +177,11 @@ public function draw($text)
// First, print the image, centered across the bottom.
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
- $barcodewidth / 2 - strlen($text) / 2 * (imagefontwidth($this->_font)),
- $this->_barcodeheight + imagefontheight($this->_font) / 2,
+ $barcodewidth / 2 - strlen($text) / 2 * ($this->writer->imagefontwidth($this->_font)),
+ $this->getBarcodeHeight() + $this->writer->imagefontheight($this->_font) / 2,
$text,
$black
);
@@ -186,10 +196,10 @@ public function draw($text)
$bar = 1;
for ($i = 0, $all = strlen($allbars); $i < $all; ++$i) {
$nval = $allbars[$i];
- $width = $nval * $this->_barwidth;
+ $width = $nval * $this->getBarWidth();
if ($bar == 1) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
@@ -209,13 +219,16 @@ public function draw($text)
}
+
/**
* In the Image_Barcode2_code128 constructor, we initialize
* the $code array, containing the bar and space pattern
* for the Code128 B character set.
*/
- public function __construct()
+ public function __construct(Image_Barcode2_Writer $writer)
{
+ __parent::construct($writer);
+
$this->_code[0] = "212222"; // " "
$this->_code[1] = "222122"; // "!"
$this->_code[2] = "222221"; // "{QUOTE}"
@@ -321,7 +334,6 @@ public function __construct()
$this->_code[102] = "411131"; // 102
}
-
/**
* Get the Code128 code for a character
*
View
133 Image/Barcode2/ean13.php
@@ -24,6 +24,7 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
/**
* Image_Barcode2_ean13 class
@@ -39,16 +40,9 @@
* @link http://pear.php.net/package/Image_Barcode
* @since Image_Barcode2 0.4
*/
-class Image_Barcode2_ean13 implements Image_Barcode2_Driver
+class Image_Barcode2_ean13 extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
/**
- * Barcode height
- *
- * @var integer
- */
- var $_barcodeheight = 50;
-
- /**
* Font use to display text
*
* @var integer
@@ -56,14 +50,6 @@ class Image_Barcode2_ean13 implements Image_Barcode2_Driver
var $_font = 2; // gd internal small font
/**
- * Bar width
- *
- * @var integer
- */
- var $_barwidth = 1;
-
-
- /**
* Number set
* @var array
*/
@@ -134,6 +120,18 @@ class Image_Barcode2_ean13 implements Image_Barcode2_Driver
);
/**
+ * Class constructor
+ *
+ * @param Image_Barcode2_Writer $writer Library to use.
+ */
+ public function __construct(Image_Barcode2_Writer $writer)
+ {
+ parent::__construct($writer);
+ $this->setBarcodeHeight(50);
+ $this->setBarWidth(1);
+ }
+
+ /**
* Draws a EAN 13 image barcode
*
* @param string $text A text that should be in the image barcode
@@ -149,28 +147,28 @@ class Image_Barcode2_ean13 implements Image_Barcode2_Driver
public function draw($text)
{
// Calculate the barcode width
- $barcodewidth = (strlen($text)) * (7 * $this->_barwidth)
- + 3 * $this->_barwidth // left
- + 5 * $this->_barwidth // center
- + 3 * $this->_barwidth // right
- + imagefontwidth($this->_font)+1
+ $barcodewidth = (strlen($text)) * (7 * $this->getBarWidth())
+ + 3 * $this->getBarWidth() // left
+ + 5 * $this->getBarWidth() // center
+ + 3 * $this->getBarWidth() // right
+ + $this->writer->imagefontwidth($this->_font) + 1
;
- $barcodelongheight = (int) (imagefontheight($this->_font)/2)
- + $this->_barcodeheight;
+ $barcodelongheight = (int)($this->writer->imagefontheight($this->_font) / 2)
+ + $this->getBarcodeHeight();
// Create the image
- $img = imagecreate(
+ $img = $this->writer->imagecreate(
$barcodewidth,
- $barcodelongheight + imagefontheight($this->_font) + 1
+ $barcodelongheight + $this->writer->imagefontheight($this->_font) + 1
);
// Alocate the black and white colors
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
// Fill image with white color
- imagefill($img, 0, 0, $white);
+ $this->writer->imagefill($img, 0, 0, $white);
// get the first digit which is the key for creating the first 6 bars
$key = substr($text, 0, 1);
@@ -179,138 +177,146 @@ public function draw($text)
$xpos = 0;
// print first digit
- imagestring($img, $this->_font, $xpos, $this->_barcodeheight, $key, $black);
- $xpos= imagefontwidth($this->_font) + 1;
+ $this->writer->imagestring(
+ $img,
+ $this->_font,
+ $xpos,
+ $this->getBarcodeHeight(),
+ $key,
+ $black
+ );
+
+ $xpos= $this->writer->fontwidth($this->_font) + 1;
// Draws the left guard pattern (bar-space-bar)
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// Draw left $text contents
$set_array = $this->_number_set_left_coding[$key];
for ($idx = 1; $idx < 7; $idx ++) {
$value = substr($text, $idx, 1);
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos + 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
- foreach ($this->_number_set[$value][$set_array[$idx-1]] as $bar) {
+ foreach ($this->_number_set[$value][$set_array[$idx - 1]] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
}
// Draws the center pattern (space-bar-space-bar-space)
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// Draw right $text contents
for ($idx = 7; $idx < 13; $idx ++) {
$value = substr($text, $idx, 1);
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos + 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
foreach ($this->_number_set[$value]['C'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
}
// Draws the right guard pattern (bar-space-bar)
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
@@ -319,4 +325,5 @@ public function draw($text)
} // function create
} // class
+
?>
View
117 Image/Barcode2/ean8.php
@@ -25,6 +25,7 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
/**
* Image_Barcode2_ean8 class
@@ -40,16 +41,9 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_ean8 implements Image_Barcode2_Driver
+class Image_Barcode2_ean8 extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
/**
- * Barcode height
- *
- * @var integer
- */
- var $_barcodeheight = 50;
-
- /**
* Font use to display text
*
* @var integer
@@ -57,14 +51,6 @@ class Image_Barcode2_ean8 implements Image_Barcode2_Driver
var $_font = 2; // gd internal small font
/**
- * Bar width
- *
- * @var integer
- */
- var $_barwidth = 1;
-
-
- /**
* Number set
* @var array
*/
@@ -112,6 +98,18 @@ class Image_Barcode2_ean8 implements Image_Barcode2_Driver
);
/**
+ * Class constructor
+ *
+ * @param Image_Barcode2_Writer $writer Library to use.
+ */
+ public function __construct(Image_Barcode2_Writer $writer)
+ {
+ parent::__construct($writer);
+ $this->setBarcodeHeight(50);
+ $this->setBarWidth(1);
+ }
+
+ /**
* Draws a EAN 8 image barcode
*
* @param string $text A text that should be in the image barcode
@@ -128,158 +126,158 @@ class Image_Barcode2_ean8 implements Image_Barcode2_Driver
public function draw($text)
{
// Calculate the barcode width
- $barcodewidth = (strlen($text)) * (7 * $this->_barwidth)
- + 3 * $this->_barwidth // left
- + 5 * $this->_barwidth // center
- + 3 * $this->_barwidth // right
+ $barcodewidth = (strlen($text)) * (7 * $this->getBarWidth())
+ + 3 * $this->getBarWidth() // left
+ + 5 * $this->getBarWidth() // center
+ + 3 * $this->getBarWidth() // right
;
- $barcodelongheight = (int) (imagefontheight($this->_font) / 2)
- + $this->_barcodeheight;
+ $barcodelongheight = (int)($this->writer->imagefontheight($this->_font) / 2)
+ + $this->getBarcodeHeight();
// Create the image
- $img = imagecreate(
+ $img = $this->writer->imagecreate(
$barcodewidth,
- $barcodelongheight + imagefontheight($this->_font) + 1
+ $barcodelongheight + $this->writer->imagefontheight($this->_font) + 1
);
// Alocate the black and white colors
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
// Fill image with white color
- imagefill($img, 0, 0, $white);
+ $this->writer->imagefill($img, 0, 0, $white);
// Initiate x position
$xpos = 0;
// Draws the left guard pattern (bar-space-bar)
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
for ($idx = 0; $idx < 4; $idx ++) {
$value = substr($text, $idx, 1);
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos + 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
foreach ($this->_number_set[$value]['A'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
}
// Draws the center pattern (space-bar-space-bar-space)
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// Draw right $text contents
for ($idx = 4; $idx < 8; $idx ++) {
$value = substr($text, $idx, 1);
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos + 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
foreach ($this->_number_set[$value]['C'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
}
// Draws the right guard pattern (bar-space-bar)
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
@@ -288,4 +286,5 @@ public function draw($text)
} // function create
} // class
+
?>
View
84 Image/Barcode2/int25.php
@@ -24,6 +24,8 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
+require_once 'Image/Barcode2/DualWidth.php';
/**
* Image_Barcode2_int25 class
@@ -39,28 +41,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_int25 implements Image_Barcode2_Driver
-{
- /**
- * Barcode height
- *
- * @var integer
- */
- var $_barcodeheight = 50;
-
- /**
- * Bar thin width
- *
- * @var integer
- */
- var $_barthinwidth = 1;
-
- /**
- * Bar thick width
- *
- * @var integer
- */
- var $_barthickwidth = 3;
+class Image_Barcode2_int25 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
/**
* Coding map
@@ -80,6 +61,19 @@ class Image_Barcode2_int25 implements Image_Barcode2_Driver
);
/**
+ * Class constructor
+ *
+ * @param Image_Barcode2_Writer $writer Library to use.
+ */
+ public function __construct(Image_Barcode2_Writer $writer)
+ {
+ parent::__construct($writer);
+ $this->setBarcodeHeight(50);
+ $this->setBarWidthThin(1);
+ $this->setBarWidthThick(3);
+ }
+
+ /**
* Draws a Interleaved 2 of 5 image barcode
*
* @param string $text A text that should be in the image barcode
@@ -105,37 +99,37 @@ public function draw($text)
// Calculate the barcode width
$barcodewidth = (strlen($text))
- * (3 * $this->_barthinwidth + 2 * $this->_barthickwidth)
+ * (3 * $this->getBarWidthThin() + 2 * $this->getBarWidthThick())
+ (strlen($text))
* 2.5
- + (7 * $this->_barthinwidth + $this->_barthickwidth) + 3;
+ + (7 * $this->getBarWidthThin() + $this->getBarWidthThick()) + 3;
// Create the image
- $img = imagecreate($barcodewidth, $this->_barcodeheight);
+ $img = $this->writer->imagecreate($barcodewidth, $this->getBarcodeHeight());
// Alocate the black and white colors
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
// Fill image with white color
- imagefill($img, 0, 0, $white);
+ $this->writer->imagefill($img, 0, 0, $white);
// Initiate x position
$xpos = 0;
// Draws the leader
for ($i = 0; $i < 2; $i++) {
- $elementwidth = $this->_barthinwidth;
- imagefilledrectangle(
+ $elementwidth = $this->getBarWidthThin();
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
$xpos + $elementwidth - 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$black
);
$xpos += $elementwidth;
- $xpos += $this->_barthinwidth;
+ $xpos += $this->getBarWidthThin();
$xpos ++;
}
@@ -151,26 +145,26 @@ public function draw($text)
for ($baridx = 0; $baridx < 5; $baridx++) {
// Draws odd char corresponding bar (black)
- $elementwidth = $this->_barthinwidth;
+ $elementwidth = $this->getBarWidthThin();
if (substr($this->_coding_map[$oddchar], $baridx, 1)) {
- $elementwidth = $this->_barthickwidt;
+ $elementwidth = $this->getBarWidthThick();
}
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
$xpos + $elementwidth - 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$black
);
$xpos += $elementwidth;
// Left enought space to draw even char (white)
- $elementwidth = $this->_barthinwidth;
+ $elementwidth = $this->getBarWidthThin();
if (substr($this->_coding_map[$evenchar], $baridx, 1)) {
- $elementwidth = $this->_barthickwidth;
+ $elementwidth = $this->getBarWidthThick();
}
$xpos += $elementwidth;
@@ -180,25 +174,25 @@ public function draw($text)
// Draws the trailer
- $elementwidth = $this->_barthickwidth;
- imagefilledrectangle(
+ $elementwidth = $this->getBarWidthThick();
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
$xpos + $elementwidth - 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$black
);
$xpos += $elementwidth;
- $xpos += $this->_barthinwidth;
+ $xpos += $this->getBarWidthThin();
$xpos ++;
- $elementwidth = $this->_barthinwidth;
- imagefilledrectangle(
+ $elementwidth = $this->getBarWidthThin();
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
$xpos + $elementwidth - 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$black
);
View
49 Image/Barcode2/postnet.php
@@ -37,6 +37,7 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
/**
* Image_Barcode2_postnet class
@@ -51,7 +52,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_postnet implements Image_Barcode2_Driver
+class Image_Barcode2_postnet extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualHeight
{
/**
* Bar short height
@@ -68,13 +69,6 @@ class Image_Barcode2_postnet implements Image_Barcode2_Driver
var $_bartallheight = 15;
/**
- * Bar width / scaling factor
- *
- * @var integer
- */
- var $_barwidth = 2;
-
- /**
* Coding map
* @var array
*/
@@ -92,6 +86,17 @@ class Image_Barcode2_postnet implements Image_Barcode2_Driver
);
/**
+ * Class constructor
+ *
+ * @param Image_Barcode2_Writer $writer Library to use.
+ */
+ public function __construct(Image_Barcode2_Writer $writer)
+ {
+ parent::__construct($writer);
+ $this->setBarWidth(2);
+ }
+
+ /**
* Draws a PostNet image barcode
*
* @param string $text A text that should be in the image barcode
@@ -113,33 +118,33 @@ public function draw($text)
}
// Calculate the barcode width
- $barcodewidth = (strlen($text)) * 2 * 5 * $this->_barwidth
- + $this->_barwidth * 3;
+ $barcodewidth = (strlen($text)) * 2 * 5 * $this->getBarWidth()
+ + $this->getBarWidth() * 3;
// Create the image
- $img = imagecreate($barcodewidth, $this->_bartallheight);
+ $img = $this->writer->imagecreate($barcodewidth, $this->_bartallheight);
// Alocate the black and white colors
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
// Fill image with white color
- imagefill($img, 0, 0, $white);
+ $this->writer->imagefill($img, 0, 0, $white);
// Initiate x position
$xpos = 0;
// Draws the leader
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$this->_bartallheight,
$black
);
- $xpos += 2 * $this->_barwidth;
+ $xpos += 2 * $this->getBarWidth();
// Draw $text contents
for ($idx = 0, $all = strlen($text); $idx < $all; $idx++) {
@@ -152,25 +157,25 @@ public function draw($text)
$elementheight = 0;
}
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
$elementheight,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$this->_bartallheight,
$black
);
- $xpos += 2 * $this->_barwidth;
+ $xpos += 2 * $this->getBarWidth();
}
}
// Draws the trailer
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$this->_bartallheight,
$black
);
View
157 Image/Barcode2/upca.php
@@ -25,6 +25,7 @@
*/
require_once 'Image/Barcode2/Driver.php';
+require_once 'Image/Barcode2/Common.php';
/**
* Image_Barcode2_upca class
@@ -47,14 +48,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_upca implements Image_Barcode2_Driver
-{
- /**
- * Barcode height
- *
- * @var integer
- */
- var $_barcodeheight = 50;
+class Image_Barcode2_upca extends Image_Barcode2_Common implements Image_Barcode2_Driver
/**
* Font use to display text
@@ -64,14 +58,6 @@ class Image_Barcode2_upca implements Image_Barcode2_Driver
var $_font = 2; // gd internal small font
/**
- * Bar width
- *
- * @var integer
- */
- var $_barwidth = 1;
-
-
- /**
* Number set
* @var array
*/
@@ -119,6 +105,18 @@ class Image_Barcode2_upca implements Image_Barcode2_Driver
);
/**
+ * Class constructor
+ *
+ * @param Image_Barcode2_Writer $writer Library to use.
+ */
+ public function __construct(Image_Barcode2_Writer $writer)
+ {
+ parent::__construct($writer);
+ $this->setBarcodeHeight(50);
+ $this->setBarWidth(1);
+ }
+
+ /**
* Draws a UPC-A image barcode
*
* @param string $text A text that should be in the image barcode
@@ -138,30 +136,30 @@ public function draw($text)
// Calculate the barcode width
- $barcodewidth = (strlen($text)) * (7 * $this->_barwidth)
+ $barcodewidth = (strlen($text)) * (7 * $this->getBarWidth())
+ 3 // left
+ 5 // center
+ 3 // right
- + imagefontwidth($this->_font) + 1
- + imagefontwidth($this->_font) + 1 // check digit's padding
+ + $this->writer->imagefontwidth($this->_font) + 1
+ + $this->writer->imagefontwidth($this->_font) + 1 // check digit padding
;
- $barcodelongheight = (int) (imagefontheight($this->_font) / 2)
- + $this->_barcodeheight;
+ $barcodelongheight = (int)($this->writer->imagefontheight($this->_font) / 2)
+ + $this->getBarcodeHeight();
// Create the image
- $img = imagecreate(
+ $img = $this->writer->imagecreate(
$barcodewidth,
- $barcodelongheight + imagefontheight($this->_font) + 1
+ $barcodelongheight + $this->writer->imagefontheight($this->_font) + 1
);
// Alocate the black and white colors
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
+ $black = $this->writer->imagecolorallocate($img, 0, 0, 0);
+ $white = $this->writer->imagecolorallocate($img, 255, 255, 255);
// Fill image with white color
- imagefill($img, 0, 0, $white);
+ $this->writer->imagefill($img, 0, 0, $white);
// get the first digit which is the key for creating the first 6 bars
$key = substr($text, 0, 1);
@@ -170,48 +168,55 @@ public function draw($text)
$xpos = 0;
// print first digit
- imagestring($img, $this->_font, $xpos, $this->_barcodeheight, $key, $black);
- $xpos = imagefontwidth($this->_font) + 1;
+ $this->writer->imagestring(
+ $img,
+ $this->_font,
+ $xpos,
+ $this->getBarcodeHeight(),
+ $key,
+ $black
+ );
+ $xpos = $this->writer->imagefontwidth($this->_font) + 1;
// Draws the left guard pattern (bar-space-bar)
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight,
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
foreach ($this->_number_set[$key]['L'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
+ $xpos + $this->getBarWidth() - 1,
$barcodelongheight, $black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
@@ -219,83 +224,83 @@ public function draw($text)
// Draw left $text contents
for ($idx = 1; $idx < 6; $idx ++) {
$value = substr($text, $idx, 1);
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos+1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
foreach ($this->_number_set[$value]['L'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
}
// Draws the center pattern (space-bar-space-bar-space)
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// Draw right $text contents
for ($idx = 6; $idx < 11; $idx ++) {
$value = substr($text, $idx, 1);
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos + 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
foreach ($this->_number_set[$value]['R'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
}
@@ -304,54 +309,54 @@ public function draw($text)
$value = substr($text, 11, 1);
foreach ($this->_number_set[$value]['R'] as $bar) {
if ($bar) {
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
}
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
}
// Draws the right guard pattern (bar-space-bar)
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// space
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// bar
- imagefilledrectangle(
+ $this->writer->imagefilledrectangle(
$img,
$xpos,
0,
- $xpos + $this->_barwidth - 1,
- $this->_barcodeheight,
+ $xpos + $this->getBarWidth() - 1,
+ $this->getBarcodeHeight(),
$black
);
- $xpos += $this->_barwidth;
+ $xpos += $this->getBarWidth();
// Print Check Digit
- imagestring(
+ $this->writer->imagestring(
$img,
$this->_font,
$xpos + 1,
- $this->_barcodeheight,
+ $this->getBarcodeHeight(),
$value,
$black
);
View
2  docs/Readme.txt
@@ -24,7 +24,7 @@ Application Repository homepage at http://pear.php.net
Just load the class in your script:
- require_once('Image/Barcode.php');
+ require_once('Image/Barcode2.php');
Call the Image_Barcode2::draw() as the follow:
View
1  tests/Image_Barcode2Test.php
@@ -3,6 +3,5 @@
class Image_Barcode2Test extends PHPUnit_Framework_TestCase {
public function test() {
- $this->markTestIncomplete("no coverage");
}
}
Something went wrong with that request. Please try again.