repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.setFont
public function setFont($font) { if ($font === null) { throw new CINArgumentException('Font cannot be null.', 'font'); } $this->font = clone $font; $this->font->setText($this->text); $this->font->setRotationAngle($this->rotationAngle); $this->font->setBackgroundColor($this->backgroundColor); $this->font->setForegroundColor($this->foregroundColor); }
php
public function setFont($font) { if ($font === null) { throw new CINArgumentException('Font cannot be null.', 'font'); } $this->font = clone $font; $this->font->setText($this->text); $this->font->setRotationAngle($this->rotationAngle); $this->font->setBackgroundColor($this->backgroundColor); $this->font->setForegroundColor($this->foregroundColor); }
[ "public", "function", "setFont", "(", "$", "font", ")", "{", "if", "(", "$", "font", "===", "null", ")", "{", "throw", "new", "CINArgumentException", "(", "'Font cannot be null.'", ",", "'font'", ")", ";", "}", "$", "this", "->", "font", "=", "clone", "$", "font", ";", "$", "this", "->", "font", "->", "setText", "(", "$", "this", "->", "text", ")", ";", "$", "this", "->", "font", "->", "setRotationAngle", "(", "$", "this", "->", "rotationAngle", ")", ";", "$", "this", "->", "font", "->", "setBackgroundColor", "(", "$", "this", "->", "backgroundColor", ")", ";", "$", "this", "->", "font", "->", "setForegroundColor", "(", "$", "this", "->", "foregroundColor", ")", ";", "}" ]
Sets the font. @param CINFont $font
[ "Sets", "the", "font", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L93-L103
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.setPosition
public function setPosition($position) { $position = intval($position); if ($position !== self::POSITION_TOP && $position !== self::POSITION_RIGHT && $position !== self::POSITION_BOTTOM && $position !== self::POSITION_LEFT) { throw new CINArgumentException('The text position must be one of a valid constant.', 'position'); } $this->position = $position; }
php
public function setPosition($position) { $position = intval($position); if ($position !== self::POSITION_TOP && $position !== self::POSITION_RIGHT && $position !== self::POSITION_BOTTOM && $position !== self::POSITION_LEFT) { throw new CINArgumentException('The text position must be one of a valid constant.', 'position'); } $this->position = $position; }
[ "public", "function", "setPosition", "(", "$", "position", ")", "{", "$", "position", "=", "intval", "(", "$", "position", ")", ";", "if", "(", "$", "position", "!==", "self", "::", "POSITION_TOP", "&&", "$", "position", "!==", "self", "::", "POSITION_RIGHT", "&&", "$", "position", "!==", "self", "::", "POSITION_BOTTOM", "&&", "$", "position", "!==", "self", "::", "POSITION_LEFT", ")", "{", "throw", "new", "CINArgumentException", "(", "'The text position must be one of a valid constant.'", ",", "'position'", ")", ";", "}", "$", "this", "->", "position", "=", "$", "position", ";", "}" ]
Sets the text position for drawing. @param int $position
[ "Sets", "the", "text", "position", "for", "drawing", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L119-L126
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.setAlignment
public function setAlignment($alignment) { $alignment = intval($alignment); if ($alignment !== self::ALIGN_LEFT && $alignment !== self::ALIGN_TOP && $alignment !== self::ALIGN_CENTER && $alignment !== self::ALIGN_RIGHT && $alignment !== self::ALIGN_BOTTOM) { throw new CINArgumentException('The text alignment must be one of a valid constant.', 'alignment'); } $this->alignment = $alignment; }
php
public function setAlignment($alignment) { $alignment = intval($alignment); if ($alignment !== self::ALIGN_LEFT && $alignment !== self::ALIGN_TOP && $alignment !== self::ALIGN_CENTER && $alignment !== self::ALIGN_RIGHT && $alignment !== self::ALIGN_BOTTOM) { throw new CINArgumentException('The text alignment must be one of a valid constant.', 'alignment'); } $this->alignment = $alignment; }
[ "public", "function", "setAlignment", "(", "$", "alignment", ")", "{", "$", "alignment", "=", "intval", "(", "$", "alignment", ")", ";", "if", "(", "$", "alignment", "!==", "self", "::", "ALIGN_LEFT", "&&", "$", "alignment", "!==", "self", "::", "ALIGN_TOP", "&&", "$", "alignment", "!==", "self", "::", "ALIGN_CENTER", "&&", "$", "alignment", "!==", "self", "::", "ALIGN_RIGHT", "&&", "$", "alignment", "!==", "self", "::", "ALIGN_BOTTOM", ")", "{", "throw", "new", "CINArgumentException", "(", "'The text alignment must be one of a valid constant.'", ",", "'alignment'", ")", ";", "}", "$", "this", "->", "alignment", "=", "$", "alignment", ";", "}" ]
Sets the text alignment for drawing. @param int $alignment
[ "Sets", "the", "text", "alignment", "for", "drawing", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L142-L149
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.setRotationAngle
public function setRotationAngle($rotationAngle) { $this->rotationAngle = intval($rotationAngle); $this->font->setRotationAngle($this->rotationAngle); }
php
public function setRotationAngle($rotationAngle) { $this->rotationAngle = intval($rotationAngle); $this->font->setRotationAngle($this->rotationAngle); }
[ "public", "function", "setRotationAngle", "(", "$", "rotationAngle", ")", "{", "$", "this", "->", "rotationAngle", "=", "intval", "(", "$", "rotationAngle", ")", ";", "$", "this", "->", "font", "->", "setRotationAngle", "(", "$", "this", "->", "rotationAngle", ")", ";", "}" ]
Sets the rotation angle in degree. @param int $rotationAngle
[ "Sets", "the", "rotation", "angle", "in", "degree", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L201-L204
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.setBackgroundColor
public /*internal*/ function setBackgroundColor($backgroundColor) { $this->backgroundColor = $backgroundColor; $this->font->setBackgroundColor($this->backgroundColor); }
php
public /*internal*/ function setBackgroundColor($backgroundColor) { $this->backgroundColor = $backgroundColor; $this->font->setBackgroundColor($this->backgroundColor); }
[ "public", "/*internal*/", "function", "setBackgroundColor", "(", "$", "backgroundColor", ")", "{", "$", "this", "->", "backgroundColor", "=", "$", "backgroundColor", ";", "$", "this", "->", "font", "->", "setBackgroundColor", "(", "$", "this", "->", "backgroundColor", ")", ";", "}" ]
Sets the background color in case of rotation. @param CINColor $backgroundColor
[ "Sets", "the", "background", "color", "in", "case", "of", "rotation", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L220-L223
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.setForegroundColor
public function setForegroundColor($foregroundColor) { $this->foregroundColor = $foregroundColor; $this->font->setForegroundColor($this->foregroundColor); }
php
public function setForegroundColor($foregroundColor) { $this->foregroundColor = $foregroundColor; $this->font->setForegroundColor($this->foregroundColor); }
[ "public", "function", "setForegroundColor", "(", "$", "foregroundColor", ")", "{", "$", "this", "->", "foregroundColor", "=", "$", "foregroundColor", ";", "$", "this", "->", "font", "->", "setForegroundColor", "(", "$", "this", "->", "foregroundColor", ")", ";", "}" ]
Sets the foreground color. @param CINColor $foregroundColor
[ "Sets", "the", "foreground", "color", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L239-L242
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.getDimension
public function getDimension() { $w = 0; $h = 0; $dimension = $this->font->getDimension(); $w = $dimension[0]; $h = $dimension[1]; if ($this->position === self::POSITION_TOP || $this->position === self::POSITION_BOTTOM) { $h += $this->spacing; $w += max(0, $this->offset); } else { $w += $this->spacing; $h += max(0, $this->offset); } return array($w, $h); }
php
public function getDimension() { $w = 0; $h = 0; $dimension = $this->font->getDimension(); $w = $dimension[0]; $h = $dimension[1]; if ($this->position === self::POSITION_TOP || $this->position === self::POSITION_BOTTOM) { $h += $this->spacing; $w += max(0, $this->offset); } else { $w += $this->spacing; $h += max(0, $this->offset); } return array($w, $h); }
[ "public", "function", "getDimension", "(", ")", "{", "$", "w", "=", "0", ";", "$", "h", "=", "0", ";", "$", "dimension", "=", "$", "this", "->", "font", "->", "getDimension", "(", ")", ";", "$", "w", "=", "$", "dimension", "[", "0", "]", ";", "$", "h", "=", "$", "dimension", "[", "1", "]", ";", "if", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_TOP", "||", "$", "this", "->", "position", "===", "self", "::", "POSITION_BOTTOM", ")", "{", "$", "h", "+=", "$", "this", "->", "spacing", ";", "$", "w", "+=", "max", "(", "0", ",", "$", "this", "->", "offset", ")", ";", "}", "else", "{", "$", "w", "+=", "$", "this", "->", "spacing", ";", "$", "h", "+=", "max", "(", "0", ",", "$", "this", "->", "offset", ")", ";", "}", "return", "array", "(", "$", "w", ",", "$", "h", ")", ";", "}" ]
Gets the dimension taken by the label, including the spacing and offset. [0]: width [1]: height @return int[]
[ "Gets", "the", "dimension", "taken", "by", "the", "label", "including", "the", "spacing", "and", "offset", ".", "[", "0", "]", ":", "width", "[", "1", "]", ":", "height" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L251-L268
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINLabel.php
CINLabel.draw
public /*internal*/ function draw($im, $x1, $y1, $x2, $y2) { $x = 0; $y = 0; $fontDimension = $this->font->getDimension(); if ($this->position === self::POSITION_TOP || $this->position === self::POSITION_BOTTOM) { if ($this->position === self::POSITION_TOP) { $y = $y1 - $this->spacing - $fontDimension[1]; } elseif ($this->position === self::POSITION_BOTTOM) { $y = $y2 + $this->spacing; } if ($this->alignment === self::ALIGN_CENTER) { $x = ($x2 - $x1) / 2 + $x1 - $fontDimension[0] / 2 + $this->offset; } elseif ($this->alignment === self::ALIGN_LEFT) { $x = $x1 + $this->offset; } else { $x = $x2 + $this->offset - $fontDimension[0]; } } else { if ($this->position === self::POSITION_LEFT) { $x = $x1 - $this->spacing - $fontDimension[0]; } elseif ($this->position === self::POSITION_RIGHT) { $x = $x2 + $this->spacing; } if ($this->alignment === self::ALIGN_CENTER) { $y = ($y2 - $y1) / 2 + $y1 - $fontDimension[1] / 2 + $this->offset; } elseif ($this->alignment === self::ALIGN_TOP) { $y = $y1 + $this->offset; } else { $y = $y2 + $this->offset - $fontDimension[1]; } } $this->font->setText($this->text); $this->font->draw($im, $x, $y); }
php
public /*internal*/ function draw($im, $x1, $y1, $x2, $y2) { $x = 0; $y = 0; $fontDimension = $this->font->getDimension(); if ($this->position === self::POSITION_TOP || $this->position === self::POSITION_BOTTOM) { if ($this->position === self::POSITION_TOP) { $y = $y1 - $this->spacing - $fontDimension[1]; } elseif ($this->position === self::POSITION_BOTTOM) { $y = $y2 + $this->spacing; } if ($this->alignment === self::ALIGN_CENTER) { $x = ($x2 - $x1) / 2 + $x1 - $fontDimension[0] / 2 + $this->offset; } elseif ($this->alignment === self::ALIGN_LEFT) { $x = $x1 + $this->offset; } else { $x = $x2 + $this->offset - $fontDimension[0]; } } else { if ($this->position === self::POSITION_LEFT) { $x = $x1 - $this->spacing - $fontDimension[0]; } elseif ($this->position === self::POSITION_RIGHT) { $x = $x2 + $this->spacing; } if ($this->alignment === self::ALIGN_CENTER) { $y = ($y2 - $y1) / 2 + $y1 - $fontDimension[1] / 2 + $this->offset; } elseif ($this->alignment === self::ALIGN_TOP) { $y = $y1 + $this->offset; } else { $y = $y2 + $this->offset - $fontDimension[1]; } } $this->font->setText($this->text); $this->font->draw($im, $x, $y); }
[ "public", "/*internal*/", "function", "draw", "(", "$", "im", ",", "$", "x1", ",", "$", "y1", ",", "$", "x2", ",", "$", "y2", ")", "{", "$", "x", "=", "0", ";", "$", "y", "=", "0", ";", "$", "fontDimension", "=", "$", "this", "->", "font", "->", "getDimension", "(", ")", ";", "if", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_TOP", "||", "$", "this", "->", "position", "===", "self", "::", "POSITION_BOTTOM", ")", "{", "if", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_TOP", ")", "{", "$", "y", "=", "$", "y1", "-", "$", "this", "->", "spacing", "-", "$", "fontDimension", "[", "1", "]", ";", "}", "elseif", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_BOTTOM", ")", "{", "$", "y", "=", "$", "y2", "+", "$", "this", "->", "spacing", ";", "}", "if", "(", "$", "this", "->", "alignment", "===", "self", "::", "ALIGN_CENTER", ")", "{", "$", "x", "=", "(", "$", "x2", "-", "$", "x1", ")", "/", "2", "+", "$", "x1", "-", "$", "fontDimension", "[", "0", "]", "/", "2", "+", "$", "this", "->", "offset", ";", "}", "elseif", "(", "$", "this", "->", "alignment", "===", "self", "::", "ALIGN_LEFT", ")", "{", "$", "x", "=", "$", "x1", "+", "$", "this", "->", "offset", ";", "}", "else", "{", "$", "x", "=", "$", "x2", "+", "$", "this", "->", "offset", "-", "$", "fontDimension", "[", "0", "]", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_LEFT", ")", "{", "$", "x", "=", "$", "x1", "-", "$", "this", "->", "spacing", "-", "$", "fontDimension", "[", "0", "]", ";", "}", "elseif", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_RIGHT", ")", "{", "$", "x", "=", "$", "x2", "+", "$", "this", "->", "spacing", ";", "}", "if", "(", "$", "this", "->", "alignment", "===", "self", "::", "ALIGN_CENTER", ")", "{", "$", "y", "=", "(", "$", "y2", "-", "$", "y1", ")", "/", "2", "+", "$", "y1", "-", "$", "fontDimension", "[", "1", "]", "/", "2", "+", "$", "this", "->", "offset", ";", "}", "elseif", "(", "$", "this", "->", "alignment", "===", "self", "::", "ALIGN_TOP", ")", "{", "$", "y", "=", "$", "y1", "+", "$", "this", "->", "offset", ";", "}", "else", "{", "$", "y", "=", "$", "y2", "+", "$", "this", "->", "offset", "-", "$", "fontDimension", "[", "1", "]", ";", "}", "}", "$", "this", "->", "font", "->", "setText", "(", "$", "this", "->", "text", ")", ";", "$", "this", "->", "font", "->", "draw", "(", "$", "im", ",", "$", "x", ",", "$", "y", ")", ";", "}" ]
Draws the text. The coordinate passed are the positions of the barcode. $x1 and $y1 represent the top left corner. $x2 and $y2 represent the bottom right corner. @param resource $im @param int $x1 @param int $y1 @param int $x2 @param int $y2
[ "Draws", "the", "text", ".", "The", "coordinate", "passed", "are", "the", "positions", "of", "the", "barcode", ".", "$x1", "and", "$y1", "represent", "the", "top", "left", "corner", ".", "$x2", "and", "$y2", "represent", "the", "bottom", "right", "corner", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINLabel.php#L282-L320
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.setStart
public function setStart($table) { if ($table !== 'A' && $table !== 'B' && $table !== 'C' && $table !== null) { throw new CINArgumentException('The starting table must be A, B, C or null.', 'table'); } $this->starting_text = $table; }
php
public function setStart($table) { if ($table !== 'A' && $table !== 'B' && $table !== 'C' && $table !== null) { throw new CINArgumentException('The starting table must be A, B, C or null.', 'table'); } $this->starting_text = $table; }
[ "public", "function", "setStart", "(", "$", "table", ")", "{", "if", "(", "$", "table", "!==", "'A'", "&&", "$", "table", "!==", "'B'", "&&", "$", "table", "!==", "'C'", "&&", "$", "table", "!==", "null", ")", "{", "throw", "new", "CINArgumentException", "(", "'The starting table must be A, B, C or null.'", ",", "'table'", ")", ";", "}", "$", "this", "->", "starting_text", "=", "$", "table", ";", "}" ]
Specifies the start code. Can be 'A', 'B', 'C', or null - Table A: Capitals + ASCII 0-31 + punct - Table B: Capitals + LowerCase + punct - Table C: Numbers If null is specified, the table selection is automatically made. The default is null. @param string $table
[ "Specifies", "the", "start", "code", ".", "Can", "be", "A", "B", "C", "or", "null", "-", "Table", "A", ":", "Capitals", "+", "ASCII", "0", "-", "31", "+", "punct", "-", "Table", "B", ":", "Capitals", "+", "LowerCase", "+", "punct", "-", "Table", "C", ":", "Numbers" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L231-L237
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.parse
public function parse($text) { $this->setStartFromText($text); $this->text = ''; $seq = ''; $currentMode = $this->starting_text; // Here, we format correctly what the user gives. if (!is_array($text)) { $seq = $this->getSequence($text, $currentMode); $this->text = $text; } else { // This loop checks for UnknownText AND raises an exception if a character is not allowed in a table reset($text); while (list($key1, $val1) = each($text)) { // We take each value if (!is_array($val1)) { // This is not a table if (is_string($val1)) { // If it's a string, parse as unknown $seq .= $this->getSequence($val1, $currentMode); $this->text .= $val1; } else { // it's the case of "array(ENCODING, 'text')" // We got ENCODING in $val1, calling 'each' again will get 'text' in $val2 list($key2, $val2) = each($text); $seq .= $this->{'setParse' . $this->METHOD[$val1]}($val2, $currentMode); $this->text .= $val2; } } else { // The method is specified // $val1[0] = ENCODING // $val1[1] = 'text' $value = isset($val1[1]) ? $val1[1] : ''; // If data available $seq .= $this->{'setParse' . $this->METHOD[$val1[0]]}($value, $currentMode); $this->text .= $value; } } } if ($seq !== '') { $bitstream = $this->createBinaryStream($this->text, $seq); $this->setData($bitstream); } $this->addDefaultLabel(); }
php
public function parse($text) { $this->setStartFromText($text); $this->text = ''; $seq = ''; $currentMode = $this->starting_text; // Here, we format correctly what the user gives. if (!is_array($text)) { $seq = $this->getSequence($text, $currentMode); $this->text = $text; } else { // This loop checks for UnknownText AND raises an exception if a character is not allowed in a table reset($text); while (list($key1, $val1) = each($text)) { // We take each value if (!is_array($val1)) { // This is not a table if (is_string($val1)) { // If it's a string, parse as unknown $seq .= $this->getSequence($val1, $currentMode); $this->text .= $val1; } else { // it's the case of "array(ENCODING, 'text')" // We got ENCODING in $val1, calling 'each' again will get 'text' in $val2 list($key2, $val2) = each($text); $seq .= $this->{'setParse' . $this->METHOD[$val1]}($val2, $currentMode); $this->text .= $val2; } } else { // The method is specified // $val1[0] = ENCODING // $val1[1] = 'text' $value = isset($val1[1]) ? $val1[1] : ''; // If data available $seq .= $this->{'setParse' . $this->METHOD[$val1[0]]}($value, $currentMode); $this->text .= $value; } } } if ($seq !== '') { $bitstream = $this->createBinaryStream($this->text, $seq); $this->setData($bitstream); } $this->addDefaultLabel(); }
[ "public", "function", "parse", "(", "$", "text", ")", "{", "$", "this", "->", "setStartFromText", "(", "$", "text", ")", ";", "$", "this", "->", "text", "=", "''", ";", "$", "seq", "=", "''", ";", "$", "currentMode", "=", "$", "this", "->", "starting_text", ";", "// Here, we format correctly what the user gives.\r", "if", "(", "!", "is_array", "(", "$", "text", ")", ")", "{", "$", "seq", "=", "$", "this", "->", "getSequence", "(", "$", "text", ",", "$", "currentMode", ")", ";", "$", "this", "->", "text", "=", "$", "text", ";", "}", "else", "{", "// This loop checks for UnknownText AND raises an exception if a character is not allowed in a table\r", "reset", "(", "$", "text", ")", ";", "while", "(", "list", "(", "$", "key1", ",", "$", "val1", ")", "=", "each", "(", "$", "text", ")", ")", "{", "// We take each value\r", "if", "(", "!", "is_array", "(", "$", "val1", ")", ")", "{", "// This is not a table\r", "if", "(", "is_string", "(", "$", "val1", ")", ")", "{", "// If it's a string, parse as unknown\r", "$", "seq", ".=", "$", "this", "->", "getSequence", "(", "$", "val1", ",", "$", "currentMode", ")", ";", "$", "this", "->", "text", ".=", "$", "val1", ";", "}", "else", "{", "// it's the case of \"array(ENCODING, 'text')\"\r", "// We got ENCODING in $val1, calling 'each' again will get 'text' in $val2\r", "list", "(", "$", "key2", ",", "$", "val2", ")", "=", "each", "(", "$", "text", ")", ";", "$", "seq", ".=", "$", "this", "->", "{", "'setParse'", ".", "$", "this", "->", "METHOD", "[", "$", "val1", "]", "}", "(", "$", "val2", ",", "$", "currentMode", ")", ";", "$", "this", "->", "text", ".=", "$", "val2", ";", "}", "}", "else", "{", "// The method is specified\r", "// $val1[0] = ENCODING\r", "// $val1[1] = 'text'\r", "$", "value", "=", "isset", "(", "$", "val1", "[", "1", "]", ")", "?", "$", "val1", "[", "1", "]", ":", "''", ";", "// If data available\r", "$", "seq", ".=", "$", "this", "->", "{", "'setParse'", ".", "$", "this", "->", "METHOD", "[", "$", "val1", "[", "0", "]", "]", "}", "(", "$", "value", ",", "$", "currentMode", ")", ";", "$", "this", "->", "text", ".=", "$", "value", ";", "}", "}", "}", "if", "(", "$", "seq", "!==", "''", ")", "{", "$", "bitstream", "=", "$", "this", "->", "createBinaryStream", "(", "$", "this", "->", "text", ",", "$", "seq", ")", ";", "$", "this", "->", "setData", "(", "$", "bitstream", ")", ";", "}", "$", "this", "->", "addDefaultLabel", "(", ")", ";", "}" ]
Parses the text before displaying it. @param mixed $text
[ "Parses", "the", "text", "before", "displaying", "it", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L265-L308
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.draw
public function draw($im) { $c = count($this->data); for ($i = 0; $i < $c; $i++) { $this->drawChar($im, $this->data[$i], true); } $this->drawChar($im, '1', true); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
php
public function draw($im) { $c = count($this->data); for ($i = 0; $i < $c; $i++) { $this->drawChar($im, $this->data[$i], true); } $this->drawChar($im, '1', true); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "$", "c", "=", "count", "(", "$", "this", "->", "data", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "data", "[", "$", "i", "]", ",", "true", ")", ";", "}", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'1'", ",", "true", ")", ";", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L315-L323
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.calculateChecksum
protected function calculateChecksum() { // Checksum // First Char (START) // + Starting with the first data character following the start character, // take the value of the character (between 0 and 102, inclusive) multiply // it by its character position (1) and add that to the running checksum. // Modulated 103 $this->checksumValue = $this->indcheck[0]; $c = count($this->indcheck); for ($i = 1; $i < $c; $i++) { $this->checksumValue += $this->indcheck[$i] * $i; } $this->checksumValue = $this->checksumValue % 103; }
php
protected function calculateChecksum() { // Checksum // First Char (START) // + Starting with the first data character following the start character, // take the value of the character (between 0 and 102, inclusive) multiply // it by its character position (1) and add that to the running checksum. // Modulated 103 $this->checksumValue = $this->indcheck[0]; $c = count($this->indcheck); for ($i = 1; $i < $c; $i++) { $this->checksumValue += $this->indcheck[$i] * $i; } $this->checksumValue = $this->checksumValue % 103; }
[ "protected", "function", "calculateChecksum", "(", ")", "{", "// Checksum\r", "// First Char (START)\r", "// + Starting with the first data character following the start character,\r", "// take the value of the character (between 0 and 102, inclusive) multiply\r", "// it by its character position (1) and add that to the running checksum.\r", "// Modulated 103\r", "$", "this", "->", "checksumValue", "=", "$", "this", "->", "indcheck", "[", "0", "]", ";", "$", "c", "=", "count", "(", "$", "this", "->", "indcheck", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "this", "->", "checksumValue", "+=", "$", "this", "->", "indcheck", "[", "$", "i", "]", "*", "$", "i", ";", "}", "$", "this", "->", "checksumValue", "=", "$", "this", "->", "checksumValue", "%", "103", ";", "}" ]
Overloaded method to calculate checksum.
[ "Overloaded", "method", "to", "calculate", "checksum", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L357-L371
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.processChecksum
protected function processChecksum() { if ($this->checksumValue === false) { // Calculate the checksum only once $this->calculateChecksum(); } if ($this->checksumValue !== false) { if ($this->lastTable === 'C') { return (string)$this->checksumValue; } return $this->{'keys' . $this->lastTable}[$this->checksumValue]; } return false; }
php
protected function processChecksum() { if ($this->checksumValue === false) { // Calculate the checksum only once $this->calculateChecksum(); } if ($this->checksumValue !== false) { if ($this->lastTable === 'C') { return (string)$this->checksumValue; } return $this->{'keys' . $this->lastTable}[$this->checksumValue]; } return false; }
[ "protected", "function", "processChecksum", "(", ")", "{", "if", "(", "$", "this", "->", "checksumValue", "===", "false", ")", "{", "// Calculate the checksum only once\r", "$", "this", "->", "calculateChecksum", "(", ")", ";", "}", "if", "(", "$", "this", "->", "checksumValue", "!==", "false", ")", "{", "if", "(", "$", "this", "->", "lastTable", "===", "'C'", ")", "{", "return", "(", "string", ")", "$", "this", "->", "checksumValue", ";", "}", "return", "$", "this", "->", "{", "'keys'", ".", "$", "this", "->", "lastTable", "}", "[", "$", "this", "->", "checksumValue", "]", ";", "}", "return", "false", ";", "}" ]
Overloaded method to display the checksum.
[ "Overloaded", "method", "to", "display", "the", "checksum", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L376-L390
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.setStartFromText
private function setStartFromText($text) { if ($this->starting_text === null) { // If we have a forced table at the start, we get that one... if (is_array($text)) { if (is_array($text[0])) { // Code like array(array(ENCODING, '')) $this->starting_text = $this->METHOD[$text[0][0]]; return; } else { if (is_string($text[0])) { // Code like array('test') (Automatic text) $text = $text[0]; } else { // Code like array(ENCODING, '') $this->starting_text = $this->METHOD[$text[0]]; return; } } } // At this point, we had an "automatic" table selection... // If we can get at least 4 numbers, go in C; otherwise go in B. $tmp = preg_quote($this->keysC, '/'); $length = strlen($text); if ($length >= 4 && preg_match('/[' . $tmp . ']/', substr($text, 0, 4))) { $this->starting_text = 'C'; } else { if ($length > 0 && strpos($this->keysB, $text[0]) !== false) { $this->starting_text = 'B'; } else { $this->starting_text = 'A'; } } } }
php
private function setStartFromText($text) { if ($this->starting_text === null) { // If we have a forced table at the start, we get that one... if (is_array($text)) { if (is_array($text[0])) { // Code like array(array(ENCODING, '')) $this->starting_text = $this->METHOD[$text[0][0]]; return; } else { if (is_string($text[0])) { // Code like array('test') (Automatic text) $text = $text[0]; } else { // Code like array(ENCODING, '') $this->starting_text = $this->METHOD[$text[0]]; return; } } } // At this point, we had an "automatic" table selection... // If we can get at least 4 numbers, go in C; otherwise go in B. $tmp = preg_quote($this->keysC, '/'); $length = strlen($text); if ($length >= 4 && preg_match('/[' . $tmp . ']/', substr($text, 0, 4))) { $this->starting_text = 'C'; } else { if ($length > 0 && strpos($this->keysB, $text[0]) !== false) { $this->starting_text = 'B'; } else { $this->starting_text = 'A'; } } } }
[ "private", "function", "setStartFromText", "(", "$", "text", ")", "{", "if", "(", "$", "this", "->", "starting_text", "===", "null", ")", "{", "// If we have a forced table at the start, we get that one...\r", "if", "(", "is_array", "(", "$", "text", ")", ")", "{", "if", "(", "is_array", "(", "$", "text", "[", "0", "]", ")", ")", "{", "// Code like array(array(ENCODING, ''))\r", "$", "this", "->", "starting_text", "=", "$", "this", "->", "METHOD", "[", "$", "text", "[", "0", "]", "[", "0", "]", "]", ";", "return", ";", "}", "else", "{", "if", "(", "is_string", "(", "$", "text", "[", "0", "]", ")", ")", "{", "// Code like array('test') (Automatic text)\r", "$", "text", "=", "$", "text", "[", "0", "]", ";", "}", "else", "{", "// Code like array(ENCODING, '')\r", "$", "this", "->", "starting_text", "=", "$", "this", "->", "METHOD", "[", "$", "text", "[", "0", "]", "]", ";", "return", ";", "}", "}", "}", "// At this point, we had an \"automatic\" table selection...\r", "// If we can get at least 4 numbers, go in C; otherwise go in B.\r", "$", "tmp", "=", "preg_quote", "(", "$", "this", "->", "keysC", ",", "'/'", ")", ";", "$", "length", "=", "strlen", "(", "$", "text", ")", ";", "if", "(", "$", "length", ">=", "4", "&&", "preg_match", "(", "'/['", ".", "$", "tmp", ".", "']/'", ",", "substr", "(", "$", "text", ",", "0", ",", "4", ")", ")", ")", "{", "$", "this", "->", "starting_text", "=", "'C'", ";", "}", "else", "{", "if", "(", "$", "length", ">", "0", "&&", "strpos", "(", "$", "this", "->", "keysB", ",", "$", "text", "[", "0", "]", ")", "!==", "false", ")", "{", "$", "this", "->", "starting_text", "=", "'B'", ";", "}", "else", "{", "$", "this", "->", "starting_text", "=", "'A'", ";", "}", "}", "}", "}" ]
Specifies the starting_text table if none has been specified earlier. @param string $text
[ "Specifies", "the", "starting_text", "table", "if", "none", "has", "been", "specified", "earlier", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L397-L431
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.extractTilde
private static function extractTilde($text, $pos) { if ($text[$pos] === '~') { if (isset($text[$pos + 1])) { // Do we have a tilde? if ($text[$pos + 1] === '~') { return '~~'; } elseif ($text[$pos + 1] === 'F') { // Do we have a number after? if (isset($text[$pos + 2])) { $v = intval($text[$pos + 2]); if ($v >= 1 && $v <= 4) { return '~F' . $v; } else { throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.'); } } else { throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.'); } } else { throw new CINParseException('code128', 'Wrong code after the ~.'); } } else { throw new CINParseException('code128', 'Wrong code after the ~.'); } } else { throw new CINParseException('code128', 'There is no ~ at this location.'); } }
php
private static function extractTilde($text, $pos) { if ($text[$pos] === '~') { if (isset($text[$pos + 1])) { // Do we have a tilde? if ($text[$pos + 1] === '~') { return '~~'; } elseif ($text[$pos + 1] === 'F') { // Do we have a number after? if (isset($text[$pos + 2])) { $v = intval($text[$pos + 2]); if ($v >= 1 && $v <= 4) { return '~F' . $v; } else { throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.'); } } else { throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.'); } } else { throw new CINParseException('code128', 'Wrong code after the ~.'); } } else { throw new CINParseException('code128', 'Wrong code after the ~.'); } } else { throw new CINParseException('code128', 'There is no ~ at this location.'); } }
[ "private", "static", "function", "extractTilde", "(", "$", "text", ",", "$", "pos", ")", "{", "if", "(", "$", "text", "[", "$", "pos", "]", "===", "'~'", ")", "{", "if", "(", "isset", "(", "$", "text", "[", "$", "pos", "+", "1", "]", ")", ")", "{", "// Do we have a tilde?\r", "if", "(", "$", "text", "[", "$", "pos", "+", "1", "]", "===", "'~'", ")", "{", "return", "'~~'", ";", "}", "elseif", "(", "$", "text", "[", "$", "pos", "+", "1", "]", "===", "'F'", ")", "{", "// Do we have a number after?\r", "if", "(", "isset", "(", "$", "text", "[", "$", "pos", "+", "2", "]", ")", ")", "{", "$", "v", "=", "intval", "(", "$", "text", "[", "$", "pos", "+", "2", "]", ")", ";", "if", "(", "$", "v", ">=", "1", "&&", "$", "v", "<=", "4", ")", "{", "return", "'~F'", ".", "$", "v", ";", "}", "else", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'Bad ~F. You must provide a number from 1 to 4.'", ")", ";", "}", "}", "else", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'Bad ~F. You must provide a number from 1 to 4.'", ")", ";", "}", "}", "else", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'Wrong code after the ~.'", ")", ";", "}", "}", "else", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'Wrong code after the ~.'", ")", ";", "}", "}", "else", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'There is no ~ at this location.'", ")", ";", "}", "}" ]
Extracts the ~ value from the $text at the $pos. If the tilde is not ~~, ~F1, ~F2, ~F3, ~F4; an error is raised. @param string $text @param int $pos @return string
[ "Extracts", "the", "~", "value", "from", "the", "$text", "at", "the", "$pos", ".", "If", "the", "tilde", "is", "not", "~~", "~F1", "~F2", "~F3", "~F4", ";", "an", "error", "is", "raised", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L441-L468
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.getSequenceParsed
private function getSequenceParsed($text, $currentMode) { if ($this->tilde) { $sequence = ''; $previousPos = 0; while (($pos = strpos($text, '~', $previousPos)) !== false) { $tildeData = self::extractTilde($text, $pos); $simpleTilde = ($tildeData === '~~'); if ($simpleTilde && $currentMode !== 'B') { throw new CINParseException('code128', 'The Table ' . $currentMode . ' doesn\'t contain the character ~.'); } // At this point, we know we have ~Fx if ($tildeData !== '~F1' && $currentMode === 'C') { // The mode C doesn't support ~F2, ~F3, ~F4 throw new CINParseException('code128', 'The Table C doesn\'t contain the function ' . $tildeData . '.'); } $length = $pos - $previousPos; if ($currentMode === 'C') { if ($length % 2 === 1) { throw new CINParseException('code128', 'The text "' . $text . '" must have an even number of character to be encoded in Table C.'); } } $sequence .= str_repeat('.', $length); $sequence .= '.'; $sequence .= (!$simpleTilde) ? 'F' : ''; $previousPos = $pos + strlen($tildeData); } // Flushing $length = strlen($text) - $previousPos; if ($currentMode === 'C') { if ($length % 2 === 1) { throw new CINParseException('code128', 'The text "' . $text . '" must have an even number of character to be encoded in Table C.'); } } $sequence .= str_repeat('.', $length); return $sequence; } else { return str_repeat('.', strlen($text)); } }
php
private function getSequenceParsed($text, $currentMode) { if ($this->tilde) { $sequence = ''; $previousPos = 0; while (($pos = strpos($text, '~', $previousPos)) !== false) { $tildeData = self::extractTilde($text, $pos); $simpleTilde = ($tildeData === '~~'); if ($simpleTilde && $currentMode !== 'B') { throw new CINParseException('code128', 'The Table ' . $currentMode . ' doesn\'t contain the character ~.'); } // At this point, we know we have ~Fx if ($tildeData !== '~F1' && $currentMode === 'C') { // The mode C doesn't support ~F2, ~F3, ~F4 throw new CINParseException('code128', 'The Table C doesn\'t contain the function ' . $tildeData . '.'); } $length = $pos - $previousPos; if ($currentMode === 'C') { if ($length % 2 === 1) { throw new CINParseException('code128', 'The text "' . $text . '" must have an even number of character to be encoded in Table C.'); } } $sequence .= str_repeat('.', $length); $sequence .= '.'; $sequence .= (!$simpleTilde) ? 'F' : ''; $previousPos = $pos + strlen($tildeData); } // Flushing $length = strlen($text) - $previousPos; if ($currentMode === 'C') { if ($length % 2 === 1) { throw new CINParseException('code128', 'The text "' . $text . '" must have an even number of character to be encoded in Table C.'); } } $sequence .= str_repeat('.', $length); return $sequence; } else { return str_repeat('.', strlen($text)); } }
[ "private", "function", "getSequenceParsed", "(", "$", "text", ",", "$", "currentMode", ")", "{", "if", "(", "$", "this", "->", "tilde", ")", "{", "$", "sequence", "=", "''", ";", "$", "previousPos", "=", "0", ";", "while", "(", "(", "$", "pos", "=", "strpos", "(", "$", "text", ",", "'~'", ",", "$", "previousPos", ")", ")", "!==", "false", ")", "{", "$", "tildeData", "=", "self", "::", "extractTilde", "(", "$", "text", ",", "$", "pos", ")", ";", "$", "simpleTilde", "=", "(", "$", "tildeData", "===", "'~~'", ")", ";", "if", "(", "$", "simpleTilde", "&&", "$", "currentMode", "!==", "'B'", ")", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The Table '", ".", "$", "currentMode", ".", "' doesn\\'t contain the character ~.'", ")", ";", "}", "// At this point, we know we have ~Fx\r", "if", "(", "$", "tildeData", "!==", "'~F1'", "&&", "$", "currentMode", "===", "'C'", ")", "{", "// The mode C doesn't support ~F2, ~F3, ~F4\r", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The Table C doesn\\'t contain the function '", ".", "$", "tildeData", ".", "'.'", ")", ";", "}", "$", "length", "=", "$", "pos", "-", "$", "previousPos", ";", "if", "(", "$", "currentMode", "===", "'C'", ")", "{", "if", "(", "$", "length", "%", "2", "===", "1", ")", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The text \"'", ".", "$", "text", ".", "'\" must have an even number of character to be encoded in Table C.'", ")", ";", "}", "}", "$", "sequence", ".=", "str_repeat", "(", "'.'", ",", "$", "length", ")", ";", "$", "sequence", ".=", "'.'", ";", "$", "sequence", ".=", "(", "!", "$", "simpleTilde", ")", "?", "'F'", ":", "''", ";", "$", "previousPos", "=", "$", "pos", "+", "strlen", "(", "$", "tildeData", ")", ";", "}", "// Flushing\r", "$", "length", "=", "strlen", "(", "$", "text", ")", "-", "$", "previousPos", ";", "if", "(", "$", "currentMode", "===", "'C'", ")", "{", "if", "(", "$", "length", "%", "2", "===", "1", ")", "{", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The text \"'", ".", "$", "text", ".", "'\" must have an even number of character to be encoded in Table C.'", ")", ";", "}", "}", "$", "sequence", ".=", "str_repeat", "(", "'.'", ",", "$", "length", ")", ";", "return", "$", "sequence", ";", "}", "else", "{", "return", "str_repeat", "(", "'.'", ",", "strlen", "(", "$", "text", ")", ")", ";", "}", "}" ]
Gets the "dotted" sequence for the $text based on the $currentMode. There is also a check if we use the special tilde ~ @param string $text @param string $currentMode @return string
[ "Gets", "the", "dotted", "sequence", "for", "the", "$text", "based", "on", "the", "$currentMode", ".", "There", "is", "also", "a", "check", "if", "we", "use", "the", "special", "tilde", "~" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L478-L523
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.setParseA
private function setParseA($text, &$currentMode) { $tmp = preg_quote($this->keysA, '/'); // If we accept the ~ for special character, we must allow it. if ($this->tilde) { $tmp .= '~'; } $match = array(); if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) { // We found something not allowed throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table A. The character "' . $match[0] . '" is not allowed.'); } else { $latch = ($currentMode === 'A') ? '' : '0'; $currentMode = 'A'; return $latch . $this->getSequenceParsed($text, $currentMode); } }
php
private function setParseA($text, &$currentMode) { $tmp = preg_quote($this->keysA, '/'); // If we accept the ~ for special character, we must allow it. if ($this->tilde) { $tmp .= '~'; } $match = array(); if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) { // We found something not allowed throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table A. The character "' . $match[0] . '" is not allowed.'); } else { $latch = ($currentMode === 'A') ? '' : '0'; $currentMode = 'A'; return $latch . $this->getSequenceParsed($text, $currentMode); } }
[ "private", "function", "setParseA", "(", "$", "text", ",", "&", "$", "currentMode", ")", "{", "$", "tmp", "=", "preg_quote", "(", "$", "this", "->", "keysA", ",", "'/'", ")", ";", "// If we accept the ~ for special character, we must allow it.\r", "if", "(", "$", "this", "->", "tilde", ")", "{", "$", "tmp", ".=", "'~'", ";", "}", "$", "match", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/[^'", ".", "$", "tmp", ".", "']/'", ",", "$", "text", ",", "$", "match", ")", "===", "1", ")", "{", "// We found something not allowed\r", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The text \"'", ".", "$", "text", ".", "'\" can\\'t be parsed with the Table A. The character \"'", ".", "$", "match", "[", "0", "]", ".", "'\" is not allowed.'", ")", ";", "}", "else", "{", "$", "latch", "=", "(", "$", "currentMode", "===", "'A'", ")", "?", "''", ":", "'0'", ";", "$", "currentMode", "=", "'A'", ";", "return", "$", "latch", ".", "$", "this", "->", "getSequenceParsed", "(", "$", "text", ",", "$", "currentMode", ")", ";", "}", "}" ]
Parses the text and returns the appropriate sequence for the Table A. @param string $text @param string $currentMode @return string
[ "Parses", "the", "text", "and", "returns", "the", "appropriate", "sequence", "for", "the", "Table", "A", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L532-L550
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.setParseB
private function setParseB($text, &$currentMode) { $tmp = preg_quote($this->keysB, '/'); $match = array(); if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) { // We found something not allowed throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table B. The character "' . $match[0] . '" is not allowed.'); } else { $latch = ($currentMode === 'B') ? '' : '1'; $currentMode = 'B'; return $latch . $this->getSequenceParsed($text, $currentMode); } }
php
private function setParseB($text, &$currentMode) { $tmp = preg_quote($this->keysB, '/'); $match = array(); if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) { // We found something not allowed throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table B. The character "' . $match[0] . '" is not allowed.'); } else { $latch = ($currentMode === 'B') ? '' : '1'; $currentMode = 'B'; return $latch . $this->getSequenceParsed($text, $currentMode); } }
[ "private", "function", "setParseB", "(", "$", "text", ",", "&", "$", "currentMode", ")", "{", "$", "tmp", "=", "preg_quote", "(", "$", "this", "->", "keysB", ",", "'/'", ")", ";", "$", "match", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/[^'", ".", "$", "tmp", ".", "']/'", ",", "$", "text", ",", "$", "match", ")", "===", "1", ")", "{", "// We found something not allowed\r", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The text \"'", ".", "$", "text", ".", "'\" can\\'t be parsed with the Table B. The character \"'", ".", "$", "match", "[", "0", "]", ".", "'\" is not allowed.'", ")", ";", "}", "else", "{", "$", "latch", "=", "(", "$", "currentMode", "===", "'B'", ")", "?", "''", ":", "'1'", ";", "$", "currentMode", "=", "'B'", ";", "return", "$", "latch", ".", "$", "this", "->", "getSequenceParsed", "(", "$", "text", ",", "$", "currentMode", ")", ";", "}", "}" ]
Parses the text and returns the appropriate sequence for the Table B. @param string $text @param string $currentMode @return string
[ "Parses", "the", "text", "and", "returns", "the", "appropriate", "sequence", "for", "the", "Table", "B", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L559-L572
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.setParseC
private function setParseC($text, &$currentMode) { $tmp = preg_quote($this->keysC, '/'); // If we accept the ~ for special character, we must allow it. if ($this->tilde) { $tmp .= '~F'; } $match = array(); if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) { // We found something not allowed throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table C. The character "' . $match[0] . '" is not allowed.'); } else { $latch = ($currentMode === 'C') ? '' : '2'; $currentMode = 'C'; return $latch . $this->getSequenceParsed($text, $currentMode); } }
php
private function setParseC($text, &$currentMode) { $tmp = preg_quote($this->keysC, '/'); // If we accept the ~ for special character, we must allow it. if ($this->tilde) { $tmp .= '~F'; } $match = array(); if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) { // We found something not allowed throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table C. The character "' . $match[0] . '" is not allowed.'); } else { $latch = ($currentMode === 'C') ? '' : '2'; $currentMode = 'C'; return $latch . $this->getSequenceParsed($text, $currentMode); } }
[ "private", "function", "setParseC", "(", "$", "text", ",", "&", "$", "currentMode", ")", "{", "$", "tmp", "=", "preg_quote", "(", "$", "this", "->", "keysC", ",", "'/'", ")", ";", "// If we accept the ~ for special character, we must allow it.\r", "if", "(", "$", "this", "->", "tilde", ")", "{", "$", "tmp", ".=", "'~F'", ";", "}", "$", "match", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/[^'", ".", "$", "tmp", ".", "']/'", ",", "$", "text", ",", "$", "match", ")", "===", "1", ")", "{", "// We found something not allowed\r", "throw", "new", "CINParseException", "(", "'code128'", ",", "'The text \"'", ".", "$", "text", ".", "'\" can\\'t be parsed with the Table C. The character \"'", ".", "$", "match", "[", "0", "]", ".", "'\" is not allowed.'", ")", ";", "}", "else", "{", "$", "latch", "=", "(", "$", "currentMode", "===", "'C'", ")", "?", "''", ":", "'2'", ";", "$", "currentMode", "=", "'C'", ";", "return", "$", "latch", ".", "$", "this", "->", "getSequenceParsed", "(", "$", "text", ",", "$", "currentMode", ")", ";", "}", "}" ]
Parses the text and returns the appropriate sequence for the Table C. @param string $text @param string $currentMode @return string
[ "Parses", "the", "text", "and", "returns", "the", "appropriate", "sequence", "for", "the", "Table", "C", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L581-L599
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.getSequence
private function getSequence($text, &$starting_text) { $e = 10000; $latLen = array( array(0, 1, 1), array(1, 0, 1), array(1, 1, 0) ); $shftLen = array( array($e, 1, $e), array(1, $e, $e), array($e, $e, $e) ); $charSiz = array(2, 2, 1); $startA = $e; $startB = $e; $startC = $e; if ($starting_text === 'A') { $startA = 0; } if ($starting_text === 'B') { $startB = 0; } if ($starting_text === 'C') { $startC = 0; } $curLen = array($startA, $startB, $startC); $curSeq = array(null, null, null); $nextNumber = false; $x = 0; $xLen = strlen($text); for ($x = 0; $x < $xLen; $x++) { $input = $text[$x]; // 1. for ($i = 0; $i < 3; $i++) { for ($j = 0; $j < 3; $j++) { if (($curLen[$i] + $latLen[$i][$j]) < $curLen[$j]) { $curLen[$j] = $curLen[$i] + $latLen[$i][$j]; $curSeq[$j] = $curSeq[$i] . $j; } } } // 2. $nxtLen = array($e, $e, $e); $nxtSeq = array(); // 3. $flag = false; $posArray = array(); // Special case, we do have a tilde and we process them if ($this->tilde && $input === '~') { $tildeData = self::extractTilde($text, $x); if ($tildeData === '~~') { // We simply skip a tilde $posArray[] = 1; $x++; } elseif (substr($tildeData, 0, 2) === '~F') { $v = intval($tildeData[2]); $posArray[] = 0; $posArray[] = 1; if ($v === 1) { $posArray[] = 2; } $x += 2; $flag = true; } } else { $pos = strpos($this->keysA, $input); if ($pos !== false) { $posArray[] = 0; } $pos = strpos($this->keysB, $input); if ($pos !== false) { $posArray[] = 1; } // Do we have the next char a number?? OR a ~F1 $pos = strpos($this->keysC, $input); if ($nextNumber || ($pos !== false && isset($text[$x + 1]) && strpos($this->keysC, $text[$x + 1]) !== false)) { $nextNumber = !$nextNumber; $posArray[] = 2; } } $c = count($posArray); for ($i = 0; $i < $c; $i++) { if (($curLen[$posArray[$i]] + $charSiz[$posArray[$i]]) < $nxtLen[$posArray[$i]]) { $nxtLen[$posArray[$i]] = $curLen[$posArray[$i]] + $charSiz[$posArray[$i]]; $nxtSeq[$posArray[$i]] = $curSeq[$posArray[$i]] . '.'; } for ($j = 0; $j < 2; $j++) { if ($j === $posArray[$i]) { continue; } if (($curLen[$j] + $shftLen[$j][$posArray[$i]] + $charSiz[$posArray[$i]]) < $nxtLen[$j]) { $nxtLen[$j] = $curLen[$j] + $shftLen[$j][$posArray[$i]] + $charSiz[$posArray[$i]]; $nxtSeq[$j] = $curSeq[$j] . chr($posArray[$i] + 65) . '.'; } } } if ($c === 0) { // We found an unsuported character throw new CINParseException('code128', 'Character ' . $input . ' not supported.'); } if ($flag) { for ($i = 0; $i < 5; $i++) { if (isset($nxtSeq[$i])) { $nxtSeq[$i] .= 'F'; } } } // 4. for ($i = 0; $i < 3; $i++) { $curLen[$i] = $nxtLen[$i]; if (isset($nxtSeq[$i])) { $curSeq[$i] = $nxtSeq[$i]; } } } // Every curLen under $e is possible but we take the smallest $m = $e; $k = -1; for ($i = 0; $i < 3; $i++) { if ($curLen[$i] < $m) { $k = $i; $m = $curLen[$i]; } } if ($k === -1) { return ''; } return $curSeq[$k]; }
php
private function getSequence($text, &$starting_text) { $e = 10000; $latLen = array( array(0, 1, 1), array(1, 0, 1), array(1, 1, 0) ); $shftLen = array( array($e, 1, $e), array(1, $e, $e), array($e, $e, $e) ); $charSiz = array(2, 2, 1); $startA = $e; $startB = $e; $startC = $e; if ($starting_text === 'A') { $startA = 0; } if ($starting_text === 'B') { $startB = 0; } if ($starting_text === 'C') { $startC = 0; } $curLen = array($startA, $startB, $startC); $curSeq = array(null, null, null); $nextNumber = false; $x = 0; $xLen = strlen($text); for ($x = 0; $x < $xLen; $x++) { $input = $text[$x]; // 1. for ($i = 0; $i < 3; $i++) { for ($j = 0; $j < 3; $j++) { if (($curLen[$i] + $latLen[$i][$j]) < $curLen[$j]) { $curLen[$j] = $curLen[$i] + $latLen[$i][$j]; $curSeq[$j] = $curSeq[$i] . $j; } } } // 2. $nxtLen = array($e, $e, $e); $nxtSeq = array(); // 3. $flag = false; $posArray = array(); // Special case, we do have a tilde and we process them if ($this->tilde && $input === '~') { $tildeData = self::extractTilde($text, $x); if ($tildeData === '~~') { // We simply skip a tilde $posArray[] = 1; $x++; } elseif (substr($tildeData, 0, 2) === '~F') { $v = intval($tildeData[2]); $posArray[] = 0; $posArray[] = 1; if ($v === 1) { $posArray[] = 2; } $x += 2; $flag = true; } } else { $pos = strpos($this->keysA, $input); if ($pos !== false) { $posArray[] = 0; } $pos = strpos($this->keysB, $input); if ($pos !== false) { $posArray[] = 1; } // Do we have the next char a number?? OR a ~F1 $pos = strpos($this->keysC, $input); if ($nextNumber || ($pos !== false && isset($text[$x + 1]) && strpos($this->keysC, $text[$x + 1]) !== false)) { $nextNumber = !$nextNumber; $posArray[] = 2; } } $c = count($posArray); for ($i = 0; $i < $c; $i++) { if (($curLen[$posArray[$i]] + $charSiz[$posArray[$i]]) < $nxtLen[$posArray[$i]]) { $nxtLen[$posArray[$i]] = $curLen[$posArray[$i]] + $charSiz[$posArray[$i]]; $nxtSeq[$posArray[$i]] = $curSeq[$posArray[$i]] . '.'; } for ($j = 0; $j < 2; $j++) { if ($j === $posArray[$i]) { continue; } if (($curLen[$j] + $shftLen[$j][$posArray[$i]] + $charSiz[$posArray[$i]]) < $nxtLen[$j]) { $nxtLen[$j] = $curLen[$j] + $shftLen[$j][$posArray[$i]] + $charSiz[$posArray[$i]]; $nxtSeq[$j] = $curSeq[$j] . chr($posArray[$i] + 65) . '.'; } } } if ($c === 0) { // We found an unsuported character throw new CINParseException('code128', 'Character ' . $input . ' not supported.'); } if ($flag) { for ($i = 0; $i < 5; $i++) { if (isset($nxtSeq[$i])) { $nxtSeq[$i] .= 'F'; } } } // 4. for ($i = 0; $i < 3; $i++) { $curLen[$i] = $nxtLen[$i]; if (isset($nxtSeq[$i])) { $curSeq[$i] = $nxtSeq[$i]; } } } // Every curLen under $e is possible but we take the smallest $m = $e; $k = -1; for ($i = 0; $i < 3; $i++) { if ($curLen[$i] < $m) { $k = $i; $m = $curLen[$i]; } } if ($k === -1) { return ''; } return $curSeq[$k]; }
[ "private", "function", "getSequence", "(", "$", "text", ",", "&", "$", "starting_text", ")", "{", "$", "e", "=", "10000", ";", "$", "latLen", "=", "array", "(", "array", "(", "0", ",", "1", ",", "1", ")", ",", "array", "(", "1", ",", "0", ",", "1", ")", ",", "array", "(", "1", ",", "1", ",", "0", ")", ")", ";", "$", "shftLen", "=", "array", "(", "array", "(", "$", "e", ",", "1", ",", "$", "e", ")", ",", "array", "(", "1", ",", "$", "e", ",", "$", "e", ")", ",", "array", "(", "$", "e", ",", "$", "e", ",", "$", "e", ")", ")", ";", "$", "charSiz", "=", "array", "(", "2", ",", "2", ",", "1", ")", ";", "$", "startA", "=", "$", "e", ";", "$", "startB", "=", "$", "e", ";", "$", "startC", "=", "$", "e", ";", "if", "(", "$", "starting_text", "===", "'A'", ")", "{", "$", "startA", "=", "0", ";", "}", "if", "(", "$", "starting_text", "===", "'B'", ")", "{", "$", "startB", "=", "0", ";", "}", "if", "(", "$", "starting_text", "===", "'C'", ")", "{", "$", "startC", "=", "0", ";", "}", "$", "curLen", "=", "array", "(", "$", "startA", ",", "$", "startB", ",", "$", "startC", ")", ";", "$", "curSeq", "=", "array", "(", "null", ",", "null", ",", "null", ")", ";", "$", "nextNumber", "=", "false", ";", "$", "x", "=", "0", ";", "$", "xLen", "=", "strlen", "(", "$", "text", ")", ";", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<", "$", "xLen", ";", "$", "x", "++", ")", "{", "$", "input", "=", "$", "text", "[", "$", "x", "]", ";", "// 1.\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "3", ";", "$", "i", "++", ")", "{", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "3", ";", "$", "j", "++", ")", "{", "if", "(", "(", "$", "curLen", "[", "$", "i", "]", "+", "$", "latLen", "[", "$", "i", "]", "[", "$", "j", "]", ")", "<", "$", "curLen", "[", "$", "j", "]", ")", "{", "$", "curLen", "[", "$", "j", "]", "=", "$", "curLen", "[", "$", "i", "]", "+", "$", "latLen", "[", "$", "i", "]", "[", "$", "j", "]", ";", "$", "curSeq", "[", "$", "j", "]", "=", "$", "curSeq", "[", "$", "i", "]", ".", "$", "j", ";", "}", "}", "}", "// 2.\r", "$", "nxtLen", "=", "array", "(", "$", "e", ",", "$", "e", ",", "$", "e", ")", ";", "$", "nxtSeq", "=", "array", "(", ")", ";", "// 3.\r", "$", "flag", "=", "false", ";", "$", "posArray", "=", "array", "(", ")", ";", "// Special case, we do have a tilde and we process them\r", "if", "(", "$", "this", "->", "tilde", "&&", "$", "input", "===", "'~'", ")", "{", "$", "tildeData", "=", "self", "::", "extractTilde", "(", "$", "text", ",", "$", "x", ")", ";", "if", "(", "$", "tildeData", "===", "'~~'", ")", "{", "// We simply skip a tilde\r", "$", "posArray", "[", "]", "=", "1", ";", "$", "x", "++", ";", "}", "elseif", "(", "substr", "(", "$", "tildeData", ",", "0", ",", "2", ")", "===", "'~F'", ")", "{", "$", "v", "=", "intval", "(", "$", "tildeData", "[", "2", "]", ")", ";", "$", "posArray", "[", "]", "=", "0", ";", "$", "posArray", "[", "]", "=", "1", ";", "if", "(", "$", "v", "===", "1", ")", "{", "$", "posArray", "[", "]", "=", "2", ";", "}", "$", "x", "+=", "2", ";", "$", "flag", "=", "true", ";", "}", "}", "else", "{", "$", "pos", "=", "strpos", "(", "$", "this", "->", "keysA", ",", "$", "input", ")", ";", "if", "(", "$", "pos", "!==", "false", ")", "{", "$", "posArray", "[", "]", "=", "0", ";", "}", "$", "pos", "=", "strpos", "(", "$", "this", "->", "keysB", ",", "$", "input", ")", ";", "if", "(", "$", "pos", "!==", "false", ")", "{", "$", "posArray", "[", "]", "=", "1", ";", "}", "// Do we have the next char a number?? OR a ~F1\r", "$", "pos", "=", "strpos", "(", "$", "this", "->", "keysC", ",", "$", "input", ")", ";", "if", "(", "$", "nextNumber", "||", "(", "$", "pos", "!==", "false", "&&", "isset", "(", "$", "text", "[", "$", "x", "+", "1", "]", ")", "&&", "strpos", "(", "$", "this", "->", "keysC", ",", "$", "text", "[", "$", "x", "+", "1", "]", ")", "!==", "false", ")", ")", "{", "$", "nextNumber", "=", "!", "$", "nextNumber", ";", "$", "posArray", "[", "]", "=", "2", ";", "}", "}", "$", "c", "=", "count", "(", "$", "posArray", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "(", "$", "curLen", "[", "$", "posArray", "[", "$", "i", "]", "]", "+", "$", "charSiz", "[", "$", "posArray", "[", "$", "i", "]", "]", ")", "<", "$", "nxtLen", "[", "$", "posArray", "[", "$", "i", "]", "]", ")", "{", "$", "nxtLen", "[", "$", "posArray", "[", "$", "i", "]", "]", "=", "$", "curLen", "[", "$", "posArray", "[", "$", "i", "]", "]", "+", "$", "charSiz", "[", "$", "posArray", "[", "$", "i", "]", "]", ";", "$", "nxtSeq", "[", "$", "posArray", "[", "$", "i", "]", "]", "=", "$", "curSeq", "[", "$", "posArray", "[", "$", "i", "]", "]", ".", "'.'", ";", "}", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "2", ";", "$", "j", "++", ")", "{", "if", "(", "$", "j", "===", "$", "posArray", "[", "$", "i", "]", ")", "{", "continue", ";", "}", "if", "(", "(", "$", "curLen", "[", "$", "j", "]", "+", "$", "shftLen", "[", "$", "j", "]", "[", "$", "posArray", "[", "$", "i", "]", "]", "+", "$", "charSiz", "[", "$", "posArray", "[", "$", "i", "]", "]", ")", "<", "$", "nxtLen", "[", "$", "j", "]", ")", "{", "$", "nxtLen", "[", "$", "j", "]", "=", "$", "curLen", "[", "$", "j", "]", "+", "$", "shftLen", "[", "$", "j", "]", "[", "$", "posArray", "[", "$", "i", "]", "]", "+", "$", "charSiz", "[", "$", "posArray", "[", "$", "i", "]", "]", ";", "$", "nxtSeq", "[", "$", "j", "]", "=", "$", "curSeq", "[", "$", "j", "]", ".", "chr", "(", "$", "posArray", "[", "$", "i", "]", "+", "65", ")", ".", "'.'", ";", "}", "}", "}", "if", "(", "$", "c", "===", "0", ")", "{", "// We found an unsuported character\r", "throw", "new", "CINParseException", "(", "'code128'", ",", "'Character '", ".", "$", "input", ".", "' not supported.'", ")", ";", "}", "if", "(", "$", "flag", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "5", ";", "$", "i", "++", ")", "{", "if", "(", "isset", "(", "$", "nxtSeq", "[", "$", "i", "]", ")", ")", "{", "$", "nxtSeq", "[", "$", "i", "]", ".=", "'F'", ";", "}", "}", "}", "// 4.\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "3", ";", "$", "i", "++", ")", "{", "$", "curLen", "[", "$", "i", "]", "=", "$", "nxtLen", "[", "$", "i", "]", ";", "if", "(", "isset", "(", "$", "nxtSeq", "[", "$", "i", "]", ")", ")", "{", "$", "curSeq", "[", "$", "i", "]", "=", "$", "nxtSeq", "[", "$", "i", "]", ";", "}", "}", "}", "// Every curLen under $e is possible but we take the smallest\r", "$", "m", "=", "$", "e", ";", "$", "k", "=", "-", "1", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "3", ";", "$", "i", "++", ")", "{", "if", "(", "$", "curLen", "[", "$", "i", "]", "<", "$", "m", ")", "{", "$", "k", "=", "$", "i", ";", "$", "m", "=", "$", "curLen", "[", "$", "i", "]", ";", "}", "}", "if", "(", "$", "k", "===", "-", "1", ")", "{", "return", "''", ";", "}", "return", "$", "curSeq", "[", "$", "k", "]", ";", "}" ]
Depending on the $text, it will return the correct sequence to encode the text. @param string $text @param string $starting_text @return string
[ "Depending", "on", "the", "$text", "it", "will", "return", "the", "correct", "sequence", "to", "encode", "the", "text", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L609-L749
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.createBinaryStream
private function createBinaryStream($text, $seq) { $c = strlen($seq); $data = array(); // code stream $indcheck = array(); // index for checksum $currentEncoding = 0; if ($this->starting_text === 'A') { $currentEncoding = 0; $indcheck[] = self::KEY_STARTA; $this->lastTable = 'A'; } elseif ($this->starting_text === 'B') { $currentEncoding = 1; $indcheck[] = self::KEY_STARTB; $this->lastTable = 'B'; } elseif ($this->starting_text === 'C') { $currentEncoding = 2; $indcheck[] = self::KEY_STARTC; $this->lastTable = 'C'; } $data[] = $this->code[103 + $currentEncoding]; $temporaryEncoding = -1; for ($i = 0, $counter = 0; $i < $c; $i++) { $input = $seq[$i]; $inputI = intval($input); if ($input === '.') { $this->encodeChar($data, $currentEncoding, $seq, $text, $i, $counter, $indcheck); if ($temporaryEncoding !== -1) { $currentEncoding = $temporaryEncoding; $temporaryEncoding = -1; } } elseif ($input >= 'A' && $input <= 'B') { // We shift $encoding = ord($input) - 65; $shift = $this->shift[$currentEncoding][$encoding]; $indcheck[] = $shift; $data[] = $this->code[$shift]; if ($temporaryEncoding === -1) { $temporaryEncoding = $currentEncoding; } $currentEncoding = $encoding; } elseif ($inputI >= 0 && $inputI < 3) { $temporaryEncoding = -1; // We latch $latch = $this->latch[$currentEncoding][$inputI]; if ($latch !== null) { $indcheck[] = $latch; $this->lastTable = chr(65 + $inputI); $data[] = $this->code[$latch]; $currentEncoding = $inputI; } } } return array($indcheck, $data); }
php
private function createBinaryStream($text, $seq) { $c = strlen($seq); $data = array(); // code stream $indcheck = array(); // index for checksum $currentEncoding = 0; if ($this->starting_text === 'A') { $currentEncoding = 0; $indcheck[] = self::KEY_STARTA; $this->lastTable = 'A'; } elseif ($this->starting_text === 'B') { $currentEncoding = 1; $indcheck[] = self::KEY_STARTB; $this->lastTable = 'B'; } elseif ($this->starting_text === 'C') { $currentEncoding = 2; $indcheck[] = self::KEY_STARTC; $this->lastTable = 'C'; } $data[] = $this->code[103 + $currentEncoding]; $temporaryEncoding = -1; for ($i = 0, $counter = 0; $i < $c; $i++) { $input = $seq[$i]; $inputI = intval($input); if ($input === '.') { $this->encodeChar($data, $currentEncoding, $seq, $text, $i, $counter, $indcheck); if ($temporaryEncoding !== -1) { $currentEncoding = $temporaryEncoding; $temporaryEncoding = -1; } } elseif ($input >= 'A' && $input <= 'B') { // We shift $encoding = ord($input) - 65; $shift = $this->shift[$currentEncoding][$encoding]; $indcheck[] = $shift; $data[] = $this->code[$shift]; if ($temporaryEncoding === -1) { $temporaryEncoding = $currentEncoding; } $currentEncoding = $encoding; } elseif ($inputI >= 0 && $inputI < 3) { $temporaryEncoding = -1; // We latch $latch = $this->latch[$currentEncoding][$inputI]; if ($latch !== null) { $indcheck[] = $latch; $this->lastTable = chr(65 + $inputI); $data[] = $this->code[$latch]; $currentEncoding = $inputI; } } } return array($indcheck, $data); }
[ "private", "function", "createBinaryStream", "(", "$", "text", ",", "$", "seq", ")", "{", "$", "c", "=", "strlen", "(", "$", "seq", ")", ";", "$", "data", "=", "array", "(", ")", ";", "// code stream\r", "$", "indcheck", "=", "array", "(", ")", ";", "// index for checksum\r", "$", "currentEncoding", "=", "0", ";", "if", "(", "$", "this", "->", "starting_text", "===", "'A'", ")", "{", "$", "currentEncoding", "=", "0", ";", "$", "indcheck", "[", "]", "=", "self", "::", "KEY_STARTA", ";", "$", "this", "->", "lastTable", "=", "'A'", ";", "}", "elseif", "(", "$", "this", "->", "starting_text", "===", "'B'", ")", "{", "$", "currentEncoding", "=", "1", ";", "$", "indcheck", "[", "]", "=", "self", "::", "KEY_STARTB", ";", "$", "this", "->", "lastTable", "=", "'B'", ";", "}", "elseif", "(", "$", "this", "->", "starting_text", "===", "'C'", ")", "{", "$", "currentEncoding", "=", "2", ";", "$", "indcheck", "[", "]", "=", "self", "::", "KEY_STARTC", ";", "$", "this", "->", "lastTable", "=", "'C'", ";", "}", "$", "data", "[", "]", "=", "$", "this", "->", "code", "[", "103", "+", "$", "currentEncoding", "]", ";", "$", "temporaryEncoding", "=", "-", "1", ";", "for", "(", "$", "i", "=", "0", ",", "$", "counter", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "input", "=", "$", "seq", "[", "$", "i", "]", ";", "$", "inputI", "=", "intval", "(", "$", "input", ")", ";", "if", "(", "$", "input", "===", "'.'", ")", "{", "$", "this", "->", "encodeChar", "(", "$", "data", ",", "$", "currentEncoding", ",", "$", "seq", ",", "$", "text", ",", "$", "i", ",", "$", "counter", ",", "$", "indcheck", ")", ";", "if", "(", "$", "temporaryEncoding", "!==", "-", "1", ")", "{", "$", "currentEncoding", "=", "$", "temporaryEncoding", ";", "$", "temporaryEncoding", "=", "-", "1", ";", "}", "}", "elseif", "(", "$", "input", ">=", "'A'", "&&", "$", "input", "<=", "'B'", ")", "{", "// We shift\r", "$", "encoding", "=", "ord", "(", "$", "input", ")", "-", "65", ";", "$", "shift", "=", "$", "this", "->", "shift", "[", "$", "currentEncoding", "]", "[", "$", "encoding", "]", ";", "$", "indcheck", "[", "]", "=", "$", "shift", ";", "$", "data", "[", "]", "=", "$", "this", "->", "code", "[", "$", "shift", "]", ";", "if", "(", "$", "temporaryEncoding", "===", "-", "1", ")", "{", "$", "temporaryEncoding", "=", "$", "currentEncoding", ";", "}", "$", "currentEncoding", "=", "$", "encoding", ";", "}", "elseif", "(", "$", "inputI", ">=", "0", "&&", "$", "inputI", "<", "3", ")", "{", "$", "temporaryEncoding", "=", "-", "1", ";", "// We latch\r", "$", "latch", "=", "$", "this", "->", "latch", "[", "$", "currentEncoding", "]", "[", "$", "inputI", "]", ";", "if", "(", "$", "latch", "!==", "null", ")", "{", "$", "indcheck", "[", "]", "=", "$", "latch", ";", "$", "this", "->", "lastTable", "=", "chr", "(", "65", "+", "$", "inputI", ")", ";", "$", "data", "[", "]", "=", "$", "this", "->", "code", "[", "$", "latch", "]", ";", "$", "currentEncoding", "=", "$", "inputI", ";", "}", "}", "}", "return", "array", "(", "$", "indcheck", ",", "$", "data", ")", ";", "}" ]
Depending on the sequence $seq given (returned from getSequence()), this method will return the code stream in an array. Each char will be a string of bit based on the Code 128. Each letter from the sequence represents bits. 0 to 2 are latches A to B are Shift + Letter . is a char in the current encoding @param string $text @param string $seq @return string[][]
[ "Depending", "on", "the", "sequence", "$seq", "given", "(", "returned", "from", "getSequence", "()", ")", "this", "method", "will", "return", "the", "code", "stream", "in", "an", "array", ".", "Each", "char", "will", "be", "a", "string", "of", "bit", "based", "on", "the", "Code", "128", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L766-L825
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.encodeChar
private function encodeChar(&$data, $encoding, $seq, $text, &$i, &$counter, &$indcheck) { if (isset($seq[$i + 1]) && $seq[$i + 1] === 'F') { // We have a flag !! if ($text[$counter + 1] === 'F') { $number = $text[$counter + 2]; $fnc = $this->fnc[$encoding][$number - 1]; $indcheck[] = $fnc; $data[] = $this->code[$fnc]; // Skip F + number $counter += 2; } else { // Not supposed } $i++; } else { if ($encoding === 2) { // We take 2 numbers in the same time $code = (int)substr($text, $counter, 2); $indcheck[] = $code; $data[] = $this->code[$code]; $counter++; $i++; } else { $keys = ($encoding === 0) ? $this->keysA : $this->keysB; $pos = strpos($keys, $text[$counter]); $indcheck[] = $pos; $data[] = $this->code[$pos]; } } $counter++; }
php
private function encodeChar(&$data, $encoding, $seq, $text, &$i, &$counter, &$indcheck) { if (isset($seq[$i + 1]) && $seq[$i + 1] === 'F') { // We have a flag !! if ($text[$counter + 1] === 'F') { $number = $text[$counter + 2]; $fnc = $this->fnc[$encoding][$number - 1]; $indcheck[] = $fnc; $data[] = $this->code[$fnc]; // Skip F + number $counter += 2; } else { // Not supposed } $i++; } else { if ($encoding === 2) { // We take 2 numbers in the same time $code = (int)substr($text, $counter, 2); $indcheck[] = $code; $data[] = $this->code[$code]; $counter++; $i++; } else { $keys = ($encoding === 0) ? $this->keysA : $this->keysB; $pos = strpos($keys, $text[$counter]); $indcheck[] = $pos; $data[] = $this->code[$pos]; } } $counter++; }
[ "private", "function", "encodeChar", "(", "&", "$", "data", ",", "$", "encoding", ",", "$", "seq", ",", "$", "text", ",", "&", "$", "i", ",", "&", "$", "counter", ",", "&", "$", "indcheck", ")", "{", "if", "(", "isset", "(", "$", "seq", "[", "$", "i", "+", "1", "]", ")", "&&", "$", "seq", "[", "$", "i", "+", "1", "]", "===", "'F'", ")", "{", "// We have a flag !!\r", "if", "(", "$", "text", "[", "$", "counter", "+", "1", "]", "===", "'F'", ")", "{", "$", "number", "=", "$", "text", "[", "$", "counter", "+", "2", "]", ";", "$", "fnc", "=", "$", "this", "->", "fnc", "[", "$", "encoding", "]", "[", "$", "number", "-", "1", "]", ";", "$", "indcheck", "[", "]", "=", "$", "fnc", ";", "$", "data", "[", "]", "=", "$", "this", "->", "code", "[", "$", "fnc", "]", ";", "// Skip F + number\r", "$", "counter", "+=", "2", ";", "}", "else", "{", "// Not supposed\r", "}", "$", "i", "++", ";", "}", "else", "{", "if", "(", "$", "encoding", "===", "2", ")", "{", "// We take 2 numbers in the same time\r", "$", "code", "=", "(", "int", ")", "substr", "(", "$", "text", ",", "$", "counter", ",", "2", ")", ";", "$", "indcheck", "[", "]", "=", "$", "code", ";", "$", "data", "[", "]", "=", "$", "this", "->", "code", "[", "$", "code", "]", ";", "$", "counter", "++", ";", "$", "i", "++", ";", "}", "else", "{", "$", "keys", "=", "(", "$", "encoding", "===", "0", ")", "?", "$", "this", "->", "keysA", ":", "$", "this", "->", "keysB", ";", "$", "pos", "=", "strpos", "(", "$", "keys", ",", "$", "text", "[", "$", "counter", "]", ")", ";", "$", "indcheck", "[", "]", "=", "$", "pos", ";", "$", "data", "[", "]", "=", "$", "this", "->", "code", "[", "$", "pos", "]", ";", "}", "}", "$", "counter", "++", ";", "}" ]
Encodes characters, base on its encoding and sequence @param int[] $data @param int $encoding @param string $seq @param string $text @param int $i @param int $counter @param int[] $indcheck
[ "Encodes", "characters", "base", "on", "its", "encoding", "and", "sequence" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L838-L871
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode128.php
CINcode128.setData
private function setData($data) { $this->indcheck = $data[0]; $this->data = $data[1]; $this->calculateChecksum(); $this->data[] = $this->code[$this->checksumValue]; $this->data[] = $this->code[self::KEY_STOP]; }
php
private function setData($data) { $this->indcheck = $data[0]; $this->data = $data[1]; $this->calculateChecksum(); $this->data[] = $this->code[$this->checksumValue]; $this->data[] = $this->code[self::KEY_STOP]; }
[ "private", "function", "setData", "(", "$", "data", ")", "{", "$", "this", "->", "indcheck", "=", "$", "data", "[", "0", "]", ";", "$", "this", "->", "data", "=", "$", "data", "[", "1", "]", ";", "$", "this", "->", "calculateChecksum", "(", ")", ";", "$", "this", "->", "data", "[", "]", "=", "$", "this", "->", "code", "[", "$", "this", "->", "checksumValue", "]", ";", "$", "this", "->", "data", "[", "]", "=", "$", "this", "->", "code", "[", "self", "::", "KEY_STOP", "]", ";", "}" ]
Saves data into the classes. This method will save data, calculate real column number (if -1 was selected), the real error level (if -1 was selected)... It will add Padding to the end and generate the error codes. @param array $data
[ "Saves", "data", "into", "the", "classes", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode128.php#L883-L889
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawPNG.php
CINDrawPNG.setDPI
public function setDPI($dpi) { if (is_numeric($dpi)) { $this->dpi = max(1, $dpi); } else { $this->dpi = null; } }
php
public function setDPI($dpi) { if (is_numeric($dpi)) { $this->dpi = max(1, $dpi); } else { $this->dpi = null; } }
[ "public", "function", "setDPI", "(", "$", "dpi", ")", "{", "if", "(", "is_numeric", "(", "$", "dpi", ")", ")", "{", "$", "this", "->", "dpi", "=", "max", "(", "1", ",", "$", "dpi", ")", ";", "}", "else", "{", "$", "this", "->", "dpi", "=", "null", ";", "}", "}" ]
Sets the DPI. @param int $dpi
[ "Sets", "the", "DPI", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawPNG.php#L46-L52
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawPNG.php
CINDrawPNG.draw
public function draw() { ob_start(); imagepng($this->im); $bin = ob_get_contents(); ob_end_clean(); $this->setInternalProperties($bin); if (empty($this->filename)) { echo $bin; } else { file_put_contents($this->filename, $bin); } }
php
public function draw() { ob_start(); imagepng($this->im); $bin = ob_get_contents(); ob_end_clean(); $this->setInternalProperties($bin); if (empty($this->filename)) { echo $bin; } else { file_put_contents($this->filename, $bin); } }
[ "public", "function", "draw", "(", ")", "{", "ob_start", "(", ")", ";", "imagepng", "(", "$", "this", "->", "im", ")", ";", "$", "bin", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "this", "->", "setInternalProperties", "(", "$", "bin", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "filename", ")", ")", "{", "echo", "$", "bin", ";", "}", "else", "{", "file_put_contents", "(", "$", "this", "->", "filename", ",", "$", "bin", ")", ";", "}", "}" ]
Draws the PNG on the screen or in a file.
[ "Draws", "the", "PNG", "on", "the", "screen", "or", "in", "a", "file", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawPNG.php#L57-L70
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINFontFile.php
CINFontFile.setRotationAngle
public function setRotationAngle($rotationAngle) { $this->rotationAngle = (int)$rotationAngle; if ($this->rotationAngle !== 90 && $this->rotationAngle !== 180 && $this->rotationAngle !== 270) { $this->rotationAngle = 0; } $this->rotationAngle = (360 - $this->rotationAngle) % 360; $this->box = null; }
php
public function setRotationAngle($rotationAngle) { $this->rotationAngle = (int)$rotationAngle; if ($this->rotationAngle !== 90 && $this->rotationAngle !== 180 && $this->rotationAngle !== 270) { $this->rotationAngle = 0; } $this->rotationAngle = (360 - $this->rotationAngle) % 360; $this->box = null; }
[ "public", "function", "setRotationAngle", "(", "$", "rotationAngle", ")", "{", "$", "this", "->", "rotationAngle", "=", "(", "int", ")", "$", "rotationAngle", ";", "if", "(", "$", "this", "->", "rotationAngle", "!==", "90", "&&", "$", "this", "->", "rotationAngle", "!==", "180", "&&", "$", "this", "->", "rotationAngle", "!==", "270", ")", "{", "$", "this", "->", "rotationAngle", "=", "0", ";", "}", "$", "this", "->", "rotationAngle", "=", "(", "360", "-", "$", "this", "->", "rotationAngle", ")", "%", "360", ";", "$", "this", "->", "box", "=", "null", ";", "}" ]
Sets the rotation in degree. @param int
[ "Sets", "the", "rotation", "in", "degree", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINFontFile.php#L79-L88
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINFontFile.php
CINFontFile.getDimension
public function getDimension() { $w = 0.0; $h = 0.0; $box = $this->getBox(); if ($box !== null) { $minX = min(array($box[0], $box[2], $box[4], $box[6])); $maxX = max(array($box[0], $box[2], $box[4], $box[6])); $minY = min(array($box[1], $box[3], $box[5], $box[7])); $maxY = max(array($box[1], $box[3], $box[5], $box[7])); $w = $maxX - $minX; $h = $maxY - $minY; } $rotationAngle = $this->getRotationAngle(); if ($rotationAngle === 90 || $rotationAngle === 270) { return array($h + self::PHP_BOX_FIX, $w); } else { return array($w + self::PHP_BOX_FIX, $h); } }
php
public function getDimension() { $w = 0.0; $h = 0.0; $box = $this->getBox(); if ($box !== null) { $minX = min(array($box[0], $box[2], $box[4], $box[6])); $maxX = max(array($box[0], $box[2], $box[4], $box[6])); $minY = min(array($box[1], $box[3], $box[5], $box[7])); $maxY = max(array($box[1], $box[3], $box[5], $box[7])); $w = $maxX - $minX; $h = $maxY - $minY; } $rotationAngle = $this->getRotationAngle(); if ($rotationAngle === 90 || $rotationAngle === 270) { return array($h + self::PHP_BOX_FIX, $w); } else { return array($w + self::PHP_BOX_FIX, $h); } }
[ "public", "function", "getDimension", "(", ")", "{", "$", "w", "=", "0.0", ";", "$", "h", "=", "0.0", ";", "$", "box", "=", "$", "this", "->", "getBox", "(", ")", ";", "if", "(", "$", "box", "!==", "null", ")", "{", "$", "minX", "=", "min", "(", "array", "(", "$", "box", "[", "0", "]", ",", "$", "box", "[", "2", "]", ",", "$", "box", "[", "4", "]", ",", "$", "box", "[", "6", "]", ")", ")", ";", "$", "maxX", "=", "max", "(", "array", "(", "$", "box", "[", "0", "]", ",", "$", "box", "[", "2", "]", ",", "$", "box", "[", "4", "]", ",", "$", "box", "[", "6", "]", ")", ")", ";", "$", "minY", "=", "min", "(", "array", "(", "$", "box", "[", "1", "]", ",", "$", "box", "[", "3", "]", ",", "$", "box", "[", "5", "]", ",", "$", "box", "[", "7", "]", ")", ")", ";", "$", "maxY", "=", "max", "(", "array", "(", "$", "box", "[", "1", "]", ",", "$", "box", "[", "3", "]", ",", "$", "box", "[", "5", "]", ",", "$", "box", "[", "7", "]", ")", ")", ";", "$", "w", "=", "$", "maxX", "-", "$", "minX", ";", "$", "h", "=", "$", "maxY", "-", "$", "minY", ";", "}", "$", "rotationAngle", "=", "$", "this", "->", "getRotationAngle", "(", ")", ";", "if", "(", "$", "rotationAngle", "===", "90", "||", "$", "rotationAngle", "===", "270", ")", "{", "return", "array", "(", "$", "h", "+", "self", "::", "PHP_BOX_FIX", ",", "$", "w", ")", ";", "}", "else", "{", "return", "array", "(", "$", "w", "+", "self", "::", "PHP_BOX_FIX", ",", "$", "h", ")", ";", "}", "}" ]
Returns the width and height that the text takes to be written. @return int[]
[ "Returns", "the", "width", "and", "height", "that", "the", "text", "takes", "to", "be", "written", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINFontFile.php#L147-L168
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINFontFile.php
CINFontFile.draw
public function draw($im, $x, $y) { $drawingPosition = $this->getDrawingPosition($x, $y); imagettftext($im, $this->size, $this->rotationAngle, $drawingPosition[0], $drawingPosition[1], $this->foregroundColor->allocate($im), $this->path, $this->text); }
php
public function draw($im, $x, $y) { $drawingPosition = $this->getDrawingPosition($x, $y); imagettftext($im, $this->size, $this->rotationAngle, $drawingPosition[0], $drawingPosition[1], $this->foregroundColor->allocate($im), $this->path, $this->text); }
[ "public", "function", "draw", "(", "$", "im", ",", "$", "x", ",", "$", "y", ")", "{", "$", "drawingPosition", "=", "$", "this", "->", "getDrawingPosition", "(", "$", "x", ",", "$", "y", ")", ";", "imagettftext", "(", "$", "im", ",", "$", "this", "->", "size", ",", "$", "this", "->", "rotationAngle", ",", "$", "drawingPosition", "[", "0", "]", ",", "$", "drawingPosition", "[", "1", "]", ",", "$", "this", "->", "foregroundColor", "->", "allocate", "(", "$", "im", ")", ",", "$", "this", "->", "path", ",", "$", "this", "->", "text", ")", ";", "}" ]
Draws the text on the image at a specific position. $x and $y represent the left bottom corner. @param resource $im @param int $x @param int $y
[ "Draws", "the", "text", "on", "the", "image", "at", "a", "specific", "position", ".", "$x", "and", "$y", "represent", "the", "left", "bottom", "corner", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINFontFile.php#L178-L181
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINColor.php
CINColor.allocate
public function allocate(&$im) { $allocated = imagecolorallocate($im, $this->r, $this->g, $this->b); if ($this->transparent) { return imagecolortransparent($im, $allocated); } else { return $allocated; } }
php
public function allocate(&$im) { $allocated = imagecolorallocate($im, $this->r, $this->g, $this->b); if ($this->transparent) { return imagecolortransparent($im, $allocated); } else { return $allocated; } }
[ "public", "function", "allocate", "(", "&", "$", "im", ")", "{", "$", "allocated", "=", "imagecolorallocate", "(", "$", "im", ",", "$", "this", "->", "r", ",", "$", "this", "->", "g", ",", "$", "this", "->", "b", ")", ";", "if", "(", "$", "this", "->", "transparent", ")", "{", "return", "imagecolortransparent", "(", "$", "im", ",", "$", "allocated", ")", ";", "}", "else", "{", "return", "$", "allocated", ";", "}", "}" ]
Returns the int value for PHP color. @param resource $im @return int
[ "Returns", "the", "int", "value", "for", "PHP", "color", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINColor.php#L98-L105
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINDrawing.php
CINDrawing.draw
public function draw() { $size = $this->barcode->getDimension(0, 0); $this->w = max(1, $size[0]); $this->h = max(1, $size[1]); $this->init(); $this->barcode->draw($this->im); }
php
public function draw() { $size = $this->barcode->getDimension(0, 0); $this->w = max(1, $size[0]); $this->h = max(1, $size[1]); $this->init(); $this->barcode->draw($this->im); }
[ "public", "function", "draw", "(", ")", "{", "$", "size", "=", "$", "this", "->", "barcode", "->", "getDimension", "(", "0", ",", "0", ")", ";", "$", "this", "->", "w", "=", "max", "(", "1", ",", "$", "size", "[", "0", "]", ")", ";", "$", "this", "->", "h", "=", "max", "(", "1", ",", "$", "size", "[", "1", "]", ")", ";", "$", "this", "->", "init", "(", ")", ";", "$", "this", "->", "barcode", "->", "draw", "(", "$", "this", "->", "im", ")", ";", "}" ]
Draws the barcode on the image $im.
[ "Draws", "the", "barcode", "on", "the", "image", "$im", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINDrawing.php#L148-L154
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINDrawing.php
CINDrawing.finish
public function finish($image_style = self::IMG_FORMAT_PNG, $quality = 100) { $drawer = null; $im = $this->im; if ($this->rotateDegree > 0.0) { if (function_exists('imagerotate')) { $im = imagerotate($this->im, 360 - $this->rotateDegree, $this->color->allocate($this->im)); } else { throw new CINDrawException('The method imagerotate doesn\'t exist on your server. Do not use any rotation.'); } } if ($image_style === self::IMG_FORMAT_PNG) { $drawer = new CINDrawPNG($im); $drawer->setFilename($this->filename); $drawer->setDPI($this->dpi); } elseif ($image_style === self::IMG_FORMAT_JPEG) { $drawer = new CINDrawJPG($im); $drawer->setFilename($this->filename); $drawer->setDPI($this->dpi); $drawer->setQuality($quality); } elseif ($image_style === self::IMG_FORMAT_GIF) { // Some PHP versions have a bug if passing 2nd argument as null. if ($this->filename === null || $this->filename === '') { imagegif($im); } else { imagegif($im, $this->filename); } } elseif ($image_style === self::IMG_FORMAT_WBMP) { imagewbmp($im, $this->filename); } if ($drawer !== null) { $drawer->draw(); } }
php
public function finish($image_style = self::IMG_FORMAT_PNG, $quality = 100) { $drawer = null; $im = $this->im; if ($this->rotateDegree > 0.0) { if (function_exists('imagerotate')) { $im = imagerotate($this->im, 360 - $this->rotateDegree, $this->color->allocate($this->im)); } else { throw new CINDrawException('The method imagerotate doesn\'t exist on your server. Do not use any rotation.'); } } if ($image_style === self::IMG_FORMAT_PNG) { $drawer = new CINDrawPNG($im); $drawer->setFilename($this->filename); $drawer->setDPI($this->dpi); } elseif ($image_style === self::IMG_FORMAT_JPEG) { $drawer = new CINDrawJPG($im); $drawer->setFilename($this->filename); $drawer->setDPI($this->dpi); $drawer->setQuality($quality); } elseif ($image_style === self::IMG_FORMAT_GIF) { // Some PHP versions have a bug if passing 2nd argument as null. if ($this->filename === null || $this->filename === '') { imagegif($im); } else { imagegif($im, $this->filename); } } elseif ($image_style === self::IMG_FORMAT_WBMP) { imagewbmp($im, $this->filename); } if ($drawer !== null) { $drawer->draw(); } }
[ "public", "function", "finish", "(", "$", "image_style", "=", "self", "::", "IMG_FORMAT_PNG", ",", "$", "quality", "=", "100", ")", "{", "$", "drawer", "=", "null", ";", "$", "im", "=", "$", "this", "->", "im", ";", "if", "(", "$", "this", "->", "rotateDegree", ">", "0.0", ")", "{", "if", "(", "function_exists", "(", "'imagerotate'", ")", ")", "{", "$", "im", "=", "imagerotate", "(", "$", "this", "->", "im", ",", "360", "-", "$", "this", "->", "rotateDegree", ",", "$", "this", "->", "color", "->", "allocate", "(", "$", "this", "->", "im", ")", ")", ";", "}", "else", "{", "throw", "new", "CINDrawException", "(", "'The method imagerotate doesn\\'t exist on your server. Do not use any rotation.'", ")", ";", "}", "}", "if", "(", "$", "image_style", "===", "self", "::", "IMG_FORMAT_PNG", ")", "{", "$", "drawer", "=", "new", "CINDrawPNG", "(", "$", "im", ")", ";", "$", "drawer", "->", "setFilename", "(", "$", "this", "->", "filename", ")", ";", "$", "drawer", "->", "setDPI", "(", "$", "this", "->", "dpi", ")", ";", "}", "elseif", "(", "$", "image_style", "===", "self", "::", "IMG_FORMAT_JPEG", ")", "{", "$", "drawer", "=", "new", "CINDrawJPG", "(", "$", "im", ")", ";", "$", "drawer", "->", "setFilename", "(", "$", "this", "->", "filename", ")", ";", "$", "drawer", "->", "setDPI", "(", "$", "this", "->", "dpi", ")", ";", "$", "drawer", "->", "setQuality", "(", "$", "quality", ")", ";", "}", "elseif", "(", "$", "image_style", "===", "self", "::", "IMG_FORMAT_GIF", ")", "{", "// Some PHP versions have a bug if passing 2nd argument as null.\r", "if", "(", "$", "this", "->", "filename", "===", "null", "||", "$", "this", "->", "filename", "===", "''", ")", "{", "imagegif", "(", "$", "im", ")", ";", "}", "else", "{", "imagegif", "(", "$", "im", ",", "$", "this", "->", "filename", ")", ";", "}", "}", "elseif", "(", "$", "image_style", "===", "self", "::", "IMG_FORMAT_WBMP", ")", "{", "imagewbmp", "(", "$", "im", ",", "$", "this", "->", "filename", ")", ";", "}", "if", "(", "$", "drawer", "!==", "null", ")", "{", "$", "drawer", "->", "draw", "(", ")", ";", "}", "}" ]
Saves $im into the file (many format available). @param int $image_style @param int $quality
[ "Saves", "$im", "into", "the", "file", "(", "many", "format", "available", ")", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINDrawing.php#L162-L197
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINDrawing.php
CINDrawing.drawException
public function drawException($exception) { $this->w = 1; $this->h = 1; $this->init(); // Is the image big enough? $w = imagesx($this->im); $h = imagesy($this->im); $text = 'Error: ' . $exception->getMessage(); $width = imagefontwidth(2) * strlen($text); $height = imagefontheight(2); if ($width > $w || $height > $h) { $width = max($w, $width); $height = max($h, $height); // We change the size of the image $newimg = imagecreatetruecolor($width, $height); imagefill($newimg, 0, 0, imagecolorat($this->im, 0, 0)); imagecopy($newimg, $this->im, 0, 0, 0, 0, $w, $h); $this->im = $newimg; } $black = new CINColor('black'); imagestring($this->im, 2, 0, 0, $text, $black->allocate($this->im)); }
php
public function drawException($exception) { $this->w = 1; $this->h = 1; $this->init(); // Is the image big enough? $w = imagesx($this->im); $h = imagesy($this->im); $text = 'Error: ' . $exception->getMessage(); $width = imagefontwidth(2) * strlen($text); $height = imagefontheight(2); if ($width > $w || $height > $h) { $width = max($w, $width); $height = max($h, $height); // We change the size of the image $newimg = imagecreatetruecolor($width, $height); imagefill($newimg, 0, 0, imagecolorat($this->im, 0, 0)); imagecopy($newimg, $this->im, 0, 0, 0, 0, $w, $h); $this->im = $newimg; } $black = new CINColor('black'); imagestring($this->im, 2, 0, 0, $text, $black->allocate($this->im)); }
[ "public", "function", "drawException", "(", "$", "exception", ")", "{", "$", "this", "->", "w", "=", "1", ";", "$", "this", "->", "h", "=", "1", ";", "$", "this", "->", "init", "(", ")", ";", "// Is the image big enough?\r", "$", "w", "=", "imagesx", "(", "$", "this", "->", "im", ")", ";", "$", "h", "=", "imagesy", "(", "$", "this", "->", "im", ")", ";", "$", "text", "=", "'Error: '", ".", "$", "exception", "->", "getMessage", "(", ")", ";", "$", "width", "=", "imagefontwidth", "(", "2", ")", "*", "strlen", "(", "$", "text", ")", ";", "$", "height", "=", "imagefontheight", "(", "2", ")", ";", "if", "(", "$", "width", ">", "$", "w", "||", "$", "height", ">", "$", "h", ")", "{", "$", "width", "=", "max", "(", "$", "w", ",", "$", "width", ")", ";", "$", "height", "=", "max", "(", "$", "h", ",", "$", "height", ")", ";", "// We change the size of the image\r", "$", "newimg", "=", "imagecreatetruecolor", "(", "$", "width", ",", "$", "height", ")", ";", "imagefill", "(", "$", "newimg", ",", "0", ",", "0", ",", "imagecolorat", "(", "$", "this", "->", "im", ",", "0", ",", "0", ")", ")", ";", "imagecopy", "(", "$", "newimg", ",", "$", "this", "->", "im", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "w", ",", "$", "h", ")", ";", "$", "this", "->", "im", "=", "$", "newimg", ";", "}", "$", "black", "=", "new", "CINColor", "(", "'black'", ")", ";", "imagestring", "(", "$", "this", "->", "im", ",", "2", ",", "0", ",", "0", ",", "$", "text", ",", "$", "black", "->", "allocate", "(", "$", "this", "->", "im", ")", ")", ";", "}" ]
Writes the Error on the picture. @param Exception $exception
[ "Writes", "the", "Error", "on", "the", "picture", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINDrawing.php#L204-L230
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINDrawing.php
CINDrawing.init
private function init() { if ($this->im === null) { $this->im = imagecreatetruecolor($this->w, $this->h) or die('Can\'t Initialize the GD Libraty'); imagefilledrectangle($this->im, 0, 0, $this->w - 1, $this->h - 1, $this->color->allocate($this->im)); } }
php
private function init() { if ($this->im === null) { $this->im = imagecreatetruecolor($this->w, $this->h) or die('Can\'t Initialize the GD Libraty'); imagefilledrectangle($this->im, 0, 0, $this->w - 1, $this->h - 1, $this->color->allocate($this->im)); } }
[ "private", "function", "init", "(", ")", "{", "if", "(", "$", "this", "->", "im", "===", "null", ")", "{", "$", "this", "->", "im", "=", "imagecreatetruecolor", "(", "$", "this", "->", "w", ",", "$", "this", "->", "h", ")", "or", "die", "(", "'Can\\'t Initialize the GD Libraty'", ")", ";", "imagefilledrectangle", "(", "$", "this", "->", "im", ",", "0", ",", "0", ",", "$", "this", "->", "w", "-", "1", ",", "$", "this", "->", "h", "-", "1", ",", "$", "this", "->", "color", "->", "allocate", "(", "$", "this", "->", "im", ")", ")", ";", "}", "}" ]
Init Image and color background.
[ "Init", "Image", "and", "color", "background", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINDrawing.php#L242-L248
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupcext5.php
CINupcext5.addDefaultLabel
protected function addDefaultLabel() { parent::addDefaultLabel(); if ($this->defaultLabel !== null) { $this->defaultLabel->setPosition(CINLabel::POSITION_TOP); } }
php
protected function addDefaultLabel() { parent::addDefaultLabel(); if ($this->defaultLabel !== null) { $this->defaultLabel->setPosition(CINLabel::POSITION_TOP); } }
[ "protected", "function", "addDefaultLabel", "(", ")", "{", "parent", "::", "addDefaultLabel", "(", ")", ";", "if", "(", "$", "this", "->", "defaultLabel", "!==", "null", ")", "{", "$", "this", "->", "defaultLabel", "->", "setPosition", "(", "CINLabel", "::", "POSITION_TOP", ")", ";", "}", "}" ]
Adds the default label.
[ "Adds", "the", "default", "label", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupcext5.php#L110-L116
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupcext5.php
CINupcext5.calculateChecksum
protected function calculateChecksum() { // Calculating Checksum // Consider the right-most digit of the message to be in an "odd" position, // and assign odd/even to each character moving from right to left // Odd Position = 3, Even Position = 9 // Multiply it by the number // Add all of that and do ?mod10 $odd = true; $this->checksumValue = 0; $c = strlen($this->text); for ($i = $c; $i > 0; $i--) { if ($odd === true) { $multiplier = 3; $odd = false; } else { $multiplier = 9; $odd = true; } if (!isset($this->keys[$this->text[$i - 1]])) { return; } $this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier; } $this->checksumValue = $this->checksumValue % 10; }
php
protected function calculateChecksum() { // Calculating Checksum // Consider the right-most digit of the message to be in an "odd" position, // and assign odd/even to each character moving from right to left // Odd Position = 3, Even Position = 9 // Multiply it by the number // Add all of that and do ?mod10 $odd = true; $this->checksumValue = 0; $c = strlen($this->text); for ($i = $c; $i > 0; $i--) { if ($odd === true) { $multiplier = 3; $odd = false; } else { $multiplier = 9; $odd = true; } if (!isset($this->keys[$this->text[$i - 1]])) { return; } $this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier; } $this->checksumValue = $this->checksumValue % 10; }
[ "protected", "function", "calculateChecksum", "(", ")", "{", "// Calculating Checksum\r", "// Consider the right-most digit of the message to be in an \"odd\" position,\r", "// and assign odd/even to each character moving from right to left\r", "// Odd Position = 3, Even Position = 9\r", "// Multiply it by the number\r", "// Add all of that and do ?mod10\r", "$", "odd", "=", "true", ";", "$", "this", "->", "checksumValue", "=", "0", ";", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "for", "(", "$", "i", "=", "$", "c", ";", "$", "i", ">", "0", ";", "$", "i", "--", ")", "{", "if", "(", "$", "odd", "===", "true", ")", "{", "$", "multiplier", "=", "3", ";", "$", "odd", "=", "false", ";", "}", "else", "{", "$", "multiplier", "=", "9", ";", "$", "odd", "=", "true", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "keys", "[", "$", "this", "->", "text", "[", "$", "i", "-", "1", "]", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "checksumValue", "+=", "$", "this", "->", "keys", "[", "$", "this", "->", "text", "[", "$", "i", "-", "1", "]", "]", "*", "$", "multiplier", ";", "}", "$", "this", "->", "checksumValue", "=", "$", "this", "->", "checksumValue", "%", "10", ";", "}" ]
Overloaded method to calculate checksum.
[ "Overloaded", "method", "to", "calculate", "checksum", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupcext5.php#L145-L172
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupca.php
CINupca.draw
public function draw($im) { // The following code is exactly the same as EAN13. We just add a 0 in front of the code ! $this->text = '0' . $this->text; // We will remove it at the end... don't worry parent::draw($im); // We remove the 0 in front, as we said :) $this->text = substr($this->text, 1); }
php
public function draw($im) { // The following code is exactly the same as EAN13. We just add a 0 in front of the code ! $this->text = '0' . $this->text; // We will remove it at the end... don't worry parent::draw($im); // We remove the 0 in front, as we said :) $this->text = substr($this->text, 1); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "// The following code is exactly the same as EAN13. We just add a 0 in front of the code !\r", "$", "this", "->", "text", "=", "'0'", ".", "$", "this", "->", "text", ";", "// We will remove it at the end... don't worry\r", "parent", "::", "draw", "(", "$", "im", ")", ";", "// We remove the 0 in front, as we said :)\r", "$", "this", "->", "text", "=", "substr", "(", "$", "this", "->", "text", ",", "1", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupca.php#L41-L49
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupca.php
CINupca.drawExtendedBars
protected function drawExtendedBars($im, $plus) { $temp_text = $this->text . $this->keys[$this->checksumValue]; $rememberX = $this->positionX; $rememberH = $this->thickness; // We increase the bars // First 2 Bars $this->thickness = $this->thickness + intval($plus / $this->scale); $this->positionX = 0; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); // Attemping to increase the 2 following bars $this->positionX += 1; $temp_value = $this->findCode($temp_text[1]); $this->drawChar($im, $temp_value, false); // Center Guard Bar $this->positionX += 36; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); // Attemping to increase the 2 last bars $this->positionX += 37; $temp_value = $this->findCode($temp_text[12]); $this->drawChar($im, $temp_value, true); // Completly last bars $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX = $rememberX; $this->thickness = $rememberH; }
php
protected function drawExtendedBars($im, $plus) { $temp_text = $this->text . $this->keys[$this->checksumValue]; $rememberX = $this->positionX; $rememberH = $this->thickness; // We increase the bars // First 2 Bars $this->thickness = $this->thickness + intval($plus / $this->scale); $this->positionX = 0; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); // Attemping to increase the 2 following bars $this->positionX += 1; $temp_value = $this->findCode($temp_text[1]); $this->drawChar($im, $temp_value, false); // Center Guard Bar $this->positionX += 36; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); // Attemping to increase the 2 last bars $this->positionX += 37; $temp_value = $this->findCode($temp_text[12]); $this->drawChar($im, $temp_value, true); // Completly last bars $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX = $rememberX; $this->thickness = $rememberH; }
[ "protected", "function", "drawExtendedBars", "(", "$", "im", ",", "$", "plus", ")", "{", "$", "temp_text", "=", "$", "this", "->", "text", ".", "$", "this", "->", "keys", "[", "$", "this", "->", "checksumValue", "]", ";", "$", "rememberX", "=", "$", "this", "->", "positionX", ";", "$", "rememberH", "=", "$", "this", "->", "thickness", ";", "// We increase the bars\r", "// First 2 Bars\r", "$", "this", "->", "thickness", "=", "$", "this", "->", "thickness", "+", "intval", "(", "$", "plus", "/", "$", "this", "->", "scale", ")", ";", "$", "this", "->", "positionX", "=", "0", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "2", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "// Attemping to increase the 2 following bars\r", "$", "this", "->", "positionX", "+=", "1", ";", "$", "temp_value", "=", "$", "this", "->", "findCode", "(", "$", "temp_text", "[", "1", "]", ")", ";", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "temp_value", ",", "false", ")", ";", "// Center Guard Bar\r", "$", "this", "->", "positionX", "+=", "36", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "2", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "// Attemping to increase the 2 last bars\r", "$", "this", "->", "positionX", "+=", "37", ";", "$", "temp_value", "=", "$", "this", "->", "findCode", "(", "$", "temp_text", "[", "12", "]", ")", ";", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "temp_value", ",", "true", ")", ";", "// Completly last bars\r", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "2", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "=", "$", "rememberX", ";", "$", "this", "->", "thickness", "=", "$", "rememberH", ";", "}" ]
Draws the extended bars on the image. @param resource $im @param int $plus
[ "Draws", "the", "extended", "bars", "on", "the", "image", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupca.php#L57-L93
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINothercode.php
CINothercode.draw
public function draw($im) { $this->drawChar($im, $this->text, true); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
php
public function draw($im) { $this->drawChar($im, $this->text, true); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "text", ",", "true", ")", ";", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINothercode.php#L35-L38
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINothercode.php
CINothercode.getLabel
public function getLabel() { $label = $this->label; if ($this->label === CINBarcode1D::AUTO_LABEL) { $label = ''; } return $label; }
php
public function getLabel() { $label = $this->label; if ($this->label === CINBarcode1D::AUTO_LABEL) { $label = ''; } return $label; }
[ "public", "function", "getLabel", "(", ")", "{", "$", "label", "=", "$", "this", "->", "label", ";", "if", "(", "$", "this", "->", "label", "===", "CINBarcode1D", "::", "AUTO_LABEL", ")", "{", "$", "label", "=", "''", ";", "}", "return", "$", "label", ";", "}" ]
Gets the label. If the label was set to CINBarcode1D::AUTO_LABEL, the label will display the value from the text parsed. @return string
[ "Gets", "the", "label", ".", "If", "the", "label", "was", "set", "to", "CINBarcode1D", "::", "AUTO_LABEL", "the", "label", "will", "display", "the", "value", "from", "the", "text", "parsed", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINothercode.php#L46-L53
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINothercode.php
CINothercode.getDimension
public function getDimension($w, $h) { $array = str_split($this->text, 1); $textlength = array_sum($array) + count($array); $w += $textlength; $h += $this->thickness; return parent::getDimension($w, $h); }
php
public function getDimension($w, $h) { $array = str_split($this->text, 1); $textlength = array_sum($array) + count($array); $w += $textlength; $h += $this->thickness; return parent::getDimension($w, $h); }
[ "public", "function", "getDimension", "(", "$", "w", ",", "$", "h", ")", "{", "$", "array", "=", "str_split", "(", "$", "this", "->", "text", ",", "1", ")", ";", "$", "textlength", "=", "array_sum", "(", "$", "array", ")", "+", "count", "(", "$", "array", ")", ";", "$", "w", "+=", "$", "textlength", ";", "$", "h", "+=", "$", "this", "->", "thickness", ";", "return", "parent", "::", "getDimension", "(", "$", "w", ",", "$", "h", ")", ";", "}" ]
Returns the maximal size of a barcode. @param int $w @param int $h @return int[]
[ "Returns", "the", "maximal", "size", "of", "a", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINothercode.php#L62-L69
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINisbn.php
CINisbn.addDefaultLabel
protected function addDefaultLabel() { if ($this->isDefaultEanLabelEnabled()) { $isbn = $this->createISBNText(); $font = $this->font; $topLabel = new CINLabel($isbn, $font, CINLabel::POSITION_TOP, CINLabel::ALIGN_CENTER); $this->addLabel($topLabel); } parent::addDefaultLabel(); }
php
protected function addDefaultLabel() { if ($this->isDefaultEanLabelEnabled()) { $isbn = $this->createISBNText(); $font = $this->font; $topLabel = new CINLabel($isbn, $font, CINLabel::POSITION_TOP, CINLabel::ALIGN_CENTER); $this->addLabel($topLabel); } parent::addDefaultLabel(); }
[ "protected", "function", "addDefaultLabel", "(", ")", "{", "if", "(", "$", "this", "->", "isDefaultEanLabelEnabled", "(", ")", ")", "{", "$", "isbn", "=", "$", "this", "->", "createISBNText", "(", ")", ";", "$", "font", "=", "$", "this", "->", "font", ";", "$", "topLabel", "=", "new", "CINLabel", "(", "$", "isbn", ",", "$", "font", ",", "CINLabel", "::", "POSITION_TOP", ",", "CINLabel", "::", "ALIGN_CENTER", ")", ";", "$", "this", "->", "addLabel", "(", "$", "topLabel", ")", ";", "}", "parent", "::", "addDefaultLabel", "(", ")", ";", "}" ]
Adds the default label.
[ "Adds", "the", "default", "label", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINisbn.php#L44-L55
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINisbn.php
CINisbn.setGS1
public function setGS1($gs1) { $gs1 = (int)$gs1; if ($gs1 !== self::GS1_AUTO && $gs1 !== self::GS1_PREFIX978 && $gs1 !== self::GS1_PREFIX979) { throw new CINArgumentException('The GS1 argument must be CINisbn::GS1_AUTO, CINisbn::GS1_PREFIX978, or CINisbn::GS1_PREFIX979', 'gs1'); } $this->gs1 = $gs1; }
php
public function setGS1($gs1) { $gs1 = (int)$gs1; if ($gs1 !== self::GS1_AUTO && $gs1 !== self::GS1_PREFIX978 && $gs1 !== self::GS1_PREFIX979) { throw new CINArgumentException('The GS1 argument must be CINisbn::GS1_AUTO, CINisbn::GS1_PREFIX978, or CINisbn::GS1_PREFIX979', 'gs1'); } $this->gs1 = $gs1; }
[ "public", "function", "setGS1", "(", "$", "gs1", ")", "{", "$", "gs1", "=", "(", "int", ")", "$", "gs1", ";", "if", "(", "$", "gs1", "!==", "self", "::", "GS1_AUTO", "&&", "$", "gs1", "!==", "self", "::", "GS1_PREFIX978", "&&", "$", "gs1", "!==", "self", "::", "GS1_PREFIX979", ")", "{", "throw", "new", "CINArgumentException", "(", "'The GS1 argument must be CINisbn::GS1_AUTO, CINisbn::GS1_PREFIX978, or CINisbn::GS1_PREFIX979'", ",", "'gs1'", ")", ";", "}", "$", "this", "->", "gs1", "=", "$", "gs1", ";", "}" ]
Sets the first numbers of the barcode. - GS1_AUTO: Adds 978 before the code - GS1_PREFIX978: Adds 978 before the code - GS1_PREFIX979: Adds 979 before the code @param int $gs1
[ "Sets", "the", "first", "numbers", "of", "the", "barcode", ".", "-", "GS1_AUTO", ":", "Adds", "978", "before", "the", "code", "-", "GS1_PREFIX978", ":", "Adds", "978", "before", "the", "code", "-", "GS1_PREFIX979", ":", "Adds", "979", "before", "the", "code" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINisbn.php#L65-L72
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINisbn.php
CINisbn.checkCharsAllowed
protected function checkCharsAllowed() { $c = strlen($this->text); // Special case, if we have 10 digits, the last one can be X if ($c === 10) { if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') { throw new CINParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.'); } // Drop the last char $this->text = substr($this->text, 0, 9); } return parent::checkCharsAllowed(); }
php
protected function checkCharsAllowed() { $c = strlen($this->text); // Special case, if we have 10 digits, the last one can be X if ($c === 10) { if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') { throw new CINParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.'); } // Drop the last char $this->text = substr($this->text, 0, 9); } return parent::checkCharsAllowed(); }
[ "protected", "function", "checkCharsAllowed", "(", ")", "{", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "// Special case, if we have 10 digits, the last one can be X\r", "if", "(", "$", "c", "===", "10", ")", "{", "if", "(", "array_search", "(", "$", "this", "->", "text", "[", "9", "]", ",", "$", "this", "->", "keys", ")", "===", "false", "&&", "$", "this", "->", "text", "[", "9", "]", "!==", "'X'", ")", "{", "throw", "new", "CINParseException", "(", "'isbn'", ",", "'The character \\''", ".", "$", "this", "->", "text", "[", "9", "]", ".", "'\\' is not allowed.'", ")", ";", "}", "// Drop the last char\r", "$", "this", "->", "text", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "9", ")", ";", "}", "return", "parent", "::", "checkCharsAllowed", "(", ")", ";", "}" ]
Check chars allowed.
[ "Check", "chars", "allowed", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINisbn.php#L77-L91
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINisbn.php
CINisbn.checkCorrectLength
protected function checkCorrectLength() { $c = strlen($this->text); // If we have 13 chars just flush the last one if ($c === 13) { $this->text = substr($this->text, 0, 12); } elseif ($c === 9 || $c === 10) { if ($c === 10) { // Before dropping it, we check if it's legal if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') { throw new CINParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.'); } $this->text = substr($this->text, 0, 9); } if ($this->gs1 === self::GS1_AUTO || $this->gs1 === self::GS1_PREFIX978) { $this->text = '978' . $this->text; } elseif ($this->gs1 === self::GS1_PREFIX979) { $this->text = '979' . $this->text; } } elseif ($c !== 12) { throw new CINParseException('isbn', 'The code parsed must be 9, 10, 12, or 13 digits long.'); } }
php
protected function checkCorrectLength() { $c = strlen($this->text); // If we have 13 chars just flush the last one if ($c === 13) { $this->text = substr($this->text, 0, 12); } elseif ($c === 9 || $c === 10) { if ($c === 10) { // Before dropping it, we check if it's legal if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') { throw new CINParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.'); } $this->text = substr($this->text, 0, 9); } if ($this->gs1 === self::GS1_AUTO || $this->gs1 === self::GS1_PREFIX978) { $this->text = '978' . $this->text; } elseif ($this->gs1 === self::GS1_PREFIX979) { $this->text = '979' . $this->text; } } elseif ($c !== 12) { throw new CINParseException('isbn', 'The code parsed must be 9, 10, 12, or 13 digits long.'); } }
[ "protected", "function", "checkCorrectLength", "(", ")", "{", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "// If we have 13 chars just flush the last one\r", "if", "(", "$", "c", "===", "13", ")", "{", "$", "this", "->", "text", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "12", ")", ";", "}", "elseif", "(", "$", "c", "===", "9", "||", "$", "c", "===", "10", ")", "{", "if", "(", "$", "c", "===", "10", ")", "{", "// Before dropping it, we check if it's legal\r", "if", "(", "array_search", "(", "$", "this", "->", "text", "[", "9", "]", ",", "$", "this", "->", "keys", ")", "===", "false", "&&", "$", "this", "->", "text", "[", "9", "]", "!==", "'X'", ")", "{", "throw", "new", "CINParseException", "(", "'isbn'", ",", "'The character \\''", ".", "$", "this", "->", "text", "[", "9", "]", ".", "'\\' is not allowed.'", ")", ";", "}", "$", "this", "->", "text", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "9", ")", ";", "}", "if", "(", "$", "this", "->", "gs1", "===", "self", "::", "GS1_AUTO", "||", "$", "this", "->", "gs1", "===", "self", "::", "GS1_PREFIX978", ")", "{", "$", "this", "->", "text", "=", "'978'", ".", "$", "this", "->", "text", ";", "}", "elseif", "(", "$", "this", "->", "gs1", "===", "self", "::", "GS1_PREFIX979", ")", "{", "$", "this", "->", "text", "=", "'979'", ".", "$", "this", "->", "text", ";", "}", "}", "elseif", "(", "$", "c", "!==", "12", ")", "{", "throw", "new", "CINParseException", "(", "'isbn'", ",", "'The code parsed must be 9, 10, 12, or 13 digits long.'", ")", ";", "}", "}" ]
Check correct length.
[ "Check", "correct", "length", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINisbn.php#L96-L120
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINisbn.php
CINisbn.createISBNText
private function createISBNText() { $isbn = ''; if (!empty($this->text)) { // We try to create the ISBN Text... the hyphen really depends the ISBN agency. // We just put one before the checksum and one after the GS1 if present. $c = strlen($this->text); if ($c === 12 || $c === 13) { // If we have 13 characters now, just transform it temporarily to find the checksum... // Further in the code we take care of that anyway. $lastCharacter = ''; if ($c === 13) { $lastCharacter = $this->text[12]; $this->text = substr($this->text, 0, 12); } $checksum = $this->processChecksum(); $isbn = 'ISBN ' . substr($this->text, 0, 3) . '-' . substr($this->text, 3, 9) . '-' . $checksum; // Put the last character back if ($c === 13) { $this->text .= $lastCharacter; } } elseif ($c === 9 || $c === 10) { $checksum = 0; for ($i = 10; $i >= 2; $i--) { $checksum += $this->text[10 - $i] * $i; } $checksum = 11 - $checksum % 11; if ($checksum === 10) { $checksum = 'X'; // Changing type } $isbn = 'ISBN ' . substr($this->text, 0, 9) . '-' . $checksum; } } return $isbn; }
php
private function createISBNText() { $isbn = ''; if (!empty($this->text)) { // We try to create the ISBN Text... the hyphen really depends the ISBN agency. // We just put one before the checksum and one after the GS1 if present. $c = strlen($this->text); if ($c === 12 || $c === 13) { // If we have 13 characters now, just transform it temporarily to find the checksum... // Further in the code we take care of that anyway. $lastCharacter = ''; if ($c === 13) { $lastCharacter = $this->text[12]; $this->text = substr($this->text, 0, 12); } $checksum = $this->processChecksum(); $isbn = 'ISBN ' . substr($this->text, 0, 3) . '-' . substr($this->text, 3, 9) . '-' . $checksum; // Put the last character back if ($c === 13) { $this->text .= $lastCharacter; } } elseif ($c === 9 || $c === 10) { $checksum = 0; for ($i = 10; $i >= 2; $i--) { $checksum += $this->text[10 - $i] * $i; } $checksum = 11 - $checksum % 11; if ($checksum === 10) { $checksum = 'X'; // Changing type } $isbn = 'ISBN ' . substr($this->text, 0, 9) . '-' . $checksum; } } return $isbn; }
[ "private", "function", "createISBNText", "(", ")", "{", "$", "isbn", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "text", ")", ")", "{", "// We try to create the ISBN Text... the hyphen really depends the ISBN agency.\r", "// We just put one before the checksum and one after the GS1 if present.\r", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "if", "(", "$", "c", "===", "12", "||", "$", "c", "===", "13", ")", "{", "// If we have 13 characters now, just transform it temporarily to find the checksum...\r", "// Further in the code we take care of that anyway.\r", "$", "lastCharacter", "=", "''", ";", "if", "(", "$", "c", "===", "13", ")", "{", "$", "lastCharacter", "=", "$", "this", "->", "text", "[", "12", "]", ";", "$", "this", "->", "text", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "12", ")", ";", "}", "$", "checksum", "=", "$", "this", "->", "processChecksum", "(", ")", ";", "$", "isbn", "=", "'ISBN '", ".", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "3", ")", ".", "'-'", ".", "substr", "(", "$", "this", "->", "text", ",", "3", ",", "9", ")", ".", "'-'", ".", "$", "checksum", ";", "// Put the last character back\r", "if", "(", "$", "c", "===", "13", ")", "{", "$", "this", "->", "text", ".=", "$", "lastCharacter", ";", "}", "}", "elseif", "(", "$", "c", "===", "9", "||", "$", "c", "===", "10", ")", "{", "$", "checksum", "=", "0", ";", "for", "(", "$", "i", "=", "10", ";", "$", "i", ">=", "2", ";", "$", "i", "--", ")", "{", "$", "checksum", "+=", "$", "this", "->", "text", "[", "10", "-", "$", "i", "]", "*", "$", "i", ";", "}", "$", "checksum", "=", "11", "-", "$", "checksum", "%", "11", ";", "if", "(", "$", "checksum", "===", "10", ")", "{", "$", "checksum", "=", "'X'", ";", "// Changing type\r", "}", "$", "isbn", "=", "'ISBN '", ".", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "9", ")", ".", "'-'", ".", "$", "checksum", ";", "}", "}", "return", "$", "isbn", ";", "}" ]
Creates the ISBN text. @return string
[ "Creates", "the", "ISBN", "text", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINisbn.php#L127-L165
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.setTrackingCode
public function setTrackingCode($barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber) { $barcodeIdentifier = (string)(int)$barcodeIdentifier; $serviceTypeIdentifier = (int)$serviceTypeIdentifier; $mailerIdentifier = (int)$mailerIdentifier; $serialNumber = (string)(int)$serialNumber; $barcodeIdentifier = str_pad($barcodeIdentifier, 2, '0', STR_PAD_LEFT); if (strlen($barcodeIdentifier) !== 2) { throw new CINArgumentException('Barcode Identifier must contain 2 digits.', 'barcodeIdentifier'); } $barcodeIdentifierSecondNumber = $barcodeIdentifier[1]; if ($barcodeIdentifierSecondNumber !== '0' && $barcodeIdentifierSecondNumber !== '1' && $barcodeIdentifierSecondNumber !== '2' && $barcodeIdentifierSecondNumber !== '3' && $barcodeIdentifierSecondNumber !== '4') { throw new CINArgumentException('Barcode Identifier second digit must be a number between 0 and 4.', 'barcodeIdentifier'); } if ($serviceTypeIdentifier < 0 || $serviceTypeIdentifier > 999) { throw new CINArgumentException('Service Type Identifier must be between 0 and 999.', 'serviceTypeIdentifier'); } $mailerIdentifierLength = 6; if ($mailerIdentifier > 899999) { $mailerIdentifierLength = 9; } if ($mailerIdentifierLength === 9 && strlen($serialNumber) > 6) { throw new CINArgumentException('If the Serial Number has more than 6 digits, the Mailer Identifier must be lower than 900000.', 'mailerIdentifier'); } if ($mailerIdentifierLength === 9) { if ($mailerIdentifierLength < 0 || $mailerIdentifier > 999999999) { throw new CINArgumentException('Mailer Identifier must be between 0 and 999999999.', 'mailerIdentifier'); } } $this->barcodeIdentifier = $barcodeIdentifier; $this->serviceTypeIdentifier = str_pad($serviceTypeIdentifier, 3, '0', STR_PAD_LEFT); $this->mailerIdentifier = str_pad($mailerIdentifier, $mailerIdentifierLength, '0', STR_PAD_LEFT); $this->serialNumber = str_pad((int)$serialNumber, $mailerIdentifierLength === 6 ? 9 : 6, '0', STR_PAD_LEFT); }
php
public function setTrackingCode($barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber) { $barcodeIdentifier = (string)(int)$barcodeIdentifier; $serviceTypeIdentifier = (int)$serviceTypeIdentifier; $mailerIdentifier = (int)$mailerIdentifier; $serialNumber = (string)(int)$serialNumber; $barcodeIdentifier = str_pad($barcodeIdentifier, 2, '0', STR_PAD_LEFT); if (strlen($barcodeIdentifier) !== 2) { throw new CINArgumentException('Barcode Identifier must contain 2 digits.', 'barcodeIdentifier'); } $barcodeIdentifierSecondNumber = $barcodeIdentifier[1]; if ($barcodeIdentifierSecondNumber !== '0' && $barcodeIdentifierSecondNumber !== '1' && $barcodeIdentifierSecondNumber !== '2' && $barcodeIdentifierSecondNumber !== '3' && $barcodeIdentifierSecondNumber !== '4') { throw new CINArgumentException('Barcode Identifier second digit must be a number between 0 and 4.', 'barcodeIdentifier'); } if ($serviceTypeIdentifier < 0 || $serviceTypeIdentifier > 999) { throw new CINArgumentException('Service Type Identifier must be between 0 and 999.', 'serviceTypeIdentifier'); } $mailerIdentifierLength = 6; if ($mailerIdentifier > 899999) { $mailerIdentifierLength = 9; } if ($mailerIdentifierLength === 9 && strlen($serialNumber) > 6) { throw new CINArgumentException('If the Serial Number has more than 6 digits, the Mailer Identifier must be lower than 900000.', 'mailerIdentifier'); } if ($mailerIdentifierLength === 9) { if ($mailerIdentifierLength < 0 || $mailerIdentifier > 999999999) { throw new CINArgumentException('Mailer Identifier must be between 0 and 999999999.', 'mailerIdentifier'); } } $this->barcodeIdentifier = $barcodeIdentifier; $this->serviceTypeIdentifier = str_pad($serviceTypeIdentifier, 3, '0', STR_PAD_LEFT); $this->mailerIdentifier = str_pad($mailerIdentifier, $mailerIdentifierLength, '0', STR_PAD_LEFT); $this->serialNumber = str_pad((int)$serialNumber, $mailerIdentifierLength === 6 ? 9 : 6, '0', STR_PAD_LEFT); }
[ "public", "function", "setTrackingCode", "(", "$", "barcodeIdentifier", ",", "$", "serviceTypeIdentifier", ",", "$", "mailerIdentifier", ",", "$", "serialNumber", ")", "{", "$", "barcodeIdentifier", "=", "(", "string", ")", "(", "int", ")", "$", "barcodeIdentifier", ";", "$", "serviceTypeIdentifier", "=", "(", "int", ")", "$", "serviceTypeIdentifier", ";", "$", "mailerIdentifier", "=", "(", "int", ")", "$", "mailerIdentifier", ";", "$", "serialNumber", "=", "(", "string", ")", "(", "int", ")", "$", "serialNumber", ";", "$", "barcodeIdentifier", "=", "str_pad", "(", "$", "barcodeIdentifier", ",", "2", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "if", "(", "strlen", "(", "$", "barcodeIdentifier", ")", "!==", "2", ")", "{", "throw", "new", "CINArgumentException", "(", "'Barcode Identifier must contain 2 digits.'", ",", "'barcodeIdentifier'", ")", ";", "}", "$", "barcodeIdentifierSecondNumber", "=", "$", "barcodeIdentifier", "[", "1", "]", ";", "if", "(", "$", "barcodeIdentifierSecondNumber", "!==", "'0'", "&&", "$", "barcodeIdentifierSecondNumber", "!==", "'1'", "&&", "$", "barcodeIdentifierSecondNumber", "!==", "'2'", "&&", "$", "barcodeIdentifierSecondNumber", "!==", "'3'", "&&", "$", "barcodeIdentifierSecondNumber", "!==", "'4'", ")", "{", "throw", "new", "CINArgumentException", "(", "'Barcode Identifier second digit must be a number between 0 and 4.'", ",", "'barcodeIdentifier'", ")", ";", "}", "if", "(", "$", "serviceTypeIdentifier", "<", "0", "||", "$", "serviceTypeIdentifier", ">", "999", ")", "{", "throw", "new", "CINArgumentException", "(", "'Service Type Identifier must be between 0 and 999.'", ",", "'serviceTypeIdentifier'", ")", ";", "}", "$", "mailerIdentifierLength", "=", "6", ";", "if", "(", "$", "mailerIdentifier", ">", "899999", ")", "{", "$", "mailerIdentifierLength", "=", "9", ";", "}", "if", "(", "$", "mailerIdentifierLength", "===", "9", "&&", "strlen", "(", "$", "serialNumber", ")", ">", "6", ")", "{", "throw", "new", "CINArgumentException", "(", "'If the Serial Number has more than 6 digits, the Mailer Identifier must be lower than 900000.'", ",", "'mailerIdentifier'", ")", ";", "}", "if", "(", "$", "mailerIdentifierLength", "===", "9", ")", "{", "if", "(", "$", "mailerIdentifierLength", "<", "0", "||", "$", "mailerIdentifier", ">", "999999999", ")", "{", "throw", "new", "CINArgumentException", "(", "'Mailer Identifier must be between 0 and 999999999.'", ",", "'mailerIdentifier'", ")", ";", "}", "}", "$", "this", "->", "barcodeIdentifier", "=", "$", "barcodeIdentifier", ";", "$", "this", "->", "serviceTypeIdentifier", "=", "str_pad", "(", "$", "serviceTypeIdentifier", ",", "3", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "this", "->", "mailerIdentifier", "=", "str_pad", "(", "$", "mailerIdentifier", ",", "$", "mailerIdentifierLength", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "this", "->", "serialNumber", "=", "str_pad", "(", "(", "int", ")", "$", "serialNumber", ",", "$", "mailerIdentifierLength", "===", "6", "?", "9", ":", "6", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "}" ]
Sets the tracking code. @param int $barcodeIdentifier 2-digit number. 2nd digit must be 0-4 @param int $serviceTypeIdentifier 3 digits @param int $mailerIdentifier 6 or 9 digits @param int $serialNumber 9 (if mailerId is 6) or 6 digits (if mailerId is 9)
[ "Sets", "the", "tracking", "code", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L274-L314
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.parse
public function parse($text) { parent::parse($text); $number = self::executeStep1($this->text, $this->barcodeIdentifier, $this->serviceTypeIdentifier, $this->mailerIdentifier, $this->serialNumber); $crc = self::executeStep2($number); $codewords = self::executeStep3($number); $codewords = self::executeStep4($codewords, $crc); $characters = self::executeStep5($codewords, $crc); $this->data = self::executeStep6($characters); }
php
public function parse($text) { parent::parse($text); $number = self::executeStep1($this->text, $this->barcodeIdentifier, $this->serviceTypeIdentifier, $this->mailerIdentifier, $this->serialNumber); $crc = self::executeStep2($number); $codewords = self::executeStep3($number); $codewords = self::executeStep4($codewords, $crc); $characters = self::executeStep5($codewords, $crc); $this->data = self::executeStep6($characters); }
[ "public", "function", "parse", "(", "$", "text", ")", "{", "parent", "::", "parse", "(", "$", "text", ")", ";", "$", "number", "=", "self", "::", "executeStep1", "(", "$", "this", "->", "text", ",", "$", "this", "->", "barcodeIdentifier", ",", "$", "this", "->", "serviceTypeIdentifier", ",", "$", "this", "->", "mailerIdentifier", ",", "$", "this", "->", "serialNumber", ")", ";", "$", "crc", "=", "self", "::", "executeStep2", "(", "$", "number", ")", ";", "$", "codewords", "=", "self", "::", "executeStep3", "(", "$", "number", ")", ";", "$", "codewords", "=", "self", "::", "executeStep4", "(", "$", "codewords", ",", "$", "crc", ")", ";", "$", "characters", "=", "self", "::", "executeStep5", "(", "$", "codewords", ",", "$", "crc", ")", ";", "$", "this", "->", "data", "=", "self", "::", "executeStep6", "(", "$", "characters", ")", ";", "}" ]
Parses the text before displaying it. @param mixed $text
[ "Parses", "the", "text", "before", "displaying", "it", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L321-L330
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.draw
public function draw($im) { if ($this->quietZone) { $this->positionX += 9; } $c = strlen($this->data); for ($i = 0; $i < $c; $i++) { $this->drawChar($im, $this->data[$i]); } $this->drawText($im, 0, 0, $this->positionX, $this->thickness + ($this->quietZone ? 4 : 0)); }
php
public function draw($im) { if ($this->quietZone) { $this->positionX += 9; } $c = strlen($this->data); for ($i = 0; $i < $c; $i++) { $this->drawChar($im, $this->data[$i]); } $this->drawText($im, 0, 0, $this->positionX, $this->thickness + ($this->quietZone ? 4 : 0)); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "if", "(", "$", "this", "->", "quietZone", ")", "{", "$", "this", "->", "positionX", "+=", "9", ";", "}", "$", "c", "=", "strlen", "(", "$", "this", "->", "data", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "data", "[", "$", "i", "]", ")", ";", "}", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", "+", "(", "$", "this", "->", "quietZone", "?", "4", ":", "0", ")", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L337-L348
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.getDimension
public function getDimension($w, $h) { $w += 65 * 3; $h += $this->thickness; // We remove the white on the right $w -= 1.56; if ($this->quietZone) { $w += 18; $h += 4; } return parent::getDimension($w, $h); }
php
public function getDimension($w, $h) { $w += 65 * 3; $h += $this->thickness; // We remove the white on the right $w -= 1.56; if ($this->quietZone) { $w += 18; $h += 4; } return parent::getDimension($w, $h); }
[ "public", "function", "getDimension", "(", "$", "w", ",", "$", "h", ")", "{", "$", "w", "+=", "65", "*", "3", ";", "$", "h", "+=", "$", "this", "->", "thickness", ";", "// We remove the white on the right\r", "$", "w", "-=", "1.56", ";", "if", "(", "$", "this", "->", "quietZone", ")", "{", "$", "w", "+=", "18", ";", "$", "h", "+=", "4", ";", "}", "return", "parent", "::", "getDimension", "(", "$", "w", ",", "$", "h", ")", ";", "}" ]
Returns the maximal size of a barcode. @param int $w @param int $h @return int[]
[ "Returns", "the", "maximal", "size", "of", "a", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L357-L370
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.validate
protected function validate() { // Tracking must have been entered if ($this->barcodeIdentifier === null || $this->serviceTypeIdentifier === null || $this->mailerIdentifier === null || $this->serialNumber === null) { throw new CINParseException('intelligentmail', 'The tracking code must be set before calling the parse method.'); } // Checking if all chars are allowed $match = array(); if (preg_match('/[^0-9]/', $this->text, $match)) { throw new CINParseException('intelligentmail', 'The character \'' . $match[0] . '\' is not allowed.'); } // Must contain 0, 5, 9 or 11 chars $c = strlen($this->text); if ($c !== 0 && $c !== 5 && $c !== 9 && $c !== 11) { throw new CINParseException('intelligentmail', 'Must contain 0, 5, 9, or 11 characters.'); } parent::validate(); }
php
protected function validate() { // Tracking must have been entered if ($this->barcodeIdentifier === null || $this->serviceTypeIdentifier === null || $this->mailerIdentifier === null || $this->serialNumber === null) { throw new CINParseException('intelligentmail', 'The tracking code must be set before calling the parse method.'); } // Checking if all chars are allowed $match = array(); if (preg_match('/[^0-9]/', $this->text, $match)) { throw new CINParseException('intelligentmail', 'The character \'' . $match[0] . '\' is not allowed.'); } // Must contain 0, 5, 9 or 11 chars $c = strlen($this->text); if ($c !== 0 && $c !== 5 && $c !== 9 && $c !== 11) { throw new CINParseException('intelligentmail', 'Must contain 0, 5, 9, or 11 characters.'); } parent::validate(); }
[ "protected", "function", "validate", "(", ")", "{", "// Tracking must have been entered\r", "if", "(", "$", "this", "->", "barcodeIdentifier", "===", "null", "||", "$", "this", "->", "serviceTypeIdentifier", "===", "null", "||", "$", "this", "->", "mailerIdentifier", "===", "null", "||", "$", "this", "->", "serialNumber", "===", "null", ")", "{", "throw", "new", "CINParseException", "(", "'intelligentmail'", ",", "'The tracking code must be set before calling the parse method.'", ")", ";", "}", "// Checking if all chars are allowed\r", "$", "match", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/[^0-9]/'", ",", "$", "this", "->", "text", ",", "$", "match", ")", ")", "{", "throw", "new", "CINParseException", "(", "'intelligentmail'", ",", "'The character \\''", ".", "$", "match", "[", "0", "]", ".", "'\\' is not allowed.'", ")", ";", "}", "// Must contain 0, 5, 9 or 11 chars\r", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "if", "(", "$", "c", "!==", "0", "&&", "$", "c", "!==", "5", "&&", "$", "c", "!==", "9", "&&", "$", "c", "!==", "11", ")", "{", "throw", "new", "CINParseException", "(", "'intelligentmail'", ",", "'Must contain 0, 5, 9, or 11 characters.'", ")", ";", "}", "parent", "::", "validate", "(", ")", ";", "}" ]
Validates the input.
[ "Validates", "the", "input", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L375-L394
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.drawChar
protected function drawChar($im, $code, $startBar = true) { $y1 = 0; $y2 = 0; switch ($code) { case 'A': $y1 = 0; $y2 = $this->thickness - ($this->thickness / 2.5); break; case 'D': $y1 = 3.096; $y2 = $this->thickness - 1; break; case 'F': $y1 = 0; $y2 = $this->thickness - 1; break; case 'T': $y1 = 3.096; $y2 = $this->thickness - ($this->thickness / 2.5); break; } if ($this->quietZone) { $y1 += 2; $y2 += 2; } $this->drawFilledRectangle($im, $this->positionX, $y1, $this->positionX + 0.44, $y2, CINBarcode::COLOR_FG); $this->positionX += 3; }
php
protected function drawChar($im, $code, $startBar = true) { $y1 = 0; $y2 = 0; switch ($code) { case 'A': $y1 = 0; $y2 = $this->thickness - ($this->thickness / 2.5); break; case 'D': $y1 = 3.096; $y2 = $this->thickness - 1; break; case 'F': $y1 = 0; $y2 = $this->thickness - 1; break; case 'T': $y1 = 3.096; $y2 = $this->thickness - ($this->thickness / 2.5); break; } if ($this->quietZone) { $y1 += 2; $y2 += 2; } $this->drawFilledRectangle($im, $this->positionX, $y1, $this->positionX + 0.44, $y2, CINBarcode::COLOR_FG); $this->positionX += 3; }
[ "protected", "function", "drawChar", "(", "$", "im", ",", "$", "code", ",", "$", "startBar", "=", "true", ")", "{", "$", "y1", "=", "0", ";", "$", "y2", "=", "0", ";", "switch", "(", "$", "code", ")", "{", "case", "'A'", ":", "$", "y1", "=", "0", ";", "$", "y2", "=", "$", "this", "->", "thickness", "-", "(", "$", "this", "->", "thickness", "/", "2.5", ")", ";", "break", ";", "case", "'D'", ":", "$", "y1", "=", "3.096", ";", "$", "y2", "=", "$", "this", "->", "thickness", "-", "1", ";", "break", ";", "case", "'F'", ":", "$", "y1", "=", "0", ";", "$", "y2", "=", "$", "this", "->", "thickness", "-", "1", ";", "break", ";", "case", "'T'", ":", "$", "y1", "=", "3.096", ";", "$", "y2", "=", "$", "this", "->", "thickness", "-", "(", "$", "this", "->", "thickness", "/", "2.5", ")", ";", "break", ";", "}", "if", "(", "$", "this", "->", "quietZone", ")", "{", "$", "y1", "+=", "2", ";", "$", "y2", "+=", "2", ";", "}", "$", "this", "->", "drawFilledRectangle", "(", "$", "im", ",", "$", "this", "->", "positionX", ",", "$", "y1", ",", "$", "this", "->", "positionX", "+", "0.44", ",", "$", "y2", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "3", ";", "}" ]
Overloaded method for drawing special barcode. @param resource $im @param string $code @param boolean $startBar
[ "Overloaded", "method", "for", "drawing", "special", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L403-L432
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.executeStep1
private static function executeStep1($text, $barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber) { $number = self::conversionRoutingCode($text); $number = self::conversionTrackingCode($number, $barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber); return $number; }
php
private static function executeStep1($text, $barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber) { $number = self::conversionRoutingCode($text); $number = self::conversionTrackingCode($number, $barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber); return $number; }
[ "private", "static", "function", "executeStep1", "(", "$", "text", ",", "$", "barcodeIdentifier", ",", "$", "serviceTypeIdentifier", ",", "$", "mailerIdentifier", ",", "$", "serialNumber", ")", "{", "$", "number", "=", "self", "::", "conversionRoutingCode", "(", "$", "text", ")", ";", "$", "number", "=", "self", "::", "conversionTrackingCode", "(", "$", "number", ",", "$", "barcodeIdentifier", ",", "$", "serviceTypeIdentifier", ",", "$", "mailerIdentifier", ",", "$", "serialNumber", ")", ";", "return", "$", "number", ";", "}" ]
Executes Step 1: Conversion of Data Fields into Binary Data @param string $text @param string $barcodeIdentifier @param string $serviceTypeIdentifier @param string $mailerIdentifier @param string $serialNumber @return string BCNumber
[ "Executes", "Step", "1", ":", "Conversion", "of", "Data", "Fields", "into", "Binary", "Data" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L444-L449
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.executeStep2
private static function executeStep2($number) { $byteArray = str_pad(self::bcdecuc($number), 13, chr(0), STR_PAD_LEFT); $generatorPolynomial = 0x0f35; $frameCheckSequence = 0x07ff; $data = 0; $byteIndex = 0; $bit = 0; $data = (ord($byteArray[$byteIndex]) << 5) & 0xffff; for ($bit = 2; $bit < 8; $bit++) { if (($frameCheckSequence ^ $data) & 0x400) { $frameCheckSequence = ($frameCheckSequence << 1) ^ $generatorPolynomial; } else { $frameCheckSequence = ($frameCheckSequence << 1); } $frameCheckSequence &= 0x7ff; $data <<= 1; $data &= 0xffff; } for ($byteIndex = 1; $byteIndex < 13; $byteIndex++) { $data = (ord($byteArray[$byteIndex]) << 3) & 0xffff; for ($bit = 0; $bit < 8; $bit++) { if (($frameCheckSequence ^ $data) & 0x0400) { $frameCheckSequence = ($frameCheckSequence << 1) ^ $generatorPolynomial; } else { $frameCheckSequence = ($frameCheckSequence << 1); } $frameCheckSequence &= 0x7ff; $data <<= 1; $data &= 0xffff; } } return $frameCheckSequence; }
php
private static function executeStep2($number) { $byteArray = str_pad(self::bcdecuc($number), 13, chr(0), STR_PAD_LEFT); $generatorPolynomial = 0x0f35; $frameCheckSequence = 0x07ff; $data = 0; $byteIndex = 0; $bit = 0; $data = (ord($byteArray[$byteIndex]) << 5) & 0xffff; for ($bit = 2; $bit < 8; $bit++) { if (($frameCheckSequence ^ $data) & 0x400) { $frameCheckSequence = ($frameCheckSequence << 1) ^ $generatorPolynomial; } else { $frameCheckSequence = ($frameCheckSequence << 1); } $frameCheckSequence &= 0x7ff; $data <<= 1; $data &= 0xffff; } for ($byteIndex = 1; $byteIndex < 13; $byteIndex++) { $data = (ord($byteArray[$byteIndex]) << 3) & 0xffff; for ($bit = 0; $bit < 8; $bit++) { if (($frameCheckSequence ^ $data) & 0x0400) { $frameCheckSequence = ($frameCheckSequence << 1) ^ $generatorPolynomial; } else { $frameCheckSequence = ($frameCheckSequence << 1); } $frameCheckSequence &= 0x7ff; $data <<= 1; $data &= 0xffff; } } return $frameCheckSequence; }
[ "private", "static", "function", "executeStep2", "(", "$", "number", ")", "{", "$", "byteArray", "=", "str_pad", "(", "self", "::", "bcdecuc", "(", "$", "number", ")", ",", "13", ",", "chr", "(", "0", ")", ",", "STR_PAD_LEFT", ")", ";", "$", "generatorPolynomial", "=", "0x0f35", ";", "$", "frameCheckSequence", "=", "0x07ff", ";", "$", "data", "=", "0", ";", "$", "byteIndex", "=", "0", ";", "$", "bit", "=", "0", ";", "$", "data", "=", "(", "ord", "(", "$", "byteArray", "[", "$", "byteIndex", "]", ")", "<<", "5", ")", "&", "0xffff", ";", "for", "(", "$", "bit", "=", "2", ";", "$", "bit", "<", "8", ";", "$", "bit", "++", ")", "{", "if", "(", "(", "$", "frameCheckSequence", "^", "$", "data", ")", "&", "0x400", ")", "{", "$", "frameCheckSequence", "=", "(", "$", "frameCheckSequence", "<<", "1", ")", "^", "$", "generatorPolynomial", ";", "}", "else", "{", "$", "frameCheckSequence", "=", "(", "$", "frameCheckSequence", "<<", "1", ")", ";", "}", "$", "frameCheckSequence", "&=", "0x7ff", ";", "$", "data", "<<=", "1", ";", "$", "data", "&=", "0xffff", ";", "}", "for", "(", "$", "byteIndex", "=", "1", ";", "$", "byteIndex", "<", "13", ";", "$", "byteIndex", "++", ")", "{", "$", "data", "=", "(", "ord", "(", "$", "byteArray", "[", "$", "byteIndex", "]", ")", "<<", "3", ")", "&", "0xffff", ";", "for", "(", "$", "bit", "=", "0", ";", "$", "bit", "<", "8", ";", "$", "bit", "++", ")", "{", "if", "(", "(", "$", "frameCheckSequence", "^", "$", "data", ")", "&", "0x0400", ")", "{", "$", "frameCheckSequence", "=", "(", "$", "frameCheckSequence", "<<", "1", ")", "^", "$", "generatorPolynomial", ";", "}", "else", "{", "$", "frameCheckSequence", "=", "(", "$", "frameCheckSequence", "<<", "1", ")", ";", "}", "$", "frameCheckSequence", "&=", "0x7ff", ";", "$", "data", "<<=", "1", ";", "$", "data", "&=", "0xffff", ";", "}", "}", "return", "$", "frameCheckSequence", ";", "}" ]
Executes Step 2: Generation of 11-Bit CRC on Binary Data @param $number BCNumber @return int
[ "Executes", "Step", "2", ":", "Generation", "of", "11", "-", "Bit", "CRC", "on", "Binary", "Data" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L457-L495
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.executeStep3
private static function executeStep3($number) { $codewords = array(); $codewords[9] = (int)bcmod($number, '636'); $number = bcdiv($number, '636', 0); for ($i = 8; $i >= 0; $i--) { $codewords[$i] = (int)bcmod($number, '1365'); $number = bcdiv($number, '1365', 0); } return $codewords; }
php
private static function executeStep3($number) { $codewords = array(); $codewords[9] = (int)bcmod($number, '636'); $number = bcdiv($number, '636', 0); for ($i = 8; $i >= 0; $i--) { $codewords[$i] = (int)bcmod($number, '1365'); $number = bcdiv($number, '1365', 0); } return $codewords; }
[ "private", "static", "function", "executeStep3", "(", "$", "number", ")", "{", "$", "codewords", "=", "array", "(", ")", ";", "$", "codewords", "[", "9", "]", "=", "(", "int", ")", "bcmod", "(", "$", "number", ",", "'636'", ")", ";", "$", "number", "=", "bcdiv", "(", "$", "number", ",", "'636'", ",", "0", ")", ";", "for", "(", "$", "i", "=", "8", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "$", "codewords", "[", "$", "i", "]", "=", "(", "int", ")", "bcmod", "(", "$", "number", ",", "'1365'", ")", ";", "$", "number", "=", "bcdiv", "(", "$", "number", ",", "'1365'", ",", "0", ")", ";", "}", "return", "$", "codewords", ";", "}" ]
Executes Step 3: Conversion from Binary Data to Codewords @param string $number BCNumber @return int[]
[ "Executes", "Step", "3", ":", "Conversion", "from", "Binary", "Data", "to", "Codewords" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L503-L514
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.executeStep5
private static function executeStep5($codewords, $crc) { $characters = array(); for ($i = 0; $i < 10; $i++) { if ($codewords[$i] <= 1286) { $characters[$i] = self::$characterTable1[$codewords[$i]]; } else { $characters[$i] = self::$characterTable2[$codewords[$i] - 1287]; } } for ($i = 0; $i < 10; $i++) { $mask = 1 << $i; if ($crc & $mask) { $characters[$i] ^= 0x1fff; } } return $characters; }
php
private static function executeStep5($codewords, $crc) { $characters = array(); for ($i = 0; $i < 10; $i++) { if ($codewords[$i] <= 1286) { $characters[$i] = self::$characterTable1[$codewords[$i]]; } else { $characters[$i] = self::$characterTable2[$codewords[$i] - 1287]; } } for ($i = 0; $i < 10; $i++) { $mask = 1 << $i; if ($crc & $mask) { $characters[$i] ^= 0x1fff; } } return $characters; }
[ "private", "static", "function", "executeStep5", "(", "$", "codewords", ",", "$", "crc", ")", "{", "$", "characters", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "10", ";", "$", "i", "++", ")", "{", "if", "(", "$", "codewords", "[", "$", "i", "]", "<=", "1286", ")", "{", "$", "characters", "[", "$", "i", "]", "=", "self", "::", "$", "characterTable1", "[", "$", "codewords", "[", "$", "i", "]", "]", ";", "}", "else", "{", "$", "characters", "[", "$", "i", "]", "=", "self", "::", "$", "characterTable2", "[", "$", "codewords", "[", "$", "i", "]", "-", "1287", "]", ";", "}", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "10", ";", "$", "i", "++", ")", "{", "$", "mask", "=", "1", "<<", "$", "i", ";", "if", "(", "$", "crc", "&", "$", "mask", ")", "{", "$", "characters", "[", "$", "i", "]", "^=", "0x1fff", ";", "}", "}", "return", "$", "characters", ";", "}" ]
Executes Step 5: Conversion from Codewords to Characters @param int[] $codewords @param int $crc @return int[]
[ "Executes", "Step", "5", ":", "Conversion", "from", "Codewords", "to", "Characters" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L539-L557
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.executeStep6
private static function executeStep6($characters) { $bars = ''; for ($i = 0; $i < 65; $i++) { $barPosition = self::$barPositions[$i]; $descender = $barPosition[0]; $ascender = $barPosition[1]; $extenderDescender = !!($characters[$descender[0]] & (1 << $descender[1])); $extenderAscender = !!($characters[$ascender[0]] & (1 << $ascender[1])); if ($extenderDescender && $extenderAscender) { $bars .= 'F'; } elseif ($extenderDescender) { $bars .= 'D'; } elseif ($extenderAscender) { $bars .= 'A'; } else { $bars .= 'T'; } } return $bars; }
php
private static function executeStep6($characters) { $bars = ''; for ($i = 0; $i < 65; $i++) { $barPosition = self::$barPositions[$i]; $descender = $barPosition[0]; $ascender = $barPosition[1]; $extenderDescender = !!($characters[$descender[0]] & (1 << $descender[1])); $extenderAscender = !!($characters[$ascender[0]] & (1 << $ascender[1])); if ($extenderDescender && $extenderAscender) { $bars .= 'F'; } elseif ($extenderDescender) { $bars .= 'D'; } elseif ($extenderAscender) { $bars .= 'A'; } else { $bars .= 'T'; } } return $bars; }
[ "private", "static", "function", "executeStep6", "(", "$", "characters", ")", "{", "$", "bars", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "65", ";", "$", "i", "++", ")", "{", "$", "barPosition", "=", "self", "::", "$", "barPositions", "[", "$", "i", "]", ";", "$", "descender", "=", "$", "barPosition", "[", "0", "]", ";", "$", "ascender", "=", "$", "barPosition", "[", "1", "]", ";", "$", "extenderDescender", "=", "!", "!", "(", "$", "characters", "[", "$", "descender", "[", "0", "]", "]", "&", "(", "1", "<<", "$", "descender", "[", "1", "]", ")", ")", ";", "$", "extenderAscender", "=", "!", "!", "(", "$", "characters", "[", "$", "ascender", "[", "0", "]", "]", "&", "(", "1", "<<", "$", "ascender", "[", "1", "]", ")", ")", ";", "if", "(", "$", "extenderDescender", "&&", "$", "extenderAscender", ")", "{", "$", "bars", ".=", "'F'", ";", "}", "elseif", "(", "$", "extenderDescender", ")", "{", "$", "bars", ".=", "'D'", ";", "}", "elseif", "(", "$", "extenderAscender", ")", "{", "$", "bars", ".=", "'A'", ";", "}", "else", "{", "$", "bars", ".=", "'T'", ";", "}", "}", "return", "$", "bars", ";", "}" ]
Executes Step 6: Conversion from Characters to the Intelligent Mail Barcode @param int[] $characters @return string
[ "Executes", "Step", "6", ":", "Conversion", "from", "Characters", "to", "the", "Intelligent", "Mail", "Barcode" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L565-L586
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.conversionRoutingCode
private static function conversionRoutingCode($zipcode) { $number = $zipcode; switch (strlen($zipcode)) { case 11: $number = bcadd($number, '1000000000', 0); case 9: $number = bcadd($number, '100000', 0); case 5: $number = bcadd($number, '1', 0); default: return $number; } }
php
private static function conversionRoutingCode($zipcode) { $number = $zipcode; switch (strlen($zipcode)) { case 11: $number = bcadd($number, '1000000000', 0); case 9: $number = bcadd($number, '100000', 0); case 5: $number = bcadd($number, '1', 0); default: return $number; } }
[ "private", "static", "function", "conversionRoutingCode", "(", "$", "zipcode", ")", "{", "$", "number", "=", "$", "zipcode", ";", "switch", "(", "strlen", "(", "$", "zipcode", ")", ")", "{", "case", "11", ":", "$", "number", "=", "bcadd", "(", "$", "number", ",", "'1000000000'", ",", "0", ")", ";", "case", "9", ":", "$", "number", "=", "bcadd", "(", "$", "number", ",", "'100000'", ",", "0", ")", ";", "case", "5", ":", "$", "number", "=", "bcadd", "(", "$", "number", ",", "'1'", ",", "0", ")", ";", "default", ":", "return", "$", "number", ";", "}", "}" ]
Converts the routing code zipcode. @param string $zipcode @return string BCNumber
[ "Converts", "the", "routing", "code", "zipcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L594-L606
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.conversionTrackingCode
private static function conversionTrackingCode($number, $barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber) { $number = bcmul($number, 10, 0); $number = bcadd($number, $barcodeIdentifier[0], 0); $number = bcmul($number, 5, 0); $number = bcadd($number, $barcodeIdentifier[1], 0); $temp = $serviceTypeIdentifier . $mailerIdentifier . $serialNumber; for ($i = 0; $i < 18; $i++) { $number = bcmul($number, 10, 0); $number = bcadd($number, $temp[$i], 0); } return $number; }
php
private static function conversionTrackingCode($number, $barcodeIdentifier, $serviceTypeIdentifier, $mailerIdentifier, $serialNumber) { $number = bcmul($number, 10, 0); $number = bcadd($number, $barcodeIdentifier[0], 0); $number = bcmul($number, 5, 0); $number = bcadd($number, $barcodeIdentifier[1], 0); $temp = $serviceTypeIdentifier . $mailerIdentifier . $serialNumber; for ($i = 0; $i < 18; $i++) { $number = bcmul($number, 10, 0); $number = bcadd($number, $temp[$i], 0); } return $number; }
[ "private", "static", "function", "conversionTrackingCode", "(", "$", "number", ",", "$", "barcodeIdentifier", ",", "$", "serviceTypeIdentifier", ",", "$", "mailerIdentifier", ",", "$", "serialNumber", ")", "{", "$", "number", "=", "bcmul", "(", "$", "number", ",", "10", ",", "0", ")", ";", "$", "number", "=", "bcadd", "(", "$", "number", ",", "$", "barcodeIdentifier", "[", "0", "]", ",", "0", ")", ";", "$", "number", "=", "bcmul", "(", "$", "number", ",", "5", ",", "0", ")", ";", "$", "number", "=", "bcadd", "(", "$", "number", ",", "$", "barcodeIdentifier", "[", "1", "]", ",", "0", ")", ";", "$", "temp", "=", "$", "serviceTypeIdentifier", ".", "$", "mailerIdentifier", ".", "$", "serialNumber", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "18", ";", "$", "i", "++", ")", "{", "$", "number", "=", "bcmul", "(", "$", "number", ",", "10", ",", "0", ")", ";", "$", "number", "=", "bcadd", "(", "$", "number", ",", "$", "temp", "[", "$", "i", "]", ",", "0", ")", ";", "}", "return", "$", "number", ";", "}" ]
Converts the tracking code number. @param string $number BCNumber @param string $barcodeIdentifier @param string $serviceTypeIdentifier @param string $mailerIdentifier @param string $serialNumber @return string BCNumber
[ "Converts", "the", "tracking", "code", "number", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L618-L631
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php
CINintelligentmail.bcdecuc
private static function bcdecuc($dec) { $last = bcmod($dec, 256); $remain = bcdiv(bcsub($dec, $last), 256, 0); if ($remain == 0) { return pack('C', $last); } else { return self::bcdecuc($remain) . pack('C', $last); } }
php
private static function bcdecuc($dec) { $last = bcmod($dec, 256); $remain = bcdiv(bcsub($dec, $last), 256, 0); if ($remain == 0) { return pack('C', $last); } else { return self::bcdecuc($remain) . pack('C', $last); } }
[ "private", "static", "function", "bcdecuc", "(", "$", "dec", ")", "{", "$", "last", "=", "bcmod", "(", "$", "dec", ",", "256", ")", ";", "$", "remain", "=", "bcdiv", "(", "bcsub", "(", "$", "dec", ",", "$", "last", ")", ",", "256", ",", "0", ")", ";", "if", "(", "$", "remain", "==", "0", ")", "{", "return", "pack", "(", "'C'", ",", "$", "last", ")", ";", "}", "else", "{", "return", "self", "::", "bcdecuc", "(", "$", "remain", ")", ".", "pack", "(", "'C'", ",", "$", "last", ")", ";", "}", "}" ]
Transforms a BCNumber into unsigned char*. @param string $dec BCNumber @param string
[ "Transforms", "a", "BCNumber", "into", "unsigned", "char", "*", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINintelligentmail.php#L639-L648
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/QrCode.php
QrCode.setStructureAppend
public function setStructureAppend($n, $m, $parity, $original_data) { $this->structure_append_n = $n; $this->structure_append_m = $m; $this->structure_append_parity = $parity; $this->structure_append_original_data = $original_data; return $this; }
php
public function setStructureAppend($n, $m, $parity, $original_data) { $this->structure_append_n = $n; $this->structure_append_m = $m; $this->structure_append_parity = $parity; $this->structure_append_original_data = $original_data; return $this; }
[ "public", "function", "setStructureAppend", "(", "$", "n", ",", "$", "m", ",", "$", "parity", ",", "$", "original_data", ")", "{", "$", "this", "->", "structure_append_n", "=", "$", "n", ";", "$", "this", "->", "structure_append_m", "=", "$", "m", ";", "$", "this", "->", "structure_append_parity", "=", "$", "parity", ";", "$", "this", "->", "structure_append_original_data", "=", "$", "original_data", ";", "return", "$", "this", ";", "}" ]
Set structure append. @param int $n @param int $m @param int $parity Parity @param string $original_data Original data @return QrCode
[ "Set", "structure", "append", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/QrCode.php#L184-L192
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/QrCode.php
QrCode.setErrorCorrection
public function setErrorCorrection($error_correction) { if (!is_numeric($error_correction)) { $level_constant = 'CodeItNow\BarcodeBundle\Utils\QrCode::LEVEL_'.strtoupper($error_correction); $error_correction = constant($level_constant); } if (in_array($error_correction, $this->error_corrections_available)) { $this->error_correction = $error_correction; } return $this; }
php
public function setErrorCorrection($error_correction) { if (!is_numeric($error_correction)) { $level_constant = 'CodeItNow\BarcodeBundle\Utils\QrCode::LEVEL_'.strtoupper($error_correction); $error_correction = constant($level_constant); } if (in_array($error_correction, $this->error_corrections_available)) { $this->error_correction = $error_correction; } return $this; }
[ "public", "function", "setErrorCorrection", "(", "$", "error_correction", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "error_correction", ")", ")", "{", "$", "level_constant", "=", "'CodeItNow\\BarcodeBundle\\Utils\\QrCode::LEVEL_'", ".", "strtoupper", "(", "$", "error_correction", ")", ";", "$", "error_correction", "=", "constant", "(", "$", "level_constant", ")", ";", "}", "if", "(", "in_array", "(", "$", "error_correction", ",", "$", "this", "->", "error_corrections_available", ")", ")", "{", "$", "this", "->", "error_correction", "=", "$", "error_correction", ";", "}", "return", "$", "this", ";", "}" ]
Set QR Code error correction level. @param mixed $error_correction Error Correction Level @return QrCode
[ "Set", "QR", "Code", "error", "correction", "level", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/QrCode.php#L227-L239
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/QrCode.php
QrCode.getDataUri
public function getDataUri() { if (empty($this->image)) { $this->create(); } ob_start(); call_user_func('image'.$this->image_type, $this->image); $contents = ob_get_clean(); return 'data:image/'.$this->image_type.';base64,'.base64_encode($contents); }
php
public function getDataUri() { if (empty($this->image)) { $this->create(); } ob_start(); call_user_func('image'.$this->image_type, $this->image); $contents = ob_get_clean(); return 'data:image/'.$this->image_type.';base64,'.base64_encode($contents); }
[ "public", "function", "getDataUri", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "image", ")", ")", "{", "$", "this", "->", "create", "(", ")", ";", "}", "ob_start", "(", ")", ";", "call_user_func", "(", "'image'", ".", "$", "this", "->", "image_type", ",", "$", "this", "->", "image", ")", ";", "$", "contents", "=", "ob_get_clean", "(", ")", ";", "return", "'data:image/'", ".", "$", "this", "->", "image_type", ".", "';base64,'", ".", "base64_encode", "(", "$", "contents", ")", ";", "}" ]
Return the data URI. @return string
[ "Return", "the", "data", "URI", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/QrCode.php#L686-L697
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/QrCode.php
QrCode.render
public function render($filename = null, $format = 'png') { $this->create(); if ($format == 'jpg') { $format = 'jpeg'; } if (!in_array($format, $this->image_types_available)) { $format = $this->image_type; } if (!function_exists('image'.$format)) { throw new Exception('QRCode: function image'.$format.' does not exists.'); } if ($filename === null) { $success = call_user_func('image'.$format, $this->image); } else { $success = call_user_func_array('image'.$format, array($this->image, $filename)); } if ($success === false) { throw new Exception('QRCode: function image'.$format.' failed.'); } return $this; }
php
public function render($filename = null, $format = 'png') { $this->create(); if ($format == 'jpg') { $format = 'jpeg'; } if (!in_array($format, $this->image_types_available)) { $format = $this->image_type; } if (!function_exists('image'.$format)) { throw new Exception('QRCode: function image'.$format.' does not exists.'); } if ($filename === null) { $success = call_user_func('image'.$format, $this->image); } else { $success = call_user_func_array('image'.$format, array($this->image, $filename)); } if ($success === false) { throw new Exception('QRCode: function image'.$format.' failed.'); } return $this; }
[ "public", "function", "render", "(", "$", "filename", "=", "null", ",", "$", "format", "=", "'png'", ")", "{", "$", "this", "->", "create", "(", ")", ";", "if", "(", "$", "format", "==", "'jpg'", ")", "{", "$", "format", "=", "'jpeg'", ";", "}", "if", "(", "!", "in_array", "(", "$", "format", ",", "$", "this", "->", "image_types_available", ")", ")", "{", "$", "format", "=", "$", "this", "->", "image_type", ";", "}", "if", "(", "!", "function_exists", "(", "'image'", ".", "$", "format", ")", ")", "{", "throw", "new", "Exception", "(", "'QRCode: function image'", ".", "$", "format", ".", "' does not exists.'", ")", ";", "}", "if", "(", "$", "filename", "===", "null", ")", "{", "$", "success", "=", "call_user_func", "(", "'image'", ".", "$", "format", ",", "$", "this", "->", "image", ")", ";", "}", "else", "{", "$", "success", "=", "call_user_func_array", "(", "'image'", ".", "$", "format", ",", "array", "(", "$", "this", "->", "image", ",", "$", "filename", ")", ")", ";", "}", "if", "(", "$", "success", "===", "false", ")", "{", "throw", "new", "Exception", "(", "'QRCode: function image'", ".", "$", "format", ".", "' failed.'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Render the QR Code then save it to given file name or output it to the browser when file name omitted. @param null|string $filename File name of the QR Code @param null|string $format Format of the file (png, jpeg, jpg, gif, wbmp) @throws Exception @throws Exception @return QrCode
[ "Render", "the", "QR", "Code", "then", "save", "it", "to", "given", "file", "name", "or", "output", "it", "to", "the", "browser", "when", "file", "name", "omitted", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/QrCode.php#L725-L752
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/QrCode.php
QrCode.create
public function create() { $image_path = $this->image_path; $path = $this->path; $version_ul = 40; $qrcode_data_string = $this->text;//Previously from $_GET["d"]; $qrcode_error_correct = $this->error_correction;//Previously from $_GET["e"]; $qrcode_module_size = $this->module_size;//Previously from $_GET["s"]; $qrcode_version = $this->version;//Previously from $_GET["v"]; $qrcode_image_type = $this->image_type;//Previously from $_GET["t"]; $qrcode_structureappend_n = $this->structure_append_n;//Previously from $_GET["n"]; $qrcode_structureappend_m = $this->structure_append_m;//Previously from $_GET["m"]; $qrcode_structureappend_parity = $this->structure_append_parity;//Previously from $_GET["p"]; $qrcode_structureappend_originaldata = $this->structure_append_original_data;//Previously from $_GET["o"]; if ($qrcode_module_size > 0) { } else { if ($qrcode_image_type == 'jpeg') { $qrcode_module_size = 8; } else { $qrcode_module_size = 4; } } $data_length = strlen($qrcode_data_string); if ($data_length <= 0) { throw new Exception('QRCode: data does not exist.'); } $data_counter = 0; if ($qrcode_structureappend_n > 1 && $qrcode_structureappend_n <= 16 && $qrcode_structureappend_m > 0 && $qrcode_structureappend_m <= 16) { $data_value[0] = 3; $data_bits[0] = 4; $data_value[1] = $qrcode_structureappend_m - 1; $data_bits[1] = 4; $data_value[2] = $qrcode_structureappend_n - 1; $data_bits[2] = 4; $originaldata_length = strlen($qrcode_structureappend_originaldata); if ($originaldata_length > 1) { $qrcode_structureappend_parity = 0; $i = 0; while ($i < $originaldata_length) { $qrcode_structureappend_parity = ($qrcode_structureappend_parity ^ ord(substr($qrcode_structureappend_originaldata, $i, 1))); ++$i; } } $data_value[3] = $qrcode_structureappend_parity; $data_bits[3] = 8; $data_counter = 4; } $data_bits[$data_counter] = 4; /* --- determine encode mode */ if (preg_match('/[^0-9]/', $qrcode_data_string) != 0) { if (preg_match("/[^0-9A-Z \$\*\%\+\.\/\:\-]/", $qrcode_data_string) != 0) { /* --- 8bit byte mode */ $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ); $data_value[$data_counter] = 4; ++$data_counter; $data_value[$data_counter] = $data_length; $data_bits[$data_counter] = 8; /* #version 1-9 */ $codeword_num_counter_value = $data_counter; ++$data_counter; $i = 0; while ($i < $data_length) { $data_value[$data_counter] = ord(substr($qrcode_data_string, $i, 1)); $data_bits[$data_counter] = 8; ++$data_counter; ++$i; } } else { /* ---- alphanumeric mode */ $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ); $data_value[$data_counter] = 2; ++$data_counter; $data_value[$data_counter] = $data_length; $data_bits[$data_counter] = 9; /* #version 1-9 */ $codeword_num_counter_value = $data_counter; $alphanumeric_character_hash = array('0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35, ' ' => 36, '$' => 37, '%' => 38, '*' => 39, '+' => 40, '-' => 41, '.' => 42, '/' => 43, ':' => 44, ); $i = 0; ++$data_counter; while ($i < $data_length) { if (($i % 2) == 0) { $data_value[$data_counter] = $alphanumeric_character_hash[substr($qrcode_data_string, $i, 1)]; $data_bits[$data_counter] = 6; } else { $data_value[$data_counter] = $data_value[$data_counter] * 45 + $alphanumeric_character_hash[substr($qrcode_data_string, $i, 1)]; $data_bits[$data_counter] = 11; ++$data_counter; } ++$i; } } } else { /* ---- numeric mode */ $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ); $data_value[$data_counter] = 1; ++$data_counter; $data_value[$data_counter] = $data_length; $data_bits[$data_counter] = 10; /* #version 1-9 */ $codeword_num_counter_value = $data_counter; $i = 0; ++$data_counter; while ($i < $data_length) { if (($i % 3) == 0) { $data_value[$data_counter] = substr($qrcode_data_string, $i, 1); $data_bits[$data_counter] = 4; } else { $data_value[$data_counter] = $data_value[$data_counter] * 10 + substr($qrcode_data_string, $i, 1); if (($i % 3) == 1) { $data_bits[$data_counter] = 7; } else { $data_bits[$data_counter] = 10; ++$data_counter; } } ++$i; } } if (array_key_exists($data_counter, $data_bits) && $data_bits[$data_counter] > 0) { ++$data_counter; } $i = 0; $total_data_bits = 0; while ($i < $data_counter) { $total_data_bits += $data_bits[$i]; ++$i; } $ecc_character_hash = array('L' => '1', 'l' => '1', 'M' => '0', 'm' => '0', 'Q' => '3', 'q' => '3', 'H' => '2', 'h' => '2', ); if (!is_numeric($qrcode_error_correct)) { $ec = @$ecc_character_hash[$qrcode_error_correct]; } else { $ec = $qrcode_error_correct; } if (!$ec) { $ec = 0; } $max_data_bits = 0; $max_data_bits_array = array( 0, 128, 224, 352, 512, 688, 864, 992, 1232, 1456, 1728, 2032, 2320, 2672, 2920, 3320, 3624, 4056, 4504, 5016, 5352, 5712, 6256, 6880, 7312, 8000, 8496, 9024, 9544, 10136, 10984, 11640, 12328, 13048, 13800, 14496, 15312, 15936, 16816, 17728, 18672, 152, 272, 440, 640, 864, 1088, 1248, 1552, 1856, 2192, 2592, 2960, 3424, 3688, 4184, 4712, 5176, 5768, 6360, 6888, 7456, 8048, 8752, 9392, 10208, 10960, 11744, 12248, 13048, 13880, 14744, 15640, 16568, 17528, 18448, 19472, 20528, 21616, 22496, 23648, 72, 128, 208, 288, 368, 480, 528, 688, 800, 976, 1120, 1264, 1440, 1576, 1784, 2024, 2264, 2504, 2728, 3080, 3248, 3536, 3712, 4112, 4304, 4768, 5024, 5288, 5608, 5960, 6344, 6760, 7208, 7688, 7888, 8432, 8768, 9136, 9776, 10208, 104, 176, 272, 384, 496, 608, 704, 880, 1056, 1232, 1440, 1648, 1952, 2088, 2360, 2600, 2936, 3176, 3560, 3880, 4096, 4544, 4912, 5312, 5744, 6032, 6464, 6968, 7288, 7880, 8264, 8920, 9368, 9848, 10288, 10832, 11408, 12016, 12656, 13328, ); if (!is_numeric($qrcode_version)) { $qrcode_version = 0; } if (!$qrcode_version) { /* #--- auto version select */ $i = 1 + 40 * $ec; $j = $i + 39; $qrcode_version = 1; while ($i <= $j) { if (($max_data_bits_array[$i]) >= $total_data_bits + $codeword_num_plus[$qrcode_version]) { $max_data_bits = $max_data_bits_array[$i]; break; } ++$i; ++$qrcode_version; } } else { $max_data_bits = $max_data_bits_array[$qrcode_version + 40 * $ec]; } if ($qrcode_version > $version_ul) { throw new Exception('QRCode : version too large'); } $total_data_bits += $codeword_num_plus[$qrcode_version]; $data_bits[$codeword_num_counter_value] += $codeword_num_plus[$qrcode_version]; $max_codewords_array = array(0, 26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706, ); $max_codewords = $max_codewords_array[$qrcode_version]; $max_modules_1side = 17 + ($qrcode_version << 2); $matrix_remain_bit = array(0, 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, ); /* ---- read version ECC data file */ $byte_num = $matrix_remain_bit[$qrcode_version] + ($max_codewords << 3); $filename = $path.'/qrv'.$qrcode_version.'_'.$ec.'.dat'; $fp1 = fopen($filename, 'rb'); $matx = fread($fp1, $byte_num); $maty = fread($fp1, $byte_num); $masks = fread($fp1, $byte_num); $fi_x = fread($fp1, 15); $fi_y = fread($fp1, 15); $rs_ecc_codewords = ord(fread($fp1, 1)); $rso = fread($fp1, 128); fclose($fp1); $matrix_x_array = unpack('C*', $matx); $matrix_y_array = unpack('C*', $maty); $mask_array = unpack('C*', $masks); $rs_block_order = unpack('C*', $rso); $format_information_x2 = unpack('C*', $fi_x); $format_information_y2 = unpack('C*', $fi_y); $format_information_x1 = array(0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8); $format_information_y1 = array(8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0); $max_data_codewords = ($max_data_bits >> 3); $filename = $path.'/rsc'.$rs_ecc_codewords.'.dat'; $fp0 = fopen($filename, 'rb'); $i = 0; $rs_cal_table_array = array(); while ($i < 256) { $rs_cal_table_array[$i] = fread($fp0, $rs_ecc_codewords); ++$i; } fclose($fp0); /* --- set terminator */ if ($total_data_bits <= $max_data_bits - 4) { $data_value[$data_counter] = 0; $data_bits[$data_counter] = 4; } else { if ($total_data_bits < $max_data_bits) { $data_value[$data_counter] = 0; $data_bits[$data_counter] = $max_data_bits - $total_data_bits; } else { if ($total_data_bits > $max_data_bits) { throw new \OverflowException('QRCode: overflow error'); } } } /* ----divide data by 8bit */ $i = 0; $codewords_counter = 0; $codewords[0] = 0; $remaining_bits = 8; while ($i <= $data_counter) { $buffer = @$data_value[$i]; $buffer_bits = @$data_bits[$i]; $flag = 1; while ($flag) { if ($remaining_bits > $buffer_bits) { $codewords[$codewords_counter] = ((@$codewords[$codewords_counter] << $buffer_bits) | $buffer); $remaining_bits -= $buffer_bits; $flag = 0; } else { $buffer_bits -= $remaining_bits; $codewords[$codewords_counter] = (($codewords[$codewords_counter] << $remaining_bits) | ($buffer >> $buffer_bits)); if ($buffer_bits == 0) { $flag = 0; } else { $buffer = ($buffer & ((1 << $buffer_bits) - 1)); $flag = 1; } ++$codewords_counter; if ($codewords_counter < $max_data_codewords - 1) { $codewords[$codewords_counter] = 0; } $remaining_bits = 8; } } ++$i; } if ($remaining_bits != 8) { $codewords[$codewords_counter] = $codewords[$codewords_counter] << $remaining_bits; } else { --$codewords_counter; } /* ---- set padding character */ if ($codewords_counter < $max_data_codewords - 1) { $flag = 1; while ($codewords_counter < $max_data_codewords - 1) { ++$codewords_counter; if ($flag == 1) { $codewords[$codewords_counter] = 236; } else { $codewords[$codewords_counter] = 17; } $flag = $flag * (-1); } } /* ---- RS-ECC prepare */ $i = 0; $j = 0; $rs_block_number = 0; $rs_temp[0] = ''; while ($i < $max_data_codewords) { $rs_temp[$rs_block_number] .= chr($codewords[$i]); ++$j; if ($j >= $rs_block_order[$rs_block_number + 1] - $rs_ecc_codewords) { $j = 0; ++$rs_block_number; $rs_temp[$rs_block_number] = ''; } ++$i; } /* # # RS-ECC main # */ $rs_block_number = 0; $rs_block_order_num = count($rs_block_order); while ($rs_block_number < $rs_block_order_num) { $rs_codewords = $rs_block_order[$rs_block_number + 1]; $rs_data_codewords = $rs_codewords - $rs_ecc_codewords; $rstemp = $rs_temp[$rs_block_number].str_repeat(chr(0), $rs_ecc_codewords); $padding_data = str_repeat(chr(0), $rs_data_codewords); $j = $rs_data_codewords; while ($j > 0) { $first = ord(substr($rstemp, 0, 1)); if ($first) { $left_chr = substr($rstemp, 1); $cal = $rs_cal_table_array[$first].$padding_data; $rstemp = $left_chr ^ $cal; } else { $rstemp = substr($rstemp, 1); } --$j; } $codewords = array_merge($codewords, unpack('C*', $rstemp)); ++$rs_block_number; } /* ---- flash matrix */ $matrix_content = array(); $i = 0; while ($i < $max_modules_1side) { $j = 0; while ($j < $max_modules_1side) { $matrix_content[$j][$i] = 0; ++$j; } ++$i; } /* --- attach data */ $i = 0; while ($i < $max_codewords) { $codeword_i = $codewords[$i]; $j = 8; while ($j >= 1) { $codeword_bits_number = ($i << 3) + $j; $matrix_content[ $matrix_x_array[$codeword_bits_number] ][ $matrix_y_array[$codeword_bits_number] ] = ((255 * ($codeword_i & 1)) ^ $mask_array[$codeword_bits_number]); $codeword_i = $codeword_i >> 1; --$j; } ++$i; } $matrix_remain = $matrix_remain_bit[$qrcode_version]; while ($matrix_remain) { $remain_bit_temp = $matrix_remain + ($max_codewords << 3); $matrix_content[ $matrix_x_array[$remain_bit_temp] ][ $matrix_y_array[$remain_bit_temp] ] = (255 ^ $mask_array[$remain_bit_temp]); --$matrix_remain; } #--- mask select $min_demerit_score = 0; $hor_master = ''; $ver_master = ''; $k = 0; while ($k < $max_modules_1side) { $l = 0; while ($l < $max_modules_1side) { $hor_master = $hor_master.chr($matrix_content[$l][$k]); $ver_master = $ver_master.chr($matrix_content[$k][$l]); ++$l; } ++$k; } $i = 0; $all_matrix = $max_modules_1side * $max_modules_1side; $mask_number = 0; while ($i < 8) { $demerit_n1 = 0; $ptn_temp = array(); $bit = 1 << $i; $bit_r = (~$bit) & 255; $bit_mask = str_repeat(chr($bit), $all_matrix); $hor = $hor_master & $bit_mask; $ver = $ver_master & $bit_mask; $ver_shift1 = $ver.str_repeat(chr(170), $max_modules_1side); $ver_shift2 = str_repeat(chr(170), $max_modules_1side).$ver; $ver_shift1_0 = $ver.str_repeat(chr(0), $max_modules_1side); $ver_shift2_0 = str_repeat(chr(0), $max_modules_1side).$ver; $ver_or = chunk_split(~($ver_shift1 | $ver_shift2), $max_modules_1side, chr(170)); $ver_and = chunk_split(~($ver_shift1_0 & $ver_shift2_0), $max_modules_1side, chr(170)); $hor = chunk_split(~$hor, $max_modules_1side, chr(170)); $ver = chunk_split(~$ver, $max_modules_1side, chr(170)); $hor = $hor.chr(170).$ver; $n1_search = '/'.str_repeat(chr(255), 5).'+|'.str_repeat(chr($bit_r), 5).'+/'; $n3_search = chr($bit_r).chr(255).chr($bit_r).chr($bit_r).chr($bit_r).chr(255).chr($bit_r); $demerit_n3 = substr_count($hor, $n3_search) * 40; $demerit_n4 = floor(abs(((100 * (substr_count($ver, chr($bit_r)) / ($byte_num))) - 50) / 5)) * 10; $n2_search1 = '/'.chr($bit_r).chr($bit_r).'+/'; $n2_search2 = '/'.chr(255).chr(255).'+/'; $demerit_n2 = 0; preg_match_all($n2_search1, $ver_and, $ptn_temp); foreach ($ptn_temp[0] as $str_temp) { $demerit_n2 += (strlen($str_temp) - 1); } $ptn_temp = array(); preg_match_all($n2_search2, $ver_or, $ptn_temp); foreach ($ptn_temp[0] as $str_temp) { $demerit_n2 += (strlen($str_temp) - 1); } $demerit_n2 *= 3; $ptn_temp = array(); preg_match_all($n1_search, $hor, $ptn_temp); foreach ($ptn_temp[0] as $str_temp) { $demerit_n1 += (strlen($str_temp) - 2); } $demerit_score = $demerit_n1 + $demerit_n2 + $demerit_n3 + $demerit_n4; if ($demerit_score <= $min_demerit_score || $i == 0) { $mask_number = $i; $min_demerit_score = $demerit_score; } ++$i; } $mask_content = 1 << $mask_number; # --- format information $format_information_value = (($ec << 3) | $mask_number); $format_information_array = array('101010000010010', '101000100100101', '101111001111100', '101101101001011', '100010111111001', '100000011001110', '100111110010111', '100101010100000', '111011111000100', '111001011110011', '111110110101010', '111100010011101', '110011000101111', '110001100011000', '110110001000001', '110100101110110', '001011010001001', '001001110111110', '001110011100111', '001100111010000', '000011101100010', '000001001010101', '000110100001100', '000100000111011', '011010101011111', '011000001101000', '011111100110001', '011101000000110', '010010010110100', '010000110000011', '010111011011010', '010101111101101', ); $i = 0; while ($i < 15) { $content = substr($format_information_array[$format_information_value], $i, 1); $matrix_content[$format_information_x1[$i]][$format_information_y1[$i]] = $content * 255; $matrix_content[$format_information_x2[$i + 1]][$format_information_y2[$i + 1]] = $content * 255; ++$i; } $mib = $max_modules_1side + 8; if ($this->size == 0) { $this->size = $mib * $qrcode_module_size; if ($this->size > 1480) { throw new Exception('QRCode: image size too large'); } } $image_width = $this->size + $this->padding * 2; $image_height = $this->size + $this->padding * 2; if (!empty($this->label)) { if (!function_exists('imagettfbbox')) { throw new Exception('QRCode: missing function "imagettfbbox". Did you install the FreeType library?'); } $font_box = imagettfbbox($this->label_font_size, 0, $this->label_font_path, $this->label); $label_width = (int) $font_box[2] - (int) $font_box[0]; $label_height = (int) $font_box[0] - (int) $font_box[7]; if ($this->label_valign == self::LABEL_VALIGN_MIDDLE) { $image_height += $label_height + $this->padding; } else { $image_height += $label_height; } } $output_image = imagecreate($image_width, $image_height); imagecolorallocate($output_image, 255, 255, 255); $image_path = $image_path.'/qrv'.$qrcode_version.'.png'; $base_image = imagecreatefrompng($image_path); $code_size = $this->size; $module_size = function ($size = 1) use ($code_size, $base_image) { return round($code_size / imagesx($base_image) * $size); }; $col[1] = imagecolorallocate($base_image, 0, 0, 0); $col[0] = imagecolorallocate($base_image, 255, 255, 255); $i = 4; $mxe = 4 + $max_modules_1side; $ii = 0; while ($i < $mxe) { $j = 4; $jj = 0; while ($j < $mxe) { if ($matrix_content[$ii][$jj] & $mask_content) { imagesetpixel($base_image, $i, $j, $col[1]); } ++$j; ++$jj; } ++$i; ++$ii; } if ($this->draw_quiet_zone == true) { imagecopyresampled($output_image, $base_image, $this->padding, $this->padding, 0, 0, $this->size, $this->size, $mib, $mib); } else { imagecopyresampled($output_image, $base_image, $this->padding, $this->padding, 4, 4, $this->size, $this->size, $mib - 8, $mib - 8); } if ($this->draw_border == true) { $border_width = $this->padding; $border_height = $this->size + $this->padding - 1; $border_color = imagecolorallocate($output_image, 0, 0, 0); imagerectangle($output_image, $border_width, $border_width, $border_height, $border_height, $border_color); } if (!empty($this->label)) { // Label horizontal alignment switch ($this->label_halign) { case self::LABEL_HALIGN_LEFT: $font_x = 0; break; case self::LABEL_HALIGN_LEFT_BORDER: $font_x = $this->padding; break; case self::LABEL_HALIGN_LEFT_CODE: if ($this->draw_quiet_zone == true) { $font_x = $this->padding + $module_size(4); } else { $font_x = $this->padding; } break; case self::LABEL_HALIGN_RIGHT: $font_x = $this->size + ($this->padding * 2) - $label_width; break; case self::LABEL_HALIGN_RIGHT_BORDER: $font_x = $this->size + $this->padding - $label_width; break; case self::LABEL_HALIGN_RIGHT_CODE: if ($this->draw_quiet_zone == true) { $font_x = $this->size + $this->padding - $label_width - $module_size(4); } else { $font_x = $this->size + $this->padding - $label_width; } break; default: $font_x = floor($image_width - $label_width) / 2; } // Label vertical alignment switch ($this->label_valign) { case self::LABEL_VALIGN_TOP_NO_BORDER: $font_y = $image_height - $this->padding - 1; break; case self::LABEL_VALIGN_BOTTOM: $font_y = $image_height; break; default: $font_y = $image_height - $this->padding; } $label_bg_x1 = $font_x - $module_size(2); $label_bg_y1 = $font_y - $label_height; $label_bg_x2 = $font_x + $label_width + $module_size(2); $label_bg_y2 = $font_y; $color = imagecolorallocate($output_image, 0, 0, 0); $label_bg_color = imagecolorallocate($output_image, 255, 255, 255); imagefilledrectangle($output_image, $label_bg_x1, $label_bg_y1, $label_bg_x2, $label_bg_y2, $label_bg_color); imagettftext($output_image, $this->label_font_size, 0, $font_x, $font_y, $color, $this->label_font_path, $this->label); } $imagecolorset_function = new ReflectionFunction('imagecolorset'); $allow_alpha = $imagecolorset_function->getNumberOfParameters() == 6; if ($this->color_background != null) { $index = imagecolorclosest($output_image, 255, 255, 255); if ($allow_alpha) { imagecolorset($output_image, $index, $this->color_background['r'], $this->color_background['g'], $this->color_background['b'], $this->color_background['a']); } else { imagecolorset($output_image, $index, $this->color_background['r'], $this->color_background['g'], $this->color_background['b']); } } if ($this->color_foreground != null) { $index = imagecolorclosest($output_image, 0, 0, 0); if ($allow_alpha) { imagecolorset($output_image, $index, $this->color_foreground['r'], $this->color_foreground['g'], $this->color_foreground['b'], $this->color_foreground['a']); } else { imagecolorset($output_image, $index, $this->color_foreground['r'], $this->color_foreground['g'], $this->color_foreground['b']); } } $this->image = $output_image; }
php
public function create() { $image_path = $this->image_path; $path = $this->path; $version_ul = 40; $qrcode_data_string = $this->text;//Previously from $_GET["d"]; $qrcode_error_correct = $this->error_correction;//Previously from $_GET["e"]; $qrcode_module_size = $this->module_size;//Previously from $_GET["s"]; $qrcode_version = $this->version;//Previously from $_GET["v"]; $qrcode_image_type = $this->image_type;//Previously from $_GET["t"]; $qrcode_structureappend_n = $this->structure_append_n;//Previously from $_GET["n"]; $qrcode_structureappend_m = $this->structure_append_m;//Previously from $_GET["m"]; $qrcode_structureappend_parity = $this->structure_append_parity;//Previously from $_GET["p"]; $qrcode_structureappend_originaldata = $this->structure_append_original_data;//Previously from $_GET["o"]; if ($qrcode_module_size > 0) { } else { if ($qrcode_image_type == 'jpeg') { $qrcode_module_size = 8; } else { $qrcode_module_size = 4; } } $data_length = strlen($qrcode_data_string); if ($data_length <= 0) { throw new Exception('QRCode: data does not exist.'); } $data_counter = 0; if ($qrcode_structureappend_n > 1 && $qrcode_structureappend_n <= 16 && $qrcode_structureappend_m > 0 && $qrcode_structureappend_m <= 16) { $data_value[0] = 3; $data_bits[0] = 4; $data_value[1] = $qrcode_structureappend_m - 1; $data_bits[1] = 4; $data_value[2] = $qrcode_structureappend_n - 1; $data_bits[2] = 4; $originaldata_length = strlen($qrcode_structureappend_originaldata); if ($originaldata_length > 1) { $qrcode_structureappend_parity = 0; $i = 0; while ($i < $originaldata_length) { $qrcode_structureappend_parity = ($qrcode_structureappend_parity ^ ord(substr($qrcode_structureappend_originaldata, $i, 1))); ++$i; } } $data_value[3] = $qrcode_structureappend_parity; $data_bits[3] = 8; $data_counter = 4; } $data_bits[$data_counter] = 4; /* --- determine encode mode */ if (preg_match('/[^0-9]/', $qrcode_data_string) != 0) { if (preg_match("/[^0-9A-Z \$\*\%\+\.\/\:\-]/", $qrcode_data_string) != 0) { /* --- 8bit byte mode */ $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ); $data_value[$data_counter] = 4; ++$data_counter; $data_value[$data_counter] = $data_length; $data_bits[$data_counter] = 8; /* #version 1-9 */ $codeword_num_counter_value = $data_counter; ++$data_counter; $i = 0; while ($i < $data_length) { $data_value[$data_counter] = ord(substr($qrcode_data_string, $i, 1)); $data_bits[$data_counter] = 8; ++$data_counter; ++$i; } } else { /* ---- alphanumeric mode */ $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ); $data_value[$data_counter] = 2; ++$data_counter; $data_value[$data_counter] = $data_length; $data_bits[$data_counter] = 9; /* #version 1-9 */ $codeword_num_counter_value = $data_counter; $alphanumeric_character_hash = array('0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35, ' ' => 36, '$' => 37, '%' => 38, '*' => 39, '+' => 40, '-' => 41, '.' => 42, '/' => 43, ':' => 44, ); $i = 0; ++$data_counter; while ($i < $data_length) { if (($i % 2) == 0) { $data_value[$data_counter] = $alphanumeric_character_hash[substr($qrcode_data_string, $i, 1)]; $data_bits[$data_counter] = 6; } else { $data_value[$data_counter] = $data_value[$data_counter] * 45 + $alphanumeric_character_hash[substr($qrcode_data_string, $i, 1)]; $data_bits[$data_counter] = 11; ++$data_counter; } ++$i; } } } else { /* ---- numeric mode */ $codeword_num_plus = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ); $data_value[$data_counter] = 1; ++$data_counter; $data_value[$data_counter] = $data_length; $data_bits[$data_counter] = 10; /* #version 1-9 */ $codeword_num_counter_value = $data_counter; $i = 0; ++$data_counter; while ($i < $data_length) { if (($i % 3) == 0) { $data_value[$data_counter] = substr($qrcode_data_string, $i, 1); $data_bits[$data_counter] = 4; } else { $data_value[$data_counter] = $data_value[$data_counter] * 10 + substr($qrcode_data_string, $i, 1); if (($i % 3) == 1) { $data_bits[$data_counter] = 7; } else { $data_bits[$data_counter] = 10; ++$data_counter; } } ++$i; } } if (array_key_exists($data_counter, $data_bits) && $data_bits[$data_counter] > 0) { ++$data_counter; } $i = 0; $total_data_bits = 0; while ($i < $data_counter) { $total_data_bits += $data_bits[$i]; ++$i; } $ecc_character_hash = array('L' => '1', 'l' => '1', 'M' => '0', 'm' => '0', 'Q' => '3', 'q' => '3', 'H' => '2', 'h' => '2', ); if (!is_numeric($qrcode_error_correct)) { $ec = @$ecc_character_hash[$qrcode_error_correct]; } else { $ec = $qrcode_error_correct; } if (!$ec) { $ec = 0; } $max_data_bits = 0; $max_data_bits_array = array( 0, 128, 224, 352, 512, 688, 864, 992, 1232, 1456, 1728, 2032, 2320, 2672, 2920, 3320, 3624, 4056, 4504, 5016, 5352, 5712, 6256, 6880, 7312, 8000, 8496, 9024, 9544, 10136, 10984, 11640, 12328, 13048, 13800, 14496, 15312, 15936, 16816, 17728, 18672, 152, 272, 440, 640, 864, 1088, 1248, 1552, 1856, 2192, 2592, 2960, 3424, 3688, 4184, 4712, 5176, 5768, 6360, 6888, 7456, 8048, 8752, 9392, 10208, 10960, 11744, 12248, 13048, 13880, 14744, 15640, 16568, 17528, 18448, 19472, 20528, 21616, 22496, 23648, 72, 128, 208, 288, 368, 480, 528, 688, 800, 976, 1120, 1264, 1440, 1576, 1784, 2024, 2264, 2504, 2728, 3080, 3248, 3536, 3712, 4112, 4304, 4768, 5024, 5288, 5608, 5960, 6344, 6760, 7208, 7688, 7888, 8432, 8768, 9136, 9776, 10208, 104, 176, 272, 384, 496, 608, 704, 880, 1056, 1232, 1440, 1648, 1952, 2088, 2360, 2600, 2936, 3176, 3560, 3880, 4096, 4544, 4912, 5312, 5744, 6032, 6464, 6968, 7288, 7880, 8264, 8920, 9368, 9848, 10288, 10832, 11408, 12016, 12656, 13328, ); if (!is_numeric($qrcode_version)) { $qrcode_version = 0; } if (!$qrcode_version) { /* #--- auto version select */ $i = 1 + 40 * $ec; $j = $i + 39; $qrcode_version = 1; while ($i <= $j) { if (($max_data_bits_array[$i]) >= $total_data_bits + $codeword_num_plus[$qrcode_version]) { $max_data_bits = $max_data_bits_array[$i]; break; } ++$i; ++$qrcode_version; } } else { $max_data_bits = $max_data_bits_array[$qrcode_version + 40 * $ec]; } if ($qrcode_version > $version_ul) { throw new Exception('QRCode : version too large'); } $total_data_bits += $codeword_num_plus[$qrcode_version]; $data_bits[$codeword_num_counter_value] += $codeword_num_plus[$qrcode_version]; $max_codewords_array = array(0, 26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706, ); $max_codewords = $max_codewords_array[$qrcode_version]; $max_modules_1side = 17 + ($qrcode_version << 2); $matrix_remain_bit = array(0, 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, ); /* ---- read version ECC data file */ $byte_num = $matrix_remain_bit[$qrcode_version] + ($max_codewords << 3); $filename = $path.'/qrv'.$qrcode_version.'_'.$ec.'.dat'; $fp1 = fopen($filename, 'rb'); $matx = fread($fp1, $byte_num); $maty = fread($fp1, $byte_num); $masks = fread($fp1, $byte_num); $fi_x = fread($fp1, 15); $fi_y = fread($fp1, 15); $rs_ecc_codewords = ord(fread($fp1, 1)); $rso = fread($fp1, 128); fclose($fp1); $matrix_x_array = unpack('C*', $matx); $matrix_y_array = unpack('C*', $maty); $mask_array = unpack('C*', $masks); $rs_block_order = unpack('C*', $rso); $format_information_x2 = unpack('C*', $fi_x); $format_information_y2 = unpack('C*', $fi_y); $format_information_x1 = array(0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8); $format_information_y1 = array(8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0); $max_data_codewords = ($max_data_bits >> 3); $filename = $path.'/rsc'.$rs_ecc_codewords.'.dat'; $fp0 = fopen($filename, 'rb'); $i = 0; $rs_cal_table_array = array(); while ($i < 256) { $rs_cal_table_array[$i] = fread($fp0, $rs_ecc_codewords); ++$i; } fclose($fp0); /* --- set terminator */ if ($total_data_bits <= $max_data_bits - 4) { $data_value[$data_counter] = 0; $data_bits[$data_counter] = 4; } else { if ($total_data_bits < $max_data_bits) { $data_value[$data_counter] = 0; $data_bits[$data_counter] = $max_data_bits - $total_data_bits; } else { if ($total_data_bits > $max_data_bits) { throw new \OverflowException('QRCode: overflow error'); } } } /* ----divide data by 8bit */ $i = 0; $codewords_counter = 0; $codewords[0] = 0; $remaining_bits = 8; while ($i <= $data_counter) { $buffer = @$data_value[$i]; $buffer_bits = @$data_bits[$i]; $flag = 1; while ($flag) { if ($remaining_bits > $buffer_bits) { $codewords[$codewords_counter] = ((@$codewords[$codewords_counter] << $buffer_bits) | $buffer); $remaining_bits -= $buffer_bits; $flag = 0; } else { $buffer_bits -= $remaining_bits; $codewords[$codewords_counter] = (($codewords[$codewords_counter] << $remaining_bits) | ($buffer >> $buffer_bits)); if ($buffer_bits == 0) { $flag = 0; } else { $buffer = ($buffer & ((1 << $buffer_bits) - 1)); $flag = 1; } ++$codewords_counter; if ($codewords_counter < $max_data_codewords - 1) { $codewords[$codewords_counter] = 0; } $remaining_bits = 8; } } ++$i; } if ($remaining_bits != 8) { $codewords[$codewords_counter] = $codewords[$codewords_counter] << $remaining_bits; } else { --$codewords_counter; } /* ---- set padding character */ if ($codewords_counter < $max_data_codewords - 1) { $flag = 1; while ($codewords_counter < $max_data_codewords - 1) { ++$codewords_counter; if ($flag == 1) { $codewords[$codewords_counter] = 236; } else { $codewords[$codewords_counter] = 17; } $flag = $flag * (-1); } } /* ---- RS-ECC prepare */ $i = 0; $j = 0; $rs_block_number = 0; $rs_temp[0] = ''; while ($i < $max_data_codewords) { $rs_temp[$rs_block_number] .= chr($codewords[$i]); ++$j; if ($j >= $rs_block_order[$rs_block_number + 1] - $rs_ecc_codewords) { $j = 0; ++$rs_block_number; $rs_temp[$rs_block_number] = ''; } ++$i; } /* # # RS-ECC main # */ $rs_block_number = 0; $rs_block_order_num = count($rs_block_order); while ($rs_block_number < $rs_block_order_num) { $rs_codewords = $rs_block_order[$rs_block_number + 1]; $rs_data_codewords = $rs_codewords - $rs_ecc_codewords; $rstemp = $rs_temp[$rs_block_number].str_repeat(chr(0), $rs_ecc_codewords); $padding_data = str_repeat(chr(0), $rs_data_codewords); $j = $rs_data_codewords; while ($j > 0) { $first = ord(substr($rstemp, 0, 1)); if ($first) { $left_chr = substr($rstemp, 1); $cal = $rs_cal_table_array[$first].$padding_data; $rstemp = $left_chr ^ $cal; } else { $rstemp = substr($rstemp, 1); } --$j; } $codewords = array_merge($codewords, unpack('C*', $rstemp)); ++$rs_block_number; } /* ---- flash matrix */ $matrix_content = array(); $i = 0; while ($i < $max_modules_1side) { $j = 0; while ($j < $max_modules_1side) { $matrix_content[$j][$i] = 0; ++$j; } ++$i; } /* --- attach data */ $i = 0; while ($i < $max_codewords) { $codeword_i = $codewords[$i]; $j = 8; while ($j >= 1) { $codeword_bits_number = ($i << 3) + $j; $matrix_content[ $matrix_x_array[$codeword_bits_number] ][ $matrix_y_array[$codeword_bits_number] ] = ((255 * ($codeword_i & 1)) ^ $mask_array[$codeword_bits_number]); $codeword_i = $codeword_i >> 1; --$j; } ++$i; } $matrix_remain = $matrix_remain_bit[$qrcode_version]; while ($matrix_remain) { $remain_bit_temp = $matrix_remain + ($max_codewords << 3); $matrix_content[ $matrix_x_array[$remain_bit_temp] ][ $matrix_y_array[$remain_bit_temp] ] = (255 ^ $mask_array[$remain_bit_temp]); --$matrix_remain; } #--- mask select $min_demerit_score = 0; $hor_master = ''; $ver_master = ''; $k = 0; while ($k < $max_modules_1side) { $l = 0; while ($l < $max_modules_1side) { $hor_master = $hor_master.chr($matrix_content[$l][$k]); $ver_master = $ver_master.chr($matrix_content[$k][$l]); ++$l; } ++$k; } $i = 0; $all_matrix = $max_modules_1side * $max_modules_1side; $mask_number = 0; while ($i < 8) { $demerit_n1 = 0; $ptn_temp = array(); $bit = 1 << $i; $bit_r = (~$bit) & 255; $bit_mask = str_repeat(chr($bit), $all_matrix); $hor = $hor_master & $bit_mask; $ver = $ver_master & $bit_mask; $ver_shift1 = $ver.str_repeat(chr(170), $max_modules_1side); $ver_shift2 = str_repeat(chr(170), $max_modules_1side).$ver; $ver_shift1_0 = $ver.str_repeat(chr(0), $max_modules_1side); $ver_shift2_0 = str_repeat(chr(0), $max_modules_1side).$ver; $ver_or = chunk_split(~($ver_shift1 | $ver_shift2), $max_modules_1side, chr(170)); $ver_and = chunk_split(~($ver_shift1_0 & $ver_shift2_0), $max_modules_1side, chr(170)); $hor = chunk_split(~$hor, $max_modules_1side, chr(170)); $ver = chunk_split(~$ver, $max_modules_1side, chr(170)); $hor = $hor.chr(170).$ver; $n1_search = '/'.str_repeat(chr(255), 5).'+|'.str_repeat(chr($bit_r), 5).'+/'; $n3_search = chr($bit_r).chr(255).chr($bit_r).chr($bit_r).chr($bit_r).chr(255).chr($bit_r); $demerit_n3 = substr_count($hor, $n3_search) * 40; $demerit_n4 = floor(abs(((100 * (substr_count($ver, chr($bit_r)) / ($byte_num))) - 50) / 5)) * 10; $n2_search1 = '/'.chr($bit_r).chr($bit_r).'+/'; $n2_search2 = '/'.chr(255).chr(255).'+/'; $demerit_n2 = 0; preg_match_all($n2_search1, $ver_and, $ptn_temp); foreach ($ptn_temp[0] as $str_temp) { $demerit_n2 += (strlen($str_temp) - 1); } $ptn_temp = array(); preg_match_all($n2_search2, $ver_or, $ptn_temp); foreach ($ptn_temp[0] as $str_temp) { $demerit_n2 += (strlen($str_temp) - 1); } $demerit_n2 *= 3; $ptn_temp = array(); preg_match_all($n1_search, $hor, $ptn_temp); foreach ($ptn_temp[0] as $str_temp) { $demerit_n1 += (strlen($str_temp) - 2); } $demerit_score = $demerit_n1 + $demerit_n2 + $demerit_n3 + $demerit_n4; if ($demerit_score <= $min_demerit_score || $i == 0) { $mask_number = $i; $min_demerit_score = $demerit_score; } ++$i; } $mask_content = 1 << $mask_number; # --- format information $format_information_value = (($ec << 3) | $mask_number); $format_information_array = array('101010000010010', '101000100100101', '101111001111100', '101101101001011', '100010111111001', '100000011001110', '100111110010111', '100101010100000', '111011111000100', '111001011110011', '111110110101010', '111100010011101', '110011000101111', '110001100011000', '110110001000001', '110100101110110', '001011010001001', '001001110111110', '001110011100111', '001100111010000', '000011101100010', '000001001010101', '000110100001100', '000100000111011', '011010101011111', '011000001101000', '011111100110001', '011101000000110', '010010010110100', '010000110000011', '010111011011010', '010101111101101', ); $i = 0; while ($i < 15) { $content = substr($format_information_array[$format_information_value], $i, 1); $matrix_content[$format_information_x1[$i]][$format_information_y1[$i]] = $content * 255; $matrix_content[$format_information_x2[$i + 1]][$format_information_y2[$i + 1]] = $content * 255; ++$i; } $mib = $max_modules_1side + 8; if ($this->size == 0) { $this->size = $mib * $qrcode_module_size; if ($this->size > 1480) { throw new Exception('QRCode: image size too large'); } } $image_width = $this->size + $this->padding * 2; $image_height = $this->size + $this->padding * 2; if (!empty($this->label)) { if (!function_exists('imagettfbbox')) { throw new Exception('QRCode: missing function "imagettfbbox". Did you install the FreeType library?'); } $font_box = imagettfbbox($this->label_font_size, 0, $this->label_font_path, $this->label); $label_width = (int) $font_box[2] - (int) $font_box[0]; $label_height = (int) $font_box[0] - (int) $font_box[7]; if ($this->label_valign == self::LABEL_VALIGN_MIDDLE) { $image_height += $label_height + $this->padding; } else { $image_height += $label_height; } } $output_image = imagecreate($image_width, $image_height); imagecolorallocate($output_image, 255, 255, 255); $image_path = $image_path.'/qrv'.$qrcode_version.'.png'; $base_image = imagecreatefrompng($image_path); $code_size = $this->size; $module_size = function ($size = 1) use ($code_size, $base_image) { return round($code_size / imagesx($base_image) * $size); }; $col[1] = imagecolorallocate($base_image, 0, 0, 0); $col[0] = imagecolorallocate($base_image, 255, 255, 255); $i = 4; $mxe = 4 + $max_modules_1side; $ii = 0; while ($i < $mxe) { $j = 4; $jj = 0; while ($j < $mxe) { if ($matrix_content[$ii][$jj] & $mask_content) { imagesetpixel($base_image, $i, $j, $col[1]); } ++$j; ++$jj; } ++$i; ++$ii; } if ($this->draw_quiet_zone == true) { imagecopyresampled($output_image, $base_image, $this->padding, $this->padding, 0, 0, $this->size, $this->size, $mib, $mib); } else { imagecopyresampled($output_image, $base_image, $this->padding, $this->padding, 4, 4, $this->size, $this->size, $mib - 8, $mib - 8); } if ($this->draw_border == true) { $border_width = $this->padding; $border_height = $this->size + $this->padding - 1; $border_color = imagecolorallocate($output_image, 0, 0, 0); imagerectangle($output_image, $border_width, $border_width, $border_height, $border_height, $border_color); } if (!empty($this->label)) { // Label horizontal alignment switch ($this->label_halign) { case self::LABEL_HALIGN_LEFT: $font_x = 0; break; case self::LABEL_HALIGN_LEFT_BORDER: $font_x = $this->padding; break; case self::LABEL_HALIGN_LEFT_CODE: if ($this->draw_quiet_zone == true) { $font_x = $this->padding + $module_size(4); } else { $font_x = $this->padding; } break; case self::LABEL_HALIGN_RIGHT: $font_x = $this->size + ($this->padding * 2) - $label_width; break; case self::LABEL_HALIGN_RIGHT_BORDER: $font_x = $this->size + $this->padding - $label_width; break; case self::LABEL_HALIGN_RIGHT_CODE: if ($this->draw_quiet_zone == true) { $font_x = $this->size + $this->padding - $label_width - $module_size(4); } else { $font_x = $this->size + $this->padding - $label_width; } break; default: $font_x = floor($image_width - $label_width) / 2; } // Label vertical alignment switch ($this->label_valign) { case self::LABEL_VALIGN_TOP_NO_BORDER: $font_y = $image_height - $this->padding - 1; break; case self::LABEL_VALIGN_BOTTOM: $font_y = $image_height; break; default: $font_y = $image_height - $this->padding; } $label_bg_x1 = $font_x - $module_size(2); $label_bg_y1 = $font_y - $label_height; $label_bg_x2 = $font_x + $label_width + $module_size(2); $label_bg_y2 = $font_y; $color = imagecolorallocate($output_image, 0, 0, 0); $label_bg_color = imagecolorallocate($output_image, 255, 255, 255); imagefilledrectangle($output_image, $label_bg_x1, $label_bg_y1, $label_bg_x2, $label_bg_y2, $label_bg_color); imagettftext($output_image, $this->label_font_size, 0, $font_x, $font_y, $color, $this->label_font_path, $this->label); } $imagecolorset_function = new ReflectionFunction('imagecolorset'); $allow_alpha = $imagecolorset_function->getNumberOfParameters() == 6; if ($this->color_background != null) { $index = imagecolorclosest($output_image, 255, 255, 255); if ($allow_alpha) { imagecolorset($output_image, $index, $this->color_background['r'], $this->color_background['g'], $this->color_background['b'], $this->color_background['a']); } else { imagecolorset($output_image, $index, $this->color_background['r'], $this->color_background['g'], $this->color_background['b']); } } if ($this->color_foreground != null) { $index = imagecolorclosest($output_image, 0, 0, 0); if ($allow_alpha) { imagecolorset($output_image, $index, $this->color_foreground['r'], $this->color_foreground['g'], $this->color_foreground['b'], $this->color_foreground['a']); } else { imagecolorset($output_image, $index, $this->color_foreground['r'], $this->color_foreground['g'], $this->color_foreground['b']); } } $this->image = $output_image; }
[ "public", "function", "create", "(", ")", "{", "$", "image_path", "=", "$", "this", "->", "image_path", ";", "$", "path", "=", "$", "this", "->", "path", ";", "$", "version_ul", "=", "40", ";", "$", "qrcode_data_string", "=", "$", "this", "->", "text", ";", "//Previously from $_GET[\"d\"];", "$", "qrcode_error_correct", "=", "$", "this", "->", "error_correction", ";", "//Previously from $_GET[\"e\"];", "$", "qrcode_module_size", "=", "$", "this", "->", "module_size", ";", "//Previously from $_GET[\"s\"];", "$", "qrcode_version", "=", "$", "this", "->", "version", ";", "//Previously from $_GET[\"v\"];", "$", "qrcode_image_type", "=", "$", "this", "->", "image_type", ";", "//Previously from $_GET[\"t\"];", "$", "qrcode_structureappend_n", "=", "$", "this", "->", "structure_append_n", ";", "//Previously from $_GET[\"n\"];", "$", "qrcode_structureappend_m", "=", "$", "this", "->", "structure_append_m", ";", "//Previously from $_GET[\"m\"];", "$", "qrcode_structureappend_parity", "=", "$", "this", "->", "structure_append_parity", ";", "//Previously from $_GET[\"p\"];", "$", "qrcode_structureappend_originaldata", "=", "$", "this", "->", "structure_append_original_data", ";", "//Previously from $_GET[\"o\"];", "if", "(", "$", "qrcode_module_size", ">", "0", ")", "{", "}", "else", "{", "if", "(", "$", "qrcode_image_type", "==", "'jpeg'", ")", "{", "$", "qrcode_module_size", "=", "8", ";", "}", "else", "{", "$", "qrcode_module_size", "=", "4", ";", "}", "}", "$", "data_length", "=", "strlen", "(", "$", "qrcode_data_string", ")", ";", "if", "(", "$", "data_length", "<=", "0", ")", "{", "throw", "new", "Exception", "(", "'QRCode: data does not exist.'", ")", ";", "}", "$", "data_counter", "=", "0", ";", "if", "(", "$", "qrcode_structureappend_n", ">", "1", "&&", "$", "qrcode_structureappend_n", "<=", "16", "&&", "$", "qrcode_structureappend_m", ">", "0", "&&", "$", "qrcode_structureappend_m", "<=", "16", ")", "{", "$", "data_value", "[", "0", "]", "=", "3", ";", "$", "data_bits", "[", "0", "]", "=", "4", ";", "$", "data_value", "[", "1", "]", "=", "$", "qrcode_structureappend_m", "-", "1", ";", "$", "data_bits", "[", "1", "]", "=", "4", ";", "$", "data_value", "[", "2", "]", "=", "$", "qrcode_structureappend_n", "-", "1", ";", "$", "data_bits", "[", "2", "]", "=", "4", ";", "$", "originaldata_length", "=", "strlen", "(", "$", "qrcode_structureappend_originaldata", ")", ";", "if", "(", "$", "originaldata_length", ">", "1", ")", "{", "$", "qrcode_structureappend_parity", "=", "0", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "originaldata_length", ")", "{", "$", "qrcode_structureappend_parity", "=", "(", "$", "qrcode_structureappend_parity", "^", "ord", "(", "substr", "(", "$", "qrcode_structureappend_originaldata", ",", "$", "i", ",", "1", ")", ")", ")", ";", "++", "$", "i", ";", "}", "}", "$", "data_value", "[", "3", "]", "=", "$", "qrcode_structureappend_parity", ";", "$", "data_bits", "[", "3", "]", "=", "8", ";", "$", "data_counter", "=", "4", ";", "}", "$", "data_bits", "[", "$", "data_counter", "]", "=", "4", ";", "/* --- determine encode mode */", "if", "(", "preg_match", "(", "'/[^0-9]/'", ",", "$", "qrcode_data_string", ")", "!=", "0", ")", "{", "if", "(", "preg_match", "(", "\"/[^0-9A-Z \\$\\*\\%\\+\\.\\/\\:\\-]/\"", ",", "$", "qrcode_data_string", ")", "!=", "0", ")", "{", "/* --- 8bit byte mode */", "$", "codeword_num_plus", "=", "array", "(", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", ")", ";", "$", "data_value", "[", "$", "data_counter", "]", "=", "4", ";", "++", "$", "data_counter", ";", "$", "data_value", "[", "$", "data_counter", "]", "=", "$", "data_length", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "8", ";", "/* #version 1-9 */", "$", "codeword_num_counter_value", "=", "$", "data_counter", ";", "++", "$", "data_counter", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "data_length", ")", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "ord", "(", "substr", "(", "$", "qrcode_data_string", ",", "$", "i", ",", "1", ")", ")", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "8", ";", "++", "$", "data_counter", ";", "++", "$", "i", ";", "}", "}", "else", "{", "/* ---- alphanumeric mode */", "$", "codeword_num_plus", "=", "array", "(", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", ")", ";", "$", "data_value", "[", "$", "data_counter", "]", "=", "2", ";", "++", "$", "data_counter", ";", "$", "data_value", "[", "$", "data_counter", "]", "=", "$", "data_length", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "9", ";", "/* #version 1-9 */", "$", "codeword_num_counter_value", "=", "$", "data_counter", ";", "$", "alphanumeric_character_hash", "=", "array", "(", "'0'", "=>", "0", ",", "'1'", "=>", "1", ",", "'2'", "=>", "2", ",", "'3'", "=>", "3", ",", "'4'", "=>", "4", ",", "'5'", "=>", "5", ",", "'6'", "=>", "6", ",", "'7'", "=>", "7", ",", "'8'", "=>", "8", ",", "'9'", "=>", "9", ",", "'A'", "=>", "10", ",", "'B'", "=>", "11", ",", "'C'", "=>", "12", ",", "'D'", "=>", "13", ",", "'E'", "=>", "14", ",", "'F'", "=>", "15", ",", "'G'", "=>", "16", ",", "'H'", "=>", "17", ",", "'I'", "=>", "18", ",", "'J'", "=>", "19", ",", "'K'", "=>", "20", ",", "'L'", "=>", "21", ",", "'M'", "=>", "22", ",", "'N'", "=>", "23", ",", "'O'", "=>", "24", ",", "'P'", "=>", "25", ",", "'Q'", "=>", "26", ",", "'R'", "=>", "27", ",", "'S'", "=>", "28", ",", "'T'", "=>", "29", ",", "'U'", "=>", "30", ",", "'V'", "=>", "31", ",", "'W'", "=>", "32", ",", "'X'", "=>", "33", ",", "'Y'", "=>", "34", ",", "'Z'", "=>", "35", ",", "' '", "=>", "36", ",", "'$'", "=>", "37", ",", "'%'", "=>", "38", ",", "'*'", "=>", "39", ",", "'+'", "=>", "40", ",", "'-'", "=>", "41", ",", "'.'", "=>", "42", ",", "'/'", "=>", "43", ",", "':'", "=>", "44", ",", ")", ";", "$", "i", "=", "0", ";", "++", "$", "data_counter", ";", "while", "(", "$", "i", "<", "$", "data_length", ")", "{", "if", "(", "(", "$", "i", "%", "2", ")", "==", "0", ")", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "$", "alphanumeric_character_hash", "[", "substr", "(", "$", "qrcode_data_string", ",", "$", "i", ",", "1", ")", "]", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "6", ";", "}", "else", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "$", "data_value", "[", "$", "data_counter", "]", "*", "45", "+", "$", "alphanumeric_character_hash", "[", "substr", "(", "$", "qrcode_data_string", ",", "$", "i", ",", "1", ")", "]", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "11", ";", "++", "$", "data_counter", ";", "}", "++", "$", "i", ";", "}", "}", "}", "else", "{", "/* ---- numeric mode */", "$", "codeword_num_plus", "=", "array", "(", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "2", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", ")", ";", "$", "data_value", "[", "$", "data_counter", "]", "=", "1", ";", "++", "$", "data_counter", ";", "$", "data_value", "[", "$", "data_counter", "]", "=", "$", "data_length", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "10", ";", "/* #version 1-9 */", "$", "codeword_num_counter_value", "=", "$", "data_counter", ";", "$", "i", "=", "0", ";", "++", "$", "data_counter", ";", "while", "(", "$", "i", "<", "$", "data_length", ")", "{", "if", "(", "(", "$", "i", "%", "3", ")", "==", "0", ")", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "substr", "(", "$", "qrcode_data_string", ",", "$", "i", ",", "1", ")", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "4", ";", "}", "else", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "$", "data_value", "[", "$", "data_counter", "]", "*", "10", "+", "substr", "(", "$", "qrcode_data_string", ",", "$", "i", ",", "1", ")", ";", "if", "(", "(", "$", "i", "%", "3", ")", "==", "1", ")", "{", "$", "data_bits", "[", "$", "data_counter", "]", "=", "7", ";", "}", "else", "{", "$", "data_bits", "[", "$", "data_counter", "]", "=", "10", ";", "++", "$", "data_counter", ";", "}", "}", "++", "$", "i", ";", "}", "}", "if", "(", "array_key_exists", "(", "$", "data_counter", ",", "$", "data_bits", ")", "&&", "$", "data_bits", "[", "$", "data_counter", "]", ">", "0", ")", "{", "++", "$", "data_counter", ";", "}", "$", "i", "=", "0", ";", "$", "total_data_bits", "=", "0", ";", "while", "(", "$", "i", "<", "$", "data_counter", ")", "{", "$", "total_data_bits", "+=", "$", "data_bits", "[", "$", "i", "]", ";", "++", "$", "i", ";", "}", "$", "ecc_character_hash", "=", "array", "(", "'L'", "=>", "'1'", ",", "'l'", "=>", "'1'", ",", "'M'", "=>", "'0'", ",", "'m'", "=>", "'0'", ",", "'Q'", "=>", "'3'", ",", "'q'", "=>", "'3'", ",", "'H'", "=>", "'2'", ",", "'h'", "=>", "'2'", ",", ")", ";", "if", "(", "!", "is_numeric", "(", "$", "qrcode_error_correct", ")", ")", "{", "$", "ec", "=", "@", "$", "ecc_character_hash", "[", "$", "qrcode_error_correct", "]", ";", "}", "else", "{", "$", "ec", "=", "$", "qrcode_error_correct", ";", "}", "if", "(", "!", "$", "ec", ")", "{", "$", "ec", "=", "0", ";", "}", "$", "max_data_bits", "=", "0", ";", "$", "max_data_bits_array", "=", "array", "(", "0", ",", "128", ",", "224", ",", "352", ",", "512", ",", "688", ",", "864", ",", "992", ",", "1232", ",", "1456", ",", "1728", ",", "2032", ",", "2320", ",", "2672", ",", "2920", ",", "3320", ",", "3624", ",", "4056", ",", "4504", ",", "5016", ",", "5352", ",", "5712", ",", "6256", ",", "6880", ",", "7312", ",", "8000", ",", "8496", ",", "9024", ",", "9544", ",", "10136", ",", "10984", ",", "11640", ",", "12328", ",", "13048", ",", "13800", ",", "14496", ",", "15312", ",", "15936", ",", "16816", ",", "17728", ",", "18672", ",", "152", ",", "272", ",", "440", ",", "640", ",", "864", ",", "1088", ",", "1248", ",", "1552", ",", "1856", ",", "2192", ",", "2592", ",", "2960", ",", "3424", ",", "3688", ",", "4184", ",", "4712", ",", "5176", ",", "5768", ",", "6360", ",", "6888", ",", "7456", ",", "8048", ",", "8752", ",", "9392", ",", "10208", ",", "10960", ",", "11744", ",", "12248", ",", "13048", ",", "13880", ",", "14744", ",", "15640", ",", "16568", ",", "17528", ",", "18448", ",", "19472", ",", "20528", ",", "21616", ",", "22496", ",", "23648", ",", "72", ",", "128", ",", "208", ",", "288", ",", "368", ",", "480", ",", "528", ",", "688", ",", "800", ",", "976", ",", "1120", ",", "1264", ",", "1440", ",", "1576", ",", "1784", ",", "2024", ",", "2264", ",", "2504", ",", "2728", ",", "3080", ",", "3248", ",", "3536", ",", "3712", ",", "4112", ",", "4304", ",", "4768", ",", "5024", ",", "5288", ",", "5608", ",", "5960", ",", "6344", ",", "6760", ",", "7208", ",", "7688", ",", "7888", ",", "8432", ",", "8768", ",", "9136", ",", "9776", ",", "10208", ",", "104", ",", "176", ",", "272", ",", "384", ",", "496", ",", "608", ",", "704", ",", "880", ",", "1056", ",", "1232", ",", "1440", ",", "1648", ",", "1952", ",", "2088", ",", "2360", ",", "2600", ",", "2936", ",", "3176", ",", "3560", ",", "3880", ",", "4096", ",", "4544", ",", "4912", ",", "5312", ",", "5744", ",", "6032", ",", "6464", ",", "6968", ",", "7288", ",", "7880", ",", "8264", ",", "8920", ",", "9368", ",", "9848", ",", "10288", ",", "10832", ",", "11408", ",", "12016", ",", "12656", ",", "13328", ",", ")", ";", "if", "(", "!", "is_numeric", "(", "$", "qrcode_version", ")", ")", "{", "$", "qrcode_version", "=", "0", ";", "}", "if", "(", "!", "$", "qrcode_version", ")", "{", "/* #--- auto version select */", "$", "i", "=", "1", "+", "40", "*", "$", "ec", ";", "$", "j", "=", "$", "i", "+", "39", ";", "$", "qrcode_version", "=", "1", ";", "while", "(", "$", "i", "<=", "$", "j", ")", "{", "if", "(", "(", "$", "max_data_bits_array", "[", "$", "i", "]", ")", ">=", "$", "total_data_bits", "+", "$", "codeword_num_plus", "[", "$", "qrcode_version", "]", ")", "{", "$", "max_data_bits", "=", "$", "max_data_bits_array", "[", "$", "i", "]", ";", "break", ";", "}", "++", "$", "i", ";", "++", "$", "qrcode_version", ";", "}", "}", "else", "{", "$", "max_data_bits", "=", "$", "max_data_bits_array", "[", "$", "qrcode_version", "+", "40", "*", "$", "ec", "]", ";", "}", "if", "(", "$", "qrcode_version", ">", "$", "version_ul", ")", "{", "throw", "new", "Exception", "(", "'QRCode : version too large'", ")", ";", "}", "$", "total_data_bits", "+=", "$", "codeword_num_plus", "[", "$", "qrcode_version", "]", ";", "$", "data_bits", "[", "$", "codeword_num_counter_value", "]", "+=", "$", "codeword_num_plus", "[", "$", "qrcode_version", "]", ";", "$", "max_codewords_array", "=", "array", "(", "0", ",", "26", ",", "44", ",", "70", ",", "100", ",", "134", ",", "172", ",", "196", ",", "242", ",", "292", ",", "346", ",", "404", ",", "466", ",", "532", ",", "581", ",", "655", ",", "733", ",", "815", ",", "901", ",", "991", ",", "1085", ",", "1156", ",", "1258", ",", "1364", ",", "1474", ",", "1588", ",", "1706", ",", "1828", ",", "1921", ",", "2051", ",", "2185", ",", "2323", ",", "2465", ",", "2611", ",", "2761", ",", "2876", ",", "3034", ",", "3196", ",", "3362", ",", "3532", ",", "3706", ",", ")", ";", "$", "max_codewords", "=", "$", "max_codewords_array", "[", "$", "qrcode_version", "]", ";", "$", "max_modules_1side", "=", "17", "+", "(", "$", "qrcode_version", "<<", "2", ")", ";", "$", "matrix_remain_bit", "=", "array", "(", "0", ",", "0", ",", "7", ",", "7", ",", "7", ",", "7", ",", "7", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "3", ",", "3", ",", "3", ",", "3", ",", "3", ",", "3", ",", "3", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "4", ",", "3", ",", "3", ",", "3", ",", "3", ",", "3", ",", "3", ",", "3", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", ")", ";", "/* ---- read version ECC data file */", "$", "byte_num", "=", "$", "matrix_remain_bit", "[", "$", "qrcode_version", "]", "+", "(", "$", "max_codewords", "<<", "3", ")", ";", "$", "filename", "=", "$", "path", ".", "'/qrv'", ".", "$", "qrcode_version", ".", "'_'", ".", "$", "ec", ".", "'.dat'", ";", "$", "fp1", "=", "fopen", "(", "$", "filename", ",", "'rb'", ")", ";", "$", "matx", "=", "fread", "(", "$", "fp1", ",", "$", "byte_num", ")", ";", "$", "maty", "=", "fread", "(", "$", "fp1", ",", "$", "byte_num", ")", ";", "$", "masks", "=", "fread", "(", "$", "fp1", ",", "$", "byte_num", ")", ";", "$", "fi_x", "=", "fread", "(", "$", "fp1", ",", "15", ")", ";", "$", "fi_y", "=", "fread", "(", "$", "fp1", ",", "15", ")", ";", "$", "rs_ecc_codewords", "=", "ord", "(", "fread", "(", "$", "fp1", ",", "1", ")", ")", ";", "$", "rso", "=", "fread", "(", "$", "fp1", ",", "128", ")", ";", "fclose", "(", "$", "fp1", ")", ";", "$", "matrix_x_array", "=", "unpack", "(", "'C*'", ",", "$", "matx", ")", ";", "$", "matrix_y_array", "=", "unpack", "(", "'C*'", ",", "$", "maty", ")", ";", "$", "mask_array", "=", "unpack", "(", "'C*'", ",", "$", "masks", ")", ";", "$", "rs_block_order", "=", "unpack", "(", "'C*'", ",", "$", "rso", ")", ";", "$", "format_information_x2", "=", "unpack", "(", "'C*'", ",", "$", "fi_x", ")", ";", "$", "format_information_y2", "=", "unpack", "(", "'C*'", ",", "$", "fi_y", ")", ";", "$", "format_information_x1", "=", "array", "(", "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "7", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ")", ";", "$", "format_information_y1", "=", "array", "(", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "7", ",", "5", ",", "4", ",", "3", ",", "2", ",", "1", ",", "0", ")", ";", "$", "max_data_codewords", "=", "(", "$", "max_data_bits", ">>", "3", ")", ";", "$", "filename", "=", "$", "path", ".", "'/rsc'", ".", "$", "rs_ecc_codewords", ".", "'.dat'", ";", "$", "fp0", "=", "fopen", "(", "$", "filename", ",", "'rb'", ")", ";", "$", "i", "=", "0", ";", "$", "rs_cal_table_array", "=", "array", "(", ")", ";", "while", "(", "$", "i", "<", "256", ")", "{", "$", "rs_cal_table_array", "[", "$", "i", "]", "=", "fread", "(", "$", "fp0", ",", "$", "rs_ecc_codewords", ")", ";", "++", "$", "i", ";", "}", "fclose", "(", "$", "fp0", ")", ";", "/* --- set terminator */", "if", "(", "$", "total_data_bits", "<=", "$", "max_data_bits", "-", "4", ")", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "0", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "4", ";", "}", "else", "{", "if", "(", "$", "total_data_bits", "<", "$", "max_data_bits", ")", "{", "$", "data_value", "[", "$", "data_counter", "]", "=", "0", ";", "$", "data_bits", "[", "$", "data_counter", "]", "=", "$", "max_data_bits", "-", "$", "total_data_bits", ";", "}", "else", "{", "if", "(", "$", "total_data_bits", ">", "$", "max_data_bits", ")", "{", "throw", "new", "\\", "OverflowException", "(", "'QRCode: overflow error'", ")", ";", "}", "}", "}", "/* ----divide data by 8bit */", "$", "i", "=", "0", ";", "$", "codewords_counter", "=", "0", ";", "$", "codewords", "[", "0", "]", "=", "0", ";", "$", "remaining_bits", "=", "8", ";", "while", "(", "$", "i", "<=", "$", "data_counter", ")", "{", "$", "buffer", "=", "@", "$", "data_value", "[", "$", "i", "]", ";", "$", "buffer_bits", "=", "@", "$", "data_bits", "[", "$", "i", "]", ";", "$", "flag", "=", "1", ";", "while", "(", "$", "flag", ")", "{", "if", "(", "$", "remaining_bits", ">", "$", "buffer_bits", ")", "{", "$", "codewords", "[", "$", "codewords_counter", "]", "=", "(", "(", "@", "$", "codewords", "[", "$", "codewords_counter", "]", "<<", "$", "buffer_bits", ")", "|", "$", "buffer", ")", ";", "$", "remaining_bits", "-=", "$", "buffer_bits", ";", "$", "flag", "=", "0", ";", "}", "else", "{", "$", "buffer_bits", "-=", "$", "remaining_bits", ";", "$", "codewords", "[", "$", "codewords_counter", "]", "=", "(", "(", "$", "codewords", "[", "$", "codewords_counter", "]", "<<", "$", "remaining_bits", ")", "|", "(", "$", "buffer", ">>", "$", "buffer_bits", ")", ")", ";", "if", "(", "$", "buffer_bits", "==", "0", ")", "{", "$", "flag", "=", "0", ";", "}", "else", "{", "$", "buffer", "=", "(", "$", "buffer", "&", "(", "(", "1", "<<", "$", "buffer_bits", ")", "-", "1", ")", ")", ";", "$", "flag", "=", "1", ";", "}", "++", "$", "codewords_counter", ";", "if", "(", "$", "codewords_counter", "<", "$", "max_data_codewords", "-", "1", ")", "{", "$", "codewords", "[", "$", "codewords_counter", "]", "=", "0", ";", "}", "$", "remaining_bits", "=", "8", ";", "}", "}", "++", "$", "i", ";", "}", "if", "(", "$", "remaining_bits", "!=", "8", ")", "{", "$", "codewords", "[", "$", "codewords_counter", "]", "=", "$", "codewords", "[", "$", "codewords_counter", "]", "<<", "$", "remaining_bits", ";", "}", "else", "{", "--", "$", "codewords_counter", ";", "}", "/* ---- set padding character */", "if", "(", "$", "codewords_counter", "<", "$", "max_data_codewords", "-", "1", ")", "{", "$", "flag", "=", "1", ";", "while", "(", "$", "codewords_counter", "<", "$", "max_data_codewords", "-", "1", ")", "{", "++", "$", "codewords_counter", ";", "if", "(", "$", "flag", "==", "1", ")", "{", "$", "codewords", "[", "$", "codewords_counter", "]", "=", "236", ";", "}", "else", "{", "$", "codewords", "[", "$", "codewords_counter", "]", "=", "17", ";", "}", "$", "flag", "=", "$", "flag", "*", "(", "-", "1", ")", ";", "}", "}", "/* ---- RS-ECC prepare */", "$", "i", "=", "0", ";", "$", "j", "=", "0", ";", "$", "rs_block_number", "=", "0", ";", "$", "rs_temp", "[", "0", "]", "=", "''", ";", "while", "(", "$", "i", "<", "$", "max_data_codewords", ")", "{", "$", "rs_temp", "[", "$", "rs_block_number", "]", ".=", "chr", "(", "$", "codewords", "[", "$", "i", "]", ")", ";", "++", "$", "j", ";", "if", "(", "$", "j", ">=", "$", "rs_block_order", "[", "$", "rs_block_number", "+", "1", "]", "-", "$", "rs_ecc_codewords", ")", "{", "$", "j", "=", "0", ";", "++", "$", "rs_block_number", ";", "$", "rs_temp", "[", "$", "rs_block_number", "]", "=", "''", ";", "}", "++", "$", "i", ";", "}", "/*\n #\n # RS-ECC main\n #\n */", "$", "rs_block_number", "=", "0", ";", "$", "rs_block_order_num", "=", "count", "(", "$", "rs_block_order", ")", ";", "while", "(", "$", "rs_block_number", "<", "$", "rs_block_order_num", ")", "{", "$", "rs_codewords", "=", "$", "rs_block_order", "[", "$", "rs_block_number", "+", "1", "]", ";", "$", "rs_data_codewords", "=", "$", "rs_codewords", "-", "$", "rs_ecc_codewords", ";", "$", "rstemp", "=", "$", "rs_temp", "[", "$", "rs_block_number", "]", ".", "str_repeat", "(", "chr", "(", "0", ")", ",", "$", "rs_ecc_codewords", ")", ";", "$", "padding_data", "=", "str_repeat", "(", "chr", "(", "0", ")", ",", "$", "rs_data_codewords", ")", ";", "$", "j", "=", "$", "rs_data_codewords", ";", "while", "(", "$", "j", ">", "0", ")", "{", "$", "first", "=", "ord", "(", "substr", "(", "$", "rstemp", ",", "0", ",", "1", ")", ")", ";", "if", "(", "$", "first", ")", "{", "$", "left_chr", "=", "substr", "(", "$", "rstemp", ",", "1", ")", ";", "$", "cal", "=", "$", "rs_cal_table_array", "[", "$", "first", "]", ".", "$", "padding_data", ";", "$", "rstemp", "=", "$", "left_chr", "^", "$", "cal", ";", "}", "else", "{", "$", "rstemp", "=", "substr", "(", "$", "rstemp", ",", "1", ")", ";", "}", "--", "$", "j", ";", "}", "$", "codewords", "=", "array_merge", "(", "$", "codewords", ",", "unpack", "(", "'C*'", ",", "$", "rstemp", ")", ")", ";", "++", "$", "rs_block_number", ";", "}", "/* ---- flash matrix */", "$", "matrix_content", "=", "array", "(", ")", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "max_modules_1side", ")", "{", "$", "j", "=", "0", ";", "while", "(", "$", "j", "<", "$", "max_modules_1side", ")", "{", "$", "matrix_content", "[", "$", "j", "]", "[", "$", "i", "]", "=", "0", ";", "++", "$", "j", ";", "}", "++", "$", "i", ";", "}", "/* --- attach data */", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "max_codewords", ")", "{", "$", "codeword_i", "=", "$", "codewords", "[", "$", "i", "]", ";", "$", "j", "=", "8", ";", "while", "(", "$", "j", ">=", "1", ")", "{", "$", "codeword_bits_number", "=", "(", "$", "i", "<<", "3", ")", "+", "$", "j", ";", "$", "matrix_content", "[", "$", "matrix_x_array", "[", "$", "codeword_bits_number", "]", "]", "[", "$", "matrix_y_array", "[", "$", "codeword_bits_number", "]", "]", "=", "(", "(", "255", "*", "(", "$", "codeword_i", "&", "1", ")", ")", "^", "$", "mask_array", "[", "$", "codeword_bits_number", "]", ")", ";", "$", "codeword_i", "=", "$", "codeword_i", ">>", "1", ";", "--", "$", "j", ";", "}", "++", "$", "i", ";", "}", "$", "matrix_remain", "=", "$", "matrix_remain_bit", "[", "$", "qrcode_version", "]", ";", "while", "(", "$", "matrix_remain", ")", "{", "$", "remain_bit_temp", "=", "$", "matrix_remain", "+", "(", "$", "max_codewords", "<<", "3", ")", ";", "$", "matrix_content", "[", "$", "matrix_x_array", "[", "$", "remain_bit_temp", "]", "]", "[", "$", "matrix_y_array", "[", "$", "remain_bit_temp", "]", "]", "=", "(", "255", "^", "$", "mask_array", "[", "$", "remain_bit_temp", "]", ")", ";", "--", "$", "matrix_remain", ";", "}", "#--- mask select", "$", "min_demerit_score", "=", "0", ";", "$", "hor_master", "=", "''", ";", "$", "ver_master", "=", "''", ";", "$", "k", "=", "0", ";", "while", "(", "$", "k", "<", "$", "max_modules_1side", ")", "{", "$", "l", "=", "0", ";", "while", "(", "$", "l", "<", "$", "max_modules_1side", ")", "{", "$", "hor_master", "=", "$", "hor_master", ".", "chr", "(", "$", "matrix_content", "[", "$", "l", "]", "[", "$", "k", "]", ")", ";", "$", "ver_master", "=", "$", "ver_master", ".", "chr", "(", "$", "matrix_content", "[", "$", "k", "]", "[", "$", "l", "]", ")", ";", "++", "$", "l", ";", "}", "++", "$", "k", ";", "}", "$", "i", "=", "0", ";", "$", "all_matrix", "=", "$", "max_modules_1side", "*", "$", "max_modules_1side", ";", "$", "mask_number", "=", "0", ";", "while", "(", "$", "i", "<", "8", ")", "{", "$", "demerit_n1", "=", "0", ";", "$", "ptn_temp", "=", "array", "(", ")", ";", "$", "bit", "=", "1", "<<", "$", "i", ";", "$", "bit_r", "=", "(", "~", "$", "bit", ")", "&", "255", ";", "$", "bit_mask", "=", "str_repeat", "(", "chr", "(", "$", "bit", ")", ",", "$", "all_matrix", ")", ";", "$", "hor", "=", "$", "hor_master", "&", "$", "bit_mask", ";", "$", "ver", "=", "$", "ver_master", "&", "$", "bit_mask", ";", "$", "ver_shift1", "=", "$", "ver", ".", "str_repeat", "(", "chr", "(", "170", ")", ",", "$", "max_modules_1side", ")", ";", "$", "ver_shift2", "=", "str_repeat", "(", "chr", "(", "170", ")", ",", "$", "max_modules_1side", ")", ".", "$", "ver", ";", "$", "ver_shift1_0", "=", "$", "ver", ".", "str_repeat", "(", "chr", "(", "0", ")", ",", "$", "max_modules_1side", ")", ";", "$", "ver_shift2_0", "=", "str_repeat", "(", "chr", "(", "0", ")", ",", "$", "max_modules_1side", ")", ".", "$", "ver", ";", "$", "ver_or", "=", "chunk_split", "(", "~", "(", "$", "ver_shift1", "|", "$", "ver_shift2", ")", ",", "$", "max_modules_1side", ",", "chr", "(", "170", ")", ")", ";", "$", "ver_and", "=", "chunk_split", "(", "~", "(", "$", "ver_shift1_0", "&", "$", "ver_shift2_0", ")", ",", "$", "max_modules_1side", ",", "chr", "(", "170", ")", ")", ";", "$", "hor", "=", "chunk_split", "(", "~", "$", "hor", ",", "$", "max_modules_1side", ",", "chr", "(", "170", ")", ")", ";", "$", "ver", "=", "chunk_split", "(", "~", "$", "ver", ",", "$", "max_modules_1side", ",", "chr", "(", "170", ")", ")", ";", "$", "hor", "=", "$", "hor", ".", "chr", "(", "170", ")", ".", "$", "ver", ";", "$", "n1_search", "=", "'/'", ".", "str_repeat", "(", "chr", "(", "255", ")", ",", "5", ")", ".", "'+|'", ".", "str_repeat", "(", "chr", "(", "$", "bit_r", ")", ",", "5", ")", ".", "'+/'", ";", "$", "n3_search", "=", "chr", "(", "$", "bit_r", ")", ".", "chr", "(", "255", ")", ".", "chr", "(", "$", "bit_r", ")", ".", "chr", "(", "$", "bit_r", ")", ".", "chr", "(", "$", "bit_r", ")", ".", "chr", "(", "255", ")", ".", "chr", "(", "$", "bit_r", ")", ";", "$", "demerit_n3", "=", "substr_count", "(", "$", "hor", ",", "$", "n3_search", ")", "*", "40", ";", "$", "demerit_n4", "=", "floor", "(", "abs", "(", "(", "(", "100", "*", "(", "substr_count", "(", "$", "ver", ",", "chr", "(", "$", "bit_r", ")", ")", "/", "(", "$", "byte_num", ")", ")", ")", "-", "50", ")", "/", "5", ")", ")", "*", "10", ";", "$", "n2_search1", "=", "'/'", ".", "chr", "(", "$", "bit_r", ")", ".", "chr", "(", "$", "bit_r", ")", ".", "'+/'", ";", "$", "n2_search2", "=", "'/'", ".", "chr", "(", "255", ")", ".", "chr", "(", "255", ")", ".", "'+/'", ";", "$", "demerit_n2", "=", "0", ";", "preg_match_all", "(", "$", "n2_search1", ",", "$", "ver_and", ",", "$", "ptn_temp", ")", ";", "foreach", "(", "$", "ptn_temp", "[", "0", "]", "as", "$", "str_temp", ")", "{", "$", "demerit_n2", "+=", "(", "strlen", "(", "$", "str_temp", ")", "-", "1", ")", ";", "}", "$", "ptn_temp", "=", "array", "(", ")", ";", "preg_match_all", "(", "$", "n2_search2", ",", "$", "ver_or", ",", "$", "ptn_temp", ")", ";", "foreach", "(", "$", "ptn_temp", "[", "0", "]", "as", "$", "str_temp", ")", "{", "$", "demerit_n2", "+=", "(", "strlen", "(", "$", "str_temp", ")", "-", "1", ")", ";", "}", "$", "demerit_n2", "*=", "3", ";", "$", "ptn_temp", "=", "array", "(", ")", ";", "preg_match_all", "(", "$", "n1_search", ",", "$", "hor", ",", "$", "ptn_temp", ")", ";", "foreach", "(", "$", "ptn_temp", "[", "0", "]", "as", "$", "str_temp", ")", "{", "$", "demerit_n1", "+=", "(", "strlen", "(", "$", "str_temp", ")", "-", "2", ")", ";", "}", "$", "demerit_score", "=", "$", "demerit_n1", "+", "$", "demerit_n2", "+", "$", "demerit_n3", "+", "$", "demerit_n4", ";", "if", "(", "$", "demerit_score", "<=", "$", "min_demerit_score", "||", "$", "i", "==", "0", ")", "{", "$", "mask_number", "=", "$", "i", ";", "$", "min_demerit_score", "=", "$", "demerit_score", ";", "}", "++", "$", "i", ";", "}", "$", "mask_content", "=", "1", "<<", "$", "mask_number", ";", "# --- format information", "$", "format_information_value", "=", "(", "(", "$", "ec", "<<", "3", ")", "|", "$", "mask_number", ")", ";", "$", "format_information_array", "=", "array", "(", "'101010000010010'", ",", "'101000100100101'", ",", "'101111001111100'", ",", "'101101101001011'", ",", "'100010111111001'", ",", "'100000011001110'", ",", "'100111110010111'", ",", "'100101010100000'", ",", "'111011111000100'", ",", "'111001011110011'", ",", "'111110110101010'", ",", "'111100010011101'", ",", "'110011000101111'", ",", "'110001100011000'", ",", "'110110001000001'", ",", "'110100101110110'", ",", "'001011010001001'", ",", "'001001110111110'", ",", "'001110011100111'", ",", "'001100111010000'", ",", "'000011101100010'", ",", "'000001001010101'", ",", "'000110100001100'", ",", "'000100000111011'", ",", "'011010101011111'", ",", "'011000001101000'", ",", "'011111100110001'", ",", "'011101000000110'", ",", "'010010010110100'", ",", "'010000110000011'", ",", "'010111011011010'", ",", "'010101111101101'", ",", ")", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "15", ")", "{", "$", "content", "=", "substr", "(", "$", "format_information_array", "[", "$", "format_information_value", "]", ",", "$", "i", ",", "1", ")", ";", "$", "matrix_content", "[", "$", "format_information_x1", "[", "$", "i", "]", "]", "[", "$", "format_information_y1", "[", "$", "i", "]", "]", "=", "$", "content", "*", "255", ";", "$", "matrix_content", "[", "$", "format_information_x2", "[", "$", "i", "+", "1", "]", "]", "[", "$", "format_information_y2", "[", "$", "i", "+", "1", "]", "]", "=", "$", "content", "*", "255", ";", "++", "$", "i", ";", "}", "$", "mib", "=", "$", "max_modules_1side", "+", "8", ";", "if", "(", "$", "this", "->", "size", "==", "0", ")", "{", "$", "this", "->", "size", "=", "$", "mib", "*", "$", "qrcode_module_size", ";", "if", "(", "$", "this", "->", "size", ">", "1480", ")", "{", "throw", "new", "Exception", "(", "'QRCode: image size too large'", ")", ";", "}", "}", "$", "image_width", "=", "$", "this", "->", "size", "+", "$", "this", "->", "padding", "*", "2", ";", "$", "image_height", "=", "$", "this", "->", "size", "+", "$", "this", "->", "padding", "*", "2", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "label", ")", ")", "{", "if", "(", "!", "function_exists", "(", "'imagettfbbox'", ")", ")", "{", "throw", "new", "Exception", "(", "'QRCode: missing function \"imagettfbbox\". Did you install the FreeType library?'", ")", ";", "}", "$", "font_box", "=", "imagettfbbox", "(", "$", "this", "->", "label_font_size", ",", "0", ",", "$", "this", "->", "label_font_path", ",", "$", "this", "->", "label", ")", ";", "$", "label_width", "=", "(", "int", ")", "$", "font_box", "[", "2", "]", "-", "(", "int", ")", "$", "font_box", "[", "0", "]", ";", "$", "label_height", "=", "(", "int", ")", "$", "font_box", "[", "0", "]", "-", "(", "int", ")", "$", "font_box", "[", "7", "]", ";", "if", "(", "$", "this", "->", "label_valign", "==", "self", "::", "LABEL_VALIGN_MIDDLE", ")", "{", "$", "image_height", "+=", "$", "label_height", "+", "$", "this", "->", "padding", ";", "}", "else", "{", "$", "image_height", "+=", "$", "label_height", ";", "}", "}", "$", "output_image", "=", "imagecreate", "(", "$", "image_width", ",", "$", "image_height", ")", ";", "imagecolorallocate", "(", "$", "output_image", ",", "255", ",", "255", ",", "255", ")", ";", "$", "image_path", "=", "$", "image_path", ".", "'/qrv'", ".", "$", "qrcode_version", ".", "'.png'", ";", "$", "base_image", "=", "imagecreatefrompng", "(", "$", "image_path", ")", ";", "$", "code_size", "=", "$", "this", "->", "size", ";", "$", "module_size", "=", "function", "(", "$", "size", "=", "1", ")", "use", "(", "$", "code_size", ",", "$", "base_image", ")", "{", "return", "round", "(", "$", "code_size", "/", "imagesx", "(", "$", "base_image", ")", "*", "$", "size", ")", ";", "}", ";", "$", "col", "[", "1", "]", "=", "imagecolorallocate", "(", "$", "base_image", ",", "0", ",", "0", ",", "0", ")", ";", "$", "col", "[", "0", "]", "=", "imagecolorallocate", "(", "$", "base_image", ",", "255", ",", "255", ",", "255", ")", ";", "$", "i", "=", "4", ";", "$", "mxe", "=", "4", "+", "$", "max_modules_1side", ";", "$", "ii", "=", "0", ";", "while", "(", "$", "i", "<", "$", "mxe", ")", "{", "$", "j", "=", "4", ";", "$", "jj", "=", "0", ";", "while", "(", "$", "j", "<", "$", "mxe", ")", "{", "if", "(", "$", "matrix_content", "[", "$", "ii", "]", "[", "$", "jj", "]", "&", "$", "mask_content", ")", "{", "imagesetpixel", "(", "$", "base_image", ",", "$", "i", ",", "$", "j", ",", "$", "col", "[", "1", "]", ")", ";", "}", "++", "$", "j", ";", "++", "$", "jj", ";", "}", "++", "$", "i", ";", "++", "$", "ii", ";", "}", "if", "(", "$", "this", "->", "draw_quiet_zone", "==", "true", ")", "{", "imagecopyresampled", "(", "$", "output_image", ",", "$", "base_image", ",", "$", "this", "->", "padding", ",", "$", "this", "->", "padding", ",", "0", ",", "0", ",", "$", "this", "->", "size", ",", "$", "this", "->", "size", ",", "$", "mib", ",", "$", "mib", ")", ";", "}", "else", "{", "imagecopyresampled", "(", "$", "output_image", ",", "$", "base_image", ",", "$", "this", "->", "padding", ",", "$", "this", "->", "padding", ",", "4", ",", "4", ",", "$", "this", "->", "size", ",", "$", "this", "->", "size", ",", "$", "mib", "-", "8", ",", "$", "mib", "-", "8", ")", ";", "}", "if", "(", "$", "this", "->", "draw_border", "==", "true", ")", "{", "$", "border_width", "=", "$", "this", "->", "padding", ";", "$", "border_height", "=", "$", "this", "->", "size", "+", "$", "this", "->", "padding", "-", "1", ";", "$", "border_color", "=", "imagecolorallocate", "(", "$", "output_image", ",", "0", ",", "0", ",", "0", ")", ";", "imagerectangle", "(", "$", "output_image", ",", "$", "border_width", ",", "$", "border_width", ",", "$", "border_height", ",", "$", "border_height", ",", "$", "border_color", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "label", ")", ")", "{", "// Label horizontal alignment", "switch", "(", "$", "this", "->", "label_halign", ")", "{", "case", "self", "::", "LABEL_HALIGN_LEFT", ":", "$", "font_x", "=", "0", ";", "break", ";", "case", "self", "::", "LABEL_HALIGN_LEFT_BORDER", ":", "$", "font_x", "=", "$", "this", "->", "padding", ";", "break", ";", "case", "self", "::", "LABEL_HALIGN_LEFT_CODE", ":", "if", "(", "$", "this", "->", "draw_quiet_zone", "==", "true", ")", "{", "$", "font_x", "=", "$", "this", "->", "padding", "+", "$", "module_size", "(", "4", ")", ";", "}", "else", "{", "$", "font_x", "=", "$", "this", "->", "padding", ";", "}", "break", ";", "case", "self", "::", "LABEL_HALIGN_RIGHT", ":", "$", "font_x", "=", "$", "this", "->", "size", "+", "(", "$", "this", "->", "padding", "*", "2", ")", "-", "$", "label_width", ";", "break", ";", "case", "self", "::", "LABEL_HALIGN_RIGHT_BORDER", ":", "$", "font_x", "=", "$", "this", "->", "size", "+", "$", "this", "->", "padding", "-", "$", "label_width", ";", "break", ";", "case", "self", "::", "LABEL_HALIGN_RIGHT_CODE", ":", "if", "(", "$", "this", "->", "draw_quiet_zone", "==", "true", ")", "{", "$", "font_x", "=", "$", "this", "->", "size", "+", "$", "this", "->", "padding", "-", "$", "label_width", "-", "$", "module_size", "(", "4", ")", ";", "}", "else", "{", "$", "font_x", "=", "$", "this", "->", "size", "+", "$", "this", "->", "padding", "-", "$", "label_width", ";", "}", "break", ";", "default", ":", "$", "font_x", "=", "floor", "(", "$", "image_width", "-", "$", "label_width", ")", "/", "2", ";", "}", "// Label vertical alignment", "switch", "(", "$", "this", "->", "label_valign", ")", "{", "case", "self", "::", "LABEL_VALIGN_TOP_NO_BORDER", ":", "$", "font_y", "=", "$", "image_height", "-", "$", "this", "->", "padding", "-", "1", ";", "break", ";", "case", "self", "::", "LABEL_VALIGN_BOTTOM", ":", "$", "font_y", "=", "$", "image_height", ";", "break", ";", "default", ":", "$", "font_y", "=", "$", "image_height", "-", "$", "this", "->", "padding", ";", "}", "$", "label_bg_x1", "=", "$", "font_x", "-", "$", "module_size", "(", "2", ")", ";", "$", "label_bg_y1", "=", "$", "font_y", "-", "$", "label_height", ";", "$", "label_bg_x2", "=", "$", "font_x", "+", "$", "label_width", "+", "$", "module_size", "(", "2", ")", ";", "$", "label_bg_y2", "=", "$", "font_y", ";", "$", "color", "=", "imagecolorallocate", "(", "$", "output_image", ",", "0", ",", "0", ",", "0", ")", ";", "$", "label_bg_color", "=", "imagecolorallocate", "(", "$", "output_image", ",", "255", ",", "255", ",", "255", ")", ";", "imagefilledrectangle", "(", "$", "output_image", ",", "$", "label_bg_x1", ",", "$", "label_bg_y1", ",", "$", "label_bg_x2", ",", "$", "label_bg_y2", ",", "$", "label_bg_color", ")", ";", "imagettftext", "(", "$", "output_image", ",", "$", "this", "->", "label_font_size", ",", "0", ",", "$", "font_x", ",", "$", "font_y", ",", "$", "color", ",", "$", "this", "->", "label_font_path", ",", "$", "this", "->", "label", ")", ";", "}", "$", "imagecolorset_function", "=", "new", "ReflectionFunction", "(", "'imagecolorset'", ")", ";", "$", "allow_alpha", "=", "$", "imagecolorset_function", "->", "getNumberOfParameters", "(", ")", "==", "6", ";", "if", "(", "$", "this", "->", "color_background", "!=", "null", ")", "{", "$", "index", "=", "imagecolorclosest", "(", "$", "output_image", ",", "255", ",", "255", ",", "255", ")", ";", "if", "(", "$", "allow_alpha", ")", "{", "imagecolorset", "(", "$", "output_image", ",", "$", "index", ",", "$", "this", "->", "color_background", "[", "'r'", "]", ",", "$", "this", "->", "color_background", "[", "'g'", "]", ",", "$", "this", "->", "color_background", "[", "'b'", "]", ",", "$", "this", "->", "color_background", "[", "'a'", "]", ")", ";", "}", "else", "{", "imagecolorset", "(", "$", "output_image", ",", "$", "index", ",", "$", "this", "->", "color_background", "[", "'r'", "]", ",", "$", "this", "->", "color_background", "[", "'g'", "]", ",", "$", "this", "->", "color_background", "[", "'b'", "]", ")", ";", "}", "}", "if", "(", "$", "this", "->", "color_foreground", "!=", "null", ")", "{", "$", "index", "=", "imagecolorclosest", "(", "$", "output_image", ",", "0", ",", "0", ",", "0", ")", ";", "if", "(", "$", "allow_alpha", ")", "{", "imagecolorset", "(", "$", "output_image", ",", "$", "index", ",", "$", "this", "->", "color_foreground", "[", "'r'", "]", ",", "$", "this", "->", "color_foreground", "[", "'g'", "]", ",", "$", "this", "->", "color_foreground", "[", "'b'", "]", ",", "$", "this", "->", "color_foreground", "[", "'a'", "]", ")", ";", "}", "else", "{", "imagecolorset", "(", "$", "output_image", ",", "$", "index", ",", "$", "this", "->", "color_foreground", "[", "'r'", "]", ",", "$", "this", "->", "color_foreground", "[", "'g'", "]", ",", "$", "this", "->", "color_foreground", "[", "'b'", "]", ")", ";", "}", "}", "$", "this", "->", "image", "=", "$", "output_image", ";", "}" ]
Create the image. @throws Exception @throws \OverflowException
[ "Create", "the", "image", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/QrCode.php#L819-L1517
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.setForegroundColor
public function setForegroundColor($code) { if ($code instanceof CINColor) { $this->colorFg = $code; } else { $this->colorFg = new CINColor($code); } }
php
public function setForegroundColor($code) { if ($code instanceof CINColor) { $this->colorFg = $code; } else { $this->colorFg = new CINColor($code); } }
[ "public", "function", "setForegroundColor", "(", "$", "code", ")", "{", "if", "(", "$", "code", "instanceof", "CINColor", ")", "{", "$", "this", "->", "colorFg", "=", "$", "code", ";", "}", "else", "{", "$", "this", "->", "colorFg", "=", "new", "CINColor", "(", "$", "code", ")", ";", "}", "}" ]
Sets the foreground color of the barcode. It could be a CINColor value or simply a language code (white, black, yellow...) or hex value. @param mixed $code
[ "Sets", "the", "foreground", "color", "of", "the", "barcode", ".", "It", "could", "be", "a", "CINColor", "value", "or", "simply", "a", "language", "code", "(", "white", "black", "yellow", "...", ")", "or", "hex", "value", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L62-L68
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.setBackgroundColor
public function setBackgroundColor($code) { if ($code instanceof CINColor) { $this->colorBg = $code; } else { $this->colorBg = new CINColor($code); } foreach ($this->labels as $label) { $label->setBackgroundColor($this->colorBg); } }
php
public function setBackgroundColor($code) { if ($code instanceof CINColor) { $this->colorBg = $code; } else { $this->colorBg = new CINColor($code); } foreach ($this->labels as $label) { $label->setBackgroundColor($this->colorBg); } }
[ "public", "function", "setBackgroundColor", "(", "$", "code", ")", "{", "if", "(", "$", "code", "instanceof", "CINColor", ")", "{", "$", "this", "->", "colorBg", "=", "$", "code", ";", "}", "else", "{", "$", "this", "->", "colorBg", "=", "new", "CINColor", "(", "$", "code", ")", ";", "}", "foreach", "(", "$", "this", "->", "labels", "as", "$", "label", ")", "{", "$", "label", "->", "setBackgroundColor", "(", "$", "this", "->", "colorBg", ")", ";", "}", "}" ]
Sets the background color of the barcode. It could be a CINColor value or simply a language code (white, black, yellow...) or hex value. @param mixed $code
[ "Sets", "the", "background", "color", "of", "the", "barcode", ".", "It", "could", "be", "a", "CINColor", "value", "or", "simply", "a", "language", "code", "(", "white", "black", "yellow", "...", ")", "or", "hex", "value", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L85-L95
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.setScale
public function setScale($scale) { $scale = intval($scale); if ($scale <= 0) { throw new CINArgumentException('The scale must be larger than 0.', 'scale'); } $this->scale = $scale; }
php
public function setScale($scale) { $scale = intval($scale); if ($scale <= 0) { throw new CINArgumentException('The scale must be larger than 0.', 'scale'); } $this->scale = $scale; }
[ "public", "function", "setScale", "(", "$", "scale", ")", "{", "$", "scale", "=", "intval", "(", "$", "scale", ")", ";", "if", "(", "$", "scale", "<=", "0", ")", "{", "throw", "new", "CINArgumentException", "(", "'The scale must be larger than 0.'", ",", "'scale'", ")", ";", "}", "$", "this", "->", "scale", "=", "$", "scale", ";", "}" ]
Sets the scale of the barcode in pixel. If the scale is lower than 1, an exception is raised. @param int $scale
[ "Sets", "the", "scale", "of", "the", "barcode", "in", "pixel", ".", "If", "the", "scale", "is", "lower", "than", "1", "an", "exception", "is", "raised", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L123-L130
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.getDimension
public function getDimension($w, $h) { $labels = $this->getBiggestLabels(false); $pixelsAround = array(0, 0, 0, 0); // TRBL if (isset($labels[CINLabel::POSITION_TOP])) { $dimension = $labels[CINLabel::POSITION_TOP]->getDimension(); $pixelsAround[0] += $dimension[1]; } if (isset($labels[CINLabel::POSITION_RIGHT])) { $dimension = $labels[CINLabel::POSITION_RIGHT]->getDimension(); $pixelsAround[1] += $dimension[0]; } if (isset($labels[CINLabel::POSITION_BOTTOM])) { $dimension = $labels[CINLabel::POSITION_BOTTOM]->getDimension(); $pixelsAround[2] += $dimension[1]; } if (isset($labels[CINLabel::POSITION_LEFT])) { $dimension = $labels[CINLabel::POSITION_LEFT]->getDimension(); $pixelsAround[3] += $dimension[0]; } $finalW = ($w + $this->offsetX) * $this->scale; $finalH = ($h + $this->offsetY) * $this->scale; // This section will check if a top/bottom label is too big for its width and left/right too big for its height $reversedLabels = $this->getBiggestLabels(true); foreach ($reversedLabels as $label) { $dimension = $label->getDimension(); $alignment = $label->getAlignment(); if ($label->getPosition() === CINLabel::POSITION_LEFT || $label->getPosition() === CINLabel::POSITION_RIGHT) { if ($alignment === CINLabel::ALIGN_TOP) { $pixelsAround[2] = max($pixelsAround[2], $dimension[1] - $finalH); } elseif ($alignment === CINLabel::ALIGN_CENTER) { $temp = ceil(($dimension[1] - $finalH) / 2); $pixelsAround[0] = max($pixelsAround[0], $temp); $pixelsAround[2] = max($pixelsAround[2], $temp); } elseif ($alignment === CINLabel::ALIGN_BOTTOM) { $pixelsAround[0] = max($pixelsAround[0], $dimension[1] - $finalH); } } else { if ($alignment === CINLabel::ALIGN_LEFT) { $pixelsAround[1] = max($pixelsAround[1], $dimension[0] - $finalW); } elseif ($alignment === CINLabel::ALIGN_CENTER) { $temp = ceil(($dimension[0] - $finalW) / 2); $pixelsAround[1] = max($pixelsAround[1], $temp); $pixelsAround[3] = max($pixelsAround[3], $temp); } elseif ($alignment === CINLabel::ALIGN_RIGHT) { $pixelsAround[3] = max($pixelsAround[3], $dimension[0] - $finalW); } } } $this->pushLabel[0] = $pixelsAround[3]; $this->pushLabel[1] = $pixelsAround[0]; $finalW = ($w + $this->offsetX) * $this->scale + $pixelsAround[1] + $pixelsAround[3]; $finalH = ($h + $this->offsetY) * $this->scale + $pixelsAround[0] + $pixelsAround[2]; return array($finalW, $finalH); }
php
public function getDimension($w, $h) { $labels = $this->getBiggestLabels(false); $pixelsAround = array(0, 0, 0, 0); // TRBL if (isset($labels[CINLabel::POSITION_TOP])) { $dimension = $labels[CINLabel::POSITION_TOP]->getDimension(); $pixelsAround[0] += $dimension[1]; } if (isset($labels[CINLabel::POSITION_RIGHT])) { $dimension = $labels[CINLabel::POSITION_RIGHT]->getDimension(); $pixelsAround[1] += $dimension[0]; } if (isset($labels[CINLabel::POSITION_BOTTOM])) { $dimension = $labels[CINLabel::POSITION_BOTTOM]->getDimension(); $pixelsAround[2] += $dimension[1]; } if (isset($labels[CINLabel::POSITION_LEFT])) { $dimension = $labels[CINLabel::POSITION_LEFT]->getDimension(); $pixelsAround[3] += $dimension[0]; } $finalW = ($w + $this->offsetX) * $this->scale; $finalH = ($h + $this->offsetY) * $this->scale; // This section will check if a top/bottom label is too big for its width and left/right too big for its height $reversedLabels = $this->getBiggestLabels(true); foreach ($reversedLabels as $label) { $dimension = $label->getDimension(); $alignment = $label->getAlignment(); if ($label->getPosition() === CINLabel::POSITION_LEFT || $label->getPosition() === CINLabel::POSITION_RIGHT) { if ($alignment === CINLabel::ALIGN_TOP) { $pixelsAround[2] = max($pixelsAround[2], $dimension[1] - $finalH); } elseif ($alignment === CINLabel::ALIGN_CENTER) { $temp = ceil(($dimension[1] - $finalH) / 2); $pixelsAround[0] = max($pixelsAround[0], $temp); $pixelsAround[2] = max($pixelsAround[2], $temp); } elseif ($alignment === CINLabel::ALIGN_BOTTOM) { $pixelsAround[0] = max($pixelsAround[0], $dimension[1] - $finalH); } } else { if ($alignment === CINLabel::ALIGN_LEFT) { $pixelsAround[1] = max($pixelsAround[1], $dimension[0] - $finalW); } elseif ($alignment === CINLabel::ALIGN_CENTER) { $temp = ceil(($dimension[0] - $finalW) / 2); $pixelsAround[1] = max($pixelsAround[1], $temp); $pixelsAround[3] = max($pixelsAround[3], $temp); } elseif ($alignment === CINLabel::ALIGN_RIGHT) { $pixelsAround[3] = max($pixelsAround[3], $dimension[0] - $finalW); } } } $this->pushLabel[0] = $pixelsAround[3]; $this->pushLabel[1] = $pixelsAround[0]; $finalW = ($w + $this->offsetX) * $this->scale + $pixelsAround[1] + $pixelsAround[3]; $finalH = ($h + $this->offsetY) * $this->scale + $pixelsAround[0] + $pixelsAround[2]; return array($finalW, $finalH); }
[ "public", "function", "getDimension", "(", "$", "w", ",", "$", "h", ")", "{", "$", "labels", "=", "$", "this", "->", "getBiggestLabels", "(", "false", ")", ";", "$", "pixelsAround", "=", "array", "(", "0", ",", "0", ",", "0", ",", "0", ")", ";", "// TRBL\r", "if", "(", "isset", "(", "$", "labels", "[", "CINLabel", "::", "POSITION_TOP", "]", ")", ")", "{", "$", "dimension", "=", "$", "labels", "[", "CINLabel", "::", "POSITION_TOP", "]", "->", "getDimension", "(", ")", ";", "$", "pixelsAround", "[", "0", "]", "+=", "$", "dimension", "[", "1", "]", ";", "}", "if", "(", "isset", "(", "$", "labels", "[", "CINLabel", "::", "POSITION_RIGHT", "]", ")", ")", "{", "$", "dimension", "=", "$", "labels", "[", "CINLabel", "::", "POSITION_RIGHT", "]", "->", "getDimension", "(", ")", ";", "$", "pixelsAround", "[", "1", "]", "+=", "$", "dimension", "[", "0", "]", ";", "}", "if", "(", "isset", "(", "$", "labels", "[", "CINLabel", "::", "POSITION_BOTTOM", "]", ")", ")", "{", "$", "dimension", "=", "$", "labels", "[", "CINLabel", "::", "POSITION_BOTTOM", "]", "->", "getDimension", "(", ")", ";", "$", "pixelsAround", "[", "2", "]", "+=", "$", "dimension", "[", "1", "]", ";", "}", "if", "(", "isset", "(", "$", "labels", "[", "CINLabel", "::", "POSITION_LEFT", "]", ")", ")", "{", "$", "dimension", "=", "$", "labels", "[", "CINLabel", "::", "POSITION_LEFT", "]", "->", "getDimension", "(", ")", ";", "$", "pixelsAround", "[", "3", "]", "+=", "$", "dimension", "[", "0", "]", ";", "}", "$", "finalW", "=", "(", "$", "w", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", ";", "$", "finalH", "=", "(", "$", "h", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", ";", "// This section will check if a top/bottom label is too big for its width and left/right too big for its height\r", "$", "reversedLabels", "=", "$", "this", "->", "getBiggestLabels", "(", "true", ")", ";", "foreach", "(", "$", "reversedLabels", "as", "$", "label", ")", "{", "$", "dimension", "=", "$", "label", "->", "getDimension", "(", ")", ";", "$", "alignment", "=", "$", "label", "->", "getAlignment", "(", ")", ";", "if", "(", "$", "label", "->", "getPosition", "(", ")", "===", "CINLabel", "::", "POSITION_LEFT", "||", "$", "label", "->", "getPosition", "(", ")", "===", "CINLabel", "::", "POSITION_RIGHT", ")", "{", "if", "(", "$", "alignment", "===", "CINLabel", "::", "ALIGN_TOP", ")", "{", "$", "pixelsAround", "[", "2", "]", "=", "max", "(", "$", "pixelsAround", "[", "2", "]", ",", "$", "dimension", "[", "1", "]", "-", "$", "finalH", ")", ";", "}", "elseif", "(", "$", "alignment", "===", "CINLabel", "::", "ALIGN_CENTER", ")", "{", "$", "temp", "=", "ceil", "(", "(", "$", "dimension", "[", "1", "]", "-", "$", "finalH", ")", "/", "2", ")", ";", "$", "pixelsAround", "[", "0", "]", "=", "max", "(", "$", "pixelsAround", "[", "0", "]", ",", "$", "temp", ")", ";", "$", "pixelsAround", "[", "2", "]", "=", "max", "(", "$", "pixelsAround", "[", "2", "]", ",", "$", "temp", ")", ";", "}", "elseif", "(", "$", "alignment", "===", "CINLabel", "::", "ALIGN_BOTTOM", ")", "{", "$", "pixelsAround", "[", "0", "]", "=", "max", "(", "$", "pixelsAround", "[", "0", "]", ",", "$", "dimension", "[", "1", "]", "-", "$", "finalH", ")", ";", "}", "}", "else", "{", "if", "(", "$", "alignment", "===", "CINLabel", "::", "ALIGN_LEFT", ")", "{", "$", "pixelsAround", "[", "1", "]", "=", "max", "(", "$", "pixelsAround", "[", "1", "]", ",", "$", "dimension", "[", "0", "]", "-", "$", "finalW", ")", ";", "}", "elseif", "(", "$", "alignment", "===", "CINLabel", "::", "ALIGN_CENTER", ")", "{", "$", "temp", "=", "ceil", "(", "(", "$", "dimension", "[", "0", "]", "-", "$", "finalW", ")", "/", "2", ")", ";", "$", "pixelsAround", "[", "1", "]", "=", "max", "(", "$", "pixelsAround", "[", "1", "]", ",", "$", "temp", ")", ";", "$", "pixelsAround", "[", "3", "]", "=", "max", "(", "$", "pixelsAround", "[", "3", "]", ",", "$", "temp", ")", ";", "}", "elseif", "(", "$", "alignment", "===", "CINLabel", "::", "ALIGN_RIGHT", ")", "{", "$", "pixelsAround", "[", "3", "]", "=", "max", "(", "$", "pixelsAround", "[", "3", "]", ",", "$", "dimension", "[", "0", "]", "-", "$", "finalW", ")", ";", "}", "}", "}", "$", "this", "->", "pushLabel", "[", "0", "]", "=", "$", "pixelsAround", "[", "3", "]", ";", "$", "this", "->", "pushLabel", "[", "1", "]", "=", "$", "pixelsAround", "[", "0", "]", ";", "$", "finalW", "=", "(", "$", "w", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "pixelsAround", "[", "1", "]", "+", "$", "pixelsAround", "[", "3", "]", ";", "$", "finalH", "=", "(", "$", "h", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "pixelsAround", "[", "0", "]", "+", "$", "pixelsAround", "[", "2", "]", ";", "return", "array", "(", "$", "finalW", ",", "$", "finalH", ")", ";", "}" ]
Returns the maximal size of a barcode. [0]->width [1]->height @param int $w @param int $h @return int[]
[ "Returns", "the", "maximal", "size", "of", "a", "barcode", ".", "[", "0", "]", "-", ">", "width", "[", "1", "]", "-", ">", "height" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L148-L209
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.setOffsetX
public function setOffsetX($offsetX) { $offsetX = intval($offsetX); if ($offsetX < 0) { throw new CINArgumentException('The offset X must be 0 or larger.', 'offsetX'); } $this->offsetX = $offsetX; }
php
public function setOffsetX($offsetX) { $offsetX = intval($offsetX); if ($offsetX < 0) { throw new CINArgumentException('The offset X must be 0 or larger.', 'offsetX'); } $this->offsetX = $offsetX; }
[ "public", "function", "setOffsetX", "(", "$", "offsetX", ")", "{", "$", "offsetX", "=", "intval", "(", "$", "offsetX", ")", ";", "if", "(", "$", "offsetX", "<", "0", ")", "{", "throw", "new", "CINArgumentException", "(", "'The offset X must be 0 or larger.'", ",", "'offsetX'", ")", ";", "}", "$", "this", "->", "offsetX", "=", "$", "offsetX", ";", "}" ]
Sets the X offset. @param int $offsetX
[ "Sets", "the", "X", "offset", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L225-L232
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.setOffsetY
public function setOffsetY($offsetY) { $offsetY = intval($offsetY); if ($offsetY < 0) { throw new CINArgumentException('The offset Y must be 0 or larger.', 'offsetY'); } $this->offsetY = $offsetY; }
php
public function setOffsetY($offsetY) { $offsetY = intval($offsetY); if ($offsetY < 0) { throw new CINArgumentException('The offset Y must be 0 or larger.', 'offsetY'); } $this->offsetY = $offsetY; }
[ "public", "function", "setOffsetY", "(", "$", "offsetY", ")", "{", "$", "offsetY", "=", "intval", "(", "$", "offsetY", ")", ";", "if", "(", "$", "offsetY", "<", "0", ")", "{", "throw", "new", "CINArgumentException", "(", "'The offset Y must be 0 or larger.'", ",", "'offsetY'", ")", ";", "}", "$", "this", "->", "offsetY", "=", "$", "offsetY", ";", "}" ]
Sets the Y offset. @param int $offsetY
[ "Sets", "the", "Y", "offset", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L248-L255
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.addLabel
public function addLabel(CINLabel $label) { $label->setBackgroundColor($this->colorBg); $label->setForegroundColor($this->colorFg); $this->labels[] = $label; }
php
public function addLabel(CINLabel $label) { $label->setBackgroundColor($this->colorBg); $label->setForegroundColor($this->colorFg); $this->labels[] = $label; }
[ "public", "function", "addLabel", "(", "CINLabel", "$", "label", ")", "{", "$", "label", "->", "setBackgroundColor", "(", "$", "this", "->", "colorBg", ")", ";", "$", "label", "->", "setForegroundColor", "(", "$", "this", "->", "colorFg", ")", ";", "$", "this", "->", "labels", "[", "]", "=", "$", "label", ";", "}" ]
Adds the label to the drawing. @param CINLabel $label
[ "Adds", "the", "label", "to", "the", "drawing", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L262-L266
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.removeLabel
public function removeLabel(CINLabel $label) { $remove = -1; $c = count($this->labels); for ($i = 0; $i < $c; $i++) { if ($this->labels[$i] === $label) { $remove = $i; break; } } if ($remove > -1) { array_splice($this->labels, $remove, 1); } }
php
public function removeLabel(CINLabel $label) { $remove = -1; $c = count($this->labels); for ($i = 0; $i < $c; $i++) { if ($this->labels[$i] === $label) { $remove = $i; break; } } if ($remove > -1) { array_splice($this->labels, $remove, 1); } }
[ "public", "function", "removeLabel", "(", "CINLabel", "$", "label", ")", "{", "$", "remove", "=", "-", "1", ";", "$", "c", "=", "count", "(", "$", "this", "->", "labels", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "labels", "[", "$", "i", "]", "===", "$", "label", ")", "{", "$", "remove", "=", "$", "i", ";", "break", ";", "}", "}", "if", "(", "$", "remove", ">", "-", "1", ")", "{", "array_splice", "(", "$", "this", "->", "labels", ",", "$", "remove", ",", "1", ")", ";", "}", "}" ]
Removes the label from the drawing. @param CINLabel $label
[ "Removes", "the", "label", "from", "the", "drawing", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L273-L286
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.drawText
protected function drawText($im, $x1, $y1, $x2, $y2) { foreach ($this->labels as $label) { $label->draw($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1]); } }
php
protected function drawText($im, $x1, $y1, $x2, $y2) { foreach ($this->labels as $label) { $label->draw($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1]); } }
[ "protected", "function", "drawText", "(", "$", "im", ",", "$", "x1", ",", "$", "y1", ",", "$", "x2", ",", "$", "y2", ")", "{", "foreach", "(", "$", "this", "->", "labels", "as", "$", "label", ")", "{", "$", "label", "->", "draw", "(", "$", "im", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ")", ";", "}", "}" ]
Draws the text. The coordinate passed are the positions of the barcode. $x1 and $y1 represent the top left corner. $x2 and $y2 represent the bottom right corner. @param resource $im @param int $x1 @param int $y1 @param int $x2 @param int $y2
[ "Draws", "the", "text", ".", "The", "coordinate", "passed", "are", "the", "positions", "of", "the", "barcode", ".", "$x1", "and", "$y1", "represent", "the", "top", "left", "corner", ".", "$x2", "and", "$y2", "represent", "the", "bottom", "right", "corner", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L307-L315
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.drawPixel
protected function drawPixel($im, $x, $y, $color = self::COLOR_FG) { $xR = ($x + $this->offsetX) * $this->scale + $this->pushLabel[0]; $yR = ($y + $this->offsetY) * $this->scale + $this->pushLabel[1]; // We always draw a rectangle imagefilledrectangle($im, $xR, $yR, $xR + $this->scale - 1, $yR + $this->scale - 1, $this->getColor($im, $color)); }
php
protected function drawPixel($im, $x, $y, $color = self::COLOR_FG) { $xR = ($x + $this->offsetX) * $this->scale + $this->pushLabel[0]; $yR = ($y + $this->offsetY) * $this->scale + $this->pushLabel[1]; // We always draw a rectangle imagefilledrectangle($im, $xR, $yR, $xR + $this->scale - 1, $yR + $this->scale - 1, $this->getColor($im, $color)); }
[ "protected", "function", "drawPixel", "(", "$", "im", ",", "$", "x", ",", "$", "y", ",", "$", "color", "=", "self", "::", "COLOR_FG", ")", "{", "$", "xR", "=", "(", "$", "x", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ";", "$", "yR", "=", "(", "$", "y", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ";", "// We always draw a rectangle\r", "imagefilledrectangle", "(", "$", "im", ",", "$", "xR", ",", "$", "yR", ",", "$", "xR", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "yR", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "}" ]
Draws 1 pixel on the resource at a specific position with a determined color. @param resource $im @param int $x @param int $y @param int $color
[ "Draws", "1", "pixel", "on", "the", "resource", "at", "a", "specific", "position", "with", "a", "determined", "color", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L325-L336
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.drawRectangle
protected function drawRectangle($im, $x1, $y1, $x2, $y2, $color = self::COLOR_FG) { if ($this->scale === 1) { imagefilledrectangle($im, ($x1 + $this->offsetX) + $this->pushLabel[0], ($y1 + $this->offsetY) + $this->pushLabel[1], ($x2 + $this->offsetX) + $this->pushLabel[0], ($y2 + $this->offsetY) + $this->pushLabel[1], $this->getColor($im, $color)); } else { imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); imagefilledrectangle($im, ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); } }
php
protected function drawRectangle($im, $x1, $y1, $x2, $y2, $color = self::COLOR_FG) { if ($this->scale === 1) { imagefilledrectangle($im, ($x1 + $this->offsetX) + $this->pushLabel[0], ($y1 + $this->offsetY) + $this->pushLabel[1], ($x2 + $this->offsetX) + $this->pushLabel[0], ($y2 + $this->offsetY) + $this->pushLabel[1], $this->getColor($im, $color)); } else { imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); imagefilledrectangle($im, ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); } }
[ "protected", "function", "drawRectangle", "(", "$", "im", ",", "$", "x1", ",", "$", "y1", ",", "$", "x2", ",", "$", "y2", ",", "$", "color", "=", "self", "::", "COLOR_FG", ")", "{", "if", "(", "$", "this", "->", "scale", "===", "1", ")", "{", "imagefilledrectangle", "(", "$", "im", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "}", "else", "{", "imagefilledrectangle", "(", "$", "im", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "imagefilledrectangle", "(", "$", "im", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "imagefilledrectangle", "(", "$", "im", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "imagefilledrectangle", "(", "$", "im", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "}", "}" ]
Draws an empty rectangle on the resource at a specific position with a determined color. @param resource $im @param int $x1 @param int $y1 @param int $x2 @param int $y2 @param int $color
[ "Draws", "an", "empty", "rectangle", "on", "the", "resource", "at", "a", "specific", "position", "with", "a", "determined", "color", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L348-L362
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.drawFilledRectangle
protected function drawFilledRectangle($im, $x1, $y1, $x2, $y2, $color = self::COLOR_FG) { if ($x1 > $x2) { // Swap $x1 ^= $x2 ^= $x1 ^= $x2; } if ($y1 > $y2) { // Swap $y1 ^= $y2 ^= $y1 ^= $y2; } imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); }
php
protected function drawFilledRectangle($im, $x1, $y1, $x2, $y2, $color = self::COLOR_FG) { if ($x1 > $x2) { // Swap $x1 ^= $x2 ^= $x1 ^= $x2; } if ($y1 > $y2) { // Swap $y1 ^= $y2 ^= $y1 ^= $y2; } imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color)); }
[ "protected", "function", "drawFilledRectangle", "(", "$", "im", ",", "$", "x1", ",", "$", "y1", ",", "$", "x2", ",", "$", "y2", ",", "$", "color", "=", "self", "::", "COLOR_FG", ")", "{", "if", "(", "$", "x1", ">", "$", "x2", ")", "{", "// Swap\r", "$", "x1", "^=", "$", "x2", "^=", "$", "x1", "^=", "$", "x2", ";", "}", "if", "(", "$", "y1", ">", "$", "y2", ")", "{", "// Swap\r", "$", "y1", "^=", "$", "y2", "^=", "$", "y1", "^=", "$", "y2", ";", "}", "imagefilledrectangle", "(", "$", "im", ",", "(", "$", "x1", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", ",", "(", "$", "y1", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", ",", "(", "$", "x2", "+", "$", "this", "->", "offsetX", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "0", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "(", "$", "y2", "+", "$", "this", "->", "offsetY", ")", "*", "$", "this", "->", "scale", "+", "$", "this", "->", "pushLabel", "[", "1", "]", "+", "$", "this", "->", "scale", "-", "1", ",", "$", "this", "->", "getColor", "(", "$", "im", ",", "$", "color", ")", ")", ";", "}" ]
Draws a filled rectangle on the resource at a specific position with a determined color. @param resource $im @param int $x1 @param int $y1 @param int $x2 @param int $y2 @param int $color
[ "Draws", "a", "filled", "rectangle", "on", "the", "resource", "at", "a", "specific", "position", "with", "a", "determined", "color", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L374-L389
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.getColor
protected function getColor($im, $color) { if ($color === self::COLOR_BG) { return $this->colorBg->allocate($im); } else { return $this->colorFg->allocate($im); } }
php
protected function getColor($im, $color) { if ($color === self::COLOR_BG) { return $this->colorBg->allocate($im); } else { return $this->colorFg->allocate($im); } }
[ "protected", "function", "getColor", "(", "$", "im", ",", "$", "color", ")", "{", "if", "(", "$", "color", "===", "self", "::", "COLOR_BG", ")", "{", "return", "$", "this", "->", "colorBg", "->", "allocate", "(", "$", "im", ")", ";", "}", "else", "{", "return", "$", "this", "->", "colorFg", "->", "allocate", "(", "$", "im", ")", ";", "}", "}" ]
Allocates the color based on the integer. @param resource $im @param int $color @return resource
[ "Allocates", "the", "color", "based", "on", "the", "integer", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L398-L404
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINBarcode.php
CINBarcode.getBiggestLabels
private function getBiggestLabels($reversed = false) { $searchLR = $reversed ? 1 : 0; $searchTB = $reversed ? 0 : 1; $labels = array(); foreach ($this->labels as $label) { $position = $label->getPosition(); if (isset($labels[$position])) { $savedDimension = $labels[$position]->getDimension(); $dimension = $label->getDimension(); if ($position === CINLabel::POSITION_LEFT || $position === CINLabel::POSITION_RIGHT) { if ($dimension[$searchLR] > $savedDimension[$searchLR]) { $labels[$position] = $label; } } else { if ($dimension[$searchTB] > $savedDimension[$searchTB]) { $labels[$position] = $label; } } } else { $labels[$position] = $label; } } return $labels; }
php
private function getBiggestLabels($reversed = false) { $searchLR = $reversed ? 1 : 0; $searchTB = $reversed ? 0 : 1; $labels = array(); foreach ($this->labels as $label) { $position = $label->getPosition(); if (isset($labels[$position])) { $savedDimension = $labels[$position]->getDimension(); $dimension = $label->getDimension(); if ($position === CINLabel::POSITION_LEFT || $position === CINLabel::POSITION_RIGHT) { if ($dimension[$searchLR] > $savedDimension[$searchLR]) { $labels[$position] = $label; } } else { if ($dimension[$searchTB] > $savedDimension[$searchTB]) { $labels[$position] = $label; } } } else { $labels[$position] = $label; } } return $labels; }
[ "private", "function", "getBiggestLabels", "(", "$", "reversed", "=", "false", ")", "{", "$", "searchLR", "=", "$", "reversed", "?", "1", ":", "0", ";", "$", "searchTB", "=", "$", "reversed", "?", "0", ":", "1", ";", "$", "labels", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "labels", "as", "$", "label", ")", "{", "$", "position", "=", "$", "label", "->", "getPosition", "(", ")", ";", "if", "(", "isset", "(", "$", "labels", "[", "$", "position", "]", ")", ")", "{", "$", "savedDimension", "=", "$", "labels", "[", "$", "position", "]", "->", "getDimension", "(", ")", ";", "$", "dimension", "=", "$", "label", "->", "getDimension", "(", ")", ";", "if", "(", "$", "position", "===", "CINLabel", "::", "POSITION_LEFT", "||", "$", "position", "===", "CINLabel", "::", "POSITION_RIGHT", ")", "{", "if", "(", "$", "dimension", "[", "$", "searchLR", "]", ">", "$", "savedDimension", "[", "$", "searchLR", "]", ")", "{", "$", "labels", "[", "$", "position", "]", "=", "$", "label", ";", "}", "}", "else", "{", "if", "(", "$", "dimension", "[", "$", "searchTB", "]", ">", "$", "savedDimension", "[", "$", "searchTB", "]", ")", "{", "$", "labels", "[", "$", "position", "]", "=", "$", "label", ";", "}", "}", "}", "else", "{", "$", "labels", "[", "$", "position", "]", "=", "$", "label", ";", "}", "}", "return", "$", "labels", ";", "}" ]
Returning the biggest label widths for LEFT/RIGHT and heights for TOP/BOTTOM. @param bool $reversed @return CINLabel[]
[ "Returning", "the", "biggest", "label", "widths", "for", "LEFT", "/", "RIGHT", "and", "heights", "for", "TOP", "/", "BOTTOM", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINBarcode.php#L412-L437
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/JoinDraw.php
JoinDraw.findPosition
private function findPosition($size1, $size2, $alignment) { $rsize1 = max($size1, $size2); $rsize2 = min($size1, $size2); if ($alignment === self::ALIGN_LEFT) { // Or TOP return 0; } elseif ($alignment === self::ALIGN_CENTER) { return $rsize1 / 2 - $rsize2 / 2; } else { // RIGHT or TOP return $rsize1 - $rsize2; } }
php
private function findPosition($size1, $size2, $alignment) { $rsize1 = max($size1, $size2); $rsize2 = min($size1, $size2); if ($alignment === self::ALIGN_LEFT) { // Or TOP return 0; } elseif ($alignment === self::ALIGN_CENTER) { return $rsize1 / 2 - $rsize2 / 2; } else { // RIGHT or TOP return $rsize1 - $rsize2; } }
[ "private", "function", "findPosition", "(", "$", "size1", ",", "$", "size2", ",", "$", "alignment", ")", "{", "$", "rsize1", "=", "max", "(", "$", "size1", ",", "$", "size2", ")", ";", "$", "rsize2", "=", "min", "(", "$", "size1", ",", "$", "size2", ")", ";", "if", "(", "$", "alignment", "===", "self", "::", "ALIGN_LEFT", ")", "{", "// Or TOP\r", "return", "0", ";", "}", "elseif", "(", "$", "alignment", "===", "self", "::", "ALIGN_CENTER", ")", "{", "return", "$", "rsize1", "/", "2", "-", "$", "rsize2", "/", "2", ";", "}", "else", "{", "// RIGHT or TOP\r", "return", "$", "rsize1", "-", "$", "rsize2", ";", "}", "}" ]
Finds the position where the barcode should be aligned. @param int $size1 @param int $size2 @param int $ailgnment @return int
[ "Finds", "the", "position", "where", "the", "barcode", "should", "be", "aligned", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/JoinDraw.php#L84-L95
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/JoinDraw.php
JoinDraw.createIm
private function createIm() { $w1 = imagesx($this->image1); $w2 = imagesx($this->image2); $h1 = imagesy($this->image1); $h2 = imagesy($this->image2); if ($this->position === self::POSITION_LEFT || $this->position === self::POSITION_RIGHT) { $w = $w1 + $w2 + $this->space; $h = max($h1, $h2); } else { $w = max($w1, $w2); $h = $h1 + $h2 + $this->space; } $this->im = imagecreatetruecolor($w, $h); imagefill($this->im, 0, 0, $this->background->allocate($this->im)); // We start defining position of images if ($this->position === self::POSITION_TOP) { if ($w1 > $w2) { $posX1 = 0; $posX2 = $this->findPosition($w1, $w2, $this->alignment); } else { $a = $this->changeAlignment($this->alignment); $posX1 = $this->findPosition($w1, $w2, $a); $posX2 = 0; } $posY2 = 0; $posY1 = $h2 + $this->space; } elseif ($this->position === self::POSITION_LEFT) { if ($w1 > $w2) { $posY1 = 0; $posY2 = $this->findPosition($h1, $h2, $this->alignment); } else { $a = $this->changeAlignment($this->alignment); $posY2 = 0; $posY1 = $this->findPosition($h1, $h2, $a); } $posX2 = 0; $posX1 = $w2 + $this->space; } elseif ($this->position === self::POSITION_BOTTOM) { if ($w1 > $w2) { $posX2 = $this->findPosition($w1, $w2, $this->alignment); $posX1 = 0; } else { $a = $this->changeAlignment($this->alignment); $posX2 = 0; $posX1 = $this->findPosition($w1, $w2, $a); } $posY1 = 0; $posY2 = $h1 + $this->space; } else { // defaults to RIGHT if ($w1 > $w2) { $posY2 = $this->findPosition($h1, $h2, $this->alignment); $posY1 = 0; } else { $a = $this->changeAlignment($this->alignment); $posY2 = 0; $posY1 = $this->findPosition($h1, $h2, $a); } $posX1 = 0; $posX2 = $w1 + $this->space; } imagecopy($this->im, $this->image1, $posX1, $posY1, 0, 0, $w1, $h1); imagecopy($this->im, $this->image2, $posX2, $posY2, 0, 0, $w2, $h2); }
php
private function createIm() { $w1 = imagesx($this->image1); $w2 = imagesx($this->image2); $h1 = imagesy($this->image1); $h2 = imagesy($this->image2); if ($this->position === self::POSITION_LEFT || $this->position === self::POSITION_RIGHT) { $w = $w1 + $w2 + $this->space; $h = max($h1, $h2); } else { $w = max($w1, $w2); $h = $h1 + $h2 + $this->space; } $this->im = imagecreatetruecolor($w, $h); imagefill($this->im, 0, 0, $this->background->allocate($this->im)); // We start defining position of images if ($this->position === self::POSITION_TOP) { if ($w1 > $w2) { $posX1 = 0; $posX2 = $this->findPosition($w1, $w2, $this->alignment); } else { $a = $this->changeAlignment($this->alignment); $posX1 = $this->findPosition($w1, $w2, $a); $posX2 = 0; } $posY2 = 0; $posY1 = $h2 + $this->space; } elseif ($this->position === self::POSITION_LEFT) { if ($w1 > $w2) { $posY1 = 0; $posY2 = $this->findPosition($h1, $h2, $this->alignment); } else { $a = $this->changeAlignment($this->alignment); $posY2 = 0; $posY1 = $this->findPosition($h1, $h2, $a); } $posX2 = 0; $posX1 = $w2 + $this->space; } elseif ($this->position === self::POSITION_BOTTOM) { if ($w1 > $w2) { $posX2 = $this->findPosition($w1, $w2, $this->alignment); $posX1 = 0; } else { $a = $this->changeAlignment($this->alignment); $posX2 = 0; $posX1 = $this->findPosition($w1, $w2, $a); } $posY1 = 0; $posY2 = $h1 + $this->space; } else { // defaults to RIGHT if ($w1 > $w2) { $posY2 = $this->findPosition($h1, $h2, $this->alignment); $posY1 = 0; } else { $a = $this->changeAlignment($this->alignment); $posY2 = 0; $posY1 = $this->findPosition($h1, $h2, $a); } $posX1 = 0; $posX2 = $w1 + $this->space; } imagecopy($this->im, $this->image1, $posX1, $posY1, 0, 0, $w1, $h1); imagecopy($this->im, $this->image2, $posX2, $posY2, 0, 0, $w2, $h2); }
[ "private", "function", "createIm", "(", ")", "{", "$", "w1", "=", "imagesx", "(", "$", "this", "->", "image1", ")", ";", "$", "w2", "=", "imagesx", "(", "$", "this", "->", "image2", ")", ";", "$", "h1", "=", "imagesy", "(", "$", "this", "->", "image1", ")", ";", "$", "h2", "=", "imagesy", "(", "$", "this", "->", "image2", ")", ";", "if", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_LEFT", "||", "$", "this", "->", "position", "===", "self", "::", "POSITION_RIGHT", ")", "{", "$", "w", "=", "$", "w1", "+", "$", "w2", "+", "$", "this", "->", "space", ";", "$", "h", "=", "max", "(", "$", "h1", ",", "$", "h2", ")", ";", "}", "else", "{", "$", "w", "=", "max", "(", "$", "w1", ",", "$", "w2", ")", ";", "$", "h", "=", "$", "h1", "+", "$", "h2", "+", "$", "this", "->", "space", ";", "}", "$", "this", "->", "im", "=", "imagecreatetruecolor", "(", "$", "w", ",", "$", "h", ")", ";", "imagefill", "(", "$", "this", "->", "im", ",", "0", ",", "0", ",", "$", "this", "->", "background", "->", "allocate", "(", "$", "this", "->", "im", ")", ")", ";", "// We start defining position of images\r", "if", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_TOP", ")", "{", "if", "(", "$", "w1", ">", "$", "w2", ")", "{", "$", "posX1", "=", "0", ";", "$", "posX2", "=", "$", "this", "->", "findPosition", "(", "$", "w1", ",", "$", "w2", ",", "$", "this", "->", "alignment", ")", ";", "}", "else", "{", "$", "a", "=", "$", "this", "->", "changeAlignment", "(", "$", "this", "->", "alignment", ")", ";", "$", "posX1", "=", "$", "this", "->", "findPosition", "(", "$", "w1", ",", "$", "w2", ",", "$", "a", ")", ";", "$", "posX2", "=", "0", ";", "}", "$", "posY2", "=", "0", ";", "$", "posY1", "=", "$", "h2", "+", "$", "this", "->", "space", ";", "}", "elseif", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_LEFT", ")", "{", "if", "(", "$", "w1", ">", "$", "w2", ")", "{", "$", "posY1", "=", "0", ";", "$", "posY2", "=", "$", "this", "->", "findPosition", "(", "$", "h1", ",", "$", "h2", ",", "$", "this", "->", "alignment", ")", ";", "}", "else", "{", "$", "a", "=", "$", "this", "->", "changeAlignment", "(", "$", "this", "->", "alignment", ")", ";", "$", "posY2", "=", "0", ";", "$", "posY1", "=", "$", "this", "->", "findPosition", "(", "$", "h1", ",", "$", "h2", ",", "$", "a", ")", ";", "}", "$", "posX2", "=", "0", ";", "$", "posX1", "=", "$", "w2", "+", "$", "this", "->", "space", ";", "}", "elseif", "(", "$", "this", "->", "position", "===", "self", "::", "POSITION_BOTTOM", ")", "{", "if", "(", "$", "w1", ">", "$", "w2", ")", "{", "$", "posX2", "=", "$", "this", "->", "findPosition", "(", "$", "w1", ",", "$", "w2", ",", "$", "this", "->", "alignment", ")", ";", "$", "posX1", "=", "0", ";", "}", "else", "{", "$", "a", "=", "$", "this", "->", "changeAlignment", "(", "$", "this", "->", "alignment", ")", ";", "$", "posX2", "=", "0", ";", "$", "posX1", "=", "$", "this", "->", "findPosition", "(", "$", "w1", ",", "$", "w2", ",", "$", "a", ")", ";", "}", "$", "posY1", "=", "0", ";", "$", "posY2", "=", "$", "h1", "+", "$", "this", "->", "space", ";", "}", "else", "{", "// defaults to RIGHT\r", "if", "(", "$", "w1", ">", "$", "w2", ")", "{", "$", "posY2", "=", "$", "this", "->", "findPosition", "(", "$", "h1", ",", "$", "h2", ",", "$", "this", "->", "alignment", ")", ";", "$", "posY1", "=", "0", ";", "}", "else", "{", "$", "a", "=", "$", "this", "->", "changeAlignment", "(", "$", "this", "->", "alignment", ")", ";", "$", "posY2", "=", "0", ";", "$", "posY1", "=", "$", "this", "->", "findPosition", "(", "$", "h1", ",", "$", "h2", ",", "$", "a", ")", ";", "}", "$", "posX1", "=", "0", ";", "$", "posX2", "=", "$", "w1", "+", "$", "this", "->", "space", ";", "}", "imagecopy", "(", "$", "this", "->", "im", ",", "$", "this", "->", "image1", ",", "$", "posX1", ",", "$", "posY1", ",", "0", ",", "0", ",", "$", "w1", ",", "$", "h1", ")", ";", "imagecopy", "(", "$", "this", "->", "im", ",", "$", "this", "->", "image2", ",", "$", "posX2", ",", "$", "posY2", ",", "0", ",", "0", ",", "$", "w2", ",", "$", "h2", ")", ";", "}" ]
Creates the image.
[ "Creates", "the", "image", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/JoinDraw.php#L116-L186
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINi25.php
CINi25.draw
public function draw($im) { $temp_text = $this->text; // Checksum if ($this->checksum === true) { $this->calculateChecksum(); $temp_text .= $this->keys[$this->checksumValue]; } // Starting Code $this->drawChar($im, '0000', true); // Chars $c = strlen($temp_text); for ($i = 0; $i < $c; $i += 2) { $temp_bar = ''; $c2 = strlen($this->findCode($temp_text[$i])); for ($j = 0; $j < $c2; $j++) { $temp_bar .= substr($this->findCode($temp_text[$i]), $j, 1); $temp_bar .= substr($this->findCode($temp_text[$i + 1]), $j, 1); } $this->drawChar($im, $this->changeBars($temp_bar), true); } // Ending Code $this->drawChar($im, $this->changeBars('100'), true); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
php
public function draw($im) { $temp_text = $this->text; // Checksum if ($this->checksum === true) { $this->calculateChecksum(); $temp_text .= $this->keys[$this->checksumValue]; } // Starting Code $this->drawChar($im, '0000', true); // Chars $c = strlen($temp_text); for ($i = 0; $i < $c; $i += 2) { $temp_bar = ''; $c2 = strlen($this->findCode($temp_text[$i])); for ($j = 0; $j < $c2; $j++) { $temp_bar .= substr($this->findCode($temp_text[$i]), $j, 1); $temp_bar .= substr($this->findCode($temp_text[$i + 1]), $j, 1); } $this->drawChar($im, $this->changeBars($temp_bar), true); } // Ending Code $this->drawChar($im, $this->changeBars('100'), true); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "$", "temp_text", "=", "$", "this", "->", "text", ";", "// Checksum\r", "if", "(", "$", "this", "->", "checksum", "===", "true", ")", "{", "$", "this", "->", "calculateChecksum", "(", ")", ";", "$", "temp_text", ".=", "$", "this", "->", "keys", "[", "$", "this", "->", "checksumValue", "]", ";", "}", "// Starting Code\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'0000'", ",", "true", ")", ";", "// Chars\r", "$", "c", "=", "strlen", "(", "$", "temp_text", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "+=", "2", ")", "{", "$", "temp_bar", "=", "''", ";", "$", "c2", "=", "strlen", "(", "$", "this", "->", "findCode", "(", "$", "temp_text", "[", "$", "i", "]", ")", ")", ";", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "c2", ";", "$", "j", "++", ")", "{", "$", "temp_bar", ".=", "substr", "(", "$", "this", "->", "findCode", "(", "$", "temp_text", "[", "$", "i", "]", ")", ",", "$", "j", ",", "1", ")", ";", "$", "temp_bar", ".=", "substr", "(", "$", "this", "->", "findCode", "(", "$", "temp_text", "[", "$", "i", "+", "1", "]", ")", ",", "$", "j", ",", "1", ")", ";", "}", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "changeBars", "(", "$", "temp_bar", ")", ",", "true", ")", ";", "}", "// Ending Code\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "changeBars", "(", "'100'", ")", ",", "true", ")", ";", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINi25.php#L67-L95
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINi25.php
CINi25.getDimension
public function getDimension($w, $h) { $textlength = (3 + ($this->ratio + 1) * 2) * strlen($this->text); $startlength = 4; $checksumlength = 0; if ($this->checksum === true) { $checksumlength = (3 + ($this->ratio + 1) * 2); } $endlength = 2 + ($this->ratio + 1); $w += $startlength + $textlength + $checksumlength + $endlength; $h += $this->thickness; return parent::getDimension($w, $h); }
php
public function getDimension($w, $h) { $textlength = (3 + ($this->ratio + 1) * 2) * strlen($this->text); $startlength = 4; $checksumlength = 0; if ($this->checksum === true) { $checksumlength = (3 + ($this->ratio + 1) * 2); } $endlength = 2 + ($this->ratio + 1); $w += $startlength + $textlength + $checksumlength + $endlength; $h += $this->thickness; return parent::getDimension($w, $h); }
[ "public", "function", "getDimension", "(", "$", "w", ",", "$", "h", ")", "{", "$", "textlength", "=", "(", "3", "+", "(", "$", "this", "->", "ratio", "+", "1", ")", "*", "2", ")", "*", "strlen", "(", "$", "this", "->", "text", ")", ";", "$", "startlength", "=", "4", ";", "$", "checksumlength", "=", "0", ";", "if", "(", "$", "this", "->", "checksum", "===", "true", ")", "{", "$", "checksumlength", "=", "(", "3", "+", "(", "$", "this", "->", "ratio", "+", "1", ")", "*", "2", ")", ";", "}", "$", "endlength", "=", "2", "+", "(", "$", "this", "->", "ratio", "+", "1", ")", ";", "$", "w", "+=", "$", "startlength", "+", "$", "textlength", "+", "$", "checksumlength", "+", "$", "endlength", ";", "$", "h", "+=", "$", "this", "->", "thickness", ";", "return", "parent", "::", "getDimension", "(", "$", "w", ",", "$", "h", ")", ";", "}" ]
Returns the maximal size of a barcode. @param int $w @param int $h @return int[]
[ "Returns", "the", "maximal", "size", "of", "a", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINi25.php#L104-L117
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINi25.php
CINi25.validate
protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new CINParseException('i25', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new CINParseException('i25', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must be even if ($c % 2 !== 0 && $this->checksum === false) { throw new CINParseException('i25', 'i25 must contain an even amount of digits if checksum is false.'); } elseif ($c % 2 === 0 && $this->checksum === true) { throw new CINParseException('i25', 'i25 must contain an odd amount of digits if checksum is true.'); } parent::validate(); }
php
protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new CINParseException('i25', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new CINParseException('i25', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must be even if ($c % 2 !== 0 && $this->checksum === false) { throw new CINParseException('i25', 'i25 must contain an even amount of digits if checksum is false.'); } elseif ($c % 2 === 0 && $this->checksum === true) { throw new CINParseException('i25', 'i25 must contain an odd amount of digits if checksum is true.'); } parent::validate(); }
[ "protected", "function", "validate", "(", ")", "{", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "if", "(", "$", "c", "===", "0", ")", "{", "throw", "new", "CINParseException", "(", "'i25'", ",", "'No data has been entered.'", ")", ";", "}", "// Checking if all chars are allowed\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "array_search", "(", "$", "this", "->", "text", "[", "$", "i", "]", ",", "$", "this", "->", "keys", ")", "===", "false", ")", "{", "throw", "new", "CINParseException", "(", "'i25'", ",", "'The character \\''", ".", "$", "this", "->", "text", "[", "$", "i", "]", ".", "'\\' is not allowed.'", ")", ";", "}", "}", "// Must be even\r", "if", "(", "$", "c", "%", "2", "!==", "0", "&&", "$", "this", "->", "checksum", "===", "false", ")", "{", "throw", "new", "CINParseException", "(", "'i25'", ",", "'i25 must contain an even amount of digits if checksum is false.'", ")", ";", "}", "elseif", "(", "$", "c", "%", "2", "===", "0", "&&", "$", "this", "->", "checksum", "===", "true", ")", "{", "throw", "new", "CINParseException", "(", "'i25'", ",", "'i25 must contain an odd amount of digits if checksum is true.'", ")", ";", "}", "parent", "::", "validate", "(", ")", ";", "}" ]
Validates the input.
[ "Validates", "the", "input", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINi25.php#L122-L143
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINi25.php
CINi25.calculateChecksum
protected function calculateChecksum() { // Calculating Checksum // Consider the right-most digit of the message to be in an "even" position, // and assign odd/even to each character moving from right to left // Even Position = 3, Odd Position = 1 // Multiply it by the number // Add all of that and do 10-(?mod10) $even = true; $this->checksumValue = 0; $c = strlen($this->text); for ($i = $c; $i > 0; $i--) { if ($even === true) { $multiplier = 3; $even = false; } else { $multiplier = 1; $even = true; } $this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier; } $this->checksumValue = (10 - $this->checksumValue % 10) % 10; }
php
protected function calculateChecksum() { // Calculating Checksum // Consider the right-most digit of the message to be in an "even" position, // and assign odd/even to each character moving from right to left // Even Position = 3, Odd Position = 1 // Multiply it by the number // Add all of that and do 10-(?mod10) $even = true; $this->checksumValue = 0; $c = strlen($this->text); for ($i = $c; $i > 0; $i--) { if ($even === true) { $multiplier = 3; $even = false; } else { $multiplier = 1; $even = true; } $this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier; } $this->checksumValue = (10 - $this->checksumValue % 10) % 10; }
[ "protected", "function", "calculateChecksum", "(", ")", "{", "// Calculating Checksum\r", "// Consider the right-most digit of the message to be in an \"even\" position,\r", "// and assign odd/even to each character moving from right to left\r", "// Even Position = 3, Odd Position = 1\r", "// Multiply it by the number\r", "// Add all of that and do 10-(?mod10)\r", "$", "even", "=", "true", ";", "$", "this", "->", "checksumValue", "=", "0", ";", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "for", "(", "$", "i", "=", "$", "c", ";", "$", "i", ">", "0", ";", "$", "i", "--", ")", "{", "if", "(", "$", "even", "===", "true", ")", "{", "$", "multiplier", "=", "3", ";", "$", "even", "=", "false", ";", "}", "else", "{", "$", "multiplier", "=", "1", ";", "$", "even", "=", "true", ";", "}", "$", "this", "->", "checksumValue", "+=", "$", "this", "->", "keys", "[", "$", "this", "->", "text", "[", "$", "i", "-", "1", "]", "]", "*", "$", "multiplier", ";", "}", "$", "this", "->", "checksumValue", "=", "(", "10", "-", "$", "this", "->", "checksumValue", "%", "10", ")", "%", "10", ";", "}" ]
Overloaded method to calculate checksum.
[ "Overloaded", "method", "to", "calculate", "checksum", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINi25.php#L148-L171
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINi25.php
CINi25.changeBars
private function changeBars($in) { if ($this->ratio > 1) { $c = strlen($in); for ($i = 0; $i < $c; $i++) { $in[$i] = $in[$i] === '1' ? $this->ratio : $in[$i]; } } return $in; }
php
private function changeBars($in) { if ($this->ratio > 1) { $c = strlen($in); for ($i = 0; $i < $c; $i++) { $in[$i] = $in[$i] === '1' ? $this->ratio : $in[$i]; } } return $in; }
[ "private", "function", "changeBars", "(", "$", "in", ")", "{", "if", "(", "$", "this", "->", "ratio", ">", "1", ")", "{", "$", "c", "=", "strlen", "(", "$", "in", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "in", "[", "$", "i", "]", "=", "$", "in", "[", "$", "i", "]", "===", "'1'", "?", "$", "this", "->", "ratio", ":", "$", "in", "[", "$", "i", "]", ";", "}", "}", "return", "$", "in", ";", "}" ]
Changes the size of the bars based on the ratio @param string $in @return string
[ "Changes", "the", "size", "of", "the", "bars", "based", "on", "the", "ratio" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINi25.php#L194-L203
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupcext2.php
CINupcext2.draw
public function draw($im) { // Starting Code $this->drawChar($im, '001', true); // Code for ($i = 0; $i < 2; $i++) { $this->drawChar($im, self::inverse($this->findCode($this->text[$i]), $this->codeParity[intval($this->text) % 4][$i]), false); if ($i === 0) { $this->drawChar($im, '00', false); // Inter-char } } $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
php
public function draw($im) { // Starting Code $this->drawChar($im, '001', true); // Code for ($i = 0; $i < 2; $i++) { $this->drawChar($im, self::inverse($this->findCode($this->text[$i]), $this->codeParity[intval($this->text) % 4][$i]), false); if ($i === 0) { $this->drawChar($im, '00', false); // Inter-char } } $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "// Starting Code\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'001'", ",", "true", ")", ";", "// Code\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "2", ";", "$", "i", "++", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "self", "::", "inverse", "(", "$", "this", "->", "findCode", "(", "$", "this", "->", "text", "[", "$", "i", "]", ")", ",", "$", "this", "->", "codeParity", "[", "intval", "(", "$", "this", "->", "text", ")", "%", "4", "]", "[", "$", "i", "]", ")", ",", "false", ")", ";", "if", "(", "$", "i", "===", "0", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'00'", ",", "false", ")", ";", "// Inter-char\r", "}", "}", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupcext2.php#L59-L72
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupcext2.php
CINupcext2.getDimension
public function getDimension($w, $h) { $startlength = 4; $textlength = 2 * 7; $intercharlength = 2; $w += $startlength + $textlength + $intercharlength; $h += $this->thickness; return parent::getDimension($w, $h); }
php
public function getDimension($w, $h) { $startlength = 4; $textlength = 2 * 7; $intercharlength = 2; $w += $startlength + $textlength + $intercharlength; $h += $this->thickness; return parent::getDimension($w, $h); }
[ "public", "function", "getDimension", "(", "$", "w", ",", "$", "h", ")", "{", "$", "startlength", "=", "4", ";", "$", "textlength", "=", "2", "*", "7", ";", "$", "intercharlength", "=", "2", ";", "$", "w", "+=", "$", "startlength", "+", "$", "textlength", "+", "$", "intercharlength", ";", "$", "h", "+=", "$", "this", "->", "thickness", ";", "return", "parent", "::", "getDimension", "(", "$", "w", ",", "$", "h", ")", ";", "}" ]
Returns the maximal size of a barcode. @param int $w @param int $h @return int[]
[ "Returns", "the", "maximal", "size", "of", "a", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupcext2.php#L81-L89
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINcode39.php
CINcode39.calculateChecksum
protected function calculateChecksum() { $this->checksumValue = 0; $c = strlen($this->text); for ($i = 0; $i < $c; $i++) { $this->checksumValue += $this->findIndex($this->text[$i]); } $this->checksumValue = $this->checksumValue % 43; }
php
protected function calculateChecksum() { $this->checksumValue = 0; $c = strlen($this->text); for ($i = 0; $i < $c; $i++) { $this->checksumValue += $this->findIndex($this->text[$i]); } $this->checksumValue = $this->checksumValue % 43; }
[ "protected", "function", "calculateChecksum", "(", ")", "{", "$", "this", "->", "checksumValue", "=", "0", ";", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "this", "->", "checksumValue", "+=", "$", "this", "->", "findIndex", "(", "$", "this", "->", "text", "[", "$", "i", "]", ")", ";", "}", "$", "this", "->", "checksumValue", "=", "$", "this", "->", "checksumValue", "%", "43", ";", "}" ]
Overloaded method to calculate checksum.
[ "Overloaded", "method", "to", "calculate", "checksum", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINcode39.php#L170-L178
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php
BarcodeGenerator.generate
public function generate($text=null, $type=null, $format=null, $fontPath=null){ if(isset($text)){ $this->text = $text; } if(isset($type)){ $this->barcodeType = $type; } if(isset($format)){ $this->format = $format; } if(isset($fontPath)){ $this->font = $fontPath; } return $this->_render(); }
php
public function generate($text=null, $type=null, $format=null, $fontPath=null){ if(isset($text)){ $this->text = $text; } if(isset($type)){ $this->barcodeType = $type; } if(isset($format)){ $this->format = $format; } if(isset($fontPath)){ $this->font = $fontPath; } return $this->_render(); }
[ "public", "function", "generate", "(", "$", "text", "=", "null", ",", "$", "type", "=", "null", ",", "$", "format", "=", "null", ",", "$", "fontPath", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "text", ")", ")", "{", "$", "this", "->", "text", "=", "$", "text", ";", "}", "if", "(", "isset", "(", "$", "type", ")", ")", "{", "$", "this", "->", "barcodeType", "=", "$", "type", ";", "}", "if", "(", "isset", "(", "$", "format", ")", ")", "{", "$", "this", "->", "format", "=", "$", "format", ";", "}", "if", "(", "isset", "(", "$", "fontPath", ")", ")", "{", "$", "this", "->", "font", "=", "$", "fontPath", ";", "}", "return", "$", "this", "->", "_render", "(", ")", ";", "}" ]
Generate barcode @param string $text Barcode text to generate @param string $type Barcode type such as code128 @param string $format Barcode format such as png, jpeg @param string $fontPath Font path to use in barcode text @return string Base64Encoded string will return
[ "Generate", "barcode" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php#L226-L242
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php
BarcodeGenerator._getCode
private function _getCode(){ $code = null; //try{ $text = $this->text; $textColor = new CINColor($this->foregroundColor); $backgroudColor = new CINColor($this->backgroundColor); $fontPath = isset($this->font) ? $this->font : $this->_getDefaultFont(); $font = new CINFontFile($fontPath, (is_int($this->fontSize)) ? $this->fontSize : 18); $codeClass = "\\CodeItNow\\BarcodeBundle\\Generator\\".$this->barcodeType; $code = new $codeClass(); if($this->scale){ $code->setScale($this->scale); // Resolution } if($this->thickness){ $code->setThickness($this->thickness); // Thickness } if($this->label !== FALSE){ $code->setLabel($this->label); } if($this->noLengthLimit){ $code->setNoLengthLimit($this->noLengthLimit); } if($this->allowsUnknownIdentifier){ $code->setAllowsUnknownIdentifier($this->allowsUnknownIdentifier); } $code->setForegroundColor($textColor); // Color of bars $code->setBackgroundColor($backgroudColor); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text //} catch (\Exception $ex) { //} return $code; }
php
private function _getCode(){ $code = null; //try{ $text = $this->text; $textColor = new CINColor($this->foregroundColor); $backgroudColor = new CINColor($this->backgroundColor); $fontPath = isset($this->font) ? $this->font : $this->_getDefaultFont(); $font = new CINFontFile($fontPath, (is_int($this->fontSize)) ? $this->fontSize : 18); $codeClass = "\\CodeItNow\\BarcodeBundle\\Generator\\".$this->barcodeType; $code = new $codeClass(); if($this->scale){ $code->setScale($this->scale); // Resolution } if($this->thickness){ $code->setThickness($this->thickness); // Thickness } if($this->label !== FALSE){ $code->setLabel($this->label); } if($this->noLengthLimit){ $code->setNoLengthLimit($this->noLengthLimit); } if($this->allowsUnknownIdentifier){ $code->setAllowsUnknownIdentifier($this->allowsUnknownIdentifier); } $code->setForegroundColor($textColor); // Color of bars $code->setBackgroundColor($backgroudColor); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text //} catch (\Exception $ex) { //} return $code; }
[ "private", "function", "_getCode", "(", ")", "{", "$", "code", "=", "null", ";", "//try{", "$", "text", "=", "$", "this", "->", "text", ";", "$", "textColor", "=", "new", "CINColor", "(", "$", "this", "->", "foregroundColor", ")", ";", "$", "backgroudColor", "=", "new", "CINColor", "(", "$", "this", "->", "backgroundColor", ")", ";", "$", "fontPath", "=", "isset", "(", "$", "this", "->", "font", ")", "?", "$", "this", "->", "font", ":", "$", "this", "->", "_getDefaultFont", "(", ")", ";", "$", "font", "=", "new", "CINFontFile", "(", "$", "fontPath", ",", "(", "is_int", "(", "$", "this", "->", "fontSize", ")", ")", "?", "$", "this", "->", "fontSize", ":", "18", ")", ";", "$", "codeClass", "=", "\"\\\\CodeItNow\\\\BarcodeBundle\\\\Generator\\\\\"", ".", "$", "this", "->", "barcodeType", ";", "$", "code", "=", "new", "$", "codeClass", "(", ")", ";", "if", "(", "$", "this", "->", "scale", ")", "{", "$", "code", "->", "setScale", "(", "$", "this", "->", "scale", ")", ";", "// Resolution", "}", "if", "(", "$", "this", "->", "thickness", ")", "{", "$", "code", "->", "setThickness", "(", "$", "this", "->", "thickness", ")", ";", "// Thickness", "}", "if", "(", "$", "this", "->", "label", "!==", "FALSE", ")", "{", "$", "code", "->", "setLabel", "(", "$", "this", "->", "label", ")", ";", "}", "if", "(", "$", "this", "->", "noLengthLimit", ")", "{", "$", "code", "->", "setNoLengthLimit", "(", "$", "this", "->", "noLengthLimit", ")", ";", "}", "if", "(", "$", "this", "->", "allowsUnknownIdentifier", ")", "{", "$", "code", "->", "setAllowsUnknownIdentifier", "(", "$", "this", "->", "allowsUnknownIdentifier", ")", ";", "}", "$", "code", "->", "setForegroundColor", "(", "$", "textColor", ")", ";", "// Color of bars", "$", "code", "->", "setBackgroundColor", "(", "$", "backgroudColor", ")", ";", "// Color of spaces", "$", "code", "->", "setFont", "(", "$", "font", ")", ";", "// Font (or 0)", "$", "code", "->", "parse", "(", "$", "text", ")", ";", "// Text", "//} catch (\\Exception $ex) {", "//}", "return", "$", "code", ";", "}" ]
Get barcode object to create image @return object Barcode object
[ "Get", "barcode", "object", "to", "create", "image" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php#L248-L283
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php
BarcodeGenerator._render
private function _render(){ $textColor = new CINColor($this->foregroundColor); $backgroudColor = new CINColor($this->backgroundColor); /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new CINDrawing($this->filename, $backgroudColor); $drawException = null; if(isset($this->format) and !in_array(strtoupper($this->format), $this->allowedFormats)){ $drawException = $this->format .' format is not allowed.'; } if(!isset($this->barcodeType)){ $drawException = 'Unable to generate barcode for unknown type'; }else{ try{ if(!($code = $this->_getCode())){ $drawException = 'Unable to generate barcode'; } } catch(\Exception $e){ $drawException = $e->getMessage(); } } ob_start(); if($drawException) { $exception = new \Exception($drawException); $drawing->drawException($exception); } else { $drawing->setBarcode($code); $drawing->draw(); } $drawing->finish($this->_getFormat()); $barcodeImg = ob_get_clean(); $barcodeImg = base64_encode($barcodeImg); return $barcodeImg; }
php
private function _render(){ $textColor = new CINColor($this->foregroundColor); $backgroudColor = new CINColor($this->backgroundColor); /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new CINDrawing($this->filename, $backgroudColor); $drawException = null; if(isset($this->format) and !in_array(strtoupper($this->format), $this->allowedFormats)){ $drawException = $this->format .' format is not allowed.'; } if(!isset($this->barcodeType)){ $drawException = 'Unable to generate barcode for unknown type'; }else{ try{ if(!($code = $this->_getCode())){ $drawException = 'Unable to generate barcode'; } } catch(\Exception $e){ $drawException = $e->getMessage(); } } ob_start(); if($drawException) { $exception = new \Exception($drawException); $drawing->drawException($exception); } else { $drawing->setBarcode($code); $drawing->draw(); } $drawing->finish($this->_getFormat()); $barcodeImg = ob_get_clean(); $barcodeImg = base64_encode($barcodeImg); return $barcodeImg; }
[ "private", "function", "_render", "(", ")", "{", "$", "textColor", "=", "new", "CINColor", "(", "$", "this", "->", "foregroundColor", ")", ";", "$", "backgroudColor", "=", "new", "CINColor", "(", "$", "this", "->", "backgroundColor", ")", ";", "/* Here is the list of the arguments\n 1 - Filename (empty : display on screen)\n 2 - Background color */", "$", "drawing", "=", "new", "CINDrawing", "(", "$", "this", "->", "filename", ",", "$", "backgroudColor", ")", ";", "$", "drawException", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "format", ")", "and", "!", "in_array", "(", "strtoupper", "(", "$", "this", "->", "format", ")", ",", "$", "this", "->", "allowedFormats", ")", ")", "{", "$", "drawException", "=", "$", "this", "->", "format", ".", "' format is not allowed.'", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "barcodeType", ")", ")", "{", "$", "drawException", "=", "'Unable to generate barcode for unknown type'", ";", "}", "else", "{", "try", "{", "if", "(", "!", "(", "$", "code", "=", "$", "this", "->", "_getCode", "(", ")", ")", ")", "{", "$", "drawException", "=", "'Unable to generate barcode'", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "drawException", "=", "$", "e", "->", "getMessage", "(", ")", ";", "}", "}", "ob_start", "(", ")", ";", "if", "(", "$", "drawException", ")", "{", "$", "exception", "=", "new", "\\", "Exception", "(", "$", "drawException", ")", ";", "$", "drawing", "->", "drawException", "(", "$", "exception", ")", ";", "}", "else", "{", "$", "drawing", "->", "setBarcode", "(", "$", "code", ")", ";", "$", "drawing", "->", "draw", "(", ")", ";", "}", "$", "drawing", "->", "finish", "(", "$", "this", "->", "_getFormat", "(", ")", ")", ";", "$", "barcodeImg", "=", "ob_get_clean", "(", ")", ";", "$", "barcodeImg", "=", "base64_encode", "(", "$", "barcodeImg", ")", ";", "return", "$", "barcodeImg", ";", "}" ]
Render barcode as base64 encoded @return string Base64Encoded image
[ "Render", "barcode", "as", "base64", "encoded" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php#L289-L328
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php
BarcodeGenerator._getFormat
private function _getFormat(){ $format = ''; switch(strtoupper($this->format)){ case 'PNG': $format = CINDrawing::IMG_FORMAT_PNG; break; case 'JPEG': $format = CINDrawing::IMG_FORMAT_JPEG; break; case 'GIF': $format = CINDrawing::IMG_FORMAT_GIF; break; case 'WBMP': $format = CINDrawing::IMG_FORMAT_WBMP; break; default: $format = CINDrawing::IMG_FORMAT_PNG; break; } return $format; }
php
private function _getFormat(){ $format = ''; switch(strtoupper($this->format)){ case 'PNG': $format = CINDrawing::IMG_FORMAT_PNG; break; case 'JPEG': $format = CINDrawing::IMG_FORMAT_JPEG; break; case 'GIF': $format = CINDrawing::IMG_FORMAT_GIF; break; case 'WBMP': $format = CINDrawing::IMG_FORMAT_WBMP; break; default: $format = CINDrawing::IMG_FORMAT_PNG; break; } return $format; }
[ "private", "function", "_getFormat", "(", ")", "{", "$", "format", "=", "''", ";", "switch", "(", "strtoupper", "(", "$", "this", "->", "format", ")", ")", "{", "case", "'PNG'", ":", "$", "format", "=", "CINDrawing", "::", "IMG_FORMAT_PNG", ";", "break", ";", "case", "'JPEG'", ":", "$", "format", "=", "CINDrawing", "::", "IMG_FORMAT_JPEG", ";", "break", ";", "case", "'GIF'", ":", "$", "format", "=", "CINDrawing", "::", "IMG_FORMAT_GIF", ";", "break", ";", "case", "'WBMP'", ":", "$", "format", "=", "CINDrawing", "::", "IMG_FORMAT_WBMP", ";", "break", ";", "default", ":", "$", "format", "=", "CINDrawing", "::", "IMG_FORMAT_PNG", ";", "break", ";", "}", "return", "$", "format", ";", "}" ]
Barcode image format @return string
[ "Barcode", "image", "format" ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Utils/BarcodeGenerator.php#L334-L354
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINpostnet.php
CINpostnet.draw
public function draw($im) { // Checksum $checksum = 0; $c = strlen($this->text); for ($i = 0; $i < $c; $i++) { $checksum += intval($this->text[$i]); } $checksum = 10 - ($checksum % 10); // Starting Code $this->drawChar($im, '1'); // Code for ($i = 0; $i < $c; $i++) { $this->drawChar($im, $this->findCode($this->text[$i])); } // Checksum $this->drawChar($im, $this->findCode($checksum)); // Ending Code $this->drawChar($im, '1'); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
php
public function draw($im) { // Checksum $checksum = 0; $c = strlen($this->text); for ($i = 0; $i < $c; $i++) { $checksum += intval($this->text[$i]); } $checksum = 10 - ($checksum % 10); // Starting Code $this->drawChar($im, '1'); // Code for ($i = 0; $i < $c; $i++) { $this->drawChar($im, $this->findCode($this->text[$i])); } // Checksum $this->drawChar($im, $this->findCode($checksum)); // Ending Code $this->drawChar($im, '1'); $this->drawText($im, 0, 0, $this->positionX, $this->thickness); }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "// Checksum\r", "$", "checksum", "=", "0", ";", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "checksum", "+=", "intval", "(", "$", "this", "->", "text", "[", "$", "i", "]", ")", ";", "}", "$", "checksum", "=", "10", "-", "(", "$", "checksum", "%", "10", ")", ";", "// Starting Code\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'1'", ")", ";", "// Code\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "findCode", "(", "$", "this", "->", "text", "[", "$", "i", "]", ")", ")", ";", "}", "// Checksum\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "$", "this", "->", "findCode", "(", "$", "checksum", ")", ")", ";", "// Ending Code\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'1'", ")", ";", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", ")", ";", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINpostnet.php#L47-L71
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINpostnet.php
CINpostnet.drawChar
protected function drawChar($im, $code, $startBar = true) { $c = strlen($code); for ($i = 0; $i < $c; $i++) { if ($code[$i] === '0') { $posY = $this->thickness - ($this->thickness / 2.5); } else { $posY = 0; } $this->drawFilledRectangle($im, $this->positionX, $posY, $this->positionX + 0.44, $this->thickness - 1, CINBarcode::COLOR_FG); $this->positionX += 3; } }
php
protected function drawChar($im, $code, $startBar = true) { $c = strlen($code); for ($i = 0; $i < $c; $i++) { if ($code[$i] === '0') { $posY = $this->thickness - ($this->thickness / 2.5); } else { $posY = 0; } $this->drawFilledRectangle($im, $this->positionX, $posY, $this->positionX + 0.44, $this->thickness - 1, CINBarcode::COLOR_FG); $this->positionX += 3; } }
[ "protected", "function", "drawChar", "(", "$", "im", ",", "$", "code", ",", "$", "startBar", "=", "true", ")", "{", "$", "c", "=", "strlen", "(", "$", "code", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "$", "code", "[", "$", "i", "]", "===", "'0'", ")", "{", "$", "posY", "=", "$", "this", "->", "thickness", "-", "(", "$", "this", "->", "thickness", "/", "2.5", ")", ";", "}", "else", "{", "$", "posY", "=", "0", ";", "}", "$", "this", "->", "drawFilledRectangle", "(", "$", "im", ",", "$", "this", "->", "positionX", ",", "$", "posY", ",", "$", "this", "->", "positionX", "+", "0.44", ",", "$", "this", "->", "thickness", "-", "1", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "3", ";", "}", "}" ]
Overloaded method for drawing special barcode. @param resource $im @param string $code @param boolean $startBar
[ "Overloaded", "method", "for", "drawing", "special", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINpostnet.php#L126-L138
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupce.php
CINupce.draw
public function draw($im) { $this->calculateChecksum(); // Starting Code $this->drawChar($im, '000', true); $c = strlen($this->upce); for ($i = 0; $i < $c; $i++) { $this->drawChar($im, self::inverse($this->findCode($this->upce[$i]), $this->codeParity[intval($this->text[0])][$this->checksumValue][$i]), false); } // Draw Center Guard Bar $this->drawChar($im, '00000', false); // Draw Right Bar $this->drawChar($im, '0', true); $this->text = $this->text[0] . $this->upce; $this->drawText($im, 0, 0, $this->positionX, $this->thickness); if ($this->isDefaultEanLabelEnabled()) { $dimension = $this->labelCenter->getDimension(); $this->drawExtendedBars($im, $dimension[1] - 2); } }
php
public function draw($im) { $this->calculateChecksum(); // Starting Code $this->drawChar($im, '000', true); $c = strlen($this->upce); for ($i = 0; $i < $c; $i++) { $this->drawChar($im, self::inverse($this->findCode($this->upce[$i]), $this->codeParity[intval($this->text[0])][$this->checksumValue][$i]), false); } // Draw Center Guard Bar $this->drawChar($im, '00000', false); // Draw Right Bar $this->drawChar($im, '0', true); $this->text = $this->text[0] . $this->upce; $this->drawText($im, 0, 0, $this->positionX, $this->thickness); if ($this->isDefaultEanLabelEnabled()) { $dimension = $this->labelCenter->getDimension(); $this->drawExtendedBars($im, $dimension[1] - 2); } }
[ "public", "function", "draw", "(", "$", "im", ")", "{", "$", "this", "->", "calculateChecksum", "(", ")", ";", "// Starting Code\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'000'", ",", "true", ")", ";", "$", "c", "=", "strlen", "(", "$", "this", "->", "upce", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "this", "->", "drawChar", "(", "$", "im", ",", "self", "::", "inverse", "(", "$", "this", "->", "findCode", "(", "$", "this", "->", "upce", "[", "$", "i", "]", ")", ",", "$", "this", "->", "codeParity", "[", "intval", "(", "$", "this", "->", "text", "[", "0", "]", ")", "]", "[", "$", "this", "->", "checksumValue", "]", "[", "$", "i", "]", ")", ",", "false", ")", ";", "}", "// Draw Center Guard Bar\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'00000'", ",", "false", ")", ";", "// Draw Right Bar\r", "$", "this", "->", "drawChar", "(", "$", "im", ",", "'0'", ",", "true", ")", ";", "$", "this", "->", "text", "=", "$", "this", "->", "text", "[", "0", "]", ".", "$", "this", "->", "upce", ";", "$", "this", "->", "drawText", "(", "$", "im", ",", "0", ",", "0", ",", "$", "this", "->", "positionX", ",", "$", "this", "->", "thickness", ")", ";", "if", "(", "$", "this", "->", "isDefaultEanLabelEnabled", "(", ")", ")", "{", "$", "dimension", "=", "$", "this", "->", "labelCenter", "->", "getDimension", "(", ")", ";", "$", "this", "->", "drawExtendedBars", "(", "$", "im", ",", "$", "dimension", "[", "1", "]", "-", "2", ")", ";", "}", "}" ]
Draws the barcode. @param resource $im
[ "Draws", "the", "barcode", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupce.php#L92-L114
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupce.php
CINupce.addDefaultLabel
protected function addDefaultLabel() { if ($this->isDefaultEanLabelEnabled()) { $this->processChecksum(); $font = $this->font; $this->labelLeft = new CINLabel(substr($this->text, 0, 1), $font, CINLabel::POSITION_LEFT, CINLabel::ALIGN_BOTTOM); $labelLeftDimension = $this->labelLeft->getDimension(); $this->labelLeft->setSpacing(8); $this->labelLeft->setOffset($labelLeftDimension[1] / 2); $this->labelCenter = new CINLabel($this->upce, $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT); $labelCenterDimension = $this->labelCenter->getDimension(); $this->labelCenter->setOffset(($this->scale * 46 - $labelCenterDimension[0]) / 2 + $this->scale * 2); $this->labelRight = new CINLabel($this->keys[$this->checksumValue], $font, CINLabel::POSITION_RIGHT, CINLabel::ALIGN_BOTTOM); $labelRightDimension = $this->labelRight->getDimension(); $this->labelRight->setSpacing(8); $this->labelRight->setOffset($labelRightDimension[1] / 2); $this->addLabel($this->labelLeft); $this->addLabel($this->labelCenter); $this->addLabel($this->labelRight); } }
php
protected function addDefaultLabel() { if ($this->isDefaultEanLabelEnabled()) { $this->processChecksum(); $font = $this->font; $this->labelLeft = new CINLabel(substr($this->text, 0, 1), $font, CINLabel::POSITION_LEFT, CINLabel::ALIGN_BOTTOM); $labelLeftDimension = $this->labelLeft->getDimension(); $this->labelLeft->setSpacing(8); $this->labelLeft->setOffset($labelLeftDimension[1] / 2); $this->labelCenter = new CINLabel($this->upce, $font, CINLabel::POSITION_BOTTOM, CINLabel::ALIGN_LEFT); $labelCenterDimension = $this->labelCenter->getDimension(); $this->labelCenter->setOffset(($this->scale * 46 - $labelCenterDimension[0]) / 2 + $this->scale * 2); $this->labelRight = new CINLabel($this->keys[$this->checksumValue], $font, CINLabel::POSITION_RIGHT, CINLabel::ALIGN_BOTTOM); $labelRightDimension = $this->labelRight->getDimension(); $this->labelRight->setSpacing(8); $this->labelRight->setOffset($labelRightDimension[1] / 2); $this->addLabel($this->labelLeft); $this->addLabel($this->labelCenter); $this->addLabel($this->labelRight); } }
[ "protected", "function", "addDefaultLabel", "(", ")", "{", "if", "(", "$", "this", "->", "isDefaultEanLabelEnabled", "(", ")", ")", "{", "$", "this", "->", "processChecksum", "(", ")", ";", "$", "font", "=", "$", "this", "->", "font", ";", "$", "this", "->", "labelLeft", "=", "new", "CINLabel", "(", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "1", ")", ",", "$", "font", ",", "CINLabel", "::", "POSITION_LEFT", ",", "CINLabel", "::", "ALIGN_BOTTOM", ")", ";", "$", "labelLeftDimension", "=", "$", "this", "->", "labelLeft", "->", "getDimension", "(", ")", ";", "$", "this", "->", "labelLeft", "->", "setSpacing", "(", "8", ")", ";", "$", "this", "->", "labelLeft", "->", "setOffset", "(", "$", "labelLeftDimension", "[", "1", "]", "/", "2", ")", ";", "$", "this", "->", "labelCenter", "=", "new", "CINLabel", "(", "$", "this", "->", "upce", ",", "$", "font", ",", "CINLabel", "::", "POSITION_BOTTOM", ",", "CINLabel", "::", "ALIGN_LEFT", ")", ";", "$", "labelCenterDimension", "=", "$", "this", "->", "labelCenter", "->", "getDimension", "(", ")", ";", "$", "this", "->", "labelCenter", "->", "setOffset", "(", "(", "$", "this", "->", "scale", "*", "46", "-", "$", "labelCenterDimension", "[", "0", "]", ")", "/", "2", "+", "$", "this", "->", "scale", "*", "2", ")", ";", "$", "this", "->", "labelRight", "=", "new", "CINLabel", "(", "$", "this", "->", "keys", "[", "$", "this", "->", "checksumValue", "]", ",", "$", "font", ",", "CINLabel", "::", "POSITION_RIGHT", ",", "CINLabel", "::", "ALIGN_BOTTOM", ")", ";", "$", "labelRightDimension", "=", "$", "this", "->", "labelRight", "->", "getDimension", "(", ")", ";", "$", "this", "->", "labelRight", "->", "setSpacing", "(", "8", ")", ";", "$", "this", "->", "labelRight", "->", "setOffset", "(", "$", "labelRightDimension", "[", "1", "]", "/", "2", ")", ";", "$", "this", "->", "addLabel", "(", "$", "this", "->", "labelLeft", ")", ";", "$", "this", "->", "addLabel", "(", "$", "this", "->", "labelCenter", ")", ";", "$", "this", "->", "addLabel", "(", "$", "this", "->", "labelRight", ")", ";", "}", "}" ]
Adds the default label.
[ "Adds", "the", "default", "label", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupce.php#L137-L160
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupce.php
CINupce.validate
protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new CINParseException('upce', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new CINParseException('upce', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must contain 11 chars // Must contain 6 chars (if starting with upce directly) // First Chars must be 0 or 1 if ($c !== 11 && $c !== 6) { throw new CINParseException('upce', 'You must provide a UPC-A (11 characters) or a UPC-E (6 characters).'); } elseif ($this->text[0] !== '0' && $this->text[0] !== '1' && $c !== 6) { throw new CINParseException('upce', 'UPC-A must start with 0 or 1 to be converted to UPC-E.'); } // Convert part $this->upce = ''; if ($c !== 6) { // Checking if UPC-A is convertible $temp1 = substr($this->text, 3, 3); if ($temp1 === '000' || $temp1 === '100' || $temp1 === '200') { // manufacturer code ends with 100, 200 or 300 if (substr($this->text, 6, 2) === '00') { // Product must start with 00 $this->upce = substr($this->text, 1, 2) . substr($this->text, 8, 3) . substr($this->text, 3, 1); } } elseif (substr($this->text, 4, 2) === '00') { // manufacturer code ends with 00 if (substr($this->text, 6, 3) === '000') { // Product must start with 000 $this->upce = substr($this->text, 1, 3) . substr($this->text, 9, 2) . '3'; } } elseif (substr($this->text, 5, 1) === '0') { // manufacturer code ends with 0 if (substr($this->text, 6, 4) === '0000') { // Product must start with 0000 $this->upce = substr($this->text, 1, 4) . substr($this->text, 10, 1) . '4'; } } else { // No zero leading at manufacturer code $temp2 = intval(substr($this->text, 10, 1)); if (substr($this->text, 6, 4) === '0000' && $temp2 >= 5 && $temp2 <= 9) { // Product must start with 0000 and must end by 5, 6, 7, 8 or 9 $this->upce = substr($this->text, 1, 5) . substr($this->text, 10, 1); } } } else { $this->upce = $this->text; } if ($this->upce === '') { throw new CINParseException('upce', 'Your UPC-A can\'t be converted to UPC-E.'); } if ($c === 6) { $upca = ''; // We convert UPC-E to UPC-A to find the checksum if ($this->text[5] === '0' || $this->text[5] === '1' || $this->text[5] === '2') { $upca = substr($this->text, 0, 2) . $this->text[5] . '0000' . substr($this->text, 2, 3); } elseif ($this->text[5] === '3') { $upca = substr($this->text, 0, 3) . '00000' . substr($this->text, 3, 2); } elseif ($this->text[5] === '4') { $upca = substr($this->text, 0, 4) . '00000' . $this->text[4]; } else { $upca = substr($this->text, 0, 5) . '0000' . $this->text[5]; } $this->text = '0' . $upca; } parent::validate(); }
php
protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new CINParseException('upce', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new CINParseException('upce', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must contain 11 chars // Must contain 6 chars (if starting with upce directly) // First Chars must be 0 or 1 if ($c !== 11 && $c !== 6) { throw new CINParseException('upce', 'You must provide a UPC-A (11 characters) or a UPC-E (6 characters).'); } elseif ($this->text[0] !== '0' && $this->text[0] !== '1' && $c !== 6) { throw new CINParseException('upce', 'UPC-A must start with 0 or 1 to be converted to UPC-E.'); } // Convert part $this->upce = ''; if ($c !== 6) { // Checking if UPC-A is convertible $temp1 = substr($this->text, 3, 3); if ($temp1 === '000' || $temp1 === '100' || $temp1 === '200') { // manufacturer code ends with 100, 200 or 300 if (substr($this->text, 6, 2) === '00') { // Product must start with 00 $this->upce = substr($this->text, 1, 2) . substr($this->text, 8, 3) . substr($this->text, 3, 1); } } elseif (substr($this->text, 4, 2) === '00') { // manufacturer code ends with 00 if (substr($this->text, 6, 3) === '000') { // Product must start with 000 $this->upce = substr($this->text, 1, 3) . substr($this->text, 9, 2) . '3'; } } elseif (substr($this->text, 5, 1) === '0') { // manufacturer code ends with 0 if (substr($this->text, 6, 4) === '0000') { // Product must start with 0000 $this->upce = substr($this->text, 1, 4) . substr($this->text, 10, 1) . '4'; } } else { // No zero leading at manufacturer code $temp2 = intval(substr($this->text, 10, 1)); if (substr($this->text, 6, 4) === '0000' && $temp2 >= 5 && $temp2 <= 9) { // Product must start with 0000 and must end by 5, 6, 7, 8 or 9 $this->upce = substr($this->text, 1, 5) . substr($this->text, 10, 1); } } } else { $this->upce = $this->text; } if ($this->upce === '') { throw new CINParseException('upce', 'Your UPC-A can\'t be converted to UPC-E.'); } if ($c === 6) { $upca = ''; // We convert UPC-E to UPC-A to find the checksum if ($this->text[5] === '0' || $this->text[5] === '1' || $this->text[5] === '2') { $upca = substr($this->text, 0, 2) . $this->text[5] . '0000' . substr($this->text, 2, 3); } elseif ($this->text[5] === '3') { $upca = substr($this->text, 0, 3) . '00000' . substr($this->text, 3, 2); } elseif ($this->text[5] === '4') { $upca = substr($this->text, 0, 4) . '00000' . $this->text[4]; } else { $upca = substr($this->text, 0, 5) . '0000' . $this->text[5]; } $this->text = '0' . $upca; } parent::validate(); }
[ "protected", "function", "validate", "(", ")", "{", "$", "c", "=", "strlen", "(", "$", "this", "->", "text", ")", ";", "if", "(", "$", "c", "===", "0", ")", "{", "throw", "new", "CINParseException", "(", "'upce'", ",", "'No data has been entered.'", ")", ";", "}", "// Checking if all chars are allowed\r", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "array_search", "(", "$", "this", "->", "text", "[", "$", "i", "]", ",", "$", "this", "->", "keys", ")", "===", "false", ")", "{", "throw", "new", "CINParseException", "(", "'upce'", ",", "'The character \\''", ".", "$", "this", "->", "text", "[", "$", "i", "]", ".", "'\\' is not allowed.'", ")", ";", "}", "}", "// Must contain 11 chars\r", "// Must contain 6 chars (if starting with upce directly)\r", "// First Chars must be 0 or 1\r", "if", "(", "$", "c", "!==", "11", "&&", "$", "c", "!==", "6", ")", "{", "throw", "new", "CINParseException", "(", "'upce'", ",", "'You must provide a UPC-A (11 characters) or a UPC-E (6 characters).'", ")", ";", "}", "elseif", "(", "$", "this", "->", "text", "[", "0", "]", "!==", "'0'", "&&", "$", "this", "->", "text", "[", "0", "]", "!==", "'1'", "&&", "$", "c", "!==", "6", ")", "{", "throw", "new", "CINParseException", "(", "'upce'", ",", "'UPC-A must start with 0 or 1 to be converted to UPC-E.'", ")", ";", "}", "// Convert part\r", "$", "this", "->", "upce", "=", "''", ";", "if", "(", "$", "c", "!==", "6", ")", "{", "// Checking if UPC-A is convertible\r", "$", "temp1", "=", "substr", "(", "$", "this", "->", "text", ",", "3", ",", "3", ")", ";", "if", "(", "$", "temp1", "===", "'000'", "||", "$", "temp1", "===", "'100'", "||", "$", "temp1", "===", "'200'", ")", "{", "// manufacturer code ends with 100, 200 or 300\r", "if", "(", "substr", "(", "$", "this", "->", "text", ",", "6", ",", "2", ")", "===", "'00'", ")", "{", "// Product must start with 00\r", "$", "this", "->", "upce", "=", "substr", "(", "$", "this", "->", "text", ",", "1", ",", "2", ")", ".", "substr", "(", "$", "this", "->", "text", ",", "8", ",", "3", ")", ".", "substr", "(", "$", "this", "->", "text", ",", "3", ",", "1", ")", ";", "}", "}", "elseif", "(", "substr", "(", "$", "this", "->", "text", ",", "4", ",", "2", ")", "===", "'00'", ")", "{", "// manufacturer code ends with 00\r", "if", "(", "substr", "(", "$", "this", "->", "text", ",", "6", ",", "3", ")", "===", "'000'", ")", "{", "// Product must start with 000\r", "$", "this", "->", "upce", "=", "substr", "(", "$", "this", "->", "text", ",", "1", ",", "3", ")", ".", "substr", "(", "$", "this", "->", "text", ",", "9", ",", "2", ")", ".", "'3'", ";", "}", "}", "elseif", "(", "substr", "(", "$", "this", "->", "text", ",", "5", ",", "1", ")", "===", "'0'", ")", "{", "// manufacturer code ends with 0\r", "if", "(", "substr", "(", "$", "this", "->", "text", ",", "6", ",", "4", ")", "===", "'0000'", ")", "{", "// Product must start with 0000\r", "$", "this", "->", "upce", "=", "substr", "(", "$", "this", "->", "text", ",", "1", ",", "4", ")", ".", "substr", "(", "$", "this", "->", "text", ",", "10", ",", "1", ")", ".", "'4'", ";", "}", "}", "else", "{", "// No zero leading at manufacturer code\r", "$", "temp2", "=", "intval", "(", "substr", "(", "$", "this", "->", "text", ",", "10", ",", "1", ")", ")", ";", "if", "(", "substr", "(", "$", "this", "->", "text", ",", "6", ",", "4", ")", "===", "'0000'", "&&", "$", "temp2", ">=", "5", "&&", "$", "temp2", "<=", "9", ")", "{", "// Product must start with 0000 and must end by 5, 6, 7, 8 or 9\r", "$", "this", "->", "upce", "=", "substr", "(", "$", "this", "->", "text", ",", "1", ",", "5", ")", ".", "substr", "(", "$", "this", "->", "text", ",", "10", ",", "1", ")", ";", "}", "}", "}", "else", "{", "$", "this", "->", "upce", "=", "$", "this", "->", "text", ";", "}", "if", "(", "$", "this", "->", "upce", "===", "''", ")", "{", "throw", "new", "CINParseException", "(", "'upce'", ",", "'Your UPC-A can\\'t be converted to UPC-E.'", ")", ";", "}", "if", "(", "$", "c", "===", "6", ")", "{", "$", "upca", "=", "''", ";", "// We convert UPC-E to UPC-A to find the checksum\r", "if", "(", "$", "this", "->", "text", "[", "5", "]", "===", "'0'", "||", "$", "this", "->", "text", "[", "5", "]", "===", "'1'", "||", "$", "this", "->", "text", "[", "5", "]", "===", "'2'", ")", "{", "$", "upca", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "2", ")", ".", "$", "this", "->", "text", "[", "5", "]", ".", "'0000'", ".", "substr", "(", "$", "this", "->", "text", ",", "2", ",", "3", ")", ";", "}", "elseif", "(", "$", "this", "->", "text", "[", "5", "]", "===", "'3'", ")", "{", "$", "upca", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "3", ")", ".", "'00000'", ".", "substr", "(", "$", "this", "->", "text", ",", "3", ",", "2", ")", ";", "}", "elseif", "(", "$", "this", "->", "text", "[", "5", "]", "===", "'4'", ")", "{", "$", "upca", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "4", ")", ".", "'00000'", ".", "$", "this", "->", "text", "[", "4", "]", ";", "}", "else", "{", "$", "upca", "=", "substr", "(", "$", "this", "->", "text", ",", "0", ",", "5", ")", ".", "'0000'", ".", "$", "this", "->", "text", "[", "5", "]", ";", "}", "$", "this", "->", "text", "=", "'0'", ".", "$", "upca", ";", "}", "parent", "::", "validate", "(", ")", ";", "}" ]
Validates the input.
[ "Validates", "the", "input", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupce.php#L176-L247
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/CINupce.php
CINupce.drawExtendedBars
protected function drawExtendedBars($im, $plus) { $rememberX = $this->positionX; $rememberH = $this->thickness; // We increase the bars $this->thickness = $this->thickness + intval($plus / $this->scale); $this->positionX = 0; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); // Last Bars $this->positionX += 46; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX = $rememberX; $this->thickness = $rememberH; }
php
protected function drawExtendedBars($im, $plus) { $rememberX = $this->positionX; $rememberH = $this->thickness; // We increase the bars $this->thickness = $this->thickness + intval($plus / $this->scale); $this->positionX = 0; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); // Last Bars $this->positionX += 46; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX += 2; $this->drawSingleBar($im, CINBarcode::COLOR_FG); $this->positionX = $rememberX; $this->thickness = $rememberH; }
[ "protected", "function", "drawExtendedBars", "(", "$", "im", ",", "$", "plus", ")", "{", "$", "rememberX", "=", "$", "this", "->", "positionX", ";", "$", "rememberH", "=", "$", "this", "->", "thickness", ";", "// We increase the bars\r", "$", "this", "->", "thickness", "=", "$", "this", "->", "thickness", "+", "intval", "(", "$", "plus", "/", "$", "this", "->", "scale", ")", ";", "$", "this", "->", "positionX", "=", "0", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "2", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "// Last Bars\r", "$", "this", "->", "positionX", "+=", "46", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "+=", "2", ";", "$", "this", "->", "drawSingleBar", "(", "$", "im", ",", "CINBarcode", "::", "COLOR_FG", ")", ";", "$", "this", "->", "positionX", "=", "$", "rememberX", ";", "$", "this", "->", "thickness", "=", "$", "rememberH", ";", "}" ]
Draws the extended bars on the image. @param resource $im @param int $plus
[ "Draws", "the", "extended", "bars", "on", "the", "image", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/CINupce.php#L302-L321
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawJPG.php
CINDrawJPG.setDPI
public function setDPI($dpi) { if(is_int($dpi)) { $this->dpi = max(1, $dpi); } else { $this->dpi = null; } }
php
public function setDPI($dpi) { if(is_int($dpi)) { $this->dpi = max(1, $dpi); } else { $this->dpi = null; } }
[ "public", "function", "setDPI", "(", "$", "dpi", ")", "{", "if", "(", "is_int", "(", "$", "dpi", ")", ")", "{", "$", "this", "->", "dpi", "=", "max", "(", "1", ",", "$", "dpi", ")", ";", "}", "else", "{", "$", "this", "->", "dpi", "=", "null", ";", "}", "}" ]
Sets the DPI. @param int $dpi
[ "Sets", "the", "DPI", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawJPG.php#L46-L52
codeitnowin/barcode-generator
CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawJPG.php
CINDrawJPG.draw
public function draw() { ob_start(); imagejpeg($this->im, null, $this->quality); $bin = ob_get_contents(); ob_end_clean(); $this->setInternalProperties($bin); if (empty($this->filename)) { echo $bin; } else { file_put_contents($this->filename, $bin); } }
php
public function draw() { ob_start(); imagejpeg($this->im, null, $this->quality); $bin = ob_get_contents(); ob_end_clean(); $this->setInternalProperties($bin); if (empty($this->filename)) { echo $bin; } else { file_put_contents($this->filename, $bin); } }
[ "public", "function", "draw", "(", ")", "{", "ob_start", "(", ")", ";", "imagejpeg", "(", "$", "this", "->", "im", ",", "null", ",", "$", "this", "->", "quality", ")", ";", "$", "bin", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "this", "->", "setInternalProperties", "(", "$", "bin", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "filename", ")", ")", "{", "echo", "$", "bin", ";", "}", "else", "{", "file_put_contents", "(", "$", "this", "->", "filename", ",", "$", "bin", ")", ";", "}", "}" ]
Draws the JPG on the screen or in a file.
[ "Draws", "the", "JPG", "on", "the", "screen", "or", "in", "a", "file", "." ]
train
https://github.com/codeitnowin/barcode-generator/blob/6325a15ae904ec401b947e1a3e868de1c2cc80b0/CodeItNow/BarcodeBundle/Generator/Drawer/CINDrawJPG.php#L66-L79