From bc241e8e7c49ae94bf8b18084e9345b2edba148d Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Thu, 15 Dec 2011 09:02:28 +0000 Subject: [PATCH] [*] PDF : TCPDF Tweak --- tools/tcpdf/2dbarcodes.php | 278 +- tools/tcpdf/barcodes.php | 2233 +------- tools/tcpdf/datamatrix.php | 1089 +--- tools/tcpdf/qrcode.php | 2793 +--------- tools/tcpdf/tcpdf.php | 9764 +--------------------------------- tools/tcpdf/unicode_data.php | 1 + 6 files changed, 74 insertions(+), 16084 deletions(-) diff --git a/tools/tcpdf/2dbarcodes.php b/tools/tcpdf/2dbarcodes.php index 3448ae743..750483ca4 100755 --- a/tools/tcpdf/2dbarcodes.php +++ b/tools/tcpdf/2dbarcodes.php @@ -49,285 +49,9 @@ */ class TCPDF2DBarcode { - /** - * Array representation of barcode. - * @protected - */ - protected $barcode_array = false; - - /** - * This is the class constructor. - * Return an array representations for 2D barcodes: - * @param $code (string) code to print - * @param $type (string) type of barcode: - */ - public function __construct($code, $type) { - $this->setBarcode($code, $type); - } - - /** - * Return an array representations of barcode. - * @return array - */ - public function getBarcodeArray() { - return $this->barcode_array; - } - - /** - * Send barcode as SVG image object to the standard output. - * @param $w (int) Width of a single rectangle element in user units. - * @param $h (int) Height of a single rectangle element in user units. - * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). - * @public - */ - public function getBarcodeSVG($w=3, $h=3, $color='black') { - // send headers - $code = $this->getBarcodeSVGcode($w, $h, $color); - header('Content-Type: application/svg+xml'); - header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 - header('Pragma: public'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); - //header('Content-Length: '.strlen($code)); - echo $code; - } - - /** - * Return a SVG string representation of barcode. - * @param $w (int) Width of a single rectangle element in user units. - * @param $h (int) Height of a single rectangle element in user units. - * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). - * @return string SVG code. - * @public - */ - public function getBarcodeSVGcode($w=3, $h=3, $color='black') { - // replace table for special characters - $repstr = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); - $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n"; - $svg .= ''."\n"; - $svg .= ''."\n"; - $svg .= "\t".''.strtr($this->barcode_array['code'], $repstr).''."\n"; - $svg .= "\t".''."\n"; - // print barcode elements - $y = 0; - // for each row - for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { - $x = 0; - // for each column - for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { - if ($this->barcode_array['bcode'][$r][$c] == 1) { - // draw a single barcode cell - $svg .= "\t\t".''."\n"; - } - $x += $w; - } - $y += $h; - } - $svg .= "\t".''."\n"; - $svg .= ''."\n"; - return $svg; - } - - /** - * Return an HTML representation of barcode. - * @param $w (int) Width of a single rectangle element in pixels. - * @param $h (int) Height of a single rectangle element in pixels. - * @param $color (string) Foreground color for bar elements (background is transparent). - * @return string HTML code. - * @public - */ - public function getBarcodeHTML($w=10, $h=10, $color='black') { - // replace table for special characters - $html = '
'."\n"; - // print barcode elements - $y = 0; - // for each row - for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { - $x = 0; - // for each column - for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { - if ($this->barcode_array['bcode'][$r][$c] == 1) { - // draw a single barcode cell - $html .= '
 
'."\n"; - } - $x += $w; - } - $y += $h; - } - $html .= '
'."\n"; - return $html; - } - - /** - * Return a PNG image representation of barcode (requires GD or Imagick library). - * @param $w (int) Width of a single rectangle element in pixels. - * @param $h (int) Height of a single rectangle element in pixels. - * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent). - * @return image or false in case of error. - * @public - */ - public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) { - // calculate image size - $width = ($this->barcode_array['num_cols'] * $w); - $height = ($this->barcode_array['num_rows'] * $h); - if (function_exists('imagecreate')) { - // GD library - $imagick = false; - $png = imagecreate($width, $height); - $bgcol = imagecolorallocate($png, 255, 255, 255); - imagecolortransparent($png, $bgcol); - $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]); - } elseif (extension_loaded('imagick')) { - $imagick = true; - $bgcol = new imagickpixel('rgb(255,255,255'); - $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')'); - $png = new Imagick(); - $png->newImage($width, $height, 'none', 'png'); - $bar = new imagickdraw(); - $bar->setfillcolor($fgcol); - } else { - return false; - } - // print barcode elements - $y = 0; - // for each row - for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { - $x = 0; - // for each column - for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { - if ($this->barcode_array['bcode'][$r][$c] == 1) { - // draw a single barcode cell - if ($imagick) { - $bar->rectangle($x, $y, ($x + $w), ($y + $h)); - } else { - imagefilledrectangle($png, $x, $y, ($x + $w), ($y + $h), $fgcol); - } - } - $x += $w; - } - $y += $h; - } - // send headers - header('Content-Type: image/png'); - header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 - header('Pragma: public'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - if ($imagick) { - $png->drawimage($bar); - echo $png; - } else { - imagepng($png); - imagedestroy($png); - } - } - - /** - * Set the barcode. - * @param $code (string) code to print - * @param $type (string) type of barcode: - * @return array - */ - public function setBarcode($code, $type) { - $mode = explode(',', $type); - $qrtype = strtoupper($mode[0]); - switch ($qrtype) { - case 'DATAMATRIX': { // DATAMATRIX (ISO/IEC 16022) - require_once(dirname(__FILE__).'/datamatrix.php'); - $qrcode = new Datamatrix($code); - $this->barcode_array = $qrcode->getBarcodeArray(); - $this->barcode_array['code'] = $code; - break; - } - case 'PDF417': { // PDF417 (ISO/IEC 15438:2006) - require_once(dirname(__FILE__).'/pdf417.php'); - if (!isset($mode[1]) OR ($mode[1] === '')) { - $aspectratio = 2; // default aspect ratio (width / height) - } else { - $aspectratio = floatval($mode[1]); - } - if (!isset($mode[2]) OR ($mode[2] === '')) { - $ecl = -1; // default error correction level (auto) - } else { - $ecl = intval($mode[2]); - } - // set macro block - $macro = array(); - if (isset($mode[3]) AND ($mode[3] !== '') AND isset($mode[4]) AND ($mode[4] !== '') AND isset($mode[5]) AND ($mode[5] !== '')) { - $macro['segment_total'] = intval($mode[3]); - $macro['segment_index'] = intval($mode[4]); - $macro['file_id'] = strtr($mode[5], "\xff", ','); - for ($i = 0; $i < 7; ++$i) { - $o = $i + 6; - if (isset($mode[$o]) AND ($mode[$o] !== '')) { - // add option - $macro['option_'.$i] = strtr($mode[$o], "\xff", ','); - } - } - } - $qrcode = new PDF417($code, $ecl, $aspectratio, $macro); - $this->barcode_array = $qrcode->getBarcodeArray(); - $this->barcode_array['code'] = $code; - break; - } - case 'QRCODE': { // QR-CODE - require_once(dirname(__FILE__).'/qrcode.php'); - if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) { - $mode[1] = 'L'; // Ddefault: Low error correction - } - $qrcode = new QRcode($code, strtoupper($mode[1])); - $this->barcode_array = $qrcode->getBarcodeArray(); - $this->barcode_array['code'] = $code; - break; - } - case 'RAW': - case 'RAW2': { // RAW MODE - // remove spaces - $code = preg_replace('/[\s]*/si', '', $code); - if (strlen($code) < 3) { - break; - } - if ($qrtype == 'RAW') { - // comma-separated rows - $rows = explode(',', $code); - } else { // RAW2 - // rows enclosed in square parentheses - $code = substr($code, 1, -1); - $rows = explode('][', $code); - } - $this->barcode_array['num_rows'] = count($rows); - $this->barcode_array['num_cols'] = strlen($rows[0]); - $this->barcode_array['bcode'] = array(); - foreach ($rows as $r) { - $this->barcode_array['bcode'][] = str_split($r, 1); - } - $this->barcode_array['code'] = $code; - break; - } - case 'TEST': { // TEST MODE - $this->barcode_array['num_rows'] = 5; - $this->barcode_array['num_cols'] = 15; - $this->barcode_array['bcode'] = array( - array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1), - array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0), - array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0), - array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0), - array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0)); - $this->barcode_array['code'] = $code; - break; - } - default: { - $this->barcode_array = false; - } - } - } } // end of class //============================================================+ // END OF FILE //============================================================+ + diff --git a/tools/tcpdf/barcodes.php b/tools/tcpdf/barcodes.php index e444ca0f1..193c6ee4a 100755 --- a/tools/tcpdf/barcodes.php +++ b/tools/tcpdf/barcodes.php @@ -49,2240 +49,9 @@ */ class TCPDFBarcode { - /** - * Array representation of barcode. - * @protected - */ - protected $barcode_array; - - /** - * This is the class constructor. - * Return an array representations for common 1D barcodes: - * @param $code (string) code to print - * @param $type (string) type of barcode: - * @public - */ - public function __construct($code, $type) { - $this->setBarcode($code, $type); - } - - /** - * Return an array representations of barcode. - * @return array - * @public - */ - public function getBarcodeArray() { - return $this->barcode_array; - } - - /** - * Send barcode as SVG image object to the standard output. - * @param $w (int) Minimum width of a single bar in user units. - * @param $h (int) Height of barcode in user units. - * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). - * @public - */ - public function getBarcodeSVG($w=2, $h=30, $color='black') { - // send headers - $code = $this->getBarcodeSVGcode($w, $h, $color); - header('Content-Type: application/svg+xml'); - header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 - header('Pragma: public'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); - //header('Content-Length: '.strlen($code)); - echo $code; - } - - /** - * Return a SVG string representation of barcode. - * @param $w (int) Minimum width of a single bar in user units. - * @param $h (int) Height of barcode in user units. - * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). - * @return string SVG code. - * @public - */ - public function getBarcodeSVGcode($w=2, $h=30, $color='black') { - // replace table for special characters - $repstr = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); - $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n"; - $svg .= ''."\n"; - $svg .= ''."\n"; - $svg .= "\t".''.strtr($this->barcode_array['code'], $repstr).''."\n"; - $svg .= "\t".''."\n"; - // print bars - $x = 0; - foreach ($this->barcode_array['bcode'] as $k => $v) { - $bw = round(($v['w'] * $w), 3); - $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3); - if ($v['t']) { - $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3); - // draw a vertical bar - $svg .= "\t\t".''."\n"; - } - $x += $bw; - } - $svg .= "\t".''."\n"; - $svg .= ''."\n"; - return $svg; - } - - /** - * Return an HTML representation of barcode. - * @param $w (int) Width of a single bar element in pixels. - * @param $h (int) Height of a single bar element in pixels. - * @param $color (string) Foreground color for bar elements (background is transparent). - * @return string HTML code. - * @public - */ - public function getBarcodeHTML($w=2, $h=30, $color='black') { - // replace table for special characters - $html = '
'."\n"; - // print bars - $x = 0; - foreach ($this->barcode_array['bcode'] as $k => $v) { - $bw = round(($v['w'] * $w), 3); - $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3); - if ($v['t']) { - $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3); - // draw a vertical bar - $html .= '
 
'."\n"; - } - $x += $bw; - } - $html .= '
'."\n"; - return $html; - } - - /** - * Return a PNG image representation of barcode (requires GD or Imagick library). - * @param $w (int) Width of a single bar element in pixels. - * @param $h (int) Height of a single bar element in pixels. - * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent). - * @return image or false in case of error. - * @public - */ - public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) { - // calculate image size - $width = ($this->barcode_array['maxw'] * $w); - $height = $h; - if (function_exists('imagecreate')) { - // GD library - $imagick = false; - $png = imagecreate($width, $height); - $bgcol = imagecolorallocate($png, 255, 255, 255); - imagecolortransparent($png, $bgcol); - $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]); - } elseif (extension_loaded('imagick')) { - $imagick = true; - $bgcol = new imagickpixel('rgb(255,255,255'); - $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')'); - $png = new Imagick(); - $png->newImage($width, $height, 'none', 'png'); - $bar = new imagickdraw(); - $bar->setfillcolor($fgcol); - } else { - return false; - } - // print bars - $x = 0; - foreach ($this->barcode_array['bcode'] as $k => $v) { - $bw = round(($v['w'] * $w), 3); - $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3); - if ($v['t']) { - $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3); - // draw a vertical bar - if ($imagick) { - $bar->rectangle($x, $y, ($x + $bw), ($y + $bh)); - } else { - imagefilledrectangle($png, $x, $y, ($x + $bw), ($y + $bh), $fgcol); - } - } - $x += $bw; - } - // send headers - header('Content-Type: image/png'); - header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 - header('Pragma: public'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - if ($imagick) { - $png->drawimage($bar); - echo $png; - } else { - imagepng($png); - imagedestroy($png); - } - } - - /** - * Set the barcode. - * @param $code (string) code to print - * @param $type (string) type of barcode: - * @return array barcode array - * @public - */ - public function setBarcode($code, $type) { - switch (strtoupper($type)) { - case 'C39': { // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9. - $arrcode = $this->barcode_code39($code, false, false); - break; - } - case 'C39+': { // CODE 39 with checksum - $arrcode = $this->barcode_code39($code, false, true); - break; - } - case 'C39E': { // CODE 39 EXTENDED - $arrcode = $this->barcode_code39($code, true, false); - break; - } - case 'C39E+': { // CODE 39 EXTENDED + CHECKSUM - $arrcode = $this->barcode_code39($code, true, true); - break; - } - case 'C93': { // CODE 93 - USS-93 - $arrcode = $this->barcode_code93($code); - break; - } - case 'S25': { // Standard 2 of 5 - $arrcode = $this->barcode_s25($code, false); - break; - } - case 'S25+': { // Standard 2 of 5 + CHECKSUM - $arrcode = $this->barcode_s25($code, true); - break; - } - case 'I25': { // Interleaved 2 of 5 - $arrcode = $this->barcode_i25($code, false); - break; - } - case 'I25+': { // Interleaved 2 of 5 + CHECKSUM - $arrcode = $this->barcode_i25($code, true); - break; - } - case 'C128': { // CODE 128 - $arrcode = $this->barcode_c128($code, ''); - break; - } - case 'C128A': { // CODE 128 A - $arrcode = $this->barcode_c128($code, 'A'); - break; - } - case 'C128B': { // CODE 128 B - $arrcode = $this->barcode_c128($code, 'B'); - break; - } - case 'C128C': { // CODE 128 C - $arrcode = $this->barcode_c128($code, 'C'); - break; - } - case 'EAN2': { // 2-Digits UPC-Based Extention - $arrcode = $this->barcode_eanext($code, 2); - break; - } - case 'EAN5': { // 5-Digits UPC-Based Extention - $arrcode = $this->barcode_eanext($code, 5); - break; - } - case 'EAN8': { // EAN 8 - $arrcode = $this->barcode_eanupc($code, 8); - break; - } - case 'EAN13': { // EAN 13 - $arrcode = $this->barcode_eanupc($code, 13); - break; - } - case 'UPCA': { // UPC-A - $arrcode = $this->barcode_eanupc($code, 12); - break; - } - case 'UPCE': { // UPC-E - $arrcode = $this->barcode_eanupc($code, 6); - break; - } - case 'MSI': { // MSI (Variation of Plessey code) - $arrcode = $this->barcode_msi($code, false); - break; - } - case 'MSI+': { // MSI + CHECKSUM (modulo 11) - $arrcode = $this->barcode_msi($code, true); - break; - } - case 'POSTNET': { // POSTNET - $arrcode = $this->barcode_postnet($code, false); - break; - } - case 'PLANET': { // PLANET - $arrcode = $this->barcode_postnet($code, true); - break; - } - case 'RMS4CC': { // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - $arrcode = $this->barcode_rms4cc($code, false); - break; - } - case 'KIX': { // KIX (Klant index - Customer index) - $arrcode = $this->barcode_rms4cc($code, true); - break; - } - case 'IMB': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 - $arrcode = $this->barcode_imb($code); - break; - } - case 'CODABAR': { // CODABAR - $arrcode = $this->barcode_codabar($code); - break; - } - case 'CODE11': { // CODE 11 - $arrcode = $this->barcode_code11($code); - break; - } - case 'PHARMA': { // PHARMACODE - $arrcode = $this->barcode_pharmacode($code); - break; - } - case 'PHARMA2T': { // PHARMACODE TWO-TRACKS - $arrcode = $this->barcode_pharmacode2t($code); - break; - } - default: { - $this->barcode_array = false; - $arrcode = false; - break; - } - } - $this->barcode_array = $arrcode; - } - - /** - * CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9. - * General-purpose code in very wide use world-wide - * @param $code (string) code to represent. - * @param $extended (boolean) if true uses the extended mode. - * @param $checksum (boolean) if true add a checksum to the code. - * @return array barcode representation. - * @protected - */ - protected function barcode_code39($code, $extended=false, $checksum=false) { - $chr['0'] = '111331311'; - $chr['1'] = '311311113'; - $chr['2'] = '113311113'; - $chr['3'] = '313311111'; - $chr['4'] = '111331113'; - $chr['5'] = '311331111'; - $chr['6'] = '113331111'; - $chr['7'] = '111311313'; - $chr['8'] = '311311311'; - $chr['9'] = '113311311'; - $chr['A'] = '311113113'; - $chr['B'] = '113113113'; - $chr['C'] = '313113111'; - $chr['D'] = '111133113'; - $chr['E'] = '311133111'; - $chr['F'] = '113133111'; - $chr['G'] = '111113313'; - $chr['H'] = '311113311'; - $chr['I'] = '113113311'; - $chr['J'] = '111133311'; - $chr['K'] = '311111133'; - $chr['L'] = '113111133'; - $chr['M'] = '313111131'; - $chr['N'] = '111131133'; - $chr['O'] = '311131131'; - $chr['P'] = '113131131'; - $chr['Q'] = '111111333'; - $chr['R'] = '311111331'; - $chr['S'] = '113111331'; - $chr['T'] = '111131331'; - $chr['U'] = '331111113'; - $chr['V'] = '133111113'; - $chr['W'] = '333111111'; - $chr['X'] = '131131113'; - $chr['Y'] = '331131111'; - $chr['Z'] = '133131111'; - $chr['-'] = '131111313'; - $chr['.'] = '331111311'; - $chr[' '] = '133111311'; - $chr['$'] = '131313111'; - $chr['/'] = '131311131'; - $chr['+'] = '131113131'; - $chr['%'] = '111313131'; - $chr['*'] = '131131311'; - $code = strtoupper($code); - if ($extended) { - // extended mode - $code = $this->encode_code39_ext($code); - } - if ($code === false) { - return false; - } - if ($checksum) { - // checksum - $code .= $this->checksum_code39($code); - } - // add start and stop codes - $code = '*'.$code.'*'; - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $k = 0; - $clen = strlen($code); - for ($i = 0; $i < $clen; ++$i) { - $char = $code{$i}; - if(!isset($chr[$char])) { - // invalid character - return false; - } - for ($j = 0; $j < 9; ++$j) { - if (($j % 2) == 0) { - $t = true; // bar - } else { - $t = false; // space - } - $w = $chr[$char]{$j}; - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - } - // intercharacter gap - $bararray['bcode'][$k] = array('t' => false, 'w' => 1, 'h' => 1, 'p' => 0); - $bararray['maxw'] += 1; - ++$k; - } - return $bararray; - } - - /** - * Encode a string to be used for CODE 39 Extended mode. - * @param $code (string) code to represent. - * @return encoded string. - * @protected - */ - protected function encode_code39_ext($code) { - $encode = array( - chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C', - chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G', - chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '£K', - chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O', - chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S', - chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W', - chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A', - chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E', - chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C', - chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G', - chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K', - chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O', - chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3', - chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7', - chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F', - chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J', - chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C', - chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G', - chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K', - chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O', - chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S', - chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W', - chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K', - chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O', - chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C', - chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G', - chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K', - chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O', - chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S', - chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W', - chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P', - chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T'); - $code_ext = ''; - $clen = strlen($code); - for ($i = 0 ; $i < $clen; ++$i) { - if (ord($code{$i}) > 127) { - return false; - } - $code_ext .= $encode[$code{$i}]; - } - return $code_ext; - } - - /** - * Calculate CODE 39 checksum (modulo 43). - * @param $code (string) code to represent. - * @return char checksum. - * @protected - */ - protected function checksum_code39($code) { - $chars = array( - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', - 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%'); - $sum = 0; - $clen = strlen($code); - for ($i = 0 ; $i < $clen; ++$i) { - $k = array_keys($chars, $code{$i}); - $sum += $k[0]; - } - $j = ($sum % 43); - return $chars[$j]; - } - - /** - * CODE 93 - USS-93 - * Compact code similar to Code 39 - * @param $code (string) code to represent. - * @return array barcode representation. - * @protected - */ - protected function barcode_code93($code) { - $chr[48] = '131112'; // 0 - $chr[49] = '111213'; // 1 - $chr[50] = '111312'; // 2 - $chr[51] = '111411'; // 3 - $chr[52] = '121113'; // 4 - $chr[53] = '121212'; // 5 - $chr[54] = '121311'; // 6 - $chr[55] = '111114'; // 7 - $chr[56] = '131211'; // 8 - $chr[57] = '141111'; // 9 - $chr[65] = '211113'; // A - $chr[66] = '211212'; // B - $chr[67] = '211311'; // C - $chr[68] = '221112'; // D - $chr[69] = '221211'; // E - $chr[70] = '231111'; // F - $chr[71] = '112113'; // G - $chr[72] = '112212'; // H - $chr[73] = '112311'; // I - $chr[74] = '122112'; // J - $chr[75] = '132111'; // K - $chr[76] = '111123'; // L - $chr[77] = '111222'; // M - $chr[78] = '111321'; // N - $chr[79] = '121122'; // O - $chr[80] = '131121'; // P - $chr[81] = '212112'; // Q - $chr[82] = '212211'; // R - $chr[83] = '211122'; // S - $chr[84] = '211221'; // T - $chr[85] = '221121'; // U - $chr[86] = '222111'; // V - $chr[87] = '112122'; // W - $chr[88] = '112221'; // X - $chr[89] = '122121'; // Y - $chr[90] = '123111'; // Z - $chr[45] = '121131'; // - - $chr[46] = '311112'; // . - $chr[32] = '311211'; // - $chr[36] = '321111'; // $ - $chr[47] = '112131'; // / - $chr[43] = '113121'; // + - $chr[37] = '211131'; // % - $chr[128] = '121221'; // ($) - $chr[129] = '311121'; // (/) - $chr[130] = '122211'; // (+) - $chr[131] = '312111'; // (%) - $chr[42] = '111141'; // start-stop - $code = strtoupper($code); - $encode = array( - chr(0) => chr(131).'U', chr(1) => chr(128).'A', chr(2) => chr(128).'B', chr(3) => chr(128).'C', - chr(4) => chr(128).'D', chr(5) => chr(128).'E', chr(6) => chr(128).'F', chr(7) => chr(128).'G', - chr(8) => chr(128).'H', chr(9) => chr(128).'I', chr(10) => chr(128).'J', chr(11) => '£K', - chr(12) => chr(128).'L', chr(13) => chr(128).'M', chr(14) => chr(128).'N', chr(15) => chr(128).'O', - chr(16) => chr(128).'P', chr(17) => chr(128).'Q', chr(18) => chr(128).'R', chr(19) => chr(128).'S', - chr(20) => chr(128).'T', chr(21) => chr(128).'U', chr(22) => chr(128).'V', chr(23) => chr(128).'W', - chr(24) => chr(128).'X', chr(25) => chr(128).'Y', chr(26) => chr(128).'Z', chr(27) => chr(131).'A', - chr(28) => chr(131).'B', chr(29) => chr(131).'C', chr(30) => chr(131).'D', chr(31) => chr(131).'E', - chr(32) => ' ', chr(33) => chr(129).'A', chr(34) => chr(129).'B', chr(35) => chr(129).'C', - chr(36) => chr(129).'D', chr(37) => chr(129).'E', chr(38) => chr(129).'F', chr(39) => chr(129).'G', - chr(40) => chr(129).'H', chr(41) => chr(129).'I', chr(42) => chr(129).'J', chr(43) => chr(129).'K', - chr(44) => chr(129).'L', chr(45) => '-', chr(46) => '.', chr(47) => chr(129).'O', - chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3', - chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7', - chr(56) => '8', chr(57) => '9', chr(58) => chr(129).'Z', chr(59) => chr(131).'F', - chr(60) => chr(131).'G', chr(61) => chr(131).'H', chr(62) => chr(131).'I', chr(63) => chr(131).'J', - chr(64) => chr(131).'V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C', - chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G', - chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K', - chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O', - chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S', - chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W', - chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => chr(131).'K', - chr(92) => chr(131).'L', chr(93) => chr(131).'M', chr(94) => chr(131).'N', chr(95) => chr(131).'O', - chr(96) => chr(131).'W', chr(97) => chr(130).'A', chr(98) => chr(130).'B', chr(99) => chr(130).'C', - chr(100) => chr(130).'D', chr(101) => chr(130).'E', chr(102) => chr(130).'F', chr(103) => chr(130).'G', - chr(104) => chr(130).'H', chr(105) => chr(130).'I', chr(106) => chr(130).'J', chr(107) => chr(130).'K', - chr(108) => chr(130).'L', chr(109) => chr(130).'M', chr(110) => chr(130).'N', chr(111) => chr(130).'O', - chr(112) => chr(130).'P', chr(113) => chr(130).'Q', chr(114) => chr(130).'R', chr(115) => chr(130).'S', - chr(116) => chr(130).'T', chr(117) => chr(130).'U', chr(118) => chr(130).'V', chr(119) => chr(130).'W', - chr(120) => chr(130).'X', chr(121) => chr(130).'Y', chr(122) => chr(130).'Z', chr(123) => chr(131).'P', - chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T'); - $code_ext = ''; - $clen = strlen($code); - for ($i = 0 ; $i < $clen; ++$i) { - if (ord($code{$i}) > 127) { - return false; - } - $code_ext .= $encode[$code{$i}]; - } - // checksum - $code_ext .= $this->checksum_code93($code_ext); - // add start and stop codes - $code = '*'.$code_ext.'*'; - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $k = 0; - $clen = strlen($code); - for ($i = 0; $i < $clen; ++$i) { - $char = ord($code{$i}); - if(!isset($chr[$char])) { - // invalid character - return false; - } - for ($j = 0; $j < 6; ++$j) { - if (($j % 2) == 0) { - $t = true; // bar - } else { - $t = false; // space - } - $w = $chr[$char]{$j}; - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - } - } - $bararray['bcode'][$k] = array('t' => true, 'w' => 1, 'h' => 1, 'p' => 0); - $bararray['maxw'] += 1; - ++$k; - return $bararray; - } - - /** - * Calculate CODE 93 checksum (modulo 47). - * @param $code (string) code to represent. - * @return string checksum code. - * @protected - */ - protected function checksum_code93($code) { - $chars = array( - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', - 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%', - '<', '=', '>', '?'); - // translate special characters - $code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?'); - $len = strlen($code); - // calculate check digit C - $p = 1; - $check = 0; - for ($i = ($len - 1); $i >= 0; --$i) { - $k = array_keys($chars, $code{$i}); - $check += ($k[0] * $p); - ++$p; - if ($p > 20) { - $p = 1; - } - } - $check %= 47; - $c = $chars[$check]; - $code .= $c; - // calculate check digit K - $p = 1; - $check = 0; - for ($i = $len; $i >= 0; --$i) { - $k = array_keys($chars, $code{$i}); - $check += ($k[0] * $p); - ++$p; - if ($p > 15) { - $p = 1; - } - } - $check %= 47; - $k = $chars[$check]; - $checksum = $c.$k; - // resto respecial characters - $checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130)); - return $checksum; - } - - /** - * Checksum for standard 2 of 5 barcodes. - * @param $code (string) code to process. - * @return int checksum. - * @protected - */ - protected function checksum_s25($code) { - $len = strlen($code); - $sum = 0; - for ($i = 0; $i < $len; $i+=2) { - $sum += $code{$i}; - } - $sum *= 3; - for ($i = 1; $i < $len; $i+=2) { - $sum += ($code{$i}); - } - $r = $sum % 10; - if($r > 0) { - $r = (10 - $r); - } - return $r; - } - - /** - * MSI. - * Variation of Plessey code, with similar applications - * Contains digits (0 to 9) and encodes the data only in the width of bars. - * @param $code (string) code to represent. - * @param $checksum (boolean) if true add a checksum to the code (modulo 11) - * @return array barcode representation. - * @protected - */ - protected function barcode_msi($code, $checksum=false) { - $chr['0'] = '100100100100'; - $chr['1'] = '100100100110'; - $chr['2'] = '100100110100'; - $chr['3'] = '100100110110'; - $chr['4'] = '100110100100'; - $chr['5'] = '100110100110'; - $chr['6'] = '100110110100'; - $chr['7'] = '100110110110'; - $chr['8'] = '110100100100'; - $chr['9'] = '110100100110'; - $chr['A'] = '110100110100'; - $chr['B'] = '110100110110'; - $chr['C'] = '110110100100'; - $chr['D'] = '110110100110'; - $chr['E'] = '110110110100'; - $chr['F'] = '110110110110'; - if ($checksum) { - // add checksum - $clen = strlen($code); - $p = 2; - $check = 0; - for ($i = ($clen - 1); $i >= 0; --$i) { - $check += (hexdec($code{$i}) * $p); - ++$p; - if ($p > 7) { - $p = 2; - } - } - $check %= 11; - if ($check > 0) { - $check = 11 - $check; - } - $code .= $check; - } - $seq = '110'; // left guard - $clen = strlen($code); - for ($i = 0; $i < $clen; ++$i) { - $digit = $code{$i}; - if (!isset($chr[$digit])) { - // invalid character - return false; - } - $seq .= $chr[$digit]; - } - $seq .= '1001'; // right guard - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - return $this->binseq_to_array($seq, $bararray); - } - - /** - * Standard 2 of 5 barcodes. - * Used in airline ticket marking, photofinishing - * Contains digits (0 to 9) and encodes the data only in the width of bars. - * @param $code (string) code to represent. - * @param $checksum (boolean) if true add a checksum to the code - * @return array barcode representation. - * @protected - */ - protected function barcode_s25($code, $checksum=false) { - $chr['0'] = '10101110111010'; - $chr['1'] = '11101010101110'; - $chr['2'] = '10111010101110'; - $chr['3'] = '11101110101010'; - $chr['4'] = '10101110101110'; - $chr['5'] = '11101011101010'; - $chr['6'] = '10111011101010'; - $chr['7'] = '10101011101110'; - $chr['8'] = '10101110111010'; - $chr['9'] = '10111010111010'; - if ($checksum) { - // add checksum - $code .= $this->checksum_s25($code); - } - if((strlen($code) % 2) != 0) { - // add leading zero if code-length is odd - $code = '0'.$code; - } - $seq = '11011010'; - $clen = strlen($code); - for ($i = 0; $i < $clen; ++$i) { - $digit = $code{$i}; - if (!isset($chr[$digit])) { - // invalid character - return false; - } - $seq .= $chr[$digit]; - } - $seq .= '1101011'; - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - return $this->binseq_to_array($seq, $bararray); - } - - /** - * Convert binary barcode sequence to TCPDF barcode array. - * @param $seq (string) barcode as binary sequence. - * @param $bararray (array) barcode array. - * òparam array $bararray TCPDF barcode array to fill up - * @return array barcode representation. - * @protected - */ - protected function binseq_to_array($seq, $bararray) { - $len = strlen($seq); - $w = 0; - $k = 0; - for ($i = 0; $i < $len; ++$i) { - $w += 1; - if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i+1)}))) { - if ($seq{$i} == '1') { - $t = true; // bar - } else { - $t = false; // space - } - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - $w = 0; - } - } - return $bararray; - } - - /** - * Interleaved 2 of 5 barcodes. - * Compact numeric code, widely used in industry, air cargo - * Contains digits (0 to 9) and encodes the data in the width of both bars and spaces. - * @param $code (string) code to represent. - * @param $checksum (boolean) if true add a checksum to the code - * @return array barcode representation. - * @protected - */ - protected function barcode_i25($code, $checksum=false) { - $chr['0'] = '11221'; - $chr['1'] = '21112'; - $chr['2'] = '12112'; - $chr['3'] = '22111'; - $chr['4'] = '11212'; - $chr['5'] = '21211'; - $chr['6'] = '12211'; - $chr['7'] = '11122'; - $chr['8'] = '21121'; - $chr['9'] = '12121'; - $chr['A'] = '11'; - $chr['Z'] = '21'; - if ($checksum) { - // add checksum - $code .= $this->checksum_s25($code); - } - if((strlen($code) % 2) != 0) { - // add leading zero if code-length is odd - $code = '0'.$code; - } - // add start and stop codes - $code = 'AA'.strtolower($code).'ZA'; - - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $k = 0; - $clen = strlen($code); - for ($i = 0; $i < $clen; $i = ($i + 2)) { - $char_bar = $code{$i}; - $char_space = $code{$i+1}; - if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) { - // invalid character - return false; - } - // create a bar-space sequence - $seq = ''; - $chrlen = strlen($chr[$char_bar]); - for ($s = 0; $s < $chrlen; $s++){ - $seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s}; - } - $seqlen = strlen($seq); - for ($j = 0; $j < $seqlen; ++$j) { - if (($j % 2) == 0) { - $t = true; // bar - } else { - $t = false; // space - } - $w = $seq{$j}; - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - } - } - return $bararray; - } - - /** - * C128 barcodes. - * Very capable code, excellent density, high reliability; in very wide use world-wide - * @param $code (string) code to represent. - * @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode) - * @return array barcode representation. - * @protected - */ - protected function barcode_c128($code, $type='') { - $chr = array( - '212222', /* 00 */ - '222122', /* 01 */ - '222221', /* 02 */ - '121223', /* 03 */ - '121322', /* 04 */ - '131222', /* 05 */ - '122213', /* 06 */ - '122312', /* 07 */ - '132212', /* 08 */ - '221213', /* 09 */ - '221312', /* 10 */ - '231212', /* 11 */ - '112232', /* 12 */ - '122132', /* 13 */ - '122231', /* 14 */ - '113222', /* 15 */ - '123122', /* 16 */ - '123221', /* 17 */ - '223211', /* 18 */ - '221132', /* 19 */ - '221231', /* 20 */ - '213212', /* 21 */ - '223112', /* 22 */ - '312131', /* 23 */ - '311222', /* 24 */ - '321122', /* 25 */ - '321221', /* 26 */ - '312212', /* 27 */ - '322112', /* 28 */ - '322211', /* 29 */ - '212123', /* 30 */ - '212321', /* 31 */ - '232121', /* 32 */ - '111323', /* 33 */ - '131123', /* 34 */ - '131321', /* 35 */ - '112313', /* 36 */ - '132113', /* 37 */ - '132311', /* 38 */ - '211313', /* 39 */ - '231113', /* 40 */ - '231311', /* 41 */ - '112133', /* 42 */ - '112331', /* 43 */ - '132131', /* 44 */ - '113123', /* 45 */ - '113321', /* 46 */ - '133121', /* 47 */ - '313121', /* 48 */ - '211331', /* 49 */ - '231131', /* 50 */ - '213113', /* 51 */ - '213311', /* 52 */ - '213131', /* 53 */ - '311123', /* 54 */ - '311321', /* 55 */ - '331121', /* 56 */ - '312113', /* 57 */ - '312311', /* 58 */ - '332111', /* 59 */ - '314111', /* 60 */ - '221411', /* 61 */ - '431111', /* 62 */ - '111224', /* 63 */ - '111422', /* 64 */ - '121124', /* 65 */ - '121421', /* 66 */ - '141122', /* 67 */ - '141221', /* 68 */ - '112214', /* 69 */ - '112412', /* 70 */ - '122114', /* 71 */ - '122411', /* 72 */ - '142112', /* 73 */ - '142211', /* 74 */ - '241211', /* 75 */ - '221114', /* 76 */ - '413111', /* 77 */ - '241112', /* 78 */ - '134111', /* 79 */ - '111242', /* 80 */ - '121142', /* 81 */ - '121241', /* 82 */ - '114212', /* 83 */ - '124112', /* 84 */ - '124211', /* 85 */ - '411212', /* 86 */ - '421112', /* 87 */ - '421211', /* 88 */ - '212141', /* 89 */ - '214121', /* 90 */ - '412121', /* 91 */ - '111143', /* 92 */ - '111341', /* 93 */ - '131141', /* 94 */ - '114113', /* 95 */ - '114311', /* 96 */ - '411113', /* 97 */ - '411311', /* 98 */ - '113141', /* 99 */ - '114131', /* 100 */ - '311141', /* 101 */ - '411131', /* 102 */ - '211412', /* 103 START A */ - '211214', /* 104 START B */ - '211232', /* 105 START C */ - '233111', /* STOP */ - '200000' /* END */ - ); - // ASCII characters for code A (ASCII 00 - 95) - $keys_a = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'; - $keys_a .= chr(0).chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8).chr(9); - $keys_a .= chr(10).chr(11).chr(12).chr(13).chr(14).chr(15).chr(16).chr(17).chr(18).chr(19); - $keys_a .= chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29); - $keys_a .= chr(30).chr(31); - // ASCII characters for code B (ASCII 32 - 127) - $keys_b = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127); - // special codes - $fnc_a = array(241 => 102, 242 => 97, 243 => 96, 244 => 101); - $fnc_b = array(241 => 102, 242 => 97, 243 => 96, 244 => 100); - // array of symbols - $code_data = array(); - // lenght of the code - $len = strlen($code); - switch(strtoupper($type)) { - case 'A': { // MODE A - $startid = 103; - for ($i = 0; $i < $len; ++$i) { - $char = $code{$i}; - $char_id = ord($char); - if (($char_id >= 241) AND ($char_id <= 244)) { - $code_data[] = $fnc_a[$char_id]; - } elseif (($char_id >= 0) AND ($char_id <= 95)) { - $code_data[] = strpos($keys_a, $char); - } else { - return false; - } - } - break; - } - case 'B': { // MODE B - $startid = 104; - for ($i = 0; $i < $len; ++$i) { - $char = $code{$i}; - $char_id = ord($char); - if (($char_id >= 241) AND ($char_id <= 244)) { - $code_data[] = $fnc_b[$char_id]; - } elseif (($char_id >= 32) AND ($char_id <= 127)) { - $code_data[] = strpos($keys_b, $char); - } else { - return false; - } - } - break; - } - case 'C': { // MODE C - $startid = 105; - if (ord($code{0}) == 241) { - $code_data[] = 102; - $code = substr($code, 1); - --$len; - } - if (($len % 2) != 0) { - // the length must be even - return false; - } - for ($i = 0; $i < $len; $i+=2) { - $chrnum = $code{$i}.$code{$i+1}; - if (preg_match('/([0-9]{2})/', $chrnum) > 0) { - $code_data[] = intval($chrnum); - } else { - return false; - } - } - break; - } - default: { // MODE AUTO - // split code into sequences - $sequence = array(); - // get numeric sequences (if any) - $numseq = array(); - preg_match_all('/([0-9]{4,})/', $code, $numseq, PREG_OFFSET_CAPTURE); - if (isset($numseq[1]) AND !empty($numseq[1])) { - $end_offset = 0; - foreach ($numseq[1] as $val) { - $offset = $val[1]; - if ($offset > $end_offset) { - // non numeric sequence - $sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset, ($offset - $end_offset)))); - } - // numeric sequence - $slen = strlen($val[0]); - if (($slen % 2) != 0) { - // the length must be even - --$slen; - } - $sequence[] = array('C', substr($code, $offset, $slen), $slen); - $end_offset = $offset + $slen; - } - if ($end_offset < $len) { - $sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset))); - } - } else { - // text code (non C mode) - $sequence = array_merge($sequence, $this->get128ABsequence($code)); - } - // process the sequence - foreach ($sequence as $key => $seq) { - switch($seq[0]) { - case 'A': { - if ($key == 0) { - $startid = 103; - } elseif ($sequence[($key - 1)][0] != 'A') { - if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'B') AND (!isset($sequence[($key - 1)][3]))) { - // single character shift - $code_data[] = 98; - // mark shift - $sequence[$key][3] = true; - } elseif (!isset($sequence[($key - 1)][3])) { - $code_data[] = 101; - } - } - for ($i = 0; $i < $seq[2]; ++$i) { - $char = $seq[1]{$i}; - $char_id = ord($char); - if (($char_id >= 241) AND ($char_id <= 244)) { - $code_data[] = $fnc_a[$char_id]; - } else { - $code_data[] = strpos($keys_a, $char); - } - } - break; - } - case 'B': { - if ($key == 0) { - $tmpchr = ord($seq[1]{0}); - if (($seq[2] == 1) AND ($tmpchr >= 241) AND ($tmpchr <= 244) AND isset($sequence[($key + 1)]) AND ($sequence[($key + 1)][0] != 'B')) { - switch ($sequence[($key + 1)][0]) { - case 'A': { - $startid = 103; - $sequence[$key][0] = 'A'; - $code_data[] = $fnc_a[$tmpchr]; - break; - } - case 'C': { - $startid = 105; - $sequence[$key][0] = 'C'; - $code_data[] = $fnc_a[$tmpchr]; - break; - } - } - break; - } else { - $startid = 104; - } - } elseif ($sequence[($key - 1)][0] != 'B') { - if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'A') AND (!isset($sequence[($key - 1)][3]))) { - // single character shift - $code_data[] = 98; - // mark shift - $sequence[$key][3] = true; - } elseif (!isset($sequence[($key - 1)][3])) { - $code_data[] = 100; - } - } - for ($i = 0; $i < $seq[2]; ++$i) { - $char = $seq[1]{$i}; - $char_id = ord($char); - if (($char_id >= 241) AND ($char_id <= 244)) { - $code_data[] = $fnc_b[$char_id]; - } else { - $code_data[] = strpos($keys_b, $char); - } - } - break; - } - case 'C': { - if ($key == 0) { - $startid = 105; - } elseif ($sequence[($key - 1)][0] != 'C') { - $code_data[] = 99; - } - for ($i = 0; $i < $seq[2]; $i+=2) { - $chrnum = $seq[1]{$i}.$seq[1]{$i+1}; - $code_data[] = intval($chrnum); - } - break; - } - } - } - } - } - // calculate check character - $sum = $startid; - foreach ($code_data as $key => $val) { - $sum += ($val * ($key + 1)); - } - // add check character - $code_data[] = ($sum % 103); - // add stop sequence - $code_data[] = 106; - $code_data[] = 107; - // add start code at the beginning - array_unshift($code_data, $startid); - // build barcode array - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - foreach ($code_data as $val) { - $seq = $chr[$val]; - for ($j = 0; $j < 6; ++$j) { - if (($j % 2) == 0) { - $t = true; // bar - } else { - $t = false; // space - } - $w = $seq{$j}; - $bararray['bcode'][] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - } - } - return $bararray; - } - - /** - * Split text code in A/B sequence for 128 code - * @param $code (string) code to split. - * @return array sequence - * @protected - */ - protected function get128ABsequence($code) { - $len = strlen($code); - $sequence = array(); - // get A sequences (if any) - $numseq = array(); - preg_match_all('/([\0-\31])/', $code, $numseq, PREG_OFFSET_CAPTURE); - if (isset($numseq[1]) AND !empty($numseq[1])) { - $end_offset = 0; - foreach ($numseq[1] as $val) { - $offset = $val[1]; - if ($offset > $end_offset) { - // B sequence - $sequence[] = array('B', substr($code, $end_offset, ($offset - $end_offset)), ($offset - $end_offset)); - } - // A sequence - $slen = strlen($val[0]); - $sequence[] = array('A', substr($code, $offset, $slen), $slen); - $end_offset = $offset + $slen; - } - if ($end_offset < $len) { - $sequence[] = array('B', substr($code, $end_offset), ($len - $end_offset)); - } - } else { - // only B sequence - $sequence[] = array('B', $code, $len); - } - return $sequence; - } - - /** - * EAN13 and UPC-A barcodes. - * EAN13: European Article Numbering international retail product code - * UPC-A: Universal product code seen on almost all retail products in the USA and Canada - * UPC-E: Short version of UPC symbol - * @param $code (string) code to represent. - * @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A - * @return array barcode representation. - * @protected - */ - protected function barcode_eanupc($code, $len=13) { - $upce = false; - if ($len == 6) { - $len = 12; // UPC-A - $upce = true; // UPC-E mode - } - $data_len = $len - 1; - //Padding - $code = str_pad($code, $data_len, '0', STR_PAD_LEFT); - $code_len = strlen($code); - // calculate check digit - $sum_a = 0; - for ($i = 1; $i < $data_len; $i+=2) { - $sum_a += $code{$i}; - } - if ($len > 12) { - $sum_a *= 3; - } - $sum_b = 0; - for ($i = 0; $i < $data_len; $i+=2) { - $sum_b += ($code{$i}); - } - if ($len < 13) { - $sum_b *= 3; - } - $r = ($sum_a + $sum_b) % 10; - if($r > 0) { - $r = (10 - $r); - } - if ($code_len == $data_len) { - // add check digit - $code .= $r; - } elseif ($r !== intval($code{$data_len})) { - // wrong checkdigit - return false; - } - if ($len == 12) { - // UPC-A - $code = '0'.$code; - ++$len; - } - if ($upce) { - // convert UPC-A to UPC-E - $tmp = substr($code, 4, 3); - if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) { - // manufacturer code ends in 000, 100, or 200 - $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1); - } else { - $tmp = substr($code, 5, 2); - if ($tmp == '00') { - // manufacturer code ends in 00 - $upce_code = substr($code, 2, 3).substr($code, 10, 2).'3'; - } else { - $tmp = substr($code, 6, 1); - if ($tmp == '0') { - // manufacturer code ends in 0 - $upce_code = substr($code, 2, 4).substr($code, 11, 1).'4'; - } else { - // manufacturer code does not end in zero - $upce_code = substr($code, 2, 5).substr($code, 11, 1); - } - } - } - } - //Convert digits to bars - $codes = array( - 'A'=>array( // left odd parity - '0'=>'0001101', - '1'=>'0011001', - '2'=>'0010011', - '3'=>'0111101', - '4'=>'0100011', - '5'=>'0110001', - '6'=>'0101111', - '7'=>'0111011', - '8'=>'0110111', - '9'=>'0001011'), - 'B'=>array( // left even parity - '0'=>'0100111', - '1'=>'0110011', - '2'=>'0011011', - '3'=>'0100001', - '4'=>'0011101', - '5'=>'0111001', - '6'=>'0000101', - '7'=>'0010001', - '8'=>'0001001', - '9'=>'0010111'), - 'C'=>array( // right - '0'=>'1110010', - '1'=>'1100110', - '2'=>'1101100', - '3'=>'1000010', - '4'=>'1011100', - '5'=>'1001110', - '6'=>'1010000', - '7'=>'1000100', - '8'=>'1001000', - '9'=>'1110100') - ); - $parities = array( - '0'=>array('A','A','A','A','A','A'), - '1'=>array('A','A','B','A','B','B'), - '2'=>array('A','A','B','B','A','B'), - '3'=>array('A','A','B','B','B','A'), - '4'=>array('A','B','A','A','B','B'), - '5'=>array('A','B','B','A','A','B'), - '6'=>array('A','B','B','B','A','A'), - '7'=>array('A','B','A','B','A','B'), - '8'=>array('A','B','A','B','B','A'), - '9'=>array('A','B','B','A','B','A') - ); - $upce_parities = array(); - $upce_parities[0] = array( - '0'=>array('B','B','B','A','A','A'), - '1'=>array('B','B','A','B','A','A'), - '2'=>array('B','B','A','A','B','A'), - '3'=>array('B','B','A','A','A','B'), - '4'=>array('B','A','B','B','A','A'), - '5'=>array('B','A','A','B','B','A'), - '6'=>array('B','A','A','A','B','B'), - '7'=>array('B','A','B','A','B','A'), - '8'=>array('B','A','B','A','A','B'), - '9'=>array('B','A','A','B','A','B') - ); - $upce_parities[1] = array( - '0'=>array('A','A','A','B','B','B'), - '1'=>array('A','A','B','A','B','B'), - '2'=>array('A','A','B','B','A','B'), - '3'=>array('A','A','B','B','B','A'), - '4'=>array('A','B','A','A','B','B'), - '5'=>array('A','B','B','A','A','B'), - '6'=>array('A','B','B','B','A','A'), - '7'=>array('A','B','A','B','A','B'), - '8'=>array('A','B','A','B','B','A'), - '9'=>array('A','B','B','A','B','A') - ); - $k = 0; - $seq = '101'; // left guard bar - if ($upce) { - $bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $p = $upce_parities[$code{1}][$r]; - for ($i = 0; $i < 6; ++$i) { - $seq .= $codes[$p[$i]][$upce_code{$i}]; - } - $seq .= '010101'; // right guard bar - } else { - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $half_len = ceil($len / 2); - if ($len == 8) { - for ($i = 0; $i < $half_len; ++$i) { - $seq .= $codes['A'][$code{$i}]; - } - } else { - $p = $parities[$code{0}]; - for ($i = 1; $i < $half_len; ++$i) { - $seq .= $codes[$p[$i-1]][$code{$i}]; - } - } - $seq .= '01010'; // center guard bar - for ($i = $half_len; $i < $len; ++$i) { - $seq .= $codes['C'][$code{$i}]; - } - $seq .= '101'; // right guard bar - } - $clen = strlen($seq); - $w = 0; - for ($i = 0; $i < $clen; ++$i) { - $w += 1; - if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i+1)}))) { - if ($seq{$i} == '1') { - $t = true; // bar - } else { - $t = false; // space - } - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - $w = 0; - } - } - return $bararray; - } - - /** - * UPC-Based Extentions - * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers - * 5-Digit Ext.: Used to mark suggested retail price of books - * @param $code (string) code to represent. - * @param $len (string) barcode type: 2 = 2-Digit, 5 = 5-Digit - * @return array barcode representation. - * @protected - */ - protected function barcode_eanext($code, $len=5) { - //Padding - $code = str_pad($code, $len, '0', STR_PAD_LEFT); - // calculate check digit - if ($len == 2) { - $r = $code % 4; - } elseif ($len == 5) { - $r = (3 * ($code{0} + $code{2} + $code{4})) + (9 * ($code{1} + $code{3})); - $r %= 10; - } else { - return false; - } - //Convert digits to bars - $codes = array( - 'A'=>array( // left odd parity - '0'=>'0001101', - '1'=>'0011001', - '2'=>'0010011', - '3'=>'0111101', - '4'=>'0100011', - '5'=>'0110001', - '6'=>'0101111', - '7'=>'0111011', - '8'=>'0110111', - '9'=>'0001011'), - 'B'=>array( // left even parity - '0'=>'0100111', - '1'=>'0110011', - '2'=>'0011011', - '3'=>'0100001', - '4'=>'0011101', - '5'=>'0111001', - '6'=>'0000101', - '7'=>'0010001', - '8'=>'0001001', - '9'=>'0010111') - ); - $parities = array(); - $parities[2] = array( - '0'=>array('A','A'), - '1'=>array('A','B'), - '2'=>array('B','A'), - '3'=>array('B','B') - ); - $parities[5] = array( - '0'=>array('B','B','A','A','A'), - '1'=>array('B','A','B','A','A'), - '2'=>array('B','A','A','B','A'), - '3'=>array('B','A','A','A','B'), - '4'=>array('A','B','B','A','A'), - '5'=>array('A','A','B','B','A'), - '6'=>array('A','A','A','B','B'), - '7'=>array('A','B','A','B','A'), - '8'=>array('A','B','A','A','B'), - '9'=>array('A','A','B','A','B') - ); - $p = $parities[$len][$r]; - $seq = '1011'; // left guard bar - $seq .= $codes[$p[0]][$code{0}]; - for ($i = 1; $i < $len; ++$i) { - $seq .= '01'; // separator - $seq .= $codes[$p[$i]][$code{$i}]; - } - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - return $this->binseq_to_array($seq, $bararray); - } - - /** - * POSTNET and PLANET barcodes. - * Used by U.S. Postal Service for automated mail sorting - * @param $code (string) zip code to represent. Must be a string containing a zip code of the form DDDDD or DDDDD-DDDD. - * @param $planet (boolean) if true print the PLANET barcode, otherwise print POSTNET - * @return array barcode representation. - * @protected - */ - protected function barcode_postnet($code, $planet=false) { - // bar lenght - if ($planet) { - $barlen = Array( - 0 => Array(1,1,2,2,2), - 1 => Array(2,2,2,1,1), - 2 => Array(2,2,1,2,1), - 3 => Array(2,2,1,1,2), - 4 => Array(2,1,2,2,1), - 5 => Array(2,1,2,1,2), - 6 => Array(2,1,1,2,2), - 7 => Array(1,2,2,2,1), - 8 => Array(1,2,2,1,2), - 9 => Array(1,2,1,2,2) - ); - } else { - $barlen = Array( - 0 => Array(2,2,1,1,1), - 1 => Array(1,1,1,2,2), - 2 => Array(1,1,2,1,2), - 3 => Array(1,1,2,2,1), - 4 => Array(1,2,1,1,2), - 5 => Array(1,2,1,2,1), - 6 => Array(1,2,2,1,1), - 7 => Array(2,1,1,1,2), - 8 => Array(2,1,1,2,1), - 9 => Array(2,1,2,1,1) - ); - } - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array()); - $k = 0; - $code = str_replace('-', '', $code); - $code = str_replace(' ', '', $code); - $len = strlen($code); - // calculate checksum - $sum = 0; - for ($i = 0; $i < $len; ++$i) { - $sum += intval($code{$i}); - } - $chkd = ($sum % 10); - if($chkd > 0) { - $chkd = (10 - $chkd); - } - $code .= $chkd; - $len = strlen($code); - // start bar - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 2; - for ($i = 0; $i < $len; ++$i) { - for ($j = 0; $j < 5; ++$j) { - $h = $barlen[$code{$i}][$j]; - $p = floor(1 / $h); - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); - $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 2; - } - } - // end bar - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 1; - return $bararray; - } - - /** - * RMS4CC - CBC - KIX - * RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index) - * RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service. - * @param $code (string) code to print - * @param $kix (boolean) if true prints the KIX variation (doesn't use the start and end symbols, and the checksum) - in this case the house number must be sufficed with an X and placed at the end of the code. - * @return array barcode representation. - * @protected - */ - protected function barcode_rms4cc($code, $kix=false) { - $notkix = !$kix; - // bar mode - // 1 = pos 1, length 2 - // 2 = pos 1, length 3 - // 3 = pos 2, length 1 - // 4 = pos 2, length 2 - $barmode = array( - '0' => array(3,3,2,2), - '1' => array(3,4,1,2), - '2' => array(3,4,2,1), - '3' => array(4,3,1,2), - '4' => array(4,3,2,1), - '5' => array(4,4,1,1), - '6' => array(3,1,4,2), - '7' => array(3,2,3,2), - '8' => array(3,2,4,1), - '9' => array(4,1,3,2), - 'A' => array(4,1,4,1), - 'B' => array(4,2,3,1), - 'C' => array(3,1,2,4), - 'D' => array(3,2,1,4), - 'E' => array(3,2,2,3), - 'F' => array(4,1,1,4), - 'G' => array(4,1,2,3), - 'H' => array(4,2,1,3), - 'I' => array(1,3,4,2), - 'J' => array(1,4,3,2), - 'K' => array(1,4,4,1), - 'L' => array(2,3,3,2), - 'M' => array(2,3,4,1), - 'N' => array(2,4,3,1), - 'O' => array(1,3,2,4), - 'P' => array(1,4,1,4), - 'Q' => array(1,4,2,3), - 'R' => array(2,3,1,4), - 'S' => array(2,3,2,3), - 'T' => array(2,4,1,3), - 'U' => array(1,1,4,4), - 'V' => array(1,2,3,4), - 'W' => array(1,2,4,3), - 'X' => array(2,1,3,4), - 'Y' => array(2,1,4,3), - 'Z' => array(2,2,3,3) - ); - $code = strtoupper($code); - $len = strlen($code); - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array()); - if ($notkix) { - // table for checksum calculation (row,col) - $checktable = array( - '0' => array(1,1), - '1' => array(1,2), - '2' => array(1,3), - '3' => array(1,4), - '4' => array(1,5), - '5' => array(1,0), - '6' => array(2,1), - '7' => array(2,2), - '8' => array(2,3), - '9' => array(2,4), - 'A' => array(2,5), - 'B' => array(2,0), - 'C' => array(3,1), - 'D' => array(3,2), - 'E' => array(3,3), - 'F' => array(3,4), - 'G' => array(3,5), - 'H' => array(3,0), - 'I' => array(4,1), - 'J' => array(4,2), - 'K' => array(4,3), - 'L' => array(4,4), - 'M' => array(4,5), - 'N' => array(4,0), - 'O' => array(5,1), - 'P' => array(5,2), - 'Q' => array(5,3), - 'R' => array(5,4), - 'S' => array(5,5), - 'T' => array(5,0), - 'U' => array(0,1), - 'V' => array(0,2), - 'W' => array(0,3), - 'X' => array(0,4), - 'Y' => array(0,5), - 'Z' => array(0,0) - ); - $row = 0; - $col = 0; - for ($i = 0; $i < $len; ++$i) { - $row += $checktable[$code{$i}][0]; - $col += $checktable[$code{$i}][1]; - } - $row %= 6; - $col %= 6; - $chk = array_keys($checktable, array($row,$col)); - $code .= $chk[0]; - ++$len; - } - $k = 0; - if ($notkix) { - // start bar - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 2; - } - for ($i = 0; $i < $len; ++$i) { - for ($j = 0; $j < 4; ++$j) { - switch ($barmode[$code{$i}][$j]) { - case 1: { - $p = 0; - $h = 2; - break; - } - case 2: { - $p = 0; - $h = 3; - break; - } - case 3: { - $p = 1; - $h = 1; - break; - } - case 4: { - $p = 1; - $h = 2; - break; - } - } - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); - $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 2; - } - } - if ($notkix) { - // stop bar - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 3, 'p' => 0); - $bararray['maxw'] += 1; - } - return $bararray; - } - - /** - * CODABAR barcodes. - * Older code often used in library systems, sometimes in blood banks - * @param $code (string) code to represent. - * @return array barcode representation. - * @protected - */ - protected function barcode_codabar($code) { - $chr = array( - '0' => '11111221', - '1' => '11112211', - '2' => '11121121', - '3' => '22111111', - '4' => '11211211', - '5' => '21111211', - '6' => '12111121', - '7' => '12112111', - '8' => '12211111', - '9' => '21121111', - '-' => '11122111', - '$' => '11221111', - ':' => '21112121', - '/' => '21211121', - '.' => '21212111', - '+' => '11222221', - 'A' => '11221211', - 'B' => '12121121', - 'C' => '11121221', - 'D' => '11122211' - ); - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $k = 0; - $w = 0; - $seq = ''; - $code = 'A'.strtoupper($code).'A'; - $len = strlen($code); - for ($i = 0; $i < $len; ++$i) { - if (!isset($chr[$code{$i}])) { - return false; - } - $seq = $chr[$code{$i}]; - for ($j = 0; $j < 8; ++$j) { - if (($j % 2) == 0) { - $t = true; // bar - } else { - $t = false; // space - } - $w = $seq{$j}; - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - } - } - return $bararray; - } - - /** - * CODE11 barcodes. - * Used primarily for labeling telecommunications equipment - * @param $code (string) code to represent. - * @return array barcode representation. - * @protected - */ - protected function barcode_code11($code) { - $chr = array( - '0' => '111121', - '1' => '211121', - '2' => '121121', - '3' => '221111', - '4' => '112121', - '5' => '212111', - '6' => '122111', - '7' => '111221', - '8' => '211211', - '9' => '211111', - '-' => '112111', - 'S' => '112211' - ); - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $k = 0; - $w = 0; - $seq = ''; - $len = strlen($code); - // calculate check digit C - $p = 1; - $check = 0; - for ($i = ($len - 1); $i >= 0; --$i) { - $digit = $code{$i}; - if ($digit == '-') { - $dval = 10; - } else { - $dval = intval($digit); - } - $check += ($dval * $p); - ++$p; - if ($p > 10) { - $p = 1; - } - } - $check %= 11; - if ($check == 10) { - $check = '-'; - } - $code .= $check; - if ($len > 10) { - // calculate check digit K - $p = 1; - $check = 0; - for ($i = $len; $i >= 0; --$i) { - $digit = $code{$i}; - if ($digit == '-') { - $dval = 10; - } else { - $dval = intval($digit); - } - $check += ($dval * $p); - ++$p; - if ($p > 9) { - $p = 1; - } - } - $check %= 11; - $code .= $check; - ++$len; - } - $code = 'S'.$code.'S'; - $len += 3; - for ($i = 0; $i < $len; ++$i) { - if (!isset($chr[$code{$i}])) { - return false; - } - $seq = $chr[$code{$i}]; - for ($j = 0; $j < 6; ++$j) { - if (($j % 2) == 0) { - $t = true; // bar - } else { - $t = false; // space - } - $w = $seq{$j}; - $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); - $bararray['maxw'] += $w; - ++$k; - } - } - return $bararray; - } - - /** - * Pharmacode - * Contains digits (0 to 9) - * @param $code (string) code to represent. - * @return array barcode representation. - * @protected - */ - protected function barcode_pharmacode($code) { - $seq = ''; - $code = intval($code); - while ($code > 0) { - if (($code % 2) == 0) { - $seq .= '11100'; - $code -= 2; - } else { - $seq .= '100'; - $code -= 1; - } - $code /= 2; - } - $seq = substr($seq, 0, -2); - $seq = strrev($seq); - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - return $this->binseq_to_array($seq, $bararray); - } - - /** - * Pharmacode two-track - * Contains digits (0 to 9) - * @param $code (string) code to represent. - * @return array barcode representation. - * @protected - */ - protected function barcode_pharmacode2t($code) { - $seq = ''; - $code = intval($code); - do { - switch ($code % 3) { - case 0: { - $seq .= '3'; - $code = ($code - 3) / 3; - break; - } - case 1: { - $seq .= '1'; - $code = ($code - 1) / 3; - break; - } - case 2: { - $seq .= '2'; - $code = ($code - 2) / 3; - break; - } - } - } while($code != 0); - $seq = strrev($seq); - $k = 0; - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array()); - $len = strlen($seq); - for ($i = 0; $i < $len; ++$i) { - switch ($seq{$i}) { - case '1': { - $p = 1; - $h = 1; - break; - } - case '2': { - $p = 0; - $h = 1; - break; - } - case '3': { - $p = 0; - $h = 2; - break; - } - } - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); - $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 2; - } - unset($bararray['bcode'][($k - 1)]); - --$bararray['maxw']; - return $bararray; - } - - - /** - * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 - * (requires PHP bcmath extension) - * Intelligent Mail barcode is a 65-bar code for use on mail in the United States. - * The fields are described as follows: - * @param $code (string) code to print, separate the ZIP (routing code) from the rest using a minus char '-' (BarcodeID_ServiceTypeID_MailerID_SerialNumber-RoutingCode) - * @return array barcode representation. - * @protected - */ - protected function barcode_imb($code) { - $asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8); - $dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3); - $asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2); - $dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10); - $code_arr = explode('-', $code); - $tracking_number = $code_arr[0]; - if (isset($code_arr[1])) { - $routing_code = $code_arr[1]; - } else { - $routing_code = ''; - } - // Conversion of Routing Code - switch (strlen($routing_code)) { - case 0: { - $binary_code = 0; - break; - } - case 5: { - $binary_code = bcadd($routing_code, '1'); - break; - } - case 9: { - $binary_code = bcadd($routing_code, '100001'); - break; - } - case 11: { - $binary_code = bcadd($routing_code, '1000100001'); - break; - } - default: { - return false; - break; - } - } - $binary_code = bcmul($binary_code, 10); - $binary_code = bcadd($binary_code, $tracking_number{0}); - $binary_code = bcmul($binary_code, 5); - $binary_code = bcadd($binary_code, $tracking_number{1}); - $binary_code .= substr($tracking_number, 2, 18); - // convert to hexadecimal - $binary_code = $this->dec_to_hex($binary_code); - // pad to get 13 bytes - $binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT); - // convert string to array of bytes - $binary_code_arr = chunk_split($binary_code, 2, "\r"); - $binary_code_arr = substr($binary_code_arr, 0, -1); - $binary_code_arr = explode("\r", $binary_code_arr); - // calculate frame check sequence - $fcs = $this->imb_crc11fcs($binary_code_arr); - // exclude first 2 bits from first byte - $first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2)); - $binary_code_102bit = $first_byte.substr($binary_code, 2); - // convert binary data to codewords - $codewords = array(); - $data = $this->hex_to_dec($binary_code_102bit); - $codewords[0] = bcmod($data, 636) * 2; - $data = bcdiv($data, 636); - for ($i = 1; $i < 9; ++$i) { - $codewords[$i] = bcmod($data, 1365); - $data = bcdiv($data, 1365); - } - $codewords[9] = $data; - if (($fcs >> 10) == 1) { - $codewords[9] += 659; - } - // generate lookup tables - $table2of13 = $this->imb_tables(2, 78); - $table5of13 = $this->imb_tables(5, 1287); - // convert codewords to characters - $characters = array(); - $bitmask = 512; - foreach($codewords as $k => $val) { - if ($val <= 1286) { - $chrcode = $table5of13[$val]; - } else { - $chrcode = $table2of13[($val - 1287)]; - } - if (($fcs & $bitmask) > 0) { - // bitwise invert - $chrcode = ((~$chrcode) & 8191); - } - $characters[] = $chrcode; - $bitmask /= 2; - } - $characters = array_reverse($characters); - // build bars - $k = 0; - $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array()); - for ($i = 0; $i < 65; ++$i) { - $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0); - $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0); - if ($asc AND $dsc) { - // full bar (F) - $p = 0; - $h = 3; - } elseif ($asc) { - // ascender (A) - $p = 0; - $h = 2; - } elseif ($dsc) { - // descender (D) - $p = 1; - $h = 2; - } else { - // tracker (T) - $p = 1; - $h = 1; - } - $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); - $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); - $bararray['maxw'] += 2; - } - unset($bararray['bcode'][($k - 1)]); - --$bararray['maxw']; - return $bararray; - } - - /** - * Convert large integer number to hexadecimal representation. - * (requires PHP bcmath extension) - * @param $number (string) number to convert specified as a string - * @return string hexadecimal representation - */ - public function dec_to_hex($number) { - $i = 0; - $hex = array(); - if($number == 0) { - return '00'; - } - while($number > 0) { - if($number == 0) { - array_push($hex, '0'); - } else { - array_push($hex, strtoupper(dechex(bcmod($number, '16')))); - $number = bcdiv($number, '16', 0); - } - } - $hex = array_reverse($hex); - return implode($hex); - } - - /** - * Convert large hexadecimal number to decimal representation (string). - * (requires PHP bcmath extension) - * @param $hex (string) hexadecimal number to convert specified as a string - * @return string hexadecimal representation - */ - public function hex_to_dec($hex) { - $dec = 0; - $bitval = 1; - $len = strlen($hex); - for($pos = ($len - 1); $pos >= 0; --$pos) { - $dec = bcadd($dec, bcmul(hexdec($hex{$pos}), $bitval)); - $bitval = bcmul($bitval, 16); - } - return $dec; - } - - /** - * Intelligent Mail Barcode calculation of Frame Check Sequence - * @param $code_arr (string) array of hexadecimal values (13 bytes holding 102 bits right justified). - * @return int 11 bit Frame Check Sequence as integer (decimal base) - * @protected - */ - protected function imb_crc11fcs($code_arr) { - $genpoly = 0x0F35; // generator polynomial - $fcs = 0x07FF; // Frame Check Sequence - // do most significant byte skipping the 2 most significant bits - $data = hexdec($code_arr[0]) << 5; - for ($bit = 2; $bit < 8; ++$bit) { - if (($fcs ^ $data) & 0x400) { - $fcs = ($fcs << 1) ^ $genpoly; - } else { - $fcs = ($fcs << 1); - } - $fcs &= 0x7FF; - $data <<= 1; - } - // do rest of bytes - for ($byte = 1; $byte < 13; ++$byte) { - $data = hexdec($code_arr[$byte]) << 3; - for ($bit = 0; $bit < 8; ++$bit) { - if (($fcs ^ $data) & 0x400) { - $fcs = ($fcs << 1) ^ $genpoly; - } else { - $fcs = ($fcs << 1); - } - $fcs &= 0x7FF; - $data <<= 1; - } - } - return $fcs; - } - - /** - * Reverse unsigned short value - * @param $num (int) value to reversr - * @return int reversed value - * @protected - */ - protected function imb_reverse_us($num) { - $rev = 0; - for ($i = 0; $i < 16; ++$i) { - $rev <<= 1; - $rev |= ($num & 1); - $num >>= 1; - } - return $rev; - } - - /** - * generate Nof13 tables used for Intelligent Mail Barcode - * @param $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table - * @param $size (int) size of table (78 for n=2 and 1287 for n=5) - * @return array requested table - * @protected - */ - protected function imb_tables($n, $size) { - $table = array(); - $lli = 0; // LUT lower index - $lui = $size - 1; // LUT upper index - for ($count = 0; $count < 8192; ++$count) { - $bit_count = 0; - for ($bit_index = 0; $bit_index < 13; ++$bit_index) { - $bit_count += intval(($count & (1 << $bit_index)) != 0); - } - // if we don't have the right number of bits on, go on to the next value - if ($bit_count == $n) { - $reverse = ($this->imb_reverse_us($count) >> 3); - // if the reverse is less than count, we have already visited this pair before - if ($reverse >= $count) { - // If count is symmetric, place it at the first free slot from the end of the list. - // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list - if ($reverse == $count) { - $table[$lui] = $count; - --$lui; - } else { - $table[$lli] = $count; - ++$lli; - $table[$lli] = $reverse; - ++$lli; - } - } - } - } - return $table; - } } // end of class //============================================================+ // END OF FILE //============================================================+ + diff --git a/tools/tcpdf/datamatrix.php b/tools/tcpdf/datamatrix.php index fc78bbbee..290b46916 100755 --- a/tools/tcpdf/datamatrix.php +++ b/tools/tcpdf/datamatrix.php @@ -43,60 +43,6 @@ * @version 1.0.001 */ -// custom definitions -if (!defined('DATAMATRIXDEFS')) { - - /** - * Indicate that definitions for this class are set - */ - define('DATAMATRIXDEFS', true); - - // ----------------------------------------------------- - -} // end of custom definitions - -// #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# - - -/** - * ASCII encoding: ASCII character 0 to 127 (1 byte per CW) - */ -define('ENC_ASCII', 0); - -/** - * C40 encoding: Upper-case alphanumeric (3/2 bytes per CW) - */ -define('ENC_C40', 1); - -/** - * TEXT encoding: Lower-case alphanumeric (3/2 bytes per CW) - */ -define('ENC_TXT', 2); - -/** - * X12 encoding: ANSI X12 (3/2 byte per CW) - */ -define('ENC_X12', 3); - -/** - * EDIFACT encoding: ASCII character 32 to 94 (4/3 bytes per CW) - */ -define('ENC_EDF', 4); - -/** - * BASE 256 encoding: ASCII character 0 to 255 (1 byte per CW) - */ -define('ENC_BASE256', 5); - -/** - * ASCII extended encoding: ASCII character 128 to 255 (1/2 byte per CW) - */ -define('ENC_ASCII_EXT', 6); - -/** - * ASCII number encoding: ASCII digits (2 bytes per CW) - */ -define('ENC_ASCII_NUM', 7); /** * @class Datamatrix @@ -108,1041 +54,8 @@ define('ENC_ASCII_NUM', 7); * @version 1.0.001 */ class Datamatrix { - - /** - * Barcode array to be returned which is readable by TCPDF. - * @protected - */ - protected $barcode_array = array(); - - /** - * Store last used encoding for data codewords. - * @protected - */ - protected $last_enc = ENC_ASCII; - - /** - * Table of Data Matrix ECC 200 Symbol Attributes: - * @protected - */ - protected $symbattr = array( - // square form --------------------------------------------------------------------------------------- - array(0x00a,0x00a,0x008,0x008,0x00a,0x00a,0x008,0x008,0x001,0x001,0x001,0x003,0x005,0x001,0x003,0x005), // 10x10 - array(0x00c,0x00c,0x00a,0x00a,0x00c,0x00c,0x00a,0x00a,0x001,0x001,0x001,0x005,0x007,0x001,0x005,0x007), // 12x12 - array(0x00e,0x00e,0x00c,0x00c,0x00e,0x00e,0x00c,0x00c,0x001,0x001,0x001,0x008,0x00a,0x001,0x008,0x00a), // 14x14 - array(0x010,0x010,0x00e,0x00e,0x010,0x010,0x00e,0x00e,0x001,0x001,0x001,0x00c,0x00c,0x001,0x00c,0x00c), // 16x16 - array(0x012,0x012,0x010,0x010,0x012,0x012,0x010,0x010,0x001,0x001,0x001,0x012,0x00e,0x001,0x012,0x00e), // 18x18 - array(0x014,0x014,0x012,0x012,0x014,0x014,0x012,0x012,0x001,0x001,0x001,0x016,0x012,0x001,0x016,0x012), // 20x20 - array(0x016,0x016,0x014,0x014,0x016,0x016,0x014,0x014,0x001,0x001,0x001,0x01e,0x014,0x001,0x01e,0x014), // 22x22 - array(0x018,0x018,0x016,0x016,0x018,0x018,0x016,0x016,0x001,0x001,0x001,0x024,0x018,0x001,0x024,0x018), // 24x24 - array(0x01a,0x01a,0x018,0x018,0x01a,0x01a,0x018,0x018,0x001,0x001,0x001,0x02c,0x01c,0x001,0x02c,0x01c), // 26x26 - array(0x020,0x020,0x01c,0x01c,0x010,0x010,0x00e,0x00e,0x002,0x002,0x004,0x03e,0x024,0x001,0x03e,0x024), // 32x32 - array(0x024,0x024,0x020,0x020,0x012,0x012,0x010,0x010,0x002,0x002,0x004,0x056,0x02a,0x001,0x056,0x02a), // 36x36 - array(0x028,0x028,0x024,0x024,0x014,0x014,0x012,0x012,0x002,0x002,0x004,0x072,0x030,0x001,0x072,0x030), // 40x40 - array(0x02c,0x02c,0x028,0x028,0x016,0x016,0x014,0x014,0x002,0x002,0x004,0x090,0x038,0x001,0x090,0x038), // 44x44 - array(0x030,0x030,0x02c,0x02c,0x018,0x018,0x016,0x016,0x002,0x002,0x004,0x0ae,0x044,0x001,0x0ae,0x044), // 48x48 - array(0x034,0x034,0x030,0x030,0x01a,0x01a,0x018,0x018,0x002,0x002,0x004,0x0cc,0x054,0x002,0x066,0x02a), // 52x52 - array(0x040,0x040,0x038,0x038,0x010,0x010,0x00e,0x00e,0x004,0x004,0x010,0x118,0x070,0x002,0x08c,0x038), // 64x64 - array(0x048,0x048,0x040,0x040,0x012,0x012,0x010,0x010,0x004,0x004,0x010,0x170,0x090,0x004,0x05c,0x024), // 72x72 - array(0x050,0x050,0x048,0x048,0x014,0x014,0x012,0x012,0x004,0x004,0x010,0x1c8,0x0c0,0x004,0x072,0x030), // 80x80 - array(0x058,0x058,0x050,0x050,0x016,0x016,0x014,0x014,0x004,0x004,0x010,0x240,0x0e0,0x004,0x090,0x038), // 88x88 - array(0x060,0x060,0x058,0x058,0x018,0x018,0x016,0x016,0x004,0x004,0x010,0x2b8,0x110,0x004,0x0ae,0x044), // 96x96 - array(0x068,0x068,0x060,0x060,0x01a,0x01a,0x018,0x018,0x004,0x004,0x010,0x330,0x150,0x006,0x088,0x038), // 104x104 - array(0x078,0x078,0x06c,0x06c,0x014,0x014,0x012,0x012,0x006,0x006,0x024,0x41a,0x198,0x006,0x0af,0x044), // 120x120 - array(0x084,0x084,0x078,0x078,0x016,0x016,0x014,0x014,0x006,0x006,0x024,0x518,0x1f0,0x008,0x0a3,0x03e), // 132x132 - array(0x090,0x090,0x084,0x084,0x018,0x018,0x016,0x016,0x006,0x006,0x024,0x616,0x26c,0x00a,0x09c,0x03e), // 144x144 - // rectangular form (currently unused) --------------------------------------------------------------------------- - array(0x008,0x012,0x006,0x010,0x008,0x012,0x006,0x010,0x001,0x001,0x001,0x005,0x007,0x001,0x005,0x007), // 8x18 - array(0x008,0x020,0x006,0x01c,0x008,0x010,0x006,0x00e,0x001,0x002,0x002,0x00a,0x00b,0x001,0x00a,0x00b), // 8x32 - array(0x00c,0x01a,0x00a,0x018,0x00c,0x01a,0x00a,0x018,0x001,0x001,0x001,0x010,0x00e,0x001,0x010,0x00e), // 12x26 - array(0x00c,0x024,0x00a,0x020,0x00c,0x012,0x00a,0x010,0x001,0x002,0x002,0x00c,0x012,0x001,0x00c,0x012), // 12x36 - array(0x010,0x024,0x00e,0x020,0x010,0x012,0x00e,0x010,0x001,0x002,0x002,0x020,0x018,0x001,0x020,0x018), // 16x36 - array(0x010,0x030,0x00e,0x02c,0x010,0x018,0x00e,0x016,0x001,0x002,0x002,0x031,0x01c,0x001,0x031,0x01c) // 16x48 - ); - - /** - * Map encodation modes whit character sets. - * @protected - */ - protected $chset_id = array(ENC_C40 => 'C40', ENC_TXT => 'TXT', ENC_X12 =>'X12'); - - /** - * Basic set of charactes for each encodation mode. - * @protected - */ - protected $chset = array( - 'C40' => array( // Basic set for C40 ---------------------------------------------------------------------------- - 'S1'=>0x00,'S2'=>0x01,'S3'=>0x02,0x20=>0x03,0x30=>0x04,0x31=>0x05,0x32=>0x06,0x33=>0x07,0x34=>0x08,0x35=>0x09, // - 0x36=>0x0a,0x37=>0x0b,0x38=>0x0c,0x39=>0x0d,0x41=>0x0e,0x42=>0x0f,0x43=>0x10,0x44=>0x11,0x45=>0x12,0x46=>0x13, // - 0x47=>0x14,0x48=>0x15,0x49=>0x16,0x4a=>0x17,0x4b=>0x18,0x4c=>0x19,0x4d=>0x1a,0x4e=>0x1b,0x4f=>0x1c,0x50=>0x1d, // - 0x51=>0x1e,0x52=>0x1f,0x53=>0x20,0x54=>0x21,0x55=>0x22,0x56=>0x23,0x57=>0x24,0x58=>0x25,0x59=>0x26,0x5a=>0x27),// - 'TXT' => array( // Basic set for TEXT --------------------------------------------------------------------------- - 'S1'=>0x00,'S2'=>0x01,'S3'=>0x02,0x20=>0x03,0x30=>0x04,0x31=>0x05,0x32=>0x06,0x33=>0x07,0x34=>0x08,0x35=>0x09, // - 0x36=>0x0a,0x37=>0x0b,0x38=>0x0c,0x39=>0x0d,0x61=>0x0e,0x62=>0x0f,0x63=>0x10,0x64=>0x11,0x65=>0x12,0x66=>0x13, // - 0x67=>0x14,0x68=>0x15,0x69=>0x16,0x6a=>0x17,0x6b=>0x18,0x6c=>0x19,0x6d=>0x1a,0x6e=>0x1b,0x6f=>0x1c,0x70=>0x1d, // - 0x71=>0x1e,0x72=>0x1f,0x73=>0x20,0x74=>0x21,0x75=>0x22,0x76=>0x23,0x77=>0x24,0x78=>0x25,0x79=>0x26,0x7a=>0x27),// - 'SH1' => array( // Shift 1 set ---------------------------------------------------------------------------------- - 0x00=>0x00,0x01=>0x01,0x02=>0x02,0x03=>0x03,0x04=>0x04,0x05=>0x05,0x06=>0x06,0x07=>0x07,0x08=>0x08,0x09=>0x09, // - 0x0a=>0x0a,0x0b=>0x0b,0x0c=>0x0c,0x0d=>0x0d,0x0e=>0x0e,0x0f=>0x0f,0x10=>0x10,0x11=>0x11,0x12=>0x12,0x13=>0x13, // - 0x14=>0x14,0x15=>0x15,0x16=>0x16,0x17=>0x17,0x18=>0x18,0x19=>0x19,0x1a=>0x1a,0x1b=>0x1b,0x1c=>0x1c,0x1d=>0x1d, // - 0x1e=>0x1e,0x1f=>0x1f), // - 'SH2' => array( // Shift 2 set ---------------------------------------------------------------------------------- - 0x21=>0x00,0x22=>0x01,0x23=>0x02,0x24=>0x03,0x25=>0x04,0x26=>0x05,0x27=>0x06,0x28=>0x07,0x29=>0x08,0x2a=>0x09, // - 0x2b=>0x0a,0x2c=>0x0b,0x2d=>0x0c,0x2e=>0x0d,0x2f=>0x0e,0x3a=>0x0f,0x3b=>0x10,0x3c=>0x11,0x3d=>0x12,0x3e=>0x13, // - 0x3f=>0x14,0x40=>0x15,0x5b=>0x16,0x5c=>0x17,0x5d=>0x18,0x5e=>0x19,0x5f=>0x1a,'F1'=>0x1b,'US'=>0x1e), // - 'S3C' => array( // Shift 3 set for C40 -------------------------------------------------------------------------- - 0x60=>0x00,0x61=>0x01,0x62=>0x02,0x63=>0x03,0x64=>0x04,0x65=>0x05,0x66=>0x06,0x67=>0x07,0x68=>0x08,0x69=>0x09, // - 0x6a=>0x0a,0x6b=>0x0b,0x6c=>0x0c,0x6d=>0x0d,0x6e=>0x0e,0x6f=>0x0f,0x70=>0x10,0x71=>0x11,0x72=>0x12,0x73=>0x13, // - 0x74=>0x14,0x75=>0x15,0x76=>0x16,0x77=>0x17,0x78=>0x18,0x79=>0x19,0x7a=>0x1a,0x7b=>0x1b,0x7c=>0x1c,0x7d=>0x1d, // - 0x7e=>0x1e,0x7f=>0x1f), - 'S3T' => array( // Shift 3 set for TEXT ------------------------------------------------------------------------- - 0x60=>0x00,0x41=>0x01,0x42=>0x02,0x43=>0x03,0x44=>0x04,0x45=>0x05,0x46=>0x06,0x47=>0x07,0x48=>0x08,0x49=>0x09, // - 0x4a=>0x0a,0x4b=>0x0b,0x4c=>0x0c,0x4d=>0x0d,0x4e=>0x0e,0x4f=>0x0f,0x50=>0x10,0x51=>0x11,0x52=>0x12,0x53=>0x13, // - 0x54=>0x14,0x55=>0x15,0x56=>0x16,0x57=>0x17,0x58=>0x18,0x59=>0x19,0x5a=>0x1a,0x7b=>0x1b,0x7c=>0x1c,0x7d=>0x1d, // - 0x7e=>0x1e,0x7f=>0x1f), // - 'X12' => array( // Set for X12 ---------------------------------------------------------------------------------- - 0x0d=>0x00,0x2a=>0x01,0x3e=>0x02,0x20=>0x03,0x30=>0x04,0x31=>0x05,0x32=>0x06,0x33=>0x07,0x34=>0x08,0x35=>0x09, // - 0x36=>0x0a,0x37=>0x0b,0x38=>0x0c,0x39=>0x0d,0x41=>0x0e,0x42=>0x0f,0x43=>0x10,0x44=>0x11,0x45=>0x12,0x46=>0x13, // - 0x47=>0x14,0x48=>0x15,0x49=>0x16,0x4a=>0x17,0x4b=>0x18,0x4c=>0x19,0x4d=>0x1a,0x4e=>0x1b,0x4f=>0x1c,0x50=>0x1d, // - 0x51=>0x1e,0x52=>0x1f,0x53=>0x20,0x54=>0x21,0x55=>0x22,0x56=>0x23,0x57=>0x24,0x58=>0x25,0x59=>0x26,0x5a=>0x27) // - ); - -// ----------------------------------------------------------------------------- - - /** - * This is the class constructor. - * Creates a datamatrix object - * @param $code (string) Code to represent using Datamatrix. - * @public - */ - public function __construct($code) { - $barcode_array = array(); - if ((is_null($code)) OR ($code == '\0') OR ($code == '')) { - return false; - } - // get data codewords - $cw = $this->getHighLevelEncoding($code); - // number of data codewords - $nd = count($cw); - // check size - if ($nd > 1558) { - return false; - } - // get minimum required matrix size. - foreach ($this->symbattr as $params) { - if ($params[11] >= $nd) { - break; - } - } - if ($params[11] < $nd) { - // too much data - return false; - } elseif ($params[11] > $nd) { - // add padding - if ($this->last_enc == ENC_EDF) { - // switch to ASCII encoding - $cw[] = 124; - ++$nd; - } elseif (($this->last_enc != ENC_ASCII) AND ($this->last_enc != ENC_BASE256)) { - // switch to ASCII encoding - $cw[] = 254; - ++$nd; - } - if ($params[11] > $nd) { - // add first pad - $cw[] = 129; - ++$nd; - // add remaining pads - for ($i = $nd; $i <= $params[11]; ++$i) { - $cw[] = $this->get253StateCodeword(129, $i); - } - } - } - // add error correction codewords - $cw = $this->getErrorCorrection($cw, $params[13], $params[14], $params[15]); - // initialize empty arrays - $grid = array_fill(0, ($params[2] * $params[3]), 0); - // get placement map - $places = $this->getPlacemetMap($params[2], $params[3]); - // fill the grid with data - $grid = array(); - $i = 0; - // region data row max index - $rdri = ($params[4] - 1); - // region data column max index - $rdci = ($params[5] - 1); - // for each vertical region - for ($vr = 0; $vr < $params[9]; ++$vr) { - // for each row on region - for ($r = 0; $r < $params[4]; ++$r) { - // get row - $row = (($vr * $params[4]) + $r); - // for each horizontal region - for ($hr = 0; $hr < $params[8]; ++$hr) { - // for each column on region - for ($c = 0; $c < $params[5]; ++$c) { - // get column - $col = (($hr * $params[5]) + $c); - // braw bits by case - if ($r == 0) { - // top finder pattern - if ($c % 2) { - $grid[$row][$col] = 0; - } else { - $grid[$row][$col] = 1; - } - } elseif ($r == $rdri) { - // bottom finder pattern - $grid[$row][$col] = 1; - } elseif ($c == 0) { - // left finder pattern - $grid[$row][$col] = 1; - } elseif ($c == $rdci) { - // right finder pattern - if ($r % 2) { - $grid[$row][$col] = 1; - } else { - $grid[$row][$col] = 0; - } - } else { // data bit - if ($places[$i] < 2) { - $grid[$row][$col] = $places[$i]; - } else { - // codeword ID - $cw_id = (floor($places[$i] / 10) - 1); - // codeword BIT mask - $cw_bit = pow(2, (8 - ($places[$i] % 10))); - $grid[$row][$col] = (($cw[$cw_id] & $cw_bit) == 0) ? 0 : 1; - } - ++$i; - } - } - } - } - } - $this->barcode_array['num_rows'] = $params[0]; - $this->barcode_array['num_cols'] = $params[1]; - $this->barcode_array['bcode'] = $grid; - } - - /** - * Returns a barcode array which is readable by TCPDF - * @return array barcode array readable by TCPDF; - * @public - */ - public function getBarcodeArray() { - return $this->barcode_array; - } - - /** - * Product of two numbers in a Power-of-Two Galois Field - * @param $a (int) first number to multiply. - * @param $b (int) second number to multiply. - * @param $log (array) Log table. - * @param $alog (array) Anti-Log table. - * @param $gf (array) Number of Factors of the Reed-Solomon polynomial. - * @return int product - * @protected - */ - protected function getGFProduct($a, $b, $log, $alog, $gf) { - if (($a == 0) OR ($b == 0)) { - return 0; - } - return $alog[($log[$a] + $log[$b]) % ($gf - 1)]; - } - - /** - * Add error correction codewords to data codewords array (ANNEX E). - * @param $wd (array) Array of datacodewords. - * @param $nb (int) Number of blocks. - * @param $nd (int) Number of data codewords per block. - * @param $nc (int) Number of correction codewords per block. - * @param $gf (int) numner of fields on log/antilog table (power of 2). - * @param $pp (int) The value of its prime modulus polynomial (301 for ECC200). - * @return array data codewords + error codewords - * @protected - */ - protected function getErrorCorrection($wd, $nb, $nd, $nc, $gf=256, $pp=301) { - // generate the log ($log) and antilog ($alog) tables - $log[0] = 0; - $alog[0] = 1; - for ($i = 1; $i < $gf; ++$i) { - $alog[$i] = ($alog[($i - 1)] * 2); - if ($alog[$i] >= $gf) { - $alog[$i] ^= $pp; - } - $log[$alog[$i]] = $i; - } - ksort($log); - // generate the polynomial coefficients (c) - $c = array_fill(0, ($nc + 1), 0); - $c[0] = 1; - for ($i = 1; $i <= $nc; ++$i) { - $c[$i] = $c[($i-1)]; - for ($j = ($i - 1); $j >= 1; --$j) { - $c[$j] = $c[($j - 1)] ^ $this->getGFProduct($c[$j], $alog[$i], $log, $alog, $gf); - } - $c[0] = $this->getGFProduct($c[0], $alog[$i], $log, $alog, $gf); - } - ksort($c); - // total number of data codewords - $num_wd = ($nb * $nd); - // total number of error codewords - $num_we = ($nb * $nc); - // for each block - for ($b = 0; $b < $nb; ++$b) { - // create interleaved data block - $block = array(); - for ($n = $b; $n < $num_wd; $n += $nb) { - $block[] = $wd[$n]; - } - // initialize error codewords - $we = array_fill(0, ($nc + 1), 0); - // calculate error correction codewords for this block - for ($i = 0; $i < $nd; ++$i) { - $k = ($we[0] ^ $block[$i]); - for ($j = 0; $j < $nc; ++$j) { - $we[$j] = ($we[($j + 1)] ^ $this->getGFProduct($k, $c[($nc - $j - 1)], $log, $alog, $gf)); - } - } - // add error codewords at the end of data codewords - $j = 0; - for ($i = $b; $i < $num_we; $i += $nb) { - $wd[($num_wd + $i)] = $we[$j]; - ++$j; - } - } - // reorder codewords - ksort($wd); - return $wd; - } - - /** - * Return the 253-state codeword - * @param $cwpad (int) Pad codeword. - * @param $cwpos (int) Number of data codewords from the beginning of encoded data. - * @return pad codeword - * @protected - */ - protected function get253StateCodeword($cwpad, $cwpos) { - $pad = ($cwpad + (((149 * $cwpos) % 253) + 1)); - if ($pad > 254) { - $pad -= 254; - } - return $pad; - } - - /** - * Return the 255-state codeword - * @param $cwpad (int) Pad codeword. - * @param $cwpos (int) Number of data codewords from the beginning of encoded data. - * @return pad codeword - * @protected - */ - protected function get255StateCodeword($cwpad, $cwpos) { - $pad = ($cwpad + (((149 * $cwpos) % 255) + 1)); - if ($pad > 255) { - $pad -= 256; - } - return $pad; - } - - /** - * Returns true if the char belongs to the selected mode - * @param $chr (int) Character (byte) to check. - * @param $mode (int) Current encoding mode. - * @return boolean true if the char is of the selected mode. - * @protected - */ - protected function isCharMode($chr, $mode) { - $status = false; - switch ($mode) { - case ENC_ASCII: { // ASCII character 0 to 127 - $status = (($chr >= 0) AND ($chr <= 127)); - break; - } - case ENC_C40: { // Upper-case alphanumeric - $status = (($chr == 32) OR (($chr >= 48) AND ($chr <= 57)) OR (($chr >= 65) AND ($chr <= 90))); - break; - } - case ENC_TXT: { // Lower-case alphanumeric - $status = (($chr == 32) OR (($chr >= 48) AND ($chr <= 57)) OR (($chr >= 97) AND ($chr <= 122))); - break; - } - case ENC_X12: { // ANSI X12 - $status = (($chr == 13) OR ($chr == 42) OR ($chr == 62)); - break; - } - case ENC_EDF: { // ASCII character 32 to 94 - $status = (($chr >= 32) AND ($chr <= 94)); - break; - } - case ENC_BASE256: { // Function character (FNC1, Structured Append, Reader Program, or Code Page) - $status = (($chr == 232) OR ($chr == 233) OR ($chr == 234) OR ($chr == 241)); - break; - } - case ENC_ASCII_EXT: { // ASCII character 128 to 255 - $status = (($chr >= 128) AND ($chr <= 255)); - break; - } - case ENC_ASCII_NUM: { // ASCII digits - $status = (($chr >= 48) AND ($chr <= 57)); - break; - } - } - return $status; - } - - /** - * The look-ahead test scans the data to be encoded to find the best mode (Annex P - steps from J to S). - * @param $data (string) data to encode - * @param $pos (int) current position - * @param $mode (int) current encoding mode - * @return int encoding mode - * @protected - */ - protected function lookAheadTest($data, $pos, $mode) { - $data_length = strlen($data); - if ($pos >= $data_length) { - return $mode; - } - $charscount = 0; // count processed chars - // STEP J - if ($mode == ENC_ASCII) { - $numch = array(0, 1, 1, 1, 1, 1.25); - } else { - $numch = array(1, 2, 2, 2, 2, 2.25); - $numch[$mode] = 0; - } - while (true) { - // STEP K - if (($pos + $charscount) == $data_length) { - if ($numch[ENC_ASCII] <= ceil(min($numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_X12], $numch[ENC_EDF], $numch[ENC_BASE256]))) { - return ENC_ASCII; - } - if ($numch[ENC_BASE256] < ceil(min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_X12], $numch[ENC_EDF]))) { - return ENC_BASE256; - } - if ($numch[ENC_EDF] < ceil(min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_X12], $numch[ENC_BASE256]))) { - return ENC_EDF; - } - if ($numch[ENC_TXT] < ceil(min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_X12], $numch[ENC_EDF], $numch[ENC_BASE256]))) { - return ENC_TXT; - } - if ($numch[ENC_X12] < ceil(min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_EDF], $numch[ENC_BASE256]))) { - return ENC_X12; - } - return ENC_C40; - } - // get char - $chr = ord($data{($pos + $charscount)}); - $charscount++; - // STEP L - if ($this->isCharMode($chr, ENC_ASCII_NUM)) { - $numch[ENC_ASCII] += (1 / 2); - } elseif ($this->isCharMode($chr, ENC_ASCII_EXT)) { - $numch[ENC_ASCII] = ceil($numch[ENC_ASCII]); - $numch[ENC_ASCII] += 2; - } else { - $numch[ENC_ASCII] = ceil($numch[ENC_ASCII]); - $numch[ENC_ASCII] += 1; - } - // STEP M - if ($this->isCharMode($chr, ENC_C40)) { - $numch[ENC_C40] += (2 / 3); - } elseif ($this->isCharMode($chr, ENC_ASCII_EXT)) { - $numch[ENC_C40] += (8 / 3); - } else { - $numch[ENC_C40] += (4 / 3); - } - // STEP N - if ($this->isCharMode($chr, ENC_TXT)) { - $numch[ENC_TXT] += (2 / 3); - } elseif ($this->isCharMode($chr, ENC_ASCII_EXT)) { - $numch[ENC_TXT] += (8 / 3); - } else { - $numch[ENC_TXT] += (4 / 3); - } - // STEP O - if ($this->isCharMode($chr, ENC_X12) OR $this->isCharMode($chr, ENC_C40)) { - $numch[ENC_X12] += (2 / 3); - } elseif ($this->isCharMode($chr, ENC_ASCII_EXT)) { - $numch[ENC_X12] += (13 / 3); - } else { - $numch[ENC_X12] += (10 / 3); - } - // STEP P - if ($this->isCharMode($chr, ENC_EDF)) { - $numch[ENC_EDF] += (3 / 4); - } elseif ($this->isCharMode($chr, ENC_ASCII_EXT)) { - $numch[ENC_EDF] += (17 / 4); - } else { - $numch[ENC_EDF] += (13 / 4); - } - // STEP Q - if ($this->isCharMode($chr, ENC_BASE256)) { - $numch[ENC_BASE256] += 4; - } else { - $numch[ENC_BASE256] += 1; - } - // STEP R - if ($charscount >= 4) { - if (($numch[ENC_ASCII] + 1) <= min($numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_X12], $numch[ENC_EDF], $numch[ENC_BASE256])) { - return ENC_ASCII; - } - if ((($numch[ENC_BASE256] + 1) <= $numch[ENC_ASCII]) - OR (($numch[ENC_BASE256] + 1) < min($numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_X12], $numch[ENC_EDF]))) { - return ENC_BASE256; - } - if (($numch[ENC_EDF] + 1) < min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_X12], $numch[ENC_BASE256])) { - return ENC_EDF; - } - if (($numch[ENC_TXT] + 1) < min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_X12], $numch[ENC_EDF], $numch[ENC_BASE256])) { - return ENC_TXT; - } - if (($numch[ENC_X12] + 1) < min($numch[ENC_ASCII], $numch[ENC_C40], $numch[ENC_TXT], $numch[ENC_EDF], $numch[ENC_BASE256])) { - return ENC_X12; - } - if (($numch[ENC_C40] + 1) < min($numch[ENC_ASCII], $numch[ENC_TXT], $numch[ENC_EDF], $numch[ENC_BASE256])) { - if ($numch[ENC_C40] < $numch[ENC_X12]) { - return ENC_C40; - } - if ($numch[ENC_C40] == $numch[ENC_X12]) { - $k = ($pos + $charscount + 1); - while ($k < $data_length) { - $tmpchr = ord($data{$k}); - if ($this->isCharMode($tmpchr, ENC_X12)) { - return ENC_X12; - } elseif (!($this->isCharMode($tmpchr, ENC_X12) OR $this->isCharMode($tmpchr, ENC_C40))) { - break; - } - ++$k; - } - return ENC_C40; - } - } - } - } // end of while - } - - /** - * Get the switching codeword to a new encoding mode (latch codeword) - * @param $mode (int) New encoding mode. - * @return (int) Switch codeword. - * @protected - */ - protected function getSwitchEncodingCodeword($mode) { - switch ($mode) { - case ENC_ASCII: { // ASCII character 0 to 127 - $cw = 254; - break; - } - case ENC_C40: { // Upper-case alphanumeric - $cw = 230; - break; - } - case ENC_TXT: { // Lower-case alphanumeric - $cw = 239; - break; - } - case ENC_X12: { // ANSI X12 - $cw = 238; - break; - } - case ENC_EDF: { // ASCII character 32 to 94 - $cw = 240; - break; - } - case ENC_BASE256: { // Function character (FNC1, Structured Append, Reader Program, or Code Page) - $cw = 231; - break; - } - } - return $cw; - } - - /** - * Choose the minimum matrix size and return the max number of data codewords. - * @param $numcw (int) Number of current codewords. - * @return number of data codewords in matrix - * @protected - */ - protected function getMaxDataCodewords($numcw) { - foreach ($this->symbattr as $key => $matrix) { - if ($matrix[11] >= $numcw) { - return $matrix[11]; - } - } - return 0; - } - - /** - * Get high level encoding using the minimum symbol data characters for ECC 200 - * @param $data (string) data to encode - * @return array of codewords - * @protected - */ - protected function getHighLevelEncoding($data) { - // STEP A. Start in ASCII encodation. - $enc = ENC_ASCII; // current encoding mode - $pos = 0; // current position - $cw = array(); // array of codewords to be returned - $cw_num = 0; // number of data codewords - $data_lenght = strlen($data); // number of chars - while ($pos < $data_lenght) { - switch ($enc) { - case ENC_ASCII: { // STEP B. While in ASCII encodation - if (($data_lenght > 1) AND ($pos < ($data_lenght - 1)) AND ($this->isCharMode(ord($data{($pos)}), ENC_ASCII_NUM) AND $this->isCharMode(ord($data{($pos + 1)}), ENC_ASCII_NUM))) { - // 1. If the next data sequence is at least 2 consecutive digits, encode the next two digits as a double digit in ASCII mode. - $cw[] = (intval(substr($data, $pos, 2)) + 130); - ++$cw_num; - $pos += 2; - } else { - // 2. If the look-ahead test (starting at step J) indicates another mode, switch to that mode. - $newenc = $this->lookAheadTest($data, $pos, $enc); - if ($newenc != $enc) { - // switch to new encoding - $enc = $newenc; - $cw[] = $this->getSwitchEncodingCodeword($enc); - ++$cw_num; - } else { - // get new byte - $chr = ord($data{($pos)}); - ++$pos; - if ($this->isCharMode($chr, ENC_ASCII_EXT)) { - // 3. If the next data character is extended ASCII (greater than 127) encode it in ASCII mode first using the Upper Shift (value 235) character. - $cw[] = 235; - $cw[] = ($chr - 127); - $cw_num += 2; - } else { - // 4. Otherwise process the next data character in ASCII encodation. - $cw[] = ($chr + 1); - ++$cw_num; - } - } - } - break; - } - case ENC_C40 : // Upper-case alphanumeric - case ENC_TXT : // Lower-case alphanumeric - case ENC_X12 : { // ANSI X12 - $temp_cw = array(); - $p = 0; - $epos = $pos; - // get charset ID - $set_id = $this->chset_id[$enc]; - // get basic charset for current encoding - $charset = $this->chset[$set_id]; - do { - // 2. process the next character in C40 encodation. - $chr = ord($data{($epos)}); - ++$epos; - // check for extended character - if ($chr & 0x80) { - if ($enc == ENC_X12) { - return false; - } - $chr = ($chr & 0x7f); - $temp_cw[] = 1; // shift 2 - $temp_cw[] = 30; // upper shift - $p += 2; - } - if (isset($charset[$chr])) { - $temp_cw[] = $charset[$chr]; - ++$p; - } else { - if (isset($this->chset['SH1'][$chr])) { - $temp_cw[] = 0; // shift 1 - $shiftset = $this->chset['SH1']; - } elseif (isset($chr, $this->chset['SH2'][$chr])) { - $temp_cw[] = 1; // shift 2 - $shiftset = $this->chset['SH2']; - } elseif (($enc == ENC_C40) AND isset($this->chset['S3C'][$chr])) { - $temp_cw[] = 2; // shift 3 - $shiftset = $this->chset['S3C']; - } elseif (($enc == ENC_TXT) AND isset($this->chset['S3T'][$chr])) { - $temp_cw[] = 2; // shift 3 - $shiftset = $this->chset['S3T']; - } else { - return false; - } - $temp_cw[] = $shiftset[$chr]; - $p += 2; - } - if ($p >= 3) { - $c1 = array_shift($temp_cw); - $c2 = array_shift($temp_cw); - $c3 = array_shift($temp_cw); - $p -= 3; - $tmp = ((1600 * $c1) + (40 * $c2) + $c3 + 1); - $cw[] = ($tmp >> 8); - $cw[] = ($tmp % 256); - $cw_num += 2; - $pos = $epos; - // 1. If the C40 encoding is at the point of starting a new double symbol character and if the look-ahead test (starting at step J) indicates another mode, switch to that mode. - $newenc = $this->lookAheadTest($data, $pos, $enc); - if ($newenc != $enc) { - $enc = $newenc; - $cw[] = $this->getSwitchEncodingCodeword($enc); - ++$cw_num; - break; - } - } - } while (($p > 0) AND ($epos < $data_lenght)); - // process last data (if any) - if ($p > 0) { - // get remaining number of data symbols - $cwr = ($this->getMaxDataCodewords($cw_num + 2) - $cw_num); - if (($cwr == 1) AND ($p == 1)) { - // d. If one symbol character remains and one C40 value (data character) remains to be encoded - $c1 = array_shift($temp_cw); - --$p; - $cw[] = ($c1 + 1); - ++$cw_num; - } elseif (($cwr == 2) AND ($p == 1)) { - // c. If two symbol characters remain and only one C40 value (data character) remains to be encoded - $c1 = array_shift($temp_cw); - --$p; - $cw[] = 254; - $cw[] = ($c1 + 1); - $cw_num += 2; - } elseif (($cwr == 2) AND ($p == 2)) { - // b. If two symbol characters remain and two C40 values remain to be encoded - $c1 = array_shift($temp_cw); - $c2 = array_shift($temp_cw); - $p -= 2; - $tmp = ((1600 * $c1) + (40 * $c2) + 1); - $cw[] = ($tmp >> 8); - $cw[] = ($tmp % 256); - $cw_num += 2; - } else { - // switch to ASCII encoding - $enc = ENC_ASCII; - $cw[] = $this->getSwitchEncodingCodeword($enc); - ++$cw_num; - } - } - break; - } - case ENC_EDF: { // F. While in EDIFACT (EDF) encodation - // initialize temporary array with 0 lenght - $temp_cw = array(); - $epos = $pos; - $field_lenght = 0; - while ($epos < $data_lenght) { - // 2. process the next character in EDIFACT encodation. - $chr = ord($data{($epos)}); - ++$epos; - $temp_cw[] = $chr; - ++$field_lenght; - if (($field_lenght == 4) OR ($epos == $data_lenght)) { - if ($field_lenght < 4) { - // set unlatch character - $temp_cw[] = 0x1f; - ++$field_lenght; - $enc = ENC_ASCII; - // fill empty characters - for ($i = $field_lenght; $i < 4; ++$i) { - $temp_cw[] = 0; - } - } - // encodes four data characters in three codewords - $cw[] = (($temp_cw[0] & 0x3F) << 2) + (($temp_cw[1] & 0x30) >> 4); - $cw[] = (($temp_cw[1] & 0x0F) << 4) + (($temp_cw[2] & 0x3C) >> 2); - $cw[] = (($temp_cw[2] & 0x03) << 6) + ($temp_cw[3] & 0x3F); - $cw_num += 3; - $temp_cw = array(); - $pos = $epos; - $field_lenght = 0; - } - // 1. If the EDIFACT encoding is at the point of starting a new triple symbol character and if the look-ahead test (starting at step J) indicates another mode, switch to that mode. - if ($field_lenght == 0) { - // get remaining number of data symbols - $cwr = ($this->getMaxDataCodewords($cw_num + 2) - $cw_num); - if ($cwr < 3) { - // return to ascii without unlatch - $enc = ENC_ASCII; - break; // exit from EDIFACT mode - } else { - $newenc = $this->lookAheadTest($data, $pos, $enc); - if ($newenc != $enc) { - // 1. If the look-ahead test (starting at step J) indicates another mode, switch to that mode. - $enc = $newenc; - $cw[] = $this->getSwitchEncodingCodeword($enc); - ++$cw_num; - break; // exit from EDIFACT mode - } - } - } - } - break; - } - case ENC_BASE256: { // G. While in Base 256 (B256) encodation - // initialize temporary array with 0 lenght - $temp_cw = array(); - $field_lenght = 0; - while (($pos < $data_lenght) AND ($field_lenght <= 1555)) { - $newenc = $this->lookAheadTest($data, $pos, $enc); - if ($newenc != $enc) { - // 1. If the look-ahead test (starting at step J) indicates another mode, switch to that mode. - $enc = $newenc; - $cw[] = $this->getSwitchEncodingCodeword($enc); - ++$cw_num; - break; // exit from B256 mode - } else { - // 2. Otherwise, process the next character in Base 256 encodation. - $chr = ord($data{($pos)}); - ++$pos; - $temp_cw[] = $chr; - ++$field_lenght; - } - } - // set field lenght - if ($field_lenght <= 249) { - $cw[] = $field_lenght; - ++$cw_num; - } else { - $cw[] = (floor($field_lenght / 250) + 249); - $cw[] = ($field_lenght % 250); - $cw_num += 2; - } - if (!empty($temp_cw)) { - // add B256 field - foreach ($temp_cw as $p => $cht) { - $cw[] = $this->get255StateCodeword($chr, ($cw_num + $p)); - } - } - break; - } - } // end of switch enc - } // end of while - // set last used encoding - $this->last_enc = $enc; - return $cw; - } - - /** - * Places "chr+bit" with appropriate wrapping within array[]. - * (Annex F - ECC 200 symbol character placement) - * @param $marr array Array of symbols. - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @param $row (int) Row number. - * @param $col (int) Column number. - * @param $chr (int) Char byte. - * @param $bit (int) Bit. - * @return array - * @protected - */ - protected function placeModule($marr, $nrow, $ncol, $row, $col, $chr, $bit) { - if ($row < 0) { - $row += $nrow; - $col += (4 - (($nrow + 4) % 8)); - } - if ($col < 0) { - $col += $ncol; - $row += (4 - (($ncol + 4) % 8)); - } - $marr[(($row * $ncol) + $col)] = ((10 * $chr) + $bit); - return $marr; - } - - /** - * Places the 8 bits of a utah-shaped symbol character. - * (Annex F - ECC 200 symbol character placement) - * @param $marr array Array of symbols. - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @param $row (int) Row number. - * @param $col (int) Column number. - * @param $chr (int) Char byte. - * @return array - * @protected - */ - protected function placeUtah($marr, $nrow, $ncol, $row, $col, $chr) { - $marr = $this->placeModule($marr, $nrow, $ncol, $row-2, $col-2, $chr, 1); - $marr = $this->placeModule($marr, $nrow, $ncol, $row-2, $col-1, $chr, 2); - $marr = $this->placeModule($marr, $nrow, $ncol, $row-1, $col-2, $chr, 3); - $marr = $this->placeModule($marr, $nrow, $ncol, $row-1, $col-1, $chr, 4); - $marr = $this->placeModule($marr, $nrow, $ncol, $row-1, $col, $chr, 5); - $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col-2, $chr, 6); - $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col-1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col, $chr, 8); - return $marr; - } - - /** - * Places the 8 bits of the first special corner case. - * (Annex F - ECC 200 symbol character placement) - * @param $marr array Array of symbols. - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @param $chr (int) Char byte. - * @return array - * @protected - */ - protected function placeCornerA($marr, $nrow, $ncol, $chr) { - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 1); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 1, $chr, 2); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 2, $chr, 3); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 4); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 5); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 6); - $marr = $this->placeModule($marr, $nrow, $ncol, 2, $ncol-1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 3, $ncol-1, $chr, 8); - return $marr; - } - - /** - * Places the 8 bits of the second special corner case. - * (Annex F - ECC 200 symbol character placement) - * @param $marr array Array of symbols. - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @param $chr (int) Char byte. - * @return array - * @protected - */ - protected function placeCornerB($marr, $nrow, $ncol, $chr) { - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-3, 0, $chr, 1); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-2, 0, $chr, 2); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 3); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-4, $chr, 4); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-3, $chr, 5); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 6); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 8); - return $marr; - } - - /** - * Places the 8 bits of the third special corner case. - * (Annex F - ECC 200 symbol character placement) - * @param $marr array Array of symbols. - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @param $chr (int) Char byte. - * @return array - * @protected - */ - protected function placeCornerC($marr, $nrow, $ncol, $chr) { - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-3, 0, $chr, 1); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-2, 0, $chr, 2); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 3); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 4); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 5); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 6); - $marr = $this->placeModule($marr, $nrow, $ncol, 2, $ncol-1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 3, $ncol-1, $chr, 8); - return $marr; - } - - /** - * Places the 8 bits of the fourth special corner case. - * (Annex F - ECC 200 symbol character placement) - * @param $marr array Array of symbols. - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @param $chr (int) Char byte. - * @return array - * @protected - */ - protected function placeCornerD($marr, $nrow, $ncol, $chr) { - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, 0, $chr, 1); - $marr = $this->placeModule($marr, $nrow, $ncol, $nrow-1, $ncol-1, $chr, 2); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-3, $chr, 3); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-2, $chr, 4); - $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol-1, $chr, 5); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-3, $chr, 6); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-2, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol-1, $chr, 8); - return $marr; - } - - - /** - * Build a placement map. - * (Annex F - ECC 200 symbol character placement) - * @param $nrow (int) Number of rows. - * @param $ncol (int) Number of columns. - * @return array - * @protected - */ - protected function getPlacemetMap($nrow, $ncol) { - // initialize array with zeros - $marr = array_fill(0, ($nrow * $ncol), 0); - // set starting values - $chr = 1; - $row = 4; - $col = 0; - do { - // repeatedly first check for one of the special corner cases, then - if (($row == $nrow) AND ($col == 0)) { - $marr = $this->placeCornerA($marr, $nrow, $ncol, $chr); - ++$chr; - } - if (($row == ($nrow - 2)) AND ($col == 0) AND ($ncol % 4)) { - $marr = $this->placeCornerB($marr, $nrow, $ncol, $chr); - ++$chr; - } - if (($row == ($nrow - 2)) AND ($col == 0) AND (($ncol % 8) == 4)) { - $marr = $this->placeCornerC($marr, $nrow, $ncol, $chr); - ++$chr; - } - if (($row == ($nrow + 4)) AND ($col == 2) AND (!($ncol % 8))) { - $marr = $this->placeCornerD($marr, $nrow, $ncol, $chr); - ++$chr; - } - // sweep upward diagonally, inserting successive characters, - do { - if (($row < $nrow) AND ($col >= 0) AND (!$marr[(($row * $ncol) + $col)])) { - $marr = $this->placeUtah($marr, $nrow, $ncol, $row, $col, $chr); - ++$chr; - } - $row -= 2; - $col += 2; - } while (($row >= 0) AND ($col < $ncol)); - ++$row; - $col += 3; - // & then sweep downward diagonally, inserting successive characters,... - do { - if (($row >= 0) AND ($col < $ncol) AND (!$marr[(($row * $ncol) + $col)])) { - $marr = $this->placeUtah($marr, $nrow, $ncol, $row, $col, $chr); - ++$chr; - } - $row += 2; - $col -= 2; - } while (($row < $nrow) AND ($col >= 0)); - $row += 3; - ++$col; - // ... until the entire array is scanned - } while (($row < $nrow) OR ($col < $ncol)); - // lastly, if the lower righthand corner is untouched, fill in fixed pattern - if (!$marr[(($nrow * $ncol) - 1)]) { - $marr[(($nrow * $ncol) - 1)] = 1; - $marr[(($nrow * $ncol) - $ncol - 2)] = 1; - } - return $marr; - } - } // end DataMatrix class //============================================================+ // END OF FILE //============================================================+ + diff --git a/tools/tcpdf/qrcode.php b/tools/tcpdf/qrcode.php index 4f9167679..6e511e638 100755 --- a/tools/tcpdf/qrcode.php +++ b/tools/tcpdf/qrcode.php @@ -63,215 +63,22 @@ // --------------------------------------------------------- //============================================================+ -/** - * @file - * Class to create QR-code arrays for TCPDF class. - * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. - * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. - * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. - * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode. - * - * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). - * Please read comments on this class source file for full copyright and license information. - * - * @package com.tecnick.tcpdf - * @author Nicola Asuni - * @version 1.0.009 - */ +** +* @file +* Class to create QR-code arrays for TCPDF class. +* QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. +* The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. +* This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. +* Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode. +* +* This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). +* Please read comments on this class source file for full copyright and license information. +* +* @package com.tecnick.tcpdf +* @author Nicola Asuni +* @version 1.0.009 +*/ -// definitions -if (!defined('QRCODEDEFS')) { - - /** - * Indicate that definitions for this class are set - */ - define('QRCODEDEFS', true); - - // ----------------------------------------------------- - - // Encoding modes (characters which can be encoded in QRcode) - - /** - * Encoding mode - */ - define('QR_MODE_NL', -1); - - /** - * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode. - */ - define('QR_MODE_NM', 0); - - /** - * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode. - */ - define('QR_MODE_AN', 1); - - /** - * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode. - */ - define('QR_MODE_8B', 2); - - /** - * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode. - */ - define('QR_MODE_KJ', 3); - - /** - * Encoding mode STRUCTURED (currently unsupported) - */ - define('QR_MODE_ST', 4); - - // ----------------------------------------------------- - - // Levels of error correction. - // QRcode has a function of an error correcting for miss reading that white is black. - // Error correcting is defined in 4 level as below. - - /** - * Error correction level L : About 7% or less errors can be corrected. - */ - define('QR_ECLEVEL_L', 0); - - /** - * Error correction level M : About 15% or less errors can be corrected. - */ - define('QR_ECLEVEL_M', 1); - - /** - * Error correction level Q : About 25% or less errors can be corrected. - */ - define('QR_ECLEVEL_Q', 2); - - /** - * Error correction level H : About 30% or less errors can be corrected. - */ - define('QR_ECLEVEL_H', 3); - - // ----------------------------------------------------- - - // Version. Size of QRcode is defined as version. - // Version is from 1 to 40. - // Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. - // So version 40 is 177*177 matrix. - - /** - * Maximum QR Code version. - */ - define('QRSPEC_VERSION_MAX', 40); - - /** - * Maximum matrix size for maximum version (version 40 is 177*177 matrix). - */ - define('QRSPEC_WIDTH_MAX', 177); - - // ----------------------------------------------------- - - /** - * Matrix index to get width from $capacity array. - */ - define('QRCAP_WIDTH', 0); - - /** - * Matrix index to get number of words from $capacity array. - */ - define('QRCAP_WORDS', 1); - - /** - * Matrix index to get remainder from $capacity array. - */ - define('QRCAP_REMINDER', 2); - - /** - * Matrix index to get error correction level from $capacity array. - */ - define('QRCAP_EC', 3); - - // ----------------------------------------------------- - - // Structure (currently usupported) - - /** - * Number of header bits for structured mode - */ - define('STRUCTURE_HEADER_BITS', 20); - - /** - * Max number of symbols for structured mode - */ - define('MAX_STRUCTURED_SYMBOLS', 16); - - // ----------------------------------------------------- - - // Masks - - /** - * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) - */ - define('N1', 3); - - /** - * Down point base value for case 2 mask pattern (module block of same color) - */ - define('N2', 3); - - /** - * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) - */ - define('N3', 40); - - /** - * Down point base value for case 4 mask pattern (ration of dark modules in whole) - */ - define('N4', 10); - - // ----------------------------------------------------- - - // Optimization settings - - /** - * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code - */ - define('QR_FIND_BEST_MASK', true); - - /** - * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly - */ - define('QR_FIND_FROM_RANDOM', 2); - - /** - * when QR_FIND_BEST_MASK === false - */ - define('QR_DEFAULT_MASK', 2); - - // ----------------------------------------------------- - -} // end of definitions - -// #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# - -// for compatibility with PHP4 -if (!function_exists('str_split')) { - /** - * Convert a string to an array (needed for PHP4 compatibility) - * @param $string (string) The input string. - * @param $split_length (int) Maximum length of the chunk. - * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. - */ - function str_split($string, $split_length=1) { - if ((strlen($string) > $split_length) OR (!$split_length)) { - do { - $c = strlen($string); - $parts[] = substr($string, 0, $split_length); - $string = substr($string, $split_length); - } while ($string !== false); - } else { - $parts = array($string); - } - return $parts; - } -} - -// ##################################################### /** * @class QRcode @@ -290,2577 +97,9 @@ if (!function_exists('str_split')) { */ class QRcode { - /** - * Barcode array to be returned which is readable by TCPDF. - * @protected - */ - protected $barcode_array = array(); - - /** - * QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix. - * @protected - */ - protected $version = 0; - - /** - * Levels of error correction. See definitions for possible values. - * @protected - */ - protected $level = QR_ECLEVEL_L; - - /** - * Encoding mode. - * @protected - */ - protected $hint = QR_MODE_8B; - - /** - * Boolean flag, if true the input string will be converted to uppercase. - * @protected - */ - protected $casesensitive = true; - - /** - * Structured QR code (not supported yet). - * @protected - */ - protected $structured = 0; - - /** - * Mask data. - * @protected - */ - protected $data; - - // FrameFiller - - /** - * Width. - * @protected - */ - protected $width; - - /** - * Frame. - * @protected - */ - protected $frame; - - /** - * X position of bit. - * @protected - */ - protected $x; - - /** - * Y position of bit. - * @protected - */ - protected $y; - - /** - * Direction. - * @protected - */ - protected $dir; - - /** - * Single bit value. - * @protected - */ - protected $bit; - - // ---- QRrawcode ---- - - /** - * Data code. - * @protected - */ - protected $datacode = array(); - - /** - * Error correction code. - * @protected - */ - protected $ecccode = array(); - - /** - * Blocks. - * @protected - */ - protected $blocks; - - /** - * Reed-Solomon blocks. - * @protected - */ - protected $rsblocks = array(); //of RSblock - - /** - * Counter. - * @protected - */ - protected $count; - - /** - * Data length. - * @protected - */ - protected $dataLength; - - /** - * Error correction length. - * @protected - */ - protected $eccLength; - - /** - * Value b1. - * @protected - */ - protected $b1; - - // ---- QRmask ---- - - /** - * Run length. - * @protected - */ - protected $runLength = array(); - - // ---- QRsplit ---- - - /** - * Input data string. - * @protected - */ - protected $dataStr = ''; - - /** - * Input items. - * @protected - */ - protected $items; - - // Reed-Solomon items - - /** - * Reed-Solomon items. - * @protected - */ - protected $rsitems = array(); - - /** - * Array of frames. - * @protected - */ - protected $frames = array(); - - /** - * Alphabet-numeric convesion table. - * @protected - */ - protected $anTable = array( - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // - 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // - ); - - /** - * Array Table of the capacity of symbols. - * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004. - * @protected - */ - protected $capacity = array( - array( 0, 0, 0, array( 0, 0, 0, 0)), // - array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 - array( 25, 44, 7, array( 10, 16, 22, 28)), // - array( 29, 70, 7, array( 15, 26, 36, 44)), // - array( 33, 100, 7, array( 20, 36, 52, 64)), // - array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 - array( 41, 172, 7, array( 36, 64, 96, 112)), // - array( 45, 196, 0, array( 40, 72, 108, 130)), // - array( 49, 242, 0, array( 48, 88, 132, 156)), // - array( 53, 292, 0, array( 60, 110, 160, 192)), // - array( 57, 346, 0, array( 72, 130, 192, 224)), // 10 - array( 61, 404, 0, array( 80, 150, 224, 264)), // - array( 65, 466, 0, array( 96, 176, 260, 308)), // - array( 69, 532, 0, array( 104, 198, 288, 352)), // - array( 73, 581, 3, array( 120, 216, 320, 384)), // - array( 77, 655, 3, array( 132, 240, 360, 432)), // 15 - array( 81, 733, 3, array( 144, 280, 408, 480)), // - array( 85, 815, 3, array( 168, 308, 448, 532)), // - array( 89, 901, 3, array( 180, 338, 504, 588)), // - array( 93, 991, 3, array( 196, 364, 546, 650)), // - array( 97, 1085, 3, array( 224, 416, 600, 700)), // 20 - array(101, 1156, 4, array( 224, 442, 644, 750)), // - array(105, 1258, 4, array( 252, 476, 690, 816)), // - array(109, 1364, 4, array( 270, 504, 750, 900)), // - array(113, 1474, 4, array( 300, 560, 810, 960)), // - array(117, 1588, 4, array( 312, 588, 870, 1050)), // 25 - array(121, 1706, 4, array( 336, 644, 952, 1110)), // - array(125, 1828, 4, array( 360, 700, 1020, 1200)), // - array(129, 1921, 3, array( 390, 728, 1050, 1260)), // - array(133, 2051, 3, array( 420, 784, 1140, 1350)), // - array(137, 2185, 3, array( 450, 812, 1200, 1440)), // 30 - array(141, 2323, 3, array( 480, 868, 1290, 1530)), // - array(145, 2465, 3, array( 510, 924, 1350, 1620)), // - array(149, 2611, 3, array( 540, 980, 1440, 1710)), // - array(153, 2761, 3, array( 570, 1036, 1530, 1800)), // - array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35 - array(161, 3034, 0, array( 600, 1120, 1680, 1980)), // - array(165, 3196, 0, array( 630, 1204, 1770, 2100)), // - array(169, 3362, 0, array( 660, 1260, 1860, 2220)), // - array(173, 3532, 0, array( 720, 1316, 1950, 2310)), // - array(177, 3706, 0, array( 750, 1372, 2040, 2430)) // 40 - ); - - /** - * Array Length indicator. - * @protected - */ - protected $lengthTableBits = array( - array(10, 12, 14), - array( 9, 11, 13), - array( 8, 16, 16), - array( 8, 10, 12) - ); - - /** - * Array Table of the error correction code (Reed-Solomon block). - * See Table 12-16 (pp.30-36), JIS X0510:2004. - * @protected - */ - protected $eccTable = array( - array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), // - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // - array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), // - array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), // - array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 - array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), // - array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), // - array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), // - array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), // - array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), // 10 - array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), // - array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), // - array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), // - array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), // - array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), // 15 - array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), // - array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), // - array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), // - array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), // - array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), // 20 - array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), // - array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), // - array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), // - array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), // - array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), // 25 - array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), // - array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), // - array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), // - array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), // - array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30 - array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), // - array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), // - array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), // - array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), // - array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35 - array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), // - array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), // - array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), // - array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), // - array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40 - ); - - /** - * Array Positions of alignment patterns. - * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them. - * See Table 1 in Appendix E (pp.71) of JIS X0510:2004. - * @protected - */ - protected $alignmentPattern = array( - array( 0, 0), - array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 - array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 - array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15 - array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20 - array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25 - array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30 - array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35 - array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58) // 35-40 - ); - - /** - * Array Version information pattern (BCH coded). - * See Table 1 in Appendix D (pp.68) of JIS X0510:2004. - * size: [QRSPEC_VERSION_MAX - 6] - * @protected - */ - protected $versionPattern = array( - 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, // - 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, // - 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, // - 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, // - 0x27541, 0x28c69 - ); - - /** - * Array Format information - * @protected - */ - protected $formatInfo = array( - array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), // - array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), // - array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), // - array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) // - ); - - - // ------------------------------------------------- - // ------------------------------------------------- - - - /** - * This is the class constructor. - * Creates a QRcode object - * @param $code (string) code to represent using QRcode - * @param $eclevel (string) error level: - * @public - * @since 1.0.000 - */ - public function __construct($code, $eclevel = 'L') { - $barcode_array = array(); - if ((is_null($code)) OR ($code == '\0') OR ($code == '')) { - return false; - } - // set error correction level - $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H')); - if ($this->level === false) { - $this->level = QR_ECLEVEL_L; - } - if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) { - return false; - } - if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) { - return false; - } - $this->items = array(); - $this->encodeString($code); - if (is_null($this->data)) { - return false; - } - $qrTab = $this->binarize($this->data); - $size = count($qrTab); - $barcode_array['num_rows'] = $size; - $barcode_array['num_cols'] = $size; - $barcode_array['bcode'] = array(); - foreach ($qrTab as $line) { - $arrAdd = array(); - foreach (str_split($line) as $char) { - $arrAdd[] = ($char=='1')?1:0; - } - $barcode_array['bcode'][] = $arrAdd; - } - $this->barcode_array = $barcode_array; - } - - /** - * Returns a barcode array which is readable by TCPDF - * @return array barcode array readable by TCPDF; - * @public - */ - public function getBarcodeArray() { - return $this->barcode_array; - } - - /** - * Convert the frame in binary form - * @param $frame (array) array to binarize - * @return array frame in binary form - */ - protected function binarize($frame) { - $len = count($frame); - // the frame is square (width = height) - foreach ($frame as &$frameLine) { - for ($i=0; $i<$len; $i++) { - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; - } - } - return $frame; - } - - /** - * Encode the input string to QR code - * @param $string (string) input string to encode - */ - protected function encodeString($string) { - $this->dataStr = $string; - if (!$this->casesensitive) { - $this->toUpper(); - } - $ret = $this->splitString(); - if ($ret < 0) { - return NULL; - } - $this->encodeMask(-1); - } - - /** - * Encode mask - * @param $mask (int) masking mode - */ - protected function encodeMask($mask) { - $spec = array(0, 0, 0, 0, 0); - $this->datacode = $this->getByteStream($this->items); - if (is_null($this->datacode)) { - return NULL; - } - $spec = $this->getEccSpec($this->version, $this->level, $spec); - $this->b1 = $this->rsBlockNum1($spec); - $this->dataLength = $this->rsDataLength($spec); - $this->eccLength = $this->rsEccLength($spec); - $this->ecccode = array_fill(0, $this->eccLength, 0); - $this->blocks = $this->rsBlockNum($spec); - $ret = $this->init($spec); - if ($ret < 0) { - return NULL; - } - $this->count = 0; - $this->width = $this->getWidth($this->version); - $this->frame = $this->newFrame($this->version); - $this->x = $this->width - 1; - $this->y = $this->width - 1; - $this->dir = -1; - $this->bit = -1; - // inteleaved data and ecc codes - for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) { - $code = $this->getCode(); - $bit = 0x80; - for ($j=0; $j<8; $j++) { - $addr = $this->getNextPosition(); - $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); - $bit = $bit >> 1; - } - } - // remainder bits - $j = $this->getRemainder($this->version); - for ($i=0; $i<$j; $i++) { - $addr = $this->getNextPosition(); - $this->setFrameAt($addr, 0x02); - } - // masking - $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); - if ($mask < 0) { - if (QR_FIND_BEST_MASK) { - $masked = $this->mask($this->width, $this->frame, $this->level); - } else { - $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level); - } - } else { - $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level); - } - if ($masked == NULL) { - return NULL; - } - $this->data = $masked; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // FrameFiller - - /** - * Set frame value at specified position - * @param $at (array) x,y position - * @param $val (int) value of the character to set - */ - protected function setFrameAt($at, $val) { - $this->frame[$at['y']][$at['x']] = chr($val); - } - - /** - * Get frame value at specified position - * @param $at (array) x,y position - * @return value at specified position - */ - protected function getFrameAt($at) { - return ord($this->frame[$at['y']][$at['x']]); - } - - /** - * Return the next frame position - * @return array of x,y coordinates - */ - protected function getNextPosition() { - do { - if ($this->bit == -1) { - $this->bit = 0; - return array('x'=>$this->x, 'y'=>$this->y); - } - $x = $this->x; - $y = $this->y; - $w = $this->width; - if ($this->bit == 0) { - $x--; - $this->bit++; - } else { - $x++; - $y += $this->dir; - $this->bit--; - } - if ($this->dir < 0) { - if ($y < 0) { - $y = 0; - $x -= 2; - $this->dir = 1; - if ($x == 6) { - $x--; - $y = 9; - } - } - } else { - if ($y == $w) { - $y = $w - 1; - $x -= 2; - $this->dir = -1; - if ($x == 6) { - $x--; - $y -= 8; - } - } - } - if (($x < 0) OR ($y < 0)) { - return NULL; - } - $this->x = $x; - $this->y = $y; - } while(ord($this->frame[$y][$x]) & 0x80); - return array('x'=>$x, 'y'=>$y); - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRrawcode - - /** - * Initialize code. - * @param $spec (array) array of ECC specification - * @return 0 in case of success, -1 in case of error - */ - protected function init($spec) { - $dl = $this->rsDataCodes1($spec); - $el = $this->rsEccCodes1($spec); - $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); - $blockNo = 0; - $dataPos = 0; - $eccPos = 0; - $endfor = $this->rsBlockNum1($spec); - for ($i=0; $i < $endfor; ++$i) { - $ecc = array_slice($this->ecccode, $eccPos); - $this->rsblocks[$blockNo] = array(); - $this->rsblocks[$blockNo]['dataLength'] = $dl; - $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); - $this->rsblocks[$blockNo]['eccLength'] = $el; - $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); - $this->rsblocks[$blockNo]['ecc'] = $ecc; - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); - $dataPos += $dl; - $eccPos += $el; - $blockNo++; - } - if ($this->rsBlockNum2($spec) == 0) { - return 0; - } - $dl = $this->rsDataCodes2($spec); - $el = $this->rsEccCodes2($spec); - $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); - if ($rs == NULL) { - return -1; - } - $endfor = $this->rsBlockNum2($spec); - for ($i=0; $i < $endfor; ++$i) { - $ecc = array_slice($this->ecccode, $eccPos); - $this->rsblocks[$blockNo] = array(); - $this->rsblocks[$blockNo]['dataLength'] = $dl; - $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); - $this->rsblocks[$blockNo]['eccLength'] = $el; - $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); - $this->rsblocks[$blockNo]['ecc'] = $ecc; - $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); - $dataPos += $dl; - $eccPos += $el; - $blockNo++; - } - return 0; - } - - /** - * Return Reed-Solomon block code. - * @return array rsblocks - */ - protected function getCode() { - if ($this->count < $this->dataLength) { - $row = $this->count % $this->blocks; - $col = $this->count / $this->blocks; - if ($col >= $this->rsblocks[0]['dataLength']) { - $row += $this->b1; - } - $ret = $this->rsblocks[$row]['data'][$col]; - } elseif ($this->count < $this->dataLength + $this->eccLength) { - $row = ($this->count - $this->dataLength) % $this->blocks; - $col = ($this->count - $this->dataLength) / $this->blocks; - $ret = $this->rsblocks[$row]['ecc'][$col]; - } else { - return 0; - } - $this->count++; - return $ret; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRmask - - /** - * Write Format Information on frame and returns the number of black bits - * @param $width (int) frame width - * @param $frame (array) frame - * @param $mask (array) masking mode - * @param $level (int) error correction level - * @return int blacks - */ - protected function writeFormatInformation($width, &$frame, $mask, $level) { - $blacks = 0; - $format = $this->getFormatInfo($mask, $level); - for ($i=0; $i<8; ++$i) { - if ($format & 1) { - $blacks += 2; - $v = 0x85; - } else { - $v = 0x84; - } - $frame[8][$width - 1 - $i] = chr($v); - if ($i < 6) { - $frame[$i][8] = chr($v); - } else { - $frame[$i + 1][8] = chr($v); - } - $format = $format >> 1; - } - for ($i=0; $i<7; ++$i) { - if ($format & 1) { - $blacks += 2; - $v = 0x85; - } else { - $v = 0x84; - } - $frame[$width - 7 + $i][8] = chr($v); - if ($i == 0) { - $frame[8][7] = chr($v); - } else { - $frame[8][6 - $i] = chr($v); - } - $format = $format >> 1; - } - return $blacks; - } - - /** - * mask0 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask0($x, $y) { - return ($x + $y) & 1; - } - - /** - * mask1 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask1($x, $y) { - return ($y & 1); - } - - /** - * mask2 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask2($x, $y) { - return ($x % 3); - } - - /** - * mask3 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask3($x, $y) { - return ($x + $y) % 3; - } - - /** - * mask4 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask4($x, $y) { - return (((int)($y / 2)) + ((int)($x / 3))) & 1; - } - - /** - * mask5 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask5($x, $y) { - return (($x * $y) & 1) + ($x * $y) % 3; - } - - /** - * mask6 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask6($x, $y) { - return ((($x * $y) & 1) + ($x * $y) % 3) & 1; - } - - /** - * mask7 - * @param $x (int) X position - * @param $y (int) Y position - * @return int mask - */ - protected function mask7($x, $y) { - return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; - } - - /** - * Return bitmask - * @param $maskNo (int) mask number - * @param $width (int) width - * @param $frame (array) frame - * @return array bitmask - */ - protected function generateMaskNo($maskNo, $width, $frame) { - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); - for ($y=0; $y<$width; ++$y) { - for ($x=0; $x<$width; ++$x) { - if (ord($frame[$y][$x]) & 0x80) { - $bitMask[$y][$x] = 0; - } else { - $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; - } - } - } - return $bitMask; - } - - /** - * makeMaskNo - * @param $maskNo (int) - * @param $width (int) - * @param $s (int) - * @param $d (int) - * @param $maskGenOnly (boolean) - * @return int b - */ - protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) { - $b = 0; - $bitMask = array(); - $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); - if ($maskGenOnly) { - return; - } - $d = $s; - for ($y=0; $y<$width; ++$y) { - for ($x=0; $x<$width; ++$x) { - if ($bitMask[$y][$x] == 1) { - $d[$y][$x] = chr(ord($s[$y][$x]) ^ ((int)($bitMask[$y][$x]))); - } - $b += (int)(ord($d[$y][$x]) & 1); - } - } - return $b; - } - - /** - * makeMask - * @param $width (int) - * @param $frame (array) - * @param $maskNo (int) - * @param $level (int) - * @return array mask - */ - protected function makeMask($width, $frame, $maskNo, $level) { - $masked = array_fill(0, $width, str_repeat("\0", $width)); - $this->makeMaskNo($maskNo, $width, $frame, $masked); - $this->writeFormatInformation($width, $masked, $maskNo, $level); - return $masked; - } - - /** - * calcN1N3 - * @param $length (int) - * @return int demerit - */ - protected function calcN1N3($length) { - $demerit = 0; - for ($i=0; $i<$length; ++$i) { - if ($this->runLength[$i] >= 5) { - $demerit += (N1 + ($this->runLength[$i] - 5)); - } - if ($i & 1) { - if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) { - $fact = (int)($this->runLength[$i] / 3); - if (($this->runLength[$i-2] == $fact) - AND ($this->runLength[$i-1] == $fact) - AND ($this->runLength[$i+1] == $fact) - AND ($this->runLength[$i+2] == $fact)) { - if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) { - $demerit += N3; - } elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) { - $demerit += N3; - } - } - } - } - } - return $demerit; - } - - /** - * evaluateSymbol - * @param $width (int) - * @param $frame (array) - * @return int demerit - */ - protected function evaluateSymbol($width, $frame) { - $head = 0; - $demerit = 0; - for ($y=0; $y<$width; ++$y) { - $head = 0; - $this->runLength[0] = 1; - $frameY = $frame[$y]; - if ($y > 0) { - $frameYM = $frame[$y-1]; - } - for ($x=0; $x<$width; ++$x) { - if (($x > 0) AND ($y > 0)) { - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); - if (($b22 | ($w22 ^ 1)) & 1) { - $demerit += N2; - } - } - if (($x == 0) AND (ord($frameY[$x]) & 1)) { - $this->runLength[0] = -1; - $head = 1; - $this->runLength[$head] = 1; - } elseif ($x > 0) { - if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { - $head++; - $this->runLength[$head] = 1; - } else { - $this->runLength[$head]++; - } - } - } - $demerit += $this->calcN1N3($head+1); - } - for ($x=0; $x<$width; ++$x) { - $head = 0; - $this->runLength[0] = 1; - for ($y=0; $y<$width; ++$y) { - if (($y == 0) AND (ord($frame[$y][$x]) & 1)) { - $this->runLength[0] = -1; - $head = 1; - $this->runLength[$head] = 1; - } elseif ($y > 0) { - if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { - $head++; - $this->runLength[$head] = 1; - } else { - $this->runLength[$head]++; - } - } - } - $demerit += $this->calcN1N3($head+1); - } - return $demerit; - } - - /** - * mask - * @param $width (int) - * @param $frame (array) - * @param $level (int) - * @return array best mask - */ - protected function mask($width, $frame, $level) { - $minDemerit = PHP_INT_MAX; - $bestMaskNum = 0; - $bestMask = array(); - $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); - if (QR_FIND_FROM_RANDOM !== false) { - $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); - for ($i = 0; $i < $howManuOut; ++$i) { - $remPos = rand (0, count($checked_masks)-1); - unset($checked_masks[$remPos]); - $checked_masks = array_values($checked_masks); - } - } - $bestMask = $frame; - foreach ($checked_masks as $i) { - $mask = array_fill(0, $width, str_repeat("\0", $width)); - $demerit = 0; - $blacks = 0; - $blacks = $this->makeMaskNo($i, $width, $frame, $mask); - $blacks += $this->writeFormatInformation($width, $mask, $i, $level); - $blacks = (int)(100 * $blacks / ($width * $width)); - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); - $demerit += $this->evaluateSymbol($width, $mask); - if ($demerit < $minDemerit) { - $minDemerit = $demerit; - $bestMask = $mask; - $bestMaskNum = $i; - } - } - return $bestMask; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRsplit - - /** - * Return true if the character at specified position is a number - * @param $str (string) string - * @param $pos (int) characted position - * @return boolean true of false - */ - protected function isdigitat($str, $pos) { - if ($pos >= strlen($str)) { - return false; - } - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); - } - - /** - * Return true if the character at specified position is an alphanumeric character - * @param $str (string) string - * @param $pos (int) characted position - * @return boolean true of false - */ - protected function isalnumat($str, $pos) { - if ($pos >= strlen($str)) { - return false; - } - return ($this->lookAnTable(ord($str[$pos])) >= 0); - } - - /** - * identifyMode - * @param $pos (int) - * @return int mode - */ - protected function identifyMode($pos) { - if ($pos >= strlen($this->dataStr)) { - return QR_MODE_NL; - } - $c = $this->dataStr[$pos]; - if ($this->isdigitat($this->dataStr, $pos)) { - return QR_MODE_NM; - } elseif ($this->isalnumat($this->dataStr, $pos)) { - return QR_MODE_AN; - } elseif ($this->hint == QR_MODE_KJ) { - if ($pos+1 < strlen($this->dataStr)) { - $d = $this->dataStr[$pos+1]; - $word = (ord($c) << 8) | ord($d); - if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) { - return QR_MODE_KJ; - } - } - } - return QR_MODE_8B; - } - - /** - * eatNum - * @return int run - */ - protected function eatNum() { - $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); - $p = 0; - while($this->isdigitat($this->dataStr, $p)) { - $p++; - } - $run = $p; - $mode = $this->identifyMode($p); - if ($mode == QR_MODE_8B) { - $dif = $this->estimateBitsModeNum($run) + 4 + $ln - + $this->estimateBitsMode8(1) // + 4 + l8 - - $this->estimateBitsMode8($run + 1); // - 4 - l8 - if ($dif > 0) { - return $this->eat8(); - } - } - if ($mode == QR_MODE_AN) { - $dif = $this->estimateBitsModeNum($run) + 4 + $ln - + $this->estimateBitsModeAn(1) // + 4 + la - - $this->estimateBitsModeAn($run + 1);// - 4 - la - if ($dif > 0) { - return $this->eatAn(); - } - } - $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr)); - return $run; - } - - /** - * eatAn - * @return int run - */ - protected function eatAn() { - $la = $this->lengthIndicator(QR_MODE_AN, $this->version); - $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); - $p =1 ; - while($this->isalnumat($this->dataStr, $p)) { - if ($this->isdigitat($this->dataStr, $p)) { - $q = $p; - while($this->isdigitat($this->dataStr, $q)) { - $q++; - } - $dif = $this->estimateBitsModeAn($p) // + 4 + la - + $this->estimateBitsModeNum($q - $p) + 4 + $ln - - $this->estimateBitsModeAn($q); // - 4 - la - if ($dif < 0) { - break; - } else { - $p = $q; - } - } else { - $p++; - } - } - $run = $p; - if (!$this->isalnumat($this->dataStr, $p)) { - $dif = $this->estimateBitsModeAn($run) + 4 + $la - + $this->estimateBitsMode8(1) // + 4 + l8 - - $this->estimateBitsMode8($run + 1); // - 4 - l8 - if ($dif > 0) { - return $this->eat8(); - } - } - $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr)); - return $run; - } - - /** - * eatKanji - * @return int run - */ - protected function eatKanji() { - $p = 0; - while($this->identifyMode($p) == QR_MODE_KJ) { - $p += 2; - } - $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr)); - return $run; - } - - /** - * eat8 - * @return int run - */ - protected function eat8() { - $la = $this->lengthIndicator(QR_MODE_AN, $this->version); - $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); - $p = 1; - $dataStrLen = strlen($this->dataStr); - while($p < $dataStrLen) { - $mode = $this->identifyMode($p); - if ($mode == QR_MODE_KJ) { - break; - } - if ($mode == QR_MODE_NM) { - $q = $p; - while($this->isdigitat($this->dataStr, $q)) { - $q++; - } - $dif = $this->estimateBitsMode8($p) // + 4 + l8 - + $this->estimateBitsModeNum($q - $p) + 4 + $ln - - $this->estimateBitsMode8($q); // - 4 - l8 - if ($dif < 0) { - break; - } else { - $p = $q; - } - } elseif ($mode == QR_MODE_AN) { - $q = $p; - while($this->isalnumat($this->dataStr, $q)) { - $q++; - } - $dif = $this->estimateBitsMode8($p) // + 4 + l8 - + $this->estimateBitsModeAn($q - $p) + 4 + $la - - $this->estimateBitsMode8($q); // - 4 - l8 - if ($dif < 0) { - break; - } else { - $p = $q; - } - } else { - $p++; - } - } - $run = $p; - $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr)); - return $run; - } - - /** - * splitString - */ - protected function splitString() { - while (strlen($this->dataStr) > 0) { - if ($this->dataStr == '') { - return 0; - } - $mode = $this->identifyMode(0); - switch ($mode) { - case QR_MODE_NM: { - $length = $this->eatNum(); - break; - } - case QR_MODE_AN: { - $length = $this->eatAn(); - break; - } - case QR_MODE_KJ: { - if ($hint == QR_MODE_KJ) { - $length = $this->eatKanji(); - } else { - $length = $this->eat8(); - } - break; - } - default: { - $length = $this->eat8(); - break; - } - } - if ($length == 0) { - return 0; - } - if ($length < 0) { - return -1; - } - $this->dataStr = substr($this->dataStr, $length); - } - } - - /** - * toUpper - */ - protected function toUpper() { - $stringLen = strlen($this->dataStr); - $p = 0; - while ($p < $stringLen) { - $mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint); - if ($mode == QR_MODE_KJ) { - $p += 2; - } else { - if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) { - $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); - } - $p++; - } - } - return $this->dataStr; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRinputItem - - /** - * newInputItem - * @param $mode (int) - * @param $size (int) - * @param $data (array) - * @param $bstream (array) - * @return array input item - */ - protected function newInputItem($mode, $size, $data, $bstream=null) { - $setData = array_slice($data, 0, $size); - if (count($setData) < $size) { - $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); - } - if (!$this->check($mode, $size, $setData)) { - return NULL; - } - $inputitem = array(); - $inputitem['mode'] = $mode; - $inputitem['size'] = $size; - $inputitem['data'] = $setData; - $inputitem['bstream'] = $bstream; - return $inputitem; - } - - /** - * encodeModeNum - * @param $inputitem (array) - * @param $version (int) - * @return array input item - */ - protected function encodeModeNum($inputitem, $version) { - $words = (int)($inputitem['size'] / 3); - $inputitem['bstream'] = array(); - $val = 0x1; - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']); - for ($i=0; $i < $words; ++$i) { - $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100; - $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10; - $val += (ord($inputitem['data'][$i*3+2]) - ord('0')); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val); - } - if ($inputitem['size'] - $words * 3 == 1) { - $val = ord($inputitem['data'][$words*3]) - ord('0'); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); - } elseif (($inputitem['size'] - ($words * 3)) == 2) { - $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10; - $val += (ord($inputitem['data'][$words*3+1]) - ord('0')); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val); - } - return $inputitem; - } - - /** - * encodeModeAn - * @param $inputitem (array) - * @param $version (int) - * @return array input item - */ - protected function encodeModeAn($inputitem, $version) { - $words = (int)($inputitem['size'] / 2); - $inputitem['bstream'] = array(); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']); - for ($i=0; $i < $words; ++$i) { - $val = (int)($this->lookAnTable(ord($inputitem['data'][$i*2])) * 45); - $val += (int)($this->lookAnTable(ord($inputitem['data'][($i*2)+1]))); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); - } - if ($inputitem['size'] & 1) { - $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)])); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val); - } - return $inputitem; - } - - /** - * encodeMode8 - * @param $inputitem (array) - * @param $version (int) - * @return array input item - */ - protected function encodeMode8($inputitem, $version) { - $inputitem['bstream'] = array(); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']); - for ($i=0; $i < $inputitem['size']; ++$i) { - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i])); - } - return $inputitem; - } - - /** - * encodeModeKanji - * @param $inputitem (array) - * @param $version (int) - * @return array input item - */ - protected function encodeModeKanji($inputitem, $version) { - $inputitem['bstream'] = array(); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2)); - for ($i=0; $i<$inputitem['size']; $i+=2) { - $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]); - if ($val <= 0x9ffc) { - $val -= 0x8140; - } else { - $val -= 0xc140; - } - $h = ($val >> 8) * 0xc0; - $val = ($val & 0xff) + $h; - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val); - } - return $inputitem; - } - - /** - * encodeModeStructure - * @param $inputitem (array) - * @return array input item - */ - protected function encodeModeStructure($inputitem) { - $inputitem['bstream'] = array(); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1); - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2])); - return $inputitem; - } - - /** - * encodeBitStream - * @param $inputitem (array) - * @param $version (int) - * @return array input item - */ - protected function encodeBitStream($inputitem, $version) { - $inputitem['bstream'] = array(); - $words = $this->maximumWords($inputitem['mode'], $version); - if ($inputitem['size'] > $words) { - $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']); - $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words)); - $st1 = $this->encodeBitStream($st1, $version); - $st2 = $this->encodeBitStream($st2, $version); - $inputitem['bstream'] = array(); - $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); - $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); - } else { - switch($inputitem['mode']) { - case QR_MODE_NM: { - $inputitem = $this->encodeModeNum($inputitem, $version); - break; - } - case QR_MODE_AN: { - $inputitem = $this->encodeModeAn($inputitem, $version); - break; - } - case QR_MODE_8B: { - $inputitem = $this->encodeMode8($inputitem, $version); - break; - } - case QR_MODE_KJ: { - $inputitem = $this->encodeModeKanji($inputitem, $version); - break; - } - case QR_MODE_ST: { - $inputitem = $this->encodeModeStructure($inputitem); - break; - } - default: { - break; - } - } - } - return $inputitem; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRinput - - /** - * Append data to an input object. - * The data is copied and appended to the input object. - * @param $items (arrray) input items - * @param $mode (int) encoding mode. - * @param $size (int) size of data (byte). - * @param $data (array) array of input data. - * @return items - * - */ - protected function appendNewInputItem($items, $mode, $size, $data) { - $newitem = $this->newInputItem($mode, $size, $data); - if (!empty($newitem)) { - $items[] = $newitem; - } - return $items; - } - - /** - * insertStructuredAppendHeader - * @param $items (array) - * @param $size (int) - * @param $index (int) - * @param $parity (int) - * @return array items - */ - protected function insertStructuredAppendHeader($items, $size, $index, $parity) { - if ($size > MAX_STRUCTURED_SYMBOLS) { - return -1; - } - if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) { - return -1; - } - $buf = array($size, $index, $parity); - $entry = $this->newInputItem(QR_MODE_ST, 3, buf); - array_unshift($items, $entry); - return $items; - } - - /** - * calcParity - * @param $items (array) - * @return int parity - */ - protected function calcParity($items) { - $parity = 0; - foreach ($items as $item) { - if ($item['mode'] != QR_MODE_ST) { - for ($i=$item['size']-1; $i>=0; --$i) { - $parity ^= $item['data'][$i]; - } - } - } - return $parity; - } - - /** - * checkModeNum - * @param $size (int) - * @param $data (array) - * @return boolean true or false - */ - protected function checkModeNum($size, $data) { - for ($i=0; $i<$size; ++$i) { - if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){ - return false; - } - } - return true; - } - - /** - * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). - * @param $c (int) character value - * @return value - */ - protected function lookAnTable($c) { - return (($c > 127)?-1:$this->anTable[$c]); - } - - /** - * checkModeAn - * @param $size (int) - * @param $data (array) - * @return boolean true or false - */ - protected function checkModeAn($size, $data) { - for ($i=0; $i<$size; ++$i) { - if ($this->lookAnTable(ord($data[$i])) == -1) { - return false; - } - } - return true; - } - - /** - * estimateBitsModeNum - * @param $size (int) - * @return int number of bits - */ - protected function estimateBitsModeNum($size) { - $w = (int)($size / 3); - $bits = ($w * 10); - switch($size - ($w * 3)) { - case 1: { - $bits += 4; - break; - } - case 2: { - $bits += 7; - break; - } - } - return $bits; - } - - /** - * estimateBitsModeAn - * @param $size (int) - * @return int number of bits - */ - protected function estimateBitsModeAn($size) { - $bits = (int)($size * 5.5); // (size / 2 ) * 11 - if ($size & 1) { - $bits += 6; - } - return $bits; - } - - /** - * estimateBitsMode8 - * @param $size (int) - * @return int number of bits - */ - protected function estimateBitsMode8($size) { - return (int)($size * 8); - } - - /** - * estimateBitsModeKanji - * @param $size (int) - * @return int number of bits - */ - protected function estimateBitsModeKanji($size) { - return (int)($size * 6.5); // (size / 2 ) * 13 - } - - /** - * checkModeKanji - * @param $size (int) - * @param $data (array) - * @return boolean true or false - */ - protected function checkModeKanji($size, $data) { - if ($size & 1) { - return false; - } - for ($i=0; $i<$size; $i+=2) { - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); - if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) { - return false; - } - } - return true; - } - - /** - * Validate the input data. - * @param $mode (int) encoding mode. - * @param $size (int) size of data (byte). - * @param $data (array) data to validate - * @return boolean true in case of valid data, false otherwise - */ - protected function check($mode, $size, $data) { - if ($size <= 0) { - return false; - } - switch($mode) { - case QR_MODE_NM: { - return $this->checkModeNum($size, $data); - } - case QR_MODE_AN: { - return $this->checkModeAn($size, $data); - } - case QR_MODE_KJ: { - return $this->checkModeKanji($size, $data); - } - case QR_MODE_8B: { - return true; - } - case QR_MODE_ST: { - return true; - } - default: { - break; - } - } - return false; - } - - /** - * estimateBitStreamSize - * @param $items (array) - * @param $version (int) - * @return int bits - */ - protected function estimateBitStreamSize($items, $version) { - $bits = 0; - if ($version == 0) { - $version = 1; - } - foreach ($items as $item) { - switch($item['mode']) { - case QR_MODE_NM: { - $bits = $this->estimateBitsModeNum($item['size']); - break; - } - case QR_MODE_AN: { - $bits = $this->estimateBitsModeAn($item['size']); - break; - } - case QR_MODE_8B: { - $bits = $this->estimateBitsMode8($item['size']); - break; - } - case QR_MODE_KJ: { - $bits = $this->estimateBitsModeKanji($item['size']); - break; - } - case QR_MODE_ST: { - return STRUCTURE_HEADER_BITS; - } - default: { - return 0; - } - } - $l = $this->lengthIndicator($item['mode'], $version); - $m = 1 << $l; - $num = (int)(($item['size'] + $m - 1) / $m); - $bits += $num * (4 + $l); - } - return $bits; - } - - /** - * estimateVersion - * @param $items (array) - * @return int version - */ - protected function estimateVersion($items) { - $version = 0; - $prev = 0; - do { - $prev = $version; - $bits = $this->estimateBitStreamSize($items, $prev); - $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); - if ($version < 0) { - return -1; - } - } while ($version > $prev); - return $version; - } - - /** - * lengthOfCode - * @param $mode (int) - * @param $version (int) - * @param $bits (int) - * @return int size - */ - protected function lengthOfCode($mode, $version, $bits) { - $payload = $bits - 4 - $this->lengthIndicator($mode, $version); - switch($mode) { - case QR_MODE_NM: { - $chunks = (int)($payload / 10); - $remain = $payload - $chunks * 10; - $size = $chunks * 3; - if ($remain >= 7) { - $size += 2; - } elseif ($remain >= 4) { - $size += 1; - } - break; - } - case QR_MODE_AN: { - $chunks = (int)($payload / 11); - $remain = $payload - $chunks * 11; - $size = $chunks * 2; - if ($remain >= 6) { - ++$size; - } - break; - } - case QR_MODE_8B: { - $size = (int)($payload / 8); - break; - } - case QR_MODE_KJ: { - $size = (int)(($payload / 13) * 2); - break; - } - case QR_MODE_ST: { - $size = (int)($payload / 8); - break; - } - default: { - $size = 0; - break; - } - } - $maxsize = $this->maximumWords($mode, $version); - if ($size < 0) { - $size = 0; - } - if ($size > $maxsize) { - $size = $maxsize; - } - return $size; - } - - /** - * createBitStream - * @param $items (array) - * @return array of items and total bits - */ - protected function createBitStream($items) { - $total = 0; - foreach ($items as $key => $item) { - $items[$key] = $this->encodeBitStream($item, $this->version); - $bits = count($items[$key]['bstream']); - $total += $bits; - } - return array($items, $total); - } - - /** - * convertData - * @param $items (array) - * @return array items - */ - protected function convertData($items) { - $ver = $this->estimateVersion($items); - if ($ver > $this->version) { - $this->version = $ver; - } - for (;;) { - $cbs = $this->createBitStream($items); - $items = $cbs[0]; - $bits = $cbs[1]; - if ($bits < 0) { - return -1; - } - $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); - if ($ver < 0) { - return -1; - } elseif ($ver > $this->version) { - $this->version = $ver; - } else { - break; - } - } - return $items; - } - - /** - * Append Padding Bit to bitstream - * @param $bstream (array) - * @return array bitstream - */ - protected function appendPaddingBit($bstream) { - if (is_null($bstream)) { - return null; - } - $bits = count($bstream); - $maxwords = $this->getDataLength($this->version, $this->level); - $maxbits = $maxwords * 8; - if ($maxbits == $bits) { - return $bstream; - } - if ($maxbits - $bits < 5) { - return $this->appendNum($bstream, $maxbits - $bits, 0); - } - $bits += 4; - $words = (int)(($bits + 7) / 8); - $padding = array(); - $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); - $padlen = $maxwords - $words; - if ($padlen > 0) { - $padbuf = array(); - for ($i=0; $i<$padlen; ++$i) { - $padbuf[$i] = ($i&1)?0x11:0xec; - } - $padding = $this->appendBytes($padding, $padlen, $padbuf); - } - return $this->appendBitstream($bstream, $padding); - } - - /** - * mergeBitStream - * @param $items (array) items - * @return array bitstream - */ - protected function mergeBitStream($items) { - $items = $this->convertData($items); - if (!is_array($items)) { - return null; - } - $bstream = array(); - foreach ($items as $item) { - $bstream = $this->appendBitstream($bstream, $item['bstream']); - } - return $bstream; - } - - /** - * Returns a stream of bits. - * @param $items (int) - * @return array padded merged byte stream - */ - protected function getBitStream($items) { - $bstream = $this->mergeBitStream($items); - return $this->appendPaddingBit($bstream); - } - - /** - * Pack all bit streams padding bits into a byte array. - * @param $items (int) - * @return array padded merged byte stream - */ - protected function getByteStream($items) { - $bstream = $this->getBitStream($items); - return $this->bitstreamToByte($bstream); - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRbitstream - - /** - * Return an array with zeros - * @param $setLength (int) array size - * @return array - */ - protected function allocate($setLength) { - return array_fill(0, $setLength, 0); - } - - /** - * Return new bitstream from number - * @param $bits (int) number of bits - * @param $num (int) number - * @return array bitstream - */ - protected function newFromNum($bits, $num) { - $bstream = $this->allocate($bits); - $mask = 1 << ($bits - 1); - for ($i=0; $i<$bits; ++$i) { - if ($num & $mask) { - $bstream[$i] = 1; - } else { - $bstream[$i] = 0; - } - $mask = $mask >> 1; - } - return $bstream; - } - - /** - * Return new bitstream from bytes - * @param $size (int) size - * @param $data (array) bytes - * @return array bitstream - */ - protected function newFromBytes($size, $data) { - $bstream = $this->allocate($size * 8); - $p=0; - for ($i=0; $i<$size; ++$i) { - $mask = 0x80; - for ($j=0; $j<8; ++$j) { - if ($data[$i] & $mask) { - $bstream[$p] = 1; - } else { - $bstream[$p] = 0; - } - $p++; - $mask = $mask >> 1; - } - } - return $bstream; - } - - /** - * Append one bitstream to another - * @param $bitstream (array) original bitstream - * @param $append (array) bitstream to append - * @return array bitstream - */ - protected function appendBitstream($bitstream, $append) { - if ((!is_array($append)) OR (count($append) == 0)) { - return $bitstream; - } - if (count($bitstream) == 0) { - return $append; - } - return array_values(array_merge($bitstream, $append)); - } - - /** - * Append one bitstream created from number to another - * @param $bitstream (array) original bitstream - * @param $bits (int) number of bits - * @param $num (int) number - * @return array bitstream - */ - protected function appendNum($bitstream, $bits, $num) { - if ($bits == 0) { - return 0; - } - $b = $this->newFromNum($bits, $num); - return $this->appendBitstream($bitstream, $b); - } - - /** - * Append one bitstream created from bytes to another - * @param $bitstream (array) original bitstream - * @param $size (int) size - * @param $data (array) bytes - * @return array bitstream - */ - protected function appendBytes($bitstream, $size, $data) { - if ($size == 0) { - return 0; - } - $b = $this->newFromBytes($size, $data); - return $this->appendBitstream($bitstream, $b); - } - - /** - * Convert bitstream to bytes - * @param $bstream (array) original bitstream - * @return array of bytes - */ - protected function bitstreamToByte($bstream) { - if (is_null($bstream)) { - return null; - } - $size = count($bstream); - if ($size == 0) { - return array(); - } - $data = array_fill(0, (int)(($size + 7) / 8), 0); - $bytes = (int)($size / 8); - $p = 0; - for ($i=0; $i<$bytes; $i++) { - $v = 0; - for ($j=0; $j<8; $j++) { - $v = $v << 1; - $v |= $bstream[$p]; - $p++; - } - $data[$i] = $v; - } - if ($size & 7) { - $v = 0; - for ($j=0; $j<($size & 7); $j++) { - $v = $v << 1; - $v |= $bstream[$p]; - $p++; - } - $data[$bytes] = $v; - } - return $data; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRspec - - /** - * Replace a value on the array at the specified position - * @param $srctab (array) - * @param $x (int) X position - * @param $y (int) Y position - * @param $repl (string) value to replace - * @param $replLen (int) length of the repl string - * @return array srctab - */ - protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) { - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); - return $srctab; - } - - /** - * Return maximum data code length (bytes) for the version. - * @param $version (int) version - * @param $level (int) error correction level - * @return int maximum size (bytes) - */ - protected function getDataLength($version, $level) { - return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level]; - } - - /** - * Return maximum error correction code length (bytes) for the version. - * @param $version (int) version - * @param $level (int) error correction level - * @return int ECC size (bytes) - */ - protected function getECCLength($version, $level){ - return $this->capacity[$version][QRCAP_EC][$level]; - } - - /** - * Return the width of the symbol for the version. - * @param $version (int) version - * @return int width - */ - protected function getWidth($version) { - return $this->capacity[$version][QRCAP_WIDTH]; - } - - /** - * Return the numer of remainder bits. - * @param $version (int) version - * @return int number of remainder bits - */ - protected function getRemainder($version) { - return $this->capacity[$version][QRCAP_REMINDER]; - } - - /** - * Return a version number that satisfies the input code length. - * @param $size (int) input code length (byte) - * @param $level (int) error correction level - * @return int version number - */ - protected function getMinimumVersion($size, $level) { - for ($i=1; $i <= QRSPEC_VERSION_MAX; ++$i) { - $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]; - if ($words >= $size) { - return $i; - } - } - return -1; - } - - /** - * Return the size of length indicator for the mode and version. - * @param $mode (int) encoding mode - * @param $version (int) version - * @return int the size of the appropriate length indicator (bits). - */ - protected function lengthIndicator($mode, $version) { - if ($mode == QR_MODE_ST) { - return 0; - } - if ($version <= 9) { - $l = 0; - } elseif ($version <= 26) { - $l = 1; - } else { - $l = 2; - } - return $this->lengthTableBits[$mode][$l]; - } - - /** - * Return the maximum length for the mode and version. - * @param $mode (int) encoding mode - * @param $version (int) version - * @return int the maximum length (bytes) - */ - protected function maximumWords($mode, $version) { - if ($mode == QR_MODE_ST) { - return 3; - } - if ($version <= 9) { - $l = 0; - } else if ($version <= 26) { - $l = 1; - } else { - $l = 2; - } - $bits = $this->lengthTableBits[$mode][$l]; - $words = (1 << $bits) - 1; - if ($mode == QR_MODE_KJ) { - $words *= 2; // the number of bytes is required - } - return $words; - } - - /** - * Return an array of ECC specification. - * @param $version (int) version - * @param $level (int) error correction level - * @param $spec (array) an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code} - * @return array spec - */ - protected function getEccSpec($version, $level, $spec) { - if (count($spec) < 5) { - $spec = array(0, 0, 0, 0, 0); - } - $b1 = $this->eccTable[$version][$level][0]; - $b2 = $this->eccTable[$version][$level][1]; - $data = $this->getDataLength($version, $level); - $ecc = $this->getECCLength($version, $level); - if ($b2 == 0) { - $spec[0] = $b1; - $spec[1] = (int)($data / $b1); - $spec[2] = (int)($ecc / $b1); - $spec[3] = 0; - $spec[4] = 0; - } else { - $spec[0] = $b1; - $spec[1] = (int)($data / ($b1 + $b2)); - $spec[2] = (int)($ecc / ($b1 + $b2)); - $spec[3] = $b2; - $spec[4] = $spec[1] + 1; - } - return $spec; - } - - /** - * Put an alignment marker. - * @param $frame (array) frame - * @param $ox (int) X center coordinate of the pattern - * @param $oy (int) Y center coordinate of the pattern - * @return array frame - */ - protected function putAlignmentMarker($frame, $ox, $oy) { - $finder = array( - "\xa1\xa1\xa1\xa1\xa1", - "\xa1\xa0\xa0\xa0\xa1", - "\xa1\xa0\xa1\xa0\xa1", - "\xa1\xa0\xa0\xa0\xa1", - "\xa1\xa1\xa1\xa1\xa1" - ); - $yStart = $oy - 2; - $xStart = $ox - 2; - for ($y=0; $y < 5; $y++) { - $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]); - } - return $frame; - } - - /** - * Put an alignment pattern. - * @param $version (int) version - * @param $frame (array) frame - * @param $width (int) width - * @return array frame - */ - protected function putAlignmentPattern($version, $frame, $width) { - if ($version < 2) { - return $frame; - } - $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0]; - if ($d < 0) { - $w = 2; - } else { - $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2); - } - if ($w * $w - 3 == 1) { - $x = $this->alignmentPattern[$version][0]; - $y = $this->alignmentPattern[$version][0]; - $frame = $this->putAlignmentMarker($frame, $x, $y); - return $frame; - } - $cx = $this->alignmentPattern[$version][0]; - $wo = $w - 1; - for ($x=1; $x < $wo; ++$x) { - $frame = $this->putAlignmentMarker($frame, 6, $cx); - $frame = $this->putAlignmentMarker($frame, $cx, 6); - $cx += $d; - } - $cy = $this->alignmentPattern[$version][0]; - for ($y=0; $y < $wo; ++$y) { - $cx = $this->alignmentPattern[$version][0]; - for ($x=0; $x < $wo; ++$x) { - $frame = $this->putAlignmentMarker($frame, $cx, $cy); - $cx += $d; - } - $cy += $d; - } - return $frame; - } - - /** - * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits. - * @param $version (int) version - * @return BCH encoded version information pattern - */ - protected function getVersionPattern($version) { - if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) { - return 0; - } - return $this->versionPattern[($version - 7)]; - } - - /** - * Return BCH encoded format information pattern. - * @param $mask (array) - * @param $level (int) error correction level - * @return BCH encoded format information pattern - */ - protected function getFormatInfo($mask, $level) { - if (($mask < 0) OR ($mask > 7)) { - return 0; - } - if (($level < 0) OR ($level > 3)) { - return 0; - } - return $this->formatInfo[$level][$mask]; - } - - /** - * Put a finder pattern. - * @param $frame (array) frame - * @param $ox (int) X center coordinate of the pattern - * @param $oy (int) Y center coordinate of the pattern - * @return array frame - */ - protected function putFinderPattern($frame, $ox, $oy) { - $finder = array( - "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", - "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", - "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", - "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" - ); - for ($y=0; $y < 7; $y++) { - $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]); - } - return $frame; - } - - /** - * Return a copy of initialized frame. - * @param $version (int) version - * @return Array of unsigned char. - */ - protected function createFrame($version) { - $width = $this->capacity[$version][QRCAP_WIDTH]; - $frameLine = str_repeat ("\0", $width); - $frame = array_fill(0, $width, $frameLine); - // Finder pattern - $frame = $this->putFinderPattern($frame, 0, 0); - $frame = $this->putFinderPattern($frame, $width - 7, 0); - $frame = $this->putFinderPattern($frame, 0, $width - 7); - // Separator - $yOffset = $width - 7; - for ($y=0; $y < 7; ++$y) { - $frame[$y][7] = "\xc0"; - $frame[$y][$width - 8] = "\xc0"; - $frame[$yOffset][7] = "\xc0"; - ++$yOffset; - } - $setPattern = str_repeat("\xc0", 8); - $frame = $this->qrstrset($frame, 0, 7, $setPattern); - $frame = $this->qrstrset($frame, $width-8, 7, $setPattern); - $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern); - // Format info - $setPattern = str_repeat("\x84", 9); - $frame = $this->qrstrset($frame, 0, 8, $setPattern); - $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8); - $yOffset = $width - 8; - for ($y=0; $y < 8; ++$y,++$yOffset) { - $frame[$y][8] = "\x84"; - $frame[$yOffset][8] = "\x84"; - } - // Timing pattern - $wo = $width - 15; - for ($i=1; $i < $wo; ++$i) { - $frame[6][7+$i] = chr(0x90 | ($i & 1)); - $frame[7+$i][6] = chr(0x90 | ($i & 1)); - } - // Alignment pattern - $frame = $this->putAlignmentPattern($version, $frame, $width); - // Version information - if ($version >= 7) { - $vinf = $this->getVersionPattern($version); - $v = $vinf; - for ($x=0; $x<6; ++$x) { - for ($y=0; $y<3; ++$y) { - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); - $v = $v >> 1; - } - } - $v = $vinf; - for ($y=0; $y<6; ++$y) { - for ($x=0; $x<3; ++$x) { - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); - $v = $v >> 1; - } - } - } - // and a little bit... - $frame[$width - 8][8] = "\x81"; - return $frame; - } - - /** - * Set new frame for the specified version. - * @param $version (int) version - * @return Array of unsigned char. - */ - protected function newFrame($version) { - if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) { - return NULL; - } - if (!isset($this->frames[$version])) { - $this->frames[$version] = $this->createFrame($version); - } - if (is_null($this->frames[$version])) { - return NULL; - } - return $this->frames[$version]; - } - - /** - * Return block number 0 - * @param $spec (array) - * @return int value - */ - protected function rsBlockNum($spec) { - return ($spec[0] + $spec[3]); - } - - /** - * Return block number 1 - * @param $spec (array) - * @return int value - */ - protected function rsBlockNum1($spec) { - return $spec[0]; - } - - /** - * Return data codes 1 - * @param $spec (array) - * @return int value - */ - protected function rsDataCodes1($spec) { - return $spec[1]; - } - - /** - * Return ecc codes 1 - * @param $spec (array) - * @return int value - */ - protected function rsEccCodes1($spec) { - return $spec[2]; - } - - /** - * Return block number 2 - * @param $spec (array) - * @return int value - */ - protected function rsBlockNum2($spec) { - return $spec[3]; - } - - /** - * Return data codes 2 - * @param $spec (array) - * @return int value - */ - protected function rsDataCodes2($spec) { - return $spec[4]; - } - - /** - * Return ecc codes 2 - * @param $spec (array) - * @return int value - */ - protected function rsEccCodes2($spec) { - return $spec[2]; - } - - /** - * Return data length - * @param $spec (array) - * @return int value - */ - protected function rsDataLength($spec) { - return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); - } - - /** - * Return ecc length - * @param $spec (array) - * @return int value - */ - protected function rsEccLength($spec) { - return ($spec[0] + $spec[3]) * $spec[2]; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRrs - - /** - * Initialize a Reed-Solomon codec and add it to existing rsitems - * @param $symsize (int) symbol size, bits - * @param $gfpoly (int) Field generator polynomial coefficients - * @param $fcr (int) first root of RS code generator polynomial, index form - * @param $prim (int) primitive element to generate polynomial roots - * @param $nroots (int) RS code generator polynomial degree (number of roots) - * @param $pad (int) padding bytes at front of shortened block - * @return array Array of RS values:. - */ - protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { - foreach ($this->rsitems as $rs) { - if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize) - OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) { - continue; - } - return $rs; - } - $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); - array_unshift($this->rsitems, $rs); - return $rs; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - // QRrsItem - - /** - * modnn - * @param $rs (array) RS values - * @param $x (int) X position - * @return int X osition - */ - protected function modnn($rs, $x) { - while ($x >= $rs['nn']) { - $x -= $rs['nn']; - $x = ($x >> $rs['mm']) + ($x & $rs['nn']); - } - return $x; - } - - /** - * Initialize a Reed-Solomon codec and returns an array of values. - * @param $symsize (int) symbol size, bits - * @param $gfpoly (int) Field generator polynomial coefficients - * @param $fcr (int) first root of RS code generator polynomial, index form - * @param $prim (int) primitive element to generate polynomial roots - * @param $nroots (int) RS code generator polynomial degree (number of roots) - * @param $pad (int) padding bytes at front of shortened block - * @return array Array of RS values:. - */ - protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { - // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2) - $rs = null; - // Check parameter ranges - if (($symsize < 0) OR ($symsize > 8)) { - return $rs; - } - if (($fcr < 0) OR ($fcr >= (1<<$symsize))) { - return $rs; - } - if (($prim <= 0) OR ($prim >= (1<<$symsize))) { - return $rs; - } - if (($nroots < 0) OR ($nroots >= (1<<$symsize))) { - return $rs; - } - if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) { - return $rs; - } - $rs = array(); - $rs['mm'] = $symsize; - $rs['nn'] = (1 << $symsize) - 1; - $rs['pad'] = $pad; - $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0); - $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0); - // PHP style macro replacement ;) - $NN =& $rs['nn']; - $A0 =& $NN; - // Generate Galois field lookup tables - $rs['index_of'][0] = $A0; // log(zero) = -inf - $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0 - $sr = 1; - for ($i=0; $i<$rs['nn']; ++$i) { - $rs['index_of'][$sr] = $i; - $rs['alpha_to'][$i] = $sr; - $sr <<= 1; - if ($sr & (1 << $symsize)) { - $sr ^= $gfpoly; - } - $sr &= $rs['nn']; - } - if ($sr != 1) { - // field generator polynomial is not primitive! - return NULL; - } - // Form RS code generator polynomial from its roots - $rs['genpoly'] = array_fill(0, ($nroots + 1), 0); - $rs['fcr'] = $fcr; - $rs['prim'] = $prim; - $rs['nroots'] = $nroots; - $rs['gfpoly'] = $gfpoly; - // Find prim-th root of 1, used in decoding - for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) { - ; // intentional empty-body loop! - } - $rs['iprim'] = (int)($iprim / $prim); - $rs['genpoly'][0] = 1; - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { - $rs['genpoly'][$i+1] = 1; - // Multiply rs->genpoly[] by @**(root + x) - for ($j = $i; $j > 0; --$j) { - if ($rs['genpoly'][$j] != 0) { - $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)]; - } else { - $rs['genpoly'][$j] = $rs['genpoly'][$j-1]; - } - } - // rs->genpoly[0] can never be zero - $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)]; - } - // convert rs->genpoly[] to index form for quicker encoding - for ($i = 0; $i <= $nroots; ++$i) { - $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]]; - } - return $rs; - } - - /** - * Encode a Reed-Solomon codec and returns the parity array - * @param $rs (array) RS values - * @param $data (array) data - * @param $parity (array) parity - * @return parity array - */ - protected function encode_rs_char($rs, $data, $parity) { - $MM =& $rs['mm']; // bits per symbol - $NN =& $rs['nn']; // the total number of symbols in a RS block - $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form - $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form - $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form - $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block - $FCR =& $rs['fcr']; // first consecutive root, index form - $PRIM =& $rs['prim']; // primitive element, index form - $IPRIM =& $rs['iprim']; // prim-th root of 1, index form - $PAD =& $rs['pad']; // the number of pad symbols in a block - $A0 =& $NN; - $parity = array_fill(0, $NROOTS, 0); - for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) { - $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; - if ($feedback != $A0) { - // feedback term is non-zero - // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must - // always be for the polynomials constructed by init_rs() - $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback); - for ($j=1; $j < $NROOTS; ++$j) { - $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])]; - } - } - // Shift - array_shift($parity); - if ($feedback != $A0) { - array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]); - } else { - array_push($parity, 0); - } - } - return $parity; - } - } // end QRcode class //============================================================+ // END OF FILE //============================================================+ + diff --git a/tools/tcpdf/tcpdf.php b/tools/tcpdf/tcpdf.php index b9a17725d..8dead271b 100755 --- a/tools/tcpdf/tcpdf.php +++ b/tools/tcpdf/tcpdf.php @@ -1856,16 +1856,18 @@ class TCPDF { require(dirname(__FILE__).'/htmlcolors.php'); $this->webcolor = $webcolor; // get array of custom spot colors + $this->spotcolor = array(); + /* if (file_exists(dirname(__FILE__).'/spotcolors.php')) { require(dirname(__FILE__).'/spotcolors.php'); $this->spotcolor = $spotcolor; } else { $this->spotcolor = array(); - } + }*/ require_once(dirname(__FILE__).'/unicode_data.php'); $this->unicode = new TCPDF_UNICODE_DATA(); - require_once(dirname(__FILE__).'/encodings_maps.php'); - $this->encmaps = new TCPDF_ENCODING_MAPS(); + // require_once(dirname(__FILE__).'/encodings_maps.php'); +// $this->encmaps = new TCPDF_ENCODING_MAPS(); $this->font_obj_ids = array(); $this->page_obj_id = array(); $this->form_obj_id = array(); @@ -2067,671 +2069,11 @@ class TCPDF { } } - /** - * Get page dimensions from format name. - * @param $format (mixed) The format name. It can be: - * @return array containing page width and height in points - * @public - * @since 5.0.010 (2010-05-17) - */ + public function getPageSizeFromFormat($format) { // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm) - switch (strtoupper($format)) { - // ISO 216 A Series + 2 SIS 014711 extensions - case 'A0' : {$pf = array( 2383.937, 3370.394); break;} - case 'A1' : {$pf = array( 1683.780, 2383.937); break;} - case 'A2' : {$pf = array( 1190.551, 1683.780); break;} - case 'A3' : {$pf = array( 841.890, 1190.551); break;} - case 'A4' : {$pf = array( 595.276, 841.890); break;} - case 'A5' : {$pf = array( 419.528, 595.276); break;} - case 'A6' : {$pf = array( 297.638, 419.528); break;} - case 'A7' : {$pf = array( 209.764, 297.638); break;} - case 'A8' : {$pf = array( 147.402, 209.764); break;} - case 'A9' : {$pf = array( 104.882, 147.402); break;} - case 'A10': {$pf = array( 73.701, 104.882); break;} - case 'A11': {$pf = array( 51.024, 73.701); break;} - case 'A12': {$pf = array( 36.850, 51.024); break;} - // ISO 216 B Series + 2 SIS 014711 extensions - case 'B0' : {$pf = array( 2834.646, 4008.189); break;} - case 'B1' : {$pf = array( 2004.094, 2834.646); break;} - case 'B2' : {$pf = array( 1417.323, 2004.094); break;} - case 'B3' : {$pf = array( 1000.630, 1417.323); break;} - case 'B4' : {$pf = array( 708.661, 1000.630); break;} - case 'B5' : {$pf = array( 498.898, 708.661); break;} - case 'B6' : {$pf = array( 354.331, 498.898); break;} - case 'B7' : {$pf = array( 249.449, 354.331); break;} - case 'B8' : {$pf = array( 175.748, 249.449); break;} - case 'B9' : {$pf = array( 124.724, 175.748); break;} - case 'B10': {$pf = array( 87.874, 124.724); break;} - case 'B11': {$pf = array( 62.362, 87.874); break;} - case 'B12': {$pf = array( 42.520, 62.362); break;} - // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION - case 'C0' : {$pf = array( 2599.370, 3676.535); break;} - case 'C1' : {$pf = array( 1836.850, 2599.370); break;} - case 'C2' : {$pf = array( 1298.268, 1836.850); break;} - case 'C3' : {$pf = array( 918.425, 1298.268); break;} - case 'C4' : {$pf = array( 649.134, 918.425); break;} - case 'C5' : {$pf = array( 459.213, 649.134); break;} - case 'C6' : {$pf = array( 323.150, 459.213); break;} - case 'C7' : {$pf = array( 229.606, 323.150); break;} - case 'C8' : {$pf = array( 161.575, 229.606); break;} - case 'C9' : {$pf = array( 113.386, 161.575); break;} - case 'C10': {$pf = array( 79.370, 113.386); break;} - case 'C11': {$pf = array( 56.693, 79.370); break;} - case 'C12': {$pf = array( 39.685, 56.693); break;} - case 'C76': {$pf = array( 229.606, 459.213); break;} - case 'DL' : {$pf = array( 311.811, 623.622); break;} - // SIS 014711 E Series - case 'E0' : {$pf = array( 2491.654, 3517.795); break;} - case 'E1' : {$pf = array( 1757.480, 2491.654); break;} - case 'E2' : {$pf = array( 1247.244, 1757.480); break;} - case 'E3' : {$pf = array( 878.740, 1247.244); break;} - case 'E4' : {$pf = array( 623.622, 878.740); break;} - case 'E5' : {$pf = array( 439.370, 623.622); break;} - case 'E6' : {$pf = array( 311.811, 439.370); break;} - case 'E7' : {$pf = array( 221.102, 311.811); break;} - case 'E8' : {$pf = array( 155.906, 221.102); break;} - case 'E9' : {$pf = array( 110.551, 155.906); break;} - case 'E10': {$pf = array( 76.535, 110.551); break;} - case 'E11': {$pf = array( 53.858, 76.535); break;} - case 'E12': {$pf = array( 36.850, 53.858); break;} - // SIS 014711 G Series - case 'G0' : {$pf = array( 2715.591, 3838.110); break;} - case 'G1' : {$pf = array( 1919.055, 2715.591); break;} - case 'G2' : {$pf = array( 1357.795, 1919.055); break;} - case 'G3' : {$pf = array( 958.110, 1357.795); break;} - case 'G4' : {$pf = array( 677.480, 958.110); break;} - case 'G5' : {$pf = array( 479.055, 677.480); break;} - case 'G6' : {$pf = array( 337.323, 479.055); break;} - case 'G7' : {$pf = array( 238.110, 337.323); break;} - case 'G8' : {$pf = array( 167.244, 238.110); break;} - case 'G9' : {$pf = array( 119.055, 167.244); break;} - case 'G10': {$pf = array( 82.205, 119.055); break;} - case 'G11': {$pf = array( 59.528, 82.205); break;} - case 'G12': {$pf = array( 39.685, 59.528); break;} - // ISO Press - case 'RA0': {$pf = array( 2437.795, 3458.268); break;} - case 'RA1': {$pf = array( 1729.134, 2437.795); break;} - case 'RA2': {$pf = array( 1218.898, 1729.134); break;} - case 'RA3': {$pf = array( 864.567, 1218.898); break;} - case 'RA4': {$pf = array( 609.449, 864.567); break;} - case 'SRA0': {$pf = array( 2551.181, 3628.346); break;} - case 'SRA1': {$pf = array( 1814.173, 2551.181); break;} - case 'SRA2': {$pf = array( 1275.591, 1814.173); break;} - case 'SRA3': {$pf = array( 907.087, 1275.591); break;} - case 'SRA4': {$pf = array( 637.795, 907.087); break;} - // German DIN 476 - case '4A0': {$pf = array( 4767.874, 6740.787); break;} - case '2A0': {$pf = array( 3370.394, 4767.874); break;} - // Variations on the ISO Standard - case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;} - case 'A3+' : {$pf = array( 932.598, 1369.134); break;} - case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;} - case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;} - case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;} - case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;} - case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;} - case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;} - case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;} - case 'F4' : {$pf = array( 595.276, 935.433); break;} - case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;} - case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;} - // ANSI Series - case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;} - case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;} - case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;} - case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;} - case 'ANSI_A': {$pf = array( 612.000, 792.000); break;} - // Traditional 'Loose' North American Paper Sizes - case 'USLEDGER': - case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;} - case 'ORGANIZERK': - case 'BIBLE': - case 'USTABLOID': - case 'TABLOID': {$pf = array( 792.000, 1224.000); break;} - case 'ORGANIZERM': - case 'USLETTER': - case 'LETTER' : {$pf = array( 612.000, 792.000); break;} - case 'USLEGAL': - case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;} - case 'GOVERNMENTLETTER': - case 'GLETTER': {$pf = array( 576.000, 756.000); break;} - case 'JUNIORLEGAL': - case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;} - // Other North American Paper Sizes - case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;} - case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;} - case 'QUARTO': {$pf = array( 648.000, 792.000); break;} - case 'GOVERNMENTLEGAL': - case 'FOLIO': {$pf = array( 612.000, 936.000); break;} - case 'MONARCH': - case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;} - case 'ORGANIZERL': - case 'STATEMENT': - case 'MEMO': {$pf = array( 396.000, 612.000); break;} - case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;} - case 'COMPACT': {$pf = array( 306.000, 486.000); break;} - case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;} - // Canadian standard CAN 2-9.60M - case 'P1': {$pf = array( 1587.402, 2437.795); break;} - case 'P2': {$pf = array( 1218.898, 1587.402); break;} - case 'P3': {$pf = array( 793.701, 1218.898); break;} - case 'P4': {$pf = array( 609.449, 793.701); break;} - case 'P5': {$pf = array( 396.850, 609.449); break;} - case 'P6': {$pf = array( 303.307, 396.850); break;} - // North American Architectural Sizes - case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;} - case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;} - case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;} - case 'BROADSHEET': - case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;} - case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;} - case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;} - // --- North American Envelope Sizes --- - // - Announcement Envelopes - case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;} - case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;} - case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;} - case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;} - case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;} - case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;} - // - Commercial Envelopes - case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;} - case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;} - case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;} - case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;} - case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;} - case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;} - case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;} - case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;} - // - Catalogue Envelopes - case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;} - case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;} - case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;} - case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;} - case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;} - case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;} - case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;} - case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;} - case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;} - case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;} - case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;} - case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;} - case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;} - case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;} - // Japanese (JIS P 0138-61) Standard B-Series - case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;} - case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;} - case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;} - case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;} - case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;} - case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;} - case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;} - case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;} - case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;} - case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;} - case 'JIS_B10': {$pf = array( 90.709, 127.559); break;} - case 'JIS_B11': {$pf = array( 62.362, 90.709); break;} - case 'JIS_B12': {$pf = array( 45.354, 62.362); break;} - // PA Series - case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;} - case 'PA1' : {$pf = array( 1587.402, 2381.102); break;} - case 'PA2' : {$pf = array( 1190.551, 1587.402); break;} - case 'PA3' : {$pf = array( 793.701, 1190.551); break;} - case 'PA4' : {$pf = array( 595.276, 793.701); break;} - case 'PA5' : {$pf = array( 396.850, 595.276); break;} - case 'PA6' : {$pf = array( 297.638, 396.850); break;} - case 'PA7' : {$pf = array( 198.425, 297.638); break;} - case 'PA8' : {$pf = array( 147.402, 198.425); break;} - case 'PA9' : {$pf = array( 99.213, 147.402); break;} - case 'PA10': {$pf = array( 73.701, 99.213); break;} - // Standard Photographic Print Sizes - case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;} - case 'E' : {$pf = array( 233.858, 340.157); break;} - case 'L': - case '3R' : {$pf = array( 252.283, 360.000); break;} - case 'KG': - case '4R' : {$pf = array( 289.134, 430.866); break;} - case '4D' : {$pf = array( 340.157, 430.866); break;} - case '2L': - case '5R' : {$pf = array( 360.000, 504.567); break;} - case '8P': - case '6R' : {$pf = array( 430.866, 575.433); break;} - case '6P': - case '8R' : {$pf = array( 575.433, 720.000); break;} - case '6PW': - case 'S8R' : {$pf = array( 575.433, 864.567); break;} - case '4P': - case '10R' : {$pf = array( 720.000, 864.567); break;} - case '4PW': - case 'S10R': {$pf = array( 720.000, 1080.000); break;} - case '11R' : {$pf = array( 790.866, 1009.134); break;} - case 'S11R': {$pf = array( 790.866, 1224.567); break;} - case '12R' : {$pf = array( 864.567, 1080.000); break;} - case 'S12R': {$pf = array( 864.567, 1292.598); break;} - // Common Newspaper Sizes - case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;} - case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;} - case 'NEWSPAPER_TABLOID': - case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;} - // Business Cards - case 'CREDIT_CARD': - case 'BUSINESS_CARD': - case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;} - case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;} - case 'BUSINESS_CARD_IT': - case 'BUSINESS_CARD_UK': - case 'BUSINESS_CARD_FR': - case 'BUSINESS_CARD_DE': - case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;} - case 'BUSINESS_CARD_CA': - case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;} - case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;} - case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;} - case 'BUSINESS_CARD_AU': - case 'BUSINESS_CARD_DK': - case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;} - case 'BUSINESS_CARD_RU': - case 'BUSINESS_CARD_CZ': - case 'BUSINESS_CARD_FI': - case 'BUSINESS_CARD_HU': - case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;} - // Billboards - case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;} - case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;} - case '12SHEET': {$pf = array( 8640.000, 4320.000); break;} - case '16SHEET': {$pf = array( 5760.000, 8640.000); break;} - case '32SHEET': {$pf = array(11520.000, 8640.000); break;} - case '48SHEET': {$pf = array(17280.000, 8640.000); break;} - case '64SHEET': {$pf = array(23040.000, 8640.000); break;} - case '96SHEET': {$pf = array(34560.000, 8640.000); break;} - // Old European Sizes - // - Old Imperial English Sizes - case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;} - case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;} - case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;} - case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;} - case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;} - case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;} - case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;} - case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;} - case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;} - case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;} - case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;} - case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;} - case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;} - case 'EN_SHEET': - case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;} - case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;} - case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;} - case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;} - case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;} - case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;} - case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;} - case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;} - case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;} - case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;} - case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;} - case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;} - case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;} - case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;} - // - Old Imperial Belgian Sizes - case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;} - case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;} - case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;} - case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;} - case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;} - case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;} - case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;} - case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;} - case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;} - case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;} - case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;} - case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;} - case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;} - case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;} - case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;} - case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;} - case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;} - // - Old Imperial French Sizes - case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;} - case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;} - case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;} - case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;} - case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;} - case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;} - case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;} - case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;} - case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;} - case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;} - case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;} - case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;} - case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;} - case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;} - case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;} - case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;} - case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;} - case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;} - case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;} - case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;} - case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;} - case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;} - case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;} - case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;} - case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;} - case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;} - case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;} - case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;} - // DEFAULT ISO A4 - default: {$pf = array( 595.276, 841.890); break;} - } + $pf = array( 595.276, 841.890); + return $pf; } @@ -2795,104 +2137,12 @@ class TCPDF { // remove inherited values unset($this->pagedim[$this->page]); } - if (is_string($format)) { - // get page measures from format name - $pf = $this->getPageSizeFromFormat($format); - $this->fwPt = $pf[0]; - $this->fhPt = $pf[1]; - } else { - // the boundaries of the physical medium on which the page shall be displayed or printed - if (isset($format['MediaBox'])) { - $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false); - $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k); - $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k); - } else { - if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) { - $pf = array(($format[0] * $this->k), ($format[1] * $this->k)); - } else { - if (!isset($format['format'])) { - // default value - $format['format'] = 'A4'; - } - $pf = $this->getPageSizeFromFormat($format['format']); - } - $this->fwPt = $pf[0]; - $this->fhPt = $pf[1]; - $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true); - } - // the visible region of default user space - if (isset($format['CropBox'])) { - $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false); - } - // the region to which the contents of the page shall be clipped when output in a production environment - if (isset($format['BleedBox'])) { - $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false); - } - // the intended dimensions of the finished page after trimming - if (isset($format['TrimBox'])) { - $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false); - } - // the page's meaningful content (including potential white space) - if (isset($format['ArtBox'])) { - $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false); - } - // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries - if (isset($format['BoxColorInfo'])) { - $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo']; - } - if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) { - // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90. - $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']); - } - if (isset($format['PZ'])) { - // The page's preferred zoom (magnification) factor - $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']); - } - if (isset($format['trans'])) { - // The style and duration of the visual transition to use when moving from another page to the given page during a presentation - if (isset($format['trans']['Dur'])) { - // The page's display duration - $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']); - } - $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade'); - if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) { - // The transition style that shall be used when moving to this page from another during a presentation - $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S']; - $valid_effect = array('Split', 'Blinds'); - $valid_vals = array('H', 'V'); - if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) { - $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm']; - } - $valid_effect = array('Split', 'Box', 'Fly'); - $valid_vals = array('I', 'O'); - if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) { - $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M']; - } - $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push'); - if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) { - if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe')) - OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter')) - OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) { - $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']); - } - } - if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) { - $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']); - } - if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) { - $this->pagedim[$this->page]['trans']['B'] = 'true'; - } - } else { - $this->pagedim[$this->page]['trans']['S'] = 'R'; - } - if (isset($format['trans']['D'])) { - // The duration of the transition effect, in seconds - $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']); - } else { - $this->pagedim[$this->page]['trans']['D'] = 1; - } - } - } + + // get page measures from format name + $pf = $this->getPageSizeFromFormat($format); + $this->fwPt = $pf[0]; + $this->fhPt = $pf[1]; + $this->setPageOrientation($orientation); } @@ -2913,10 +2163,11 @@ class TCPDF { // initialize array $this->pagedim[$page] = array(); } + /* $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); if (!in_array($type, $pageboxes)) { return; - } + }*/ if ($points) { $k = 1; } else { @@ -2928,27 +2179,6 @@ class TCPDF { $this->pagedim[$page][$type]['ury'] = ($ury * $k); } - /** - * Swap X and Y coordinates of page boxes (change page boxes orientation). - * @param $page (int) page number - * @protected - * @since 5.0.010 (2010-05-17) - */ - protected function swapPageBoxCoordinates($page) { - $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); - foreach ($pageboxes as $type) { - // swap X and Y coordinates - if (isset($this->pagedim[$page][$type])) { - $tmp = $this->pagedim[$page][$type]['llx']; - $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly']; - $this->pagedim[$page][$type]['lly'] = $tmp; - $tmp = $this->pagedim[$page][$type]['urx']; - $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury']; - $this->pagedim[$page][$type]['ury'] = $tmp; - } - } - } - /** * Set page orientation. * @param $orientation (string) page orientation. Possible values are (case insensitive): @@ -3545,68 +2775,8 @@ class TCPDF { } else { $this->Error('Incorrect zoom display mode: '.$zoom); } - switch ($layout) { - case 'default': - case 'single': - case 'SinglePage': { - $this->LayoutMode = 'SinglePage'; - break; - } - case 'continuous': - case 'OneColumn': { - $this->LayoutMode = 'OneColumn'; - break; - } - case 'two': - case 'TwoColumnLeft': { - $this->LayoutMode = 'TwoColumnLeft'; - break; - } - case 'TwoColumnRight': { - $this->LayoutMode = 'TwoColumnRight'; - break; - } - case 'TwoPageLeft': { - $this->LayoutMode = 'TwoPageLeft'; - break; - } - case 'TwoPageRight': { - $this->LayoutMode = 'TwoPageRight'; - break; - } - default: { - $this->LayoutMode = 'SinglePage'; - } - } - switch ($mode) { - case 'UseNone': { - $this->PageMode = 'UseNone'; - break; - } - case 'UseOutlines': { - $this->PageMode = 'UseOutlines'; - break; - } - case 'UseThumbs': { - $this->PageMode = 'UseThumbs'; - break; - } - case 'FullScreen': { - $this->PageMode = 'FullScreen'; - break; - } - case 'UseOC': { - $this->PageMode = 'UseOC'; - break; - } - case '': { - $this->PageMode = 'UseAttachments'; - break; - } - default: { - $this->PageMode = 'UseNone'; - } - } + $this->LayoutMode = 'SinglePage'; + $this->PageMode = 'UseNone'; } /** @@ -3848,29 +3018,6 @@ class TCPDF { return $this->numpages; } - /** - * Adds a new TOC (Table Of Content) page to the document. - * @param $orientation (string) page orientation. - * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat(). - * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins - * @public - * @since 5.0.001 (2010-05-06) - * @see AddPage(), startPage(), endPage(), endTOCPage() - */ - public function addTOCPage($orientation='', $format='', $keepmargins=false) { - $this->AddPage($orientation, $format, $keepmargins, true); - } - - /** - * Terminate the current TOC (Table Of Content) page - * @public - * @since 5.0.001 (2010-05-06) - * @see AddPage(), startPage(), endPage(), addTOCPage() - */ - public function endTOCPage() { - $this->endPage(true); - } - /** * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled). * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards. @@ -3995,6 +3142,31 @@ class TCPDF { $this->emptypagemrk[$this->page]= $this->pagelen[$this->page]; } + /** + * Put extgstates for object transparency + * @protected + * @since 3.0.000 (2008-03-27) + */ + protected function _putextgstates() { + if ($this->pdfa_mode) { + // transparencies are not allowed in PDF/A mode + return; + } + foreach ($this->extgstates as $i => $ext) { + $this->extgstates[$i]['n'] = $this->_newobj(); + $out = '<< /Type /ExtGState'; + foreach ($ext['parms'] as $k => $v) { + if (is_float($v)) { + $v = sprintf('%.2F', $v); + } + $out .= ' /'.$k.' '.$v; + } + $out .= ' >>'; + $out .= "\n".'endobj'; + $this->_out($out); + } + } + /** * Set start-writing mark on current page stream used to put borders and fills. * Borders and fills are always created after content and inserted on the position marked by this method. @@ -4155,123 +3327,14 @@ class TCPDF { * It is automatically called by AddPage() and could be overwritten in your own inherited class. * @public */ - public function Header() { - if ($this->header_xobjid < 0) { - // start a new XObject Template - $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin); - $headerfont = $this->getHeaderFont(); - $headerdata = $this->getHeaderData(); - $this->y = $this->header_margin; - if ($this->rtl) { - $this->x = $this->w - $this->original_rMargin; - } else { - $this->x = $this->original_lMargin; - } - if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) { - $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']); - if (($imgtype == 'eps') OR ($imgtype == 'ai')) { - $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); - } elseif ($imgtype == 'svg') { - $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); - } else { - $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); - } - $imgy = $this->getImageRBY(); - } else { - $imgy = $this->y; - } - $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2); - // set starting margin for text data cell - if ($this->getRTL()) { - $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1); - } else { - $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1); - } - $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1); - $this->SetTextColor(0, 0, 0); - // header title - $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1); - $this->SetX($header_x); - $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0); - // header string - $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]); - $this->SetX($header_x); - $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false); - // print an ending header line - $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); - $this->SetY((2.835 / $this->k) + max($imgy, $this->y)); - if ($this->rtl) { - $this->SetX($this->original_rMargin); - } else { - $this->SetX($this->original_lMargin); - } - $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C'); - $this->endTemplate(); - } - // print header template - $x = 0; - $dx = 0; - if ($this->booklet AND (($this->page % 2) == 0)) { - // adjust margins for booklet mode - $dx = ($this->original_lMargin - $this->original_rMargin); - } - if ($this->rtl) { - $x = $this->w + $dx; - } else { - $x = 0 + $dx; - } - $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); - if ($this->header_xobj_autoreset) { - // reset header xobject template at each page - $this->header_xobjid = -1; - } - } + public function Header() {} /** * This method is used to render the page footer. * It is automatically called by AddPage() and could be overwritten in your own inherited class. * @public */ - public function Footer() { - $cur_y = $this->y; - $this->SetTextColor(0, 0, 0); - //set style for cell border - $line_width = 0.85 / $this->k; - $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); - //print document barcode - $barcode = $this->getBarcode(); - if (!empty($barcode)) { - $this->Ln($line_width); - $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3); - $style = array( - 'position' => $this->rtl?'R':'L', - 'align' => $this->rtl?'R':'L', - 'stretch' => false, - 'fitwidth' => true, - 'cellfitalign' => '', - 'border' => false, - 'padding' => 0, - 'fgcolor' => array(0,0,0), - 'bgcolor' => false, - 'text' => false - ); - $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, ''); - } - if (empty($this->pagegroups)) { - $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); - } else { - $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias(); - } - $this->SetY($cur_y); - //Print page number - if ($this->getRTL()) { - $this->SetX($this->original_rMargin); - $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); - } else { - $this->SetX($this->original_lMargin); - $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R'); - } - } + public function Footer() {} /** * This method is used to render the page header. @@ -4444,130 +3507,6 @@ class TCPDF { return $this->page; } - /** - * Defines a new spot color. - * It can be expressed in RGB components or gray scale. - * The method can be called before the first page is created and the value is retained from page to page. - * @param $name (string) Full name of the spot color. - * @param $c (float) Cyan color for CMYK. Value between 0 and 100. - * @param $m (float) Magenta color for CMYK. Value between 0 and 100. - * @param $y (float) Yellow color for CMYK. Value between 0 and 100. - * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100. - * @public - * @since 4.0.024 (2008-09-12) - * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor() - */ - public function AddSpotColor($name, $c, $m, $y, $k) { - if (!isset($this->spot_colors[$name])) { - $i = (1 + count($this->spot_colors)); - $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k); - } - } - - /** - * Return the Spot color array. - * @param $name (string) Name of the spot color. - * @return (array) Spot color array or false if not defined. - * @public - * @since 5.9.125 (2011-10-03) - */ - public function getSpotColor($name) { - if (isset($this->spot_colors[$name])) { - return $this->spot_colors[$name]; - } - $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces - $color = strtolower($color); - if (isset($this->spotcolor[$color])) { - $this->AddSpotColor($this->spotcolor[$color][4], $this->spotcolor[$color][0], $this->spotcolor[$color][1], $this->spotcolor[$color][2], $this->spotcolor[$color][3]); - return $this->spot_colors[$name]; - } - return false; - } - - /** - * Set the spot color for the specified type ('draw', 'fill', 'text'). - * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text'). - * @param $name (string) Name of the spot color. - * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default). - * @return (string) PDF color command. - * @public - * @since 5.9.125 (2011-10-03) - */ - public function setSpotColor($type, $name, $tint=100) { - $spotcolor = $this->getSpotColor($name); - if ($spotcolor === false) { - $this->Error('Undefined spot color: '.$name.', you must add it on the spotcolors.php file.'); - } - $tint = (max(0, min(100, $tint)) / 100); - $intcolor = array('C' => $spotcolor['c'], 'M' => $spotcolor['m'], 'Y' => $spotcolor['y'], 'K' => $spotcolor['k'], 'name' => $spotcolor['i']); - $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']); - switch ($type) { - case 'draw': { - $pdfcolor .= sprintf('CS %.3F SCN', $tint); - $this->DrawColor = $pdfcolor; - $this->strokecolor = $intcolor; - break; - } - case 'fill': { - $pdfcolor .= sprintf('cs %.3F scn', $tint); - $this->FillColor = $pdfcolor; - $this->bgcolor = $intcolor; - break; - } - case 'text': { - $pdfcolor .= sprintf('cs %.3F scn', $tint); - $this->TextColor = $pdfcolor; - $this->fgcolor = $intcolor; - break; - } - } - $this->ColorFlag = ($this->FillColor != $this->TextColor); - if ($this->page > 0) { - $this->_out($pdfcolor); - } - if ($this->inxobj) { - // we are inside an XObject template - $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name]; - } - return $pdfcolor; - } - - /** - * Defines the spot color used for all drawing operations (lines, rectangles and cell borders). - * @param $name (string) Name of the spot color. - * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default). - * @public - * @since 4.0.024 (2008-09-12) - * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor() - */ - public function SetDrawSpotColor($name, $tint=100) { - $this->setSpotColor('draw', $name, $tint); - } - - /** - * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds). - * @param $name (string) Name of the spot color. - * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default). - * @public - * @since 4.0.024 (2008-09-12) - * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor() - */ - public function SetFillSpotColor($name, $tint=100) { - $this->setSpotColor('fill', $name, $tint); - } - - /** - * Defines the spot color used for text. - * @param $name (string) Name of the spot color. - * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default). - * @public - * @since 4.0.024 (2008-09-12) - * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor() - */ - public function SetTextSpotColor($name, $tint=100) { - $this->setSpotColor('text', $name, $tint); - } - /** * Set the color array for the specified type ('draw', 'fill', 'text'). * It can be expressed in RGB, CMYK or GRAY SCALE components. @@ -5460,25 +4399,7 @@ class TCPDF { * @see Annotation() */ protected function _putEmbeddedFiles() { - if ($this->pdfa_mode) { - // embedded files are not allowed in PDF/A mode - return; - } - reset($this->embeddedfiles); - foreach ($this->embeddedfiles as $filename => $filedata) { - $data = file_get_contents($filedata['file']); - $filter = ''; - if ($this->compress) { - $data = gzcompress($data); - $filter = ' /Filter /FlateDecode'; - } - $stream = $this->_getrawstream($data, $filedata['n']); - $out = $this->_getobj($filedata['n'])."\n"; - $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' >>'; - $out .= ' stream'."\n".$stream."\n".'endstream'; - $out .= "\n".'endobj'; - $this->_out($out); - } + return; } /** @@ -8967,17 +7888,6 @@ class TCPDF { $this->_out($out); } - /** - * Output references to page annotations - * @param $n (int) page number - * @protected - * @author Nicola Asuni - * @since 4.7.000 (2008-08-29) - * @deprecated - */ - protected function _putannotsrefs($n) { - $this->_out($this->_getannotsrefs($n)); - } /** * Get references to page annotations. @@ -8988,39 +7898,7 @@ class TCPDF { * @since 5.0.010 (2010-05-17) */ protected function _getannotsrefs($n) { - if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) { - return ''; - } - $out = ' /Annots ['; - if (isset($this->PageAnnots[$n])) { - foreach ($this->PageAnnots[$n] as $key => $val) { - if (!in_array($val['n'], $this->radio_groups)) { - $out .= ' '.$val['n'].' 0 R'; - } - } - // add radiobutton groups - if (isset($this->radiobutton_groups[$n])) { - foreach ($this->radiobutton_groups[$n] as $key => $data) { - if (isset($data['n'])) { - $out .= ' '.$data['n'].' 0 R'; - } - } - } - } - if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) { - // set reference for signature object - $out .= ' '.$this->sig_obj_id.' 0 R'; - } - if (!empty($this->empty_signature_appearance)) { - foreach ($this->empty_signature_appearance as $esa) { - if ($esa['page'] == $n) { - // set reference for empty signature objects - $out .= ' '.$esa['objid'].' 0 R'; - } - } - } - $out .= ' ]'; - return $out; + return; } /** @@ -9032,658 +7910,9 @@ class TCPDF { * @since 4.0.018 (2008-08-06) */ protected function _putannotsobjs() { - // reset object counter - for ($n=1; $n <= $this->numpages; ++$n) { - if (isset($this->PageAnnots[$n])) { - // set page annotations - foreach ($this->PageAnnots[$n] as $key => $pl) { - $annot_obj_id = $this->PageAnnots[$n][$key]['n']; - // create annotation object for grouping radiobuttons - if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) { - $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n']; - $annots = '<<'; - $annots .= ' /Type /Annot'; - $annots .= ' /Subtype /Widget'; - $annots .= ' /Rect [0 0 0 0]'; - if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) { - // read only - $annots .= ' /F 68'; - $annots .= ' /Ff 49153'; - } else { - $annots .= ' /F 4'; // default print for PDF/A - $annots .= ' /Ff 49152'; - } - $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id); - $annots .= ' /FT /Btn'; - $annots .= ' /Kids ['; - foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) { - if (isset($data['kid'])) { - $annots .= ' '.$data['kid'].' 0 R'; - if ($data['def'] !== 'Off') { - $defval = $data['def']; - } - } - } - $annots .= ' ]'; - if (isset($defval)) { - $annots .= ' /V /'.$defval; - } - $annots .= ' >>'; - $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj'); - $this->form_obj_id[] = $radio_button_obj_id; - // store object id to be used on Parent entry of Kids - $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id; - } - $formfield = false; - $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER); - $a = $pl['x'] * $this->k; - $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k); - $c = $pl['w'] * $this->k; - $d = $pl['h'] * $this->k; - $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b+$d); - // create new annotation object - $annots = '<_textstring($pl['txt'], $annot_obj_id); - $annots .= ' /P '.$this->page_obj_id[$n].' 0 R'; - $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id); - $annots .= ' /M '.$this->_datestring($annot_obj_id); - if (isset($pl['opt']['f'])) { - $fval = 0; - if (is_array($pl['opt']['f'])) { - foreach ($pl['opt']['f'] as $f) { - switch (strtolower($f)) { - case 'invisible': { - $fval += 1 << 0; - break; - } - case 'hidden': { - $fval += 1 << 1; - break; - } - case 'print': { - $fval += 1 << 2; - break; - } - case 'nozoom': { - $fval += 1 << 3; - break; - } - case 'norotate': { - $fval += 1 << 4; - break; - } - case 'noview': { - $fval += 1 << 5; - break; - } - case 'readonly': { - $fval += 1 << 6; - break; - } - case 'locked': { - $fval += 1 << 8; - break; - } - case 'togglenoview': { - $fval += 1 << 9; - break; - } - case 'lockedcontents': { - $fval += 1 << 10; - break; - } - default: { - break; - } - } - } - } else { - $fval = intval($pl['opt']['f']); - } - } else { - $fval = 4; - } - if ($this->pdfa_mode) { - // force print flag for PDF/A mode - $fval |= 4; - } - $annots .= ' /F '.intval($fval); - if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) { - $annots .= ' /AS /'.$pl['opt']['as']; - } - if (isset($pl['opt']['ap'])) { - // appearance stream - $annots .= ' /AP <<'; - if (is_array($pl['opt']['ap'])) { - foreach ($pl['opt']['ap'] as $apmode => $apdef) { - // $apmode can be: n = normal; r = rollover; d = down; - $annots .= ' /'.strtoupper($apmode); - if (is_array($apdef)) { - $annots .= ' <<'; - foreach ($apdef as $apstate => $stream) { - // reference to XObject that define the appearance for this mode-state - $apsobjid = $this->_putAPXObject($c, $d, $stream); - $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R'; - } - $annots .= ' >>'; - } else { - // reference to XObject that define the appearance for this mode - $apsobjid = $this->_putAPXObject($c, $d, $apdef); - $annots .= ' '.$apsobjid.' 0 R'; - } - } - } else { - $annots .= $pl['opt']['ap']; - } - $annots .= ' >>'; - } - if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) { - $annots .= ' /BS <<'; - $annots .= ' /Type /Border'; - if (isset($pl['opt']['bs']['w'])) { - $annots .= ' /W '.intval($pl['opt']['bs']['w']); - } - $bstyles = array('S', 'D', 'B', 'I', 'U'); - if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) { - $annots .= ' /S /'.$pl['opt']['bs']['s']; - } - if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) { - $annots .= ' /D ['; - foreach ($pl['opt']['bs']['d'] as $cord) { - $annots .= ' '.intval($cord); - } - $annots .= ']'; - } - $annots .= ' >>'; - } else { - $annots .= ' /Border ['; - if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) { - $annots .= intval($pl['opt']['border'][0]).' '; - $annots .= intval($pl['opt']['border'][1]).' '; - $annots .= intval($pl['opt']['border'][2]); - if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) { - $annots .= ' ['; - foreach ($pl['opt']['border'][3] as $dash) { - $annots .= intval($dash).' '; - } - $annots .= ']'; - } - } else { - $annots .= '0 0 0'; - } - $annots .= ']'; - } - if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) { - $annots .= ' /BE <<'; - $bstyles = array('S', 'C'); - if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $markups)) { - $annots .= ' /S /'.$pl['opt']['bs']['s']; - } else { - $annots .= ' /S /S'; - } - if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) { - $annots .= ' /I '.sprintf(' %.4F', $pl['opt']['be']['i']); - } - $annots .= '>>'; - } - if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) { - $annots .= ' /C ['; - foreach ($pl['opt']['c'] as $col) { - $col = intval($col); - $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255); - $annots .= sprintf(' %.4F', $color); - } - $annots .= ']'; - } - //$annots .= ' /StructParent '; - //$annots .= ' /OC '; - $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound'); - if (in_array(strtolower($pl['opt']['subtype']), $markups)) { - // this is a markup type - if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) { - $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id); - } - //$annots .= ' /Popup '; - if (isset($pl['opt']['ca'])) { - $annots .= ' /CA '.sprintf('%.4F', floatval($pl['opt']['ca'])); - } - if (isset($pl['opt']['rc'])) { - $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id); - } - $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id); - //$annots .= ' /IRT '; - if (isset($pl['opt']['subj'])) { - $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id); - } - //$annots .= ' /RT '; - //$annots .= ' /IT '; - //$annots .= ' /ExData '; - } - $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash'); - // Annotation types - switch (strtolower($pl['opt']['subtype'])) { - case 'text': { - if (isset($pl['opt']['open'])) { - $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false'); - } - $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); - if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { - $annots .= ' /Name /'.$pl['opt']['name']; - } else { - $annots .= ' /Name /Note'; - } - $statemodels = array('Marked', 'Review'); - if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) { - $annots .= ' /StateModel /'.$pl['opt']['statemodel']; - } else { - $pl['opt']['statemodel'] = 'Marked'; - $annots .= ' /StateModel /'.$pl['opt']['statemodel']; - } - if ($pl['opt']['statemodel'] == 'Marked') { - $states = array('Accepted', 'Unmarked'); - } else { - $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None'); - } - if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) { - $annots .= ' /State /'.$pl['opt']['state']; - } else { - if ($pl['opt']['statemodel'] == 'Marked') { - $annots .= ' /State /Unmarked'; - } else { - $annots .= ' /State /None'; - } - } - break; - } - case 'link': { - if (is_string($pl['txt'])) { - // external URI link - $annots .= ' /A <_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>'; - } else { - // internal link - $l = $this->links[$pl['txt']]; - if (isset($this->page_obj_id[($l[0])])) { - $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k))); - } - } - $hmodes = array('N', 'I', 'O', 'P'); - if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) { - $annots .= ' /H /'.$pl['opt']['h']; - } else { - $annots .= ' /H /I'; - } - //$annots .= ' /PA '; - //$annots .= ' /Quadpoints '; - break; - } - case 'freetext': { - if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) { - $annots .= ' /DA ('.$pl['opt']['da'].')'; - } - if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) { - $annots .= ' /Q '.intval($pl['opt']['q']); - } - if (isset($pl['opt']['rc'])) { - $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id); - } - if (isset($pl['opt']['ds'])) { - $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id); - } - if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) { - $annots .= ' /CL ['; - foreach ($pl['opt']['cl'] as $cl) { - $annots .= sprintf('%.4F ', $cl * $this->k); - } - $annots .= ']'; - } - $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter'); - if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) { - $annots .= ' /IT /'.$pl['opt']['it']; - } - if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) { - $l = $pl['opt']['rd'][0] * $this->k; - $r = $pl['opt']['rd'][1] * $this->k; - $t = $pl['opt']['rd'][2] * $this->k; - $b = $pl['opt']['rd'][3] * $this->k; - $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b).']'; - } - if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) { - $annots .= ' /LE /'.$pl['opt']['le']; - } - break; - } - case 'line': { - break; - } - case 'square': { - break; - } - case 'circle': { - break; - } - case 'polygon': { - break; - } - case 'polyline': { - break; - } - case 'highlight': { - break; - } - case 'underline': { - break; - } - case 'squiggly': { - break; - } - case 'strikeout': { - break; - } - case 'stamp': { - break; - } - case 'caret': { - break; - } - case 'ink': { - break; - } - case 'popup': { - break; - } - case 'fileattachment': { - if ($this->pdfa_mode) { - // embedded files are not allowed in PDF/A mode - break; - } - if (!isset($pl['opt']['fs'])) { - break; - } - $filename = basename($pl['opt']['fs']); - if (isset($this->embeddedfiles[$filename]['n'])) { - $annots .= ' /FS <_datastring($filename, $annot_obj_id).' /EF <embeddedfiles[$filename]['n'].' 0 R>> >>'; - $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag'); - if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { - $annots .= ' /Name /'.$pl['opt']['name']; - } else { - $annots .= ' /Name /PushPin'; - } - } - break; - } - case 'sound': { - if (!isset($pl['opt']['fs'])) { - break; - } - $filename = basename($pl['opt']['fs']); - if (isset($this->embeddedfiles[$filename]['n'])) { - // ... TO BE COMPLETED ... - // /R /C /B /E /CO /CP - $annots .= ' /Sound <_datastring($filename, $annot_obj_id).' /EF <embeddedfiles[$filename]['n'].' 0 R>> >>'; - $iconsapp = array('Speaker', 'Mic'); - if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { - $annots .= ' /Name /'.$pl['opt']['name']; - } else { - $annots .= ' /Name /Speaker'; - } - } - break; - } - case 'movie': { - break; - } - case 'widget': { - $hmode = array('N', 'I', 'O', 'P', 'T'); - if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) { - $annots .= ' /H /'.$pl['opt']['h']; - } - if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) { - $annots .= ' /MK <<'; - if (isset($pl['opt']['mk']['r'])) { - $annots .= ' /R '.$pl['opt']['mk']['r']; - } - if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) { - $annots .= ' /BC ['; - foreach($pl['opt']['mk']['bc'] AS $col) { - $col = intval($col); - $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255); - $annots .= sprintf(' %.2F', $color); - } - $annots .= ']'; - } - if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) { - $annots .= ' /BG ['; - foreach($pl['opt']['mk']['bg'] AS $col) { - $col = intval($col); - $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255); - $annots .= sprintf(' %.2F', $color); - } - $annots .= ']'; - } - if (isset($pl['opt']['mk']['ca'])) { - $annots .= ' /CA '.$pl['opt']['mk']['ca']; - } - if (isset($pl['opt']['mk']['rc'])) { - $annots .= ' /RC '.$pl['opt']['mk']['rc']; - } - if (isset($pl['opt']['mk']['ac'])) { - $annots .= ' /AC '.$pl['opt']['mk']['ac']; - } - if (isset($pl['opt']['mk']['i'])) { - $info = $this->getImageBuffer($pl['opt']['mk']['i']); - if ($info !== false) { - $annots .= ' /I '.$info['n'].' 0 R'; - } - } - if (isset($pl['opt']['mk']['ri'])) { - $info = $this->getImageBuffer($pl['opt']['mk']['ri']); - if ($info !== false) { - $annots .= ' /RI '.$info['n'].' 0 R'; - } - } - if (isset($pl['opt']['mk']['ix'])) { - $info = $this->getImageBuffer($pl['opt']['mk']['ix']); - if ($info !== false) { - $annots .= ' /IX '.$info['n'].' 0 R'; - } - } - if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) { - $annots .= ' /IF <<'; - $if_sw = array('A', 'B', 'S', 'N'); - if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) { - $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw']; - } - $if_s = array('A', 'P'); - if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) { - $annots .= ' /S /'.$pl['opt']['mk']['if']['s']; - } - if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) { - $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]); - } - if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) { - $annots .= ' /FB true'; - } - $annots .= '>>'; - } - if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) { - $annots .= ' /TP '.intval($pl['opt']['mk']['tp']); - } - $annots .= '>>'; - } // end MK - // --- Entries for field dictionaries --- - if (isset($this->radiobutton_groups[$n][$pl['txt']])) { - // set parent - $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R'; - } - if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) { - $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id); - } - if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) { - $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id); - } - if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) { - $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id); - } - if (isset($pl['opt']['ff'])) { - if (is_array($pl['opt']['ff'])) { - // array of bit settings - $flag = 0; - foreach($pl['opt']['ff'] as $val) { - $flag += 1 << ($val - 1); - } - } else { - $flag = intval($pl['opt']['ff']); - } - $annots .= ' /Ff '.$flag; - } - if (isset($pl['opt']['maxlen'])) { - $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']); - } - if (isset($pl['opt']['v'])) { - $annots .= ' /V'; - if (is_array($pl['opt']['v'])) { - foreach ($pl['opt']['v'] AS $optval) { - if (is_float($optval)) { - $optval = sprintf('%.2F', $optval); - } - $annots .= ' '.$optval; - } - } else { - $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id); - } - } - if (isset($pl['opt']['dv'])) { - $annots .= ' /DV'; - if (is_array($pl['opt']['dv'])) { - foreach ($pl['opt']['dv'] AS $optval) { - if (is_float($optval)) { - $optval = sprintf('%.2F', $optval); - } - $annots .= ' '.$optval; - } - } else { - $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id); - } - } - if (isset($pl['opt']['rv'])) { - $annots .= ' /RV'; - if (is_array($pl['opt']['rv'])) { - foreach ($pl['opt']['rv'] AS $optval) { - if (is_float($optval)) { - $optval = sprintf('%.2F', $optval); - } - $annots .= ' '.$optval; - } - } else { - $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id); - } - } - if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) { - $annots .= ' /A << '.$pl['opt']['a'].' >>'; - } - if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) { - $annots .= ' /AA << '.$pl['opt']['aa'].' >>'; - } - if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) { - $annots .= ' /DA ('.$pl['opt']['da'].')'; - } - if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) { - $annots .= ' /Q '.intval($pl['opt']['q']); - } - if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) { - $annots .= ' /Opt ['; - foreach($pl['opt']['opt'] AS $copt) { - if (is_array($copt)) { - $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']'; - } else { - $annots .= ' '.$this->_textstring($copt, $annot_obj_id); - } - } - $annots .= ']'; - } - if (isset($pl['opt']['ti'])) { - $annots .= ' /TI '.intval($pl['opt']['ti']); - } - if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) { - $annots .= ' /I ['; - foreach($pl['opt']['i'] AS $copt) { - $annots .= intval($copt).' '; - } - $annots .= ']'; - } - break; - } - case 'screen': { - break; - } - case 'printermark': { - break; - } - case 'trapnet': { - break; - } - case 'watermark': { - break; - } - case '3d': { - break; - } - default: { - break; - } - } - $annots .= '>>'; - // create new annotation object - $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj'); - if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) { - // store reference of form object - $this->form_obj_id[] = $annot_obj_id; - } - } - } - } // end for each page + return; } - /** - * Put appearance streams XObject used to define annotation's appearance states. - * @param $w (int) annotation width - * @param $h (int) annotation height - * @param $stream (string) appearance stream - * @return int object ID - * @protected - * @since 4.8.001 (2009-09-09) - */ - protected function _putAPXObject($w=0, $h=0, $stream='') { - $stream = trim($stream); - $out = $this->_getobj()."\n"; - $this->xobjects['AX'.$this->n] = array('n' => $this->n); - $out .= '<<'; - $out .= ' /Type /XObject'; - $out .= ' /Subtype /Form'; - $out .= ' /FormType 1'; - if ($this->compress) { - $stream = gzcompress($stream); - $out .= ' /Filter /FlateDecode'; - } - $rect = sprintf('%.2F %.2F', $w, $h); - $out .= ' /BBox [0 0 '.$rect.']'; - $out .= ' /Matrix [1 0 0 1 0 0]'; - $out .= ' /Resources 2 0 R'; - $stream = $this->_getrawstream($stream); - $out .= ' /Length '.strlen($stream); - $out .= ' >>'; - $out .= ' stream'."\n".$stream."\n".'endstream'; - $out .= "\n".'endobj'; - $this->_out($out); - return $this->n; - } /** * Get ULONG from string (Big Endian 32-bit unsigned integer). @@ -11180,8 +9409,7 @@ class TCPDF { $nextk = -1; $prevint = false; foreach ($range as $k => $ws) { - $cws = count($ws); - if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) { + if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR (count($ws) < 4))) { if (isset($range[$k]['interval'])) { unset($range[$k]['interval']); } @@ -12212,17 +10440,6 @@ class TCPDF { return $oid; } - /** - * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag. - * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method! - * @param $xmp (string) Custom XMP data. - * @since 5.9.128 (2011-10-06) - * @public - */ - public function setExtraXMP($xmp) { - $this->custom_xmp = $xmp; - } - /** * Put XMP data object and return ID. * @return (int) The object ID. @@ -14069,44 +12286,6 @@ class TCPDF { } } - /** - * Return the premission code used on encryption (P value). - * @param $permissions (Array) the set of permissions (specify the ones you want to block). - * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit. - * @protected - * @since 5.0.005 (2010-05-12) - * @author Nicola Asuni - */ - protected function getUserPermissionCode($permissions, $mode=0) { - $options = array( - 'owner' => 2, // bit 2 -- inverted logic: cleared by default - 'print' => 4, // bit 3 - 'modify' => 8, // bit 4 - 'copy' => 16, // bit 5 - 'annot-forms' => 32, // bit 6 - 'fill-forms' => 256, // bit 9 - 'extract' => 512, // bit 10 - 'assemble' => 1024,// bit 11 - 'print-high' => 2048 // bit 12 - ); - $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100) - foreach ($permissions as $permission) { - if (!isset($options[$permission])) { - $this->Error('Incorrect permission: '.$permission); - } - if (($mode > 0) OR ($options[$permission] <= 32)) { - // set only valid permissions - if ($options[$permission] == 2) { - // the logic for bit 2 is inverted (cleared by default) - $protection += $options[$permission]; - } else { - $protection -= $options[$permission]; - } - } - } - return $protection; - } - /** * Set document protection * Remark: the protection against modification is for people who have the full Acrobat product. @@ -14270,1208 +12449,6 @@ class TCPDF { // END OF ENCRYPTION FUNCTIONS ------------------------- - // START TRANSFORMATIONS SECTION ----------------------- - - /** - * Starts a 2D tranformation saving current graphic state. - * This function must be called before scaling, mirroring, translation, rotation and skewing. - * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior. - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function StartTransform() { - $this->_out('q'); - if ($this->inxobj) { - // we are inside an XObject template - $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']); - } else { - $this->transfmrk[$this->page][] = $this->pagelen[$this->page]; - } - ++$this->transfmatrix_key; - $this->transfmatrix[$this->transfmatrix_key] = array(); - } - - /** - * Stops a 2D tranformation restoring previous graphic state. - * This function must be called after scaling, mirroring, translation, rotation and skewing. - * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior. - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function StopTransform() { - $this->_out('Q'); - if (isset($this->transfmatrix[$this->transfmatrix_key])) { - array_pop($this->transfmatrix[$this->transfmatrix_key]); - --$this->transfmatrix_key; - } - if ($this->inxobj) { - // we are inside an XObject template - array_pop($this->xobjects[$this->xobjid]['transfmrk']); - } else { - array_pop($this->transfmrk[$this->page]); - } - } - /** - * Horizontal Scaling. - * @param $s_x (float) scaling factor for width as percent. 0 is not allowed. - * @param $x (int) abscissa of the scaling center. Default is current x position - * @param $y (int) ordinate of the scaling center. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function ScaleX($s_x, $x='', $y='') { - $this->Scale($s_x, 100, $x, $y); - } - - /** - * Vertical Scaling. - * @param $s_y (float) scaling factor for height as percent. 0 is not allowed. - * @param $x (int) abscissa of the scaling center. Default is current x position - * @param $y (int) ordinate of the scaling center. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function ScaleY($s_y, $x='', $y='') { - $this->Scale(100, $s_y, $x, $y); - } - - /** - * Vertical and horizontal proportional Scaling. - * @param $s (float) scaling factor for width and height as percent. 0 is not allowed. - * @param $x (int) abscissa of the scaling center. Default is current x position - * @param $y (int) ordinate of the scaling center. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function ScaleXY($s, $x='', $y='') { - $this->Scale($s, $s, $x, $y); - } - - /** - * Vertical and horizontal non-proportional Scaling. - * @param $s_x (float) scaling factor for width as percent. 0 is not allowed. - * @param $s_y (float) scaling factor for height as percent. 0 is not allowed. - * @param $x (int) abscissa of the scaling center. Default is current x position - * @param $y (int) ordinate of the scaling center. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function Scale($s_x, $s_y, $x='', $y='') { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - if (($s_x == 0) OR ($s_y == 0)) { - $this->Error('Please do not use values equal to zero for scaling'); - } - $y = ($this->h - $y) * $this->k; - $x *= $this->k; - //calculate elements of transformation matrix - $s_x /= 100; - $s_y /= 100; - $tm = array(); - $tm[0] = $s_x; - $tm[1] = 0; - $tm[2] = 0; - $tm[3] = $s_y; - $tm[4] = $x * (1 - $s_x); - $tm[5] = $y * (1 - $s_y); - //scale the coordinate system - $this->Transform($tm); - } - - /** - * Horizontal Mirroring. - * @param $x (int) abscissa of the point. Default is current x position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function MirrorH($x='') { - $this->Scale(-100, 100, $x); - } - - /** - * Verical Mirroring. - * @param $y (int) ordinate of the point. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function MirrorV($y='') { - $this->Scale(100, -100, '', $y); - } - - /** - * Point reflection mirroring. - * @param $x (int) abscissa of the point. Default is current x position - * @param $y (int) ordinate of the point. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function MirrorP($x='',$y='') { - $this->Scale(-100, -100, $x, $y); - } - - /** - * Reflection against a straight line through point (x, y) with the gradient angle (angle). - * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line). - * @param $x (int) abscissa of the point. Default is current x position - * @param $y (int) ordinate of the point. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function MirrorL($angle=0, $x='',$y='') { - $this->Scale(-100, 100, $x, $y); - $this->Rotate(-2*($angle-90), $x, $y); - } - - /** - * Translate graphic object horizontally. - * @param $t_x (int) movement to the right (or left for RTL) - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function TranslateX($t_x) { - $this->Translate($t_x, 0); - } - - /** - * Translate graphic object vertically. - * @param $t_y (int) movement to the bottom - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function TranslateY($t_y) { - $this->Translate(0, $t_y); - } - - /** - * Translate graphic object horizontally and vertically. - * @param $t_x (int) movement to the right - * @param $t_y (int) movement to the bottom - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function Translate($t_x, $t_y) { - //calculate elements of transformation matrix - $tm = array(); - $tm[0] = 1; - $tm[1] = 0; - $tm[2] = 0; - $tm[3] = 1; - $tm[4] = $t_x * $this->k; - $tm[5] = -$t_y * $this->k; - //translate the coordinate system - $this->Transform($tm); - } - - /** - * Rotate object. - * @param $angle (float) angle in degrees for counter-clockwise rotation - * @param $x (int) abscissa of the rotation center. Default is current x position - * @param $y (int) ordinate of the rotation center. Default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function Rotate($angle, $x='', $y='') { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - $y = ($this->h - $y) * $this->k; - $x *= $this->k; - //calculate elements of transformation matrix - $tm = array(); - $tm[0] = cos(deg2rad($angle)); - $tm[1] = sin(deg2rad($angle)); - $tm[2] = -$tm[1]; - $tm[3] = $tm[0]; - $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x); - $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x); - //rotate the coordinate system around ($x,$y) - $this->Transform($tm); - } - - /** - * Skew horizontally. - * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right) - * @param $x (int) abscissa of the skewing center. default is current x position - * @param $y (int) ordinate of the skewing center. default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function SkewX($angle_x, $x='', $y='') { - $this->Skew($angle_x, 0, $x, $y); - } - - /** - * Skew vertically. - * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top) - * @param $x (int) abscissa of the skewing center. default is current x position - * @param $y (int) ordinate of the skewing center. default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function SkewY($angle_y, $x='', $y='') { - $this->Skew(0, $angle_y, $x, $y); - } - - /** - * Skew. - * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right) - * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top) - * @param $x (int) abscissa of the skewing center. default is current x position - * @param $y (int) ordinate of the skewing center. default is current y position - * @public - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - public function Skew($angle_x, $angle_y, $x='', $y='') { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) { - $this->Error('Please use values between -90 and +90 degrees for Skewing.'); - } - $x *= $this->k; - $y = ($this->h - $y) * $this->k; - //calculate elements of transformation matrix - $tm = array(); - $tm[0] = 1; - $tm[1] = tan(deg2rad($angle_y)); - $tm[2] = tan(deg2rad($angle_x)); - $tm[3] = 1; - $tm[4] = -$tm[2] * $y; - $tm[5] = -$tm[1] * $x; - //skew the coordinate system - $this->Transform($tm); - } - - /** - * Apply graphic transformations. - * @param $tm (array) transformation matrix - * @protected - * @since 2.1.000 (2008-01-07) - * @see StartTransform(), StopTransform() - */ - protected function Transform($tm) { - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); - // add tranformation matrix - $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]); - // update transformation mark - if ($this->inxobj) { - // we are inside an XObject template - if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) { - $key = key($this->xobjects[$this->xobjid]['transfmrk']); - $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']); - } - } elseif (end($this->transfmrk[$this->page]) !== false) { - $key = key($this->transfmrk[$this->page]); - $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page]; - } - } - - // END TRANSFORMATIONS SECTION ------------------------- - - // START GRAPHIC FUNCTIONS SECTION --------------------- - // The following section is based on the code provided by David Hernandez Sanz - - /** - * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page. - * @param $width (float) The width. - * @public - * @since 1.0 - * @see Line(), Rect(), Cell(), MultiCell() - */ - public function SetLineWidth($width) { - //Set line width - $this->LineWidth = $width; - $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k)); - if ($this->page > 0) { - $this->_out($this->linestyleWidth); - } - } - - /** - * Returns the current the line width. - * @return int Line width - * @public - * @since 2.1.000 (2008-01-07) - * @see Line(), SetLineWidth() - */ - public function GetLineWidth() { - return $this->LineWidth; - } - - /** - * Set line style. - * @param $style (array) Line style. Array with keys among the following: - * - * @param $ret (boolean) if true do not send the command. - * @return string the PDF command - * @public - * @since 2.1.000 (2008-01-08) - */ - public function SetLineStyle($style, $ret=false) { - $s = ''; // string to be returned - if (!is_array($style)) { - return; - } - if (isset($style['width'])) { - $this->LineWidth = $style['width']; - $this->linestyleWidth = sprintf('%.2F w', ($style['width'] * $this->k)); - $s .= $this->linestyleWidth.' '; - } - if (isset($style['cap'])) { - $ca = array('butt' => 0, 'round'=> 1, 'square' => 2); - if (isset($ca[$style['cap']])) { - $this->linestyleCap = $ca[$style['cap']].' J'; - $s .= $this->linestyleCap.' '; - } - } - if (isset($style['join'])) { - $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2); - if (isset($ja[$style['join']])) { - $this->linestyleJoin = $ja[$style['join']].' j'; - $s .= $this->linestyleJoin.' '; - } - } - if (isset($style['dash'])) { - $dash_string = ''; - if ($style['dash']) { - if (preg_match('/^.+,/', $style['dash']) > 0) { - $tab = explode(',', $style['dash']); - } else { - $tab = array($style['dash']); - } - $dash_string = ''; - foreach ($tab as $i => $v) { - if ($i) { - $dash_string .= ' '; - } - $dash_string .= sprintf('%.2F', $v); - } - } - if (!isset($style['phase']) OR !$style['dash']) { - $style['phase'] = 0; - } - $this->linestyleDash = sprintf('[%s] %.2F d', $dash_string, $style['phase']); - $s .= $this->linestyleDash.' '; - } - if (isset($style['color'])) { - $s .= $this->SetDrawColorArray($style['color'], true).' '; - } - if (!$ret) { - $this->_out($s); - } - return $s; - } - - /** - * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment. - * @param $x (float) Abscissa of point. - * @param $y (float) Ordinate of point. - * @protected - * @since 2.1.000 (2008-01-08) - */ - protected function _outPoint($x, $y) { - $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k)); - } - - /** - * Append a straight line segment from the current point to the point (x, y). - * The new current point shall be (x, y). - * @param $x (float) Abscissa of end point. - * @param $y (float) Ordinate of end point. - * @protected - * @since 2.1.000 (2008-01-08) - */ - protected function _outLine($x, $y) { - $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k)); - } - - /** - * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space. - * @param $x (float) Abscissa of upper-left corner. - * @param $y (float) Ordinate of upper-left corner. - * @param $w (float) Width. - * @param $h (float) Height. - * @param $op (string) options - * @protected - * @since 2.1.000 (2008-01-08) - */ - protected function _outRect($x, $y, $w, $h, $op) { - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); - } - - /** - * Append a cubic Bézier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x2, y2) as the Bézier control points. - * The new current point shall be (x3, y3). - * @param $x1 (float) Abscissa of control point 1. - * @param $y1 (float) Ordinate of control point 1. - * @param $x2 (float) Abscissa of control point 2. - * @param $y2 (float) Ordinate of control point 2. - * @param $x3 (float) Abscissa of end point. - * @param $y3 (float) Ordinate of end point. - * @protected - * @since 2.1.000 (2008-01-08) - */ - protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) { - $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); - } - - /** - * Append a cubic Bézier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bézier control points. - * The new current point shall be (x3, y3). - * @param $x2 (float) Abscissa of control point 2. - * @param $y2 (float) Ordinate of control point 2. - * @param $x3 (float) Abscissa of end point. - * @param $y3 (float) Ordinate of end point. - * @protected - * @since 4.9.019 (2010-04-26) - */ - protected function _outCurveV($x2, $y2, $x3, $y3) { - $this->_out(sprintf('%.2F %.2F %.2F %.2F v', $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); - } - - /** - * Append a cubic Bézier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bézier control points. - * The new current point shall be (x3, y3). - * @param $x1 (float) Abscissa of control point 1. - * @param $y1 (float) Ordinate of control point 1. - * @param $x3 (float) Abscissa of end point. - * @param $y3 (float) Ordinate of end point. - * @protected - * @since 2.1.000 (2008-01-08) - */ - protected function _outCurveY($x1, $y1, $x3, $y3) { - $this->_out(sprintf('%.2F %.2F %.2F %.2F y', $x1 * $this->k, ($this->h - $y1) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); - } - - /** - * Draws a line between two points. - * @param $x1 (float) Abscissa of first point. - * @param $y1 (float) Ordinate of first point. - * @param $x2 (float) Abscissa of second point. - * @param $y2 (float) Ordinate of second point. - * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array). - * @public - * @since 1.0 - * @see SetLineWidth(), SetDrawColor(), SetLineStyle() - */ - public function Line($x1, $y1, $x2, $y2, $style=array()) { - if (is_array($style)) { - $this->SetLineStyle($style); - } - $this->_outPoint($x1, $y1); - $this->_outLine($x2, $y2); - $this->_out('S'); - } - - /** - * Draws a rectangle. - * @param $x (float) Abscissa of upper-left corner. - * @param $y (float) Ordinate of upper-left corner. - * @param $w (float) Width. - * @param $h (float) Height. - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $border_style (array) Border style of rectangle. Array with keys among the following: - * - * If a key is not present or is null, not draws the border. Default value: default line style (empty array). - * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @public - * @since 1.0 - * @see SetLineStyle() - */ - public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) { - if (!(false === strpos($style, 'F')) AND !empty($fill_color)) { - $this->SetFillColorArray($fill_color); - } - $op = $this->getPathPaintOperator($style); - if ((!$border_style) OR (isset($border_style['all']))) { - if (isset($border_style['all']) AND $border_style['all']) { - $this->SetLineStyle($border_style['all']); - $border_style = array(); - } - } - $this->_outRect($x, $y, $w, $h, $op); - if ($border_style) { - $border_style2 = array(); - foreach ($border_style as $line => $value) { - $length = strlen($line); - for ($i = 0; $i < $length; ++$i) { - $border_style2[$line[$i]] = $value; - } - } - $border_style = $border_style2; - if (isset($border_style['L']) AND $border_style['L']) { - $this->Line($x, $y, $x, $y + $h, $border_style['L']); - } - if (isset($border_style['T']) AND $border_style['T']) { - $this->Line($x, $y, $x + $w, $y, $border_style['T']); - } - if (isset($border_style['R']) AND $border_style['R']) { - $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']); - } - if (isset($border_style['B']) AND $border_style['B']) { - $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']); - } - } - } - - /** - * Draws a Bezier curve. - * The Bezier curve is a tangent to the line between the control points at - * either end of the curve. - * @param $x0 (float) Abscissa of start point. - * @param $y0 (float) Ordinate of start point. - * @param $x1 (float) Abscissa of control point 1. - * @param $y1 (float) Ordinate of control point 1. - * @param $x2 (float) Abscissa of control point 2. - * @param $y2 (float) Ordinate of control point 2. - * @param $x3 (float) Abscissa of end point. - * @param $y3 (float) Ordinate of end point. - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @public - * @see SetLineStyle() - * @since 2.1.000 (2008-01-08) - */ - public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) { - if (!(false === strpos($style, 'F')) AND isset($fill_color)) { - $this->SetFillColorArray($fill_color); - } - $op = $this->getPathPaintOperator($style); - if ($line_style) { - $this->SetLineStyle($line_style); - } - $this->_outPoint($x0, $y0); - $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3); - $this->_out($op); - } - - /** - * Draws a poly-Bezier curve. - * Each Bezier curve segment is a tangent to the line between the control points at - * either end of the curve. - * @param $x0 (float) Abscissa of start point. - * @param $y0 (float) Ordinate of start point. - * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3). - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @public - * @see SetLineStyle() - * @since 3.0008 (2008-05-12) - */ - public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) { - if (!(false === strpos($style, 'F')) AND isset($fill_color)) { - $this->SetFillColorArray($fill_color); - } - $op = $this->getPathPaintOperator($style); - if ($op == 'f') { - $line_style = array(); - } - if ($line_style) { - $this->SetLineStyle($line_style); - } - $this->_outPoint($x0, $y0); - foreach ($segments as $segment) { - list($x1, $y1, $x2, $y2, $x3, $y3) = $segment; - $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3); - } - $this->_out($op); - } - - /** - * Draws an ellipse. - * An ellipse is formed from n Bezier curves. - * @param $x0 (float) Abscissa of center point. - * @param $y0 (float) Ordinate of center point. - * @param $rx (float) Horizontal radius. - * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0. - * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0. - * @param $astart: (float) Angle start of draw line. Default value: 0. - * @param $afinish: (float) Angle finish of draw line. Default value: 360. - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse. - * @author Nicola Asuni - * @public - * @since 2.1.000 (2008-01-08) - */ - public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) { - if ($this->empty_string($ry) OR ($ry == 0)) { - $ry = $rx; - } - if (!(false === strpos($style, 'F')) AND isset($fill_color)) { - $this->SetFillColorArray($fill_color); - } - $op = $this->getPathPaintOperator($style); - if ($op == 'f') { - $line_style = array(); - } - if ($line_style) { - $this->SetLineStyle($line_style); - } - $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false); - $this->_out($op); - } - - /** - * Append an elliptical arc to the current path. - * An ellipse is formed from n Bezier curves. - * @param $xc (float) Abscissa of center point. - * @param $yc (float) Ordinate of center point. - * @param $rx (float) Horizontal radius. - * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0. - * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0. - * @param $angs: (float) Angle start of draw line. Default value: 0. - * @param $angf: (float) Angle finish of draw line. Default value: 360. - * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors). - * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse. - * @param $startpoint (boolean) if true output a starting point. - * @param $ccw (boolean) if true draws in counter-clockwise. - * @param $svg (boolean) if true the angles are in svg mode (already calculated). - * @return array bounding box coordinates (x min, y min, x max, y max) - * @author Nicola Asuni - * @protected - * @since 4.9.019 (2010-04-26) - */ - protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) { - $k = $this->k; - if ($nc < 2) { - $nc = 2; - } - $xmin = 2147483647; - $ymin = 2147483647; - $xmax = 0; - $ymax = 0; - if ($pie) { - // center of the arc - $this->_outPoint($xc, $yc); - } - $xang = deg2rad((float) $xang); - $angs = deg2rad((float) $angs); - $angf = deg2rad((float) $angf); - if ($svg) { - $as = $angs; - $af = $angf; - } else { - $as = atan2((sin($angs) / $ry), (cos($angs) / $rx)); - $af = atan2((sin($angf) / $ry), (cos($angf) / $rx)); - } - if ($as < 0) { - $as += (2 * M_PI); - } - if ($af < 0) { - $af += (2 * M_PI); - } - if ($ccw AND ($as > $af)) { - // reverse rotation - $as -= (2 * M_PI); - } elseif (!$ccw AND ($as < $af)) { - // reverse rotation - $af -= (2 * M_PI); - } - $total_angle = ($af - $as); - if ($nc < 2) { - $nc = 2; - } - // total arcs to draw - $nc *= (2 * abs($total_angle) / M_PI); - $nc = round($nc) + 1; - // angle of each arc - $arcang = ($total_angle / $nc); - // center point in PDF coordinates - $x0 = $xc; - $y0 = ($this->h - $yc); - // starting angle - $ang = $as; - $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3); - $cos_xang = cos($xang); - $sin_xang = sin($xang); - $cos_ang = cos($ang); - $sin_ang = sin($ang); - // first arc point - $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang); - $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang); - // first Bezier control point - $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang))); - $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang))); - if ($pie) { - // line from center to arc starting point - $this->_outLine($px1, $this->h - $py1); - } elseif ($startpoint) { - // arc starting point - $this->_outPoint($px1, $this->h - $py1); - } - // draw arcs - for ($i = 1; $i <= $nc; ++$i) { - // starting angle - $ang = $as + ($i * $arcang); - if ($i == $nc) { - $ang = $af; - } - $cos_ang = cos($ang); - $sin_ang = sin($ang); - // second arc point - $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang); - $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang); - // second Bezier control point - $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang))); - $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang))); - // draw arc - $cx1 = ($px1 + $qx1); - $cy1 = ($this->h - ($py1 + $qy1)); - $cx2 = ($px2 - $qx2); - $cy2 = ($this->h - ($py2 - $qy2)); - $cx3 = $px2; - $cy3 = ($this->h - $py2); - $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3); - // get bounding box coordinates - $xmin = min($xmin, $cx1, $cx2, $cx3); - $ymin = min($ymin, $cy1, $cy2, $cy3); - $xmax = max($xmax, $cx1, $cx2, $cx3); - $ymax = max($ymax, $cy1, $cy2, $cy3); - // move to next point - $px1 = $px2; - $py1 = $py2; - $qx1 = $qx2; - $qy1 = $qy2; - } - if ($pie) { - $this->_outLine($xc, $yc); - // get bounding box coordinates - $xmin = min($xmin, $xc); - $ymin = min($ymin, $yc); - $xmax = max($xmax, $xc); - $ymax = max($ymax, $yc); - } - return array($xmin, $ymin, $xmax, $ymax); - } - - /** - * Draws a circle. - * A circle is formed from n Bezier curves. - * @param $x0 (float) Abscissa of center point. - * @param $y0 (float) Ordinate of center point. - * @param $r (float) Radius. - * @param $angstr: (float) Angle start of draw line. Default value: 0. - * @param $angend: (float) Angle finish of draw line. Default value: 360. - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array). - * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle. - * @public - * @since 2.1.000 (2008-01-08) - */ - public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) { - $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc); - } - - /** - * Draws a polygonal line - * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1)) - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of polygon. Array with keys among the following: - * - * If a key is not present or is null, not draws the line. Default value is default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @since 4.8.003 (2009-09-15) - * @public - */ - public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) { - $this->Polygon($p, $style, $line_style, $fill_color, false); - } - - /** - * Draws a polygon. - * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1)) - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of polygon. Array with keys among the following: - * - * If a key is not present or is null, not draws the line. Default value is default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @param $closed (boolean) if true the polygon is closes, otherwise will remain open - * @public - * @since 2.1.000 (2008-01-08) - */ - public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) { - $nc = count($p); // number of coordinates - $np = $nc / 2; // number of points - if ($closed) { - // close polygon by adding the first 2 points at the end (one line) - for ($i = 0; $i < 4; ++$i) { - $p[$nc + $i] = $p[$i]; - } - // copy style for the last added line - if (isset($line_style[0])) { - $line_style[$np] = $line_style[0]; - } - $nc += 4; - } - if (!(false === strpos($style, 'F')) AND isset($fill_color)) { - $this->SetFillColorArray($fill_color); - } - $op = $this->getPathPaintOperator($style); - if ($op == 'f') { - $line_style = array(); - } - $draw = true; - if ($line_style) { - if (isset($line_style['all'])) { - $this->SetLineStyle($line_style['all']); - } else { - $draw = false; - if ($op == 'B') { - // draw fill - $op = 'f'; - $this->_outPoint($p[0], $p[1]); - for ($i = 2; $i < $nc; $i = $i + 2) { - $this->_outLine($p[$i], $p[$i + 1]); - } - $this->_out($op); - } - // draw outline - $this->_outPoint($p[0], $p[1]); - for ($i = 2; $i < $nc; $i = $i + 2) { - $line_num = ($i / 2) - 1; - if (isset($line_style[$line_num])) { - if ($line_style[$line_num] != 0) { - if (is_array($line_style[$line_num])) { - $this->_out('S'); - $this->SetLineStyle($line_style[$line_num]); - $this->_outPoint($p[$i - 2], $p[$i - 1]); - $this->_outLine($p[$i], $p[$i + 1]); - $this->_out('S'); - $this->_outPoint($p[$i], $p[$i + 1]); - } else { - $this->_outLine($p[$i], $p[$i + 1]); - } - } - } else { - $this->_outLine($p[$i], $p[$i + 1]); - } - } - $this->_out($op); - } - } - if ($draw) { - $this->_outPoint($p[0], $p[1]); - for ($i = 2; $i < $nc; $i = $i + 2) { - $this->_outLine($p[$i], $p[$i + 1]); - } - $this->_out($op); - } - } - - /** - * Draws a regular polygon. - * @param $x0 (float) Abscissa of center point. - * @param $y0 (float) Ordinate of center point. - * @param $r: (float) Radius of inscribed circle. - * @param $ns (integer) Number of sides. - * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0. - * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false. - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of polygon sides. Array with keys among the following: - * - * If a key is not present or is null, not draws the side. Default value is default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array). - * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are: - * - * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array). - * @public - * @since 2.1.000 (2008-01-08) - */ - public function RegularPolygon($x0, $y0, $r, $ns, $angle=0, $draw_circle=false, $style='', $line_style=array(), $fill_color=array(), $circle_style='', $circle_outLine_style=array(), $circle_fill_color=array()) { - if (3 > $ns) { - $ns = 3; - } - if ($draw_circle) { - $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color); - } - $p = array(); - for ($i = 0; $i < $ns; ++$i) { - $a = $angle + ($i * 360 / $ns); - $a_rad = deg2rad((float) $a); - $p[] = $x0 + ($r * sin($a_rad)); - $p[] = $y0 + ($r * cos($a_rad)); - } - $this->Polygon($p, $style, $line_style, $fill_color); - } - - /** - * Draws a star polygon - * @param $x0 (float) Abscissa of center point. - * @param $y0 (float) Ordinate of center point. - * @param $r (float) Radius of inscribed circle. - * @param $nv (integer) Number of vertices. - * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon). - * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0. - * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false. - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $line_style (array) Line style of polygon sides. Array with keys among the following: - * - * If a key is not present or is null, not draws the side. Default value is default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array). - * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are: - * - * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array). - * @public - * @since 2.1.000 (2008-01-08) - */ - public function StarPolygon($x0, $y0, $r, $nv, $ng, $angle=0, $draw_circle=false, $style='', $line_style=array(), $fill_color=array(), $circle_style='', $circle_outLine_style=array(), $circle_fill_color=array()) { - if ($nv < 2) { - $nv = 2; - } - if ($draw_circle) { - $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color); - } - $p2 = array(); - $visited = array(); - for ($i = 0; $i < $nv; ++$i) { - $a = $angle + ($i * 360 / $nv); - $a_rad = deg2rad((float) $a); - $p2[] = $x0 + ($r * sin($a_rad)); - $p2[] = $y0 + ($r * cos($a_rad)); - $visited[] = false; - } - $p = array(); - $i = 0; - do { - $p[] = $p2[$i * 2]; - $p[] = $p2[($i * 2) + 1]; - $visited[$i] = true; - $i += $ng; - $i %= $nv; - } while (!$visited[$i]); - $this->Polygon($p, $style, $line_style, $fill_color); - } - - /** - * Draws a rounded rectangle. - * @param $x (float) Abscissa of upper-left corner. - * @param $y (float) Ordinate of upper-left corner. - * @param $w (float) Width. - * @param $h (float) Height. - * @param $r (float) the radius of the circle used to round off the corners of the rectangle. - * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner ("1111"). - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @public - * @since 2.1.000 (2008-01-08) - */ - public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) { - $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color); - } - - /** - * Draws a rounded rectangle. - * @param $x (float) Abscissa of upper-left corner. - * @param $y (float) Ordinate of upper-left corner. - * @param $w (float) Width. - * @param $h (float) Height. - * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle. - * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle. - * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner ("1111"). - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). - * @public - * @since 4.9.019 (2010-04-22) - */ - public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) { - if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) { - // Not rounded - $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color); - return; - } - // Rounded - if (!(false === strpos($style, 'F')) AND isset($fill_color)) { - $this->SetFillColorArray($fill_color); - } - $op = $this->getPathPaintOperator($style); - if ($op == 'f') { - $border_style = array(); - } - if ($border_style) { - $this->SetLineStyle($border_style); - } - $MyArc = 4 / 3 * (sqrt(2) - 1); - $this->_outPoint($x + $rx, $y); - $xc = $x + $w - $rx; - $yc = $y + $ry; - $this->_outLine($xc, $y); - if ($round_corner[0]) { - $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc); - } else { - $this->_outLine($x + $w, $y); - } - $xc = $x + $w - $rx; - $yc = $y + $h - $ry; - $this->_outLine($x + $w, $yc); - if ($round_corner[1]) { - $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry); - } else { - $this->_outLine($x + $w, $y + $h); - } - $xc = $x + $rx; - $yc = $y + $h - $ry; - $this->_outLine($xc, $y + $h); - if ($round_corner[2]) { - $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc); - } else { - $this->_outLine($x, $y + $h); - } - $xc = $x + $rx; - $yc = $y + $ry; - $this->_outLine($x, $yc); - if ($round_corner[3]) { - $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry); - } else { - $this->_outLine($x, $y); - $this->_outLine($x + $rx, $y); - } - $this->_out($op); - } - - /** - * Draws a grahic arrow. - * @param $x0 (float) Abscissa of first point. - * @param $y0 (float) Ordinate of first point. - * @param $x1 (float) Abscissa of second point. - * @param $y1 (float) Ordinate of second point. - * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead) - * @param $arm_size (float) length of arrowhead arms - * @param $arm_angle (int) angle between an arm and the shaft - * @author Piotr Galecki, Nicola Asuni, Andy Meier - * @since 4.6.018 (2009-07-10) - */ - public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) { - // getting arrow direction angle - // 0 deg angle is when both arms go along X axis. angle grows clockwise. - $dir_angle = atan2(($y0 - $y1), ($x0 - $x1)); - if ($dir_angle < 0) { - $dir_angle += (2 * M_PI); - } - $arm_angle = deg2rad($arm_angle); - $sx1 = $x1; - $sy1 = $y1; - if ($head_style > 0) { - // calculate the stopping point for the arrow shaft - $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle)); - $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle)); - } - // main arrow line / shaft - $this->Line($x0, $y0, $sx1, $sy1); - // left arrowhead arm tip - $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle)); - $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle)); - // right arrowhead arm tip - $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle)); - $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle)); - $mode = 'D'; - $style = array(); - switch ($head_style) { - case 0: { - // draw only arrowhead arms - $mode = 'D'; - $style = array(1, 1, 0); - break; - } - case 1: { - // draw closed arrowhead, but no fill - $mode = 'D'; - break; - } - case 2: { - // closed and filled arrowhead - $mode = 'DF'; - break; - } - case 3: { - // filled arrowhead - $mode = 'F'; - break; - } - } - $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array()); - } - - // END GRAPHIC FUNCTIONS SECTION ----------------------- - // BIDIRECTIONAL TEXT SECTION -------------------------- /** @@ -16158,73 +13135,6 @@ class TCPDF { $this->_out($out); } - /** - * Adds a bookmark - alias for Bookmark(). - * @param $txt (string) Bookmark description. - * @param $level (int) Bookmark level (minimum value is 0). - * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;). - * @param $page (int) Target page number (leave empty for current page). - * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic. - * @param $color (array) RGB color array (values from 0 to 255). - * @public - */ - public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0)) { - $this->Bookmark($txt, $level, $y, $page, $style, $color); - } - - /** - * Adds a bookmark. - * @param $txt (string) Bookmark description. - * @param $level (int) Bookmark level (minimum value is 0). - * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;). - * @param $page (int) Target page number (leave empty for current page). - * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic. - * @param $color (array) RGB color array (values from 0 to 255). - * @public - * @author Olivier Plathey, Nicola Asuni - * @since 2.1.002 (2008-02-12) - */ - public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0)) { - if ($level < 0) { - $level = 0; - } - if (isset($this->outlines[0])) { - $lastoutline = end($this->outlines); - $maxlevel = $lastoutline['l'] + 1; - } else { - $maxlevel = 0; - } - if ($level > $maxlevel) { - $level = $maxlevel; - } - if ($y == -1) { - $y = $this->GetY(); - } - if (empty($page)) { - $page = $this->PageNo(); - if (empty($page)) { - return; - } - } - $this->outlines[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page, 's' => strtoupper($style), 'c' => $color); - } - - /** - * Sort bookmarks for page and key. - * @protected - * @since 5.9.119 (2011-09-19) - */ - protected function sortBookmarks() { - // get sorting columns - $outline_p = array(); - $outline_y = array(); - foreach ($this->outlines as $key => $row) { - $outline_p[$key] = $row['p']; - $outline_k[$key] = $key; - } - // sort outlines by page and original position - array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines); - } /** * Create a bookmark PDF string. @@ -16233,127 +13143,11 @@ class TCPDF { * @since 2.1.002 (2008-02-12) */ protected function _putbookmarks() { - $nb = count($this->outlines); - if ($nb == 0) { - return; - } - // sort bookmarks - $this->sortBookmarks(); - $lru = array(); - $level = 0; - foreach ($this->outlines as $i => $o) { - if ($o['l'] > 0) { - $parent = $lru[($o['l'] - 1)]; - //Set parent and last pointers - $this->outlines[$i]['parent'] = $parent; - $this->outlines[$parent]['last'] = $i; - if ($o['l'] > $level) { - //Level increasing: set first pointer - $this->outlines[$parent]['first'] = $i; - } - } else { - $this->outlines[$i]['parent'] = $nb; - } - if (($o['l'] <= $level) AND ($i > 0)) { - //Set prev and next pointers - $prev = $lru[$o['l']]; - $this->outlines[$prev]['next'] = $i; - $this->outlines[$i]['prev'] = $prev; - } - $lru[$o['l']] = $i; - $level = $o['l']; - } - //Outline items - $n = $this->n + 1; - $nltags = '/|<\/(blockquote|dd|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|ul|tcpdf|table|tr|td)>/si'; - foreach ($this->outlines as $i => $o) { - $oid = $this->_newobj(); - // covert HTML title to string - $title = preg_replace($nltags, "\n", $o['t']); - $title = preg_replace("/[\r]+/si", '', $title); - $title = preg_replace("/[\n]+/si", "\n", $title); - $title = strip_tags($title); - $title = $this->stringTrim($title); - $out = '<_textstring($title, $oid); - $out .= ' /Parent '.($n + $o['parent']).' 0 R'; - if (isset($o['prev'])) { - $out .= ' /Prev '.($n + $o['prev']).' 0 R'; - } - if (isset($o['next'])) { - $out .= ' /Next '.($n + $o['next']).' 0 R'; - } - if (isset($o['first'])) { - $out .= ' /First '.($n + $o['first']).' 0 R'; - } - if (isset($o['last'])) { - $out .= ' /Last '.($n + $o['last']).' 0 R'; - } - if (isset($this->page_obj_id[($o['p'])])) { - $out .= ' '.sprintf('/Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($o['p'])], ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k))); - } - // set font style - $style = 0; - if (!empty($o['s'])) { - // bold - if (strpos($o['s'], 'B') !== false) { - $style |= 2; - } - // oblique - if (strpos($o['s'], 'I') !== false) { - $style |= 1; - } - } - $out .= sprintf(' /F %d', $style); - // set bookmark color - if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) { - $color = array_values($o['c']); - $out .= sprintf(' /C [%.3F %.3F %.3F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255)); - } else { - // black - $out .= ' /C [0.0 0.0 0.0]'; - } - $out .= ' /Count 0'; // normally closed item - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - } - //Outline root - $this->OutlineRoot = $this->_newobj(); - $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj'); + return; } // --- JAVASCRIPT ------------------------------------------------------ - /** - * Adds a javascript - * @param $script (string) Javascript code - * @public - * @author Johannes Güntert, Nicola Asuni - * @since 2.1.002 (2008-02-12) - */ - public function IncludeJS($script) { - $this->javascript .= $script; - } - - /** - * Adds a javascript object and return object ID - * @param $script (string) Javascript code - * @param $onload (boolean) if true executes this object when opening the document - * @return int internal object ID - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function addJavascriptObject($script, $onload=false) { - if ($this->pdfa_mode) { - // javascript is not allowed in PDF/A mode - return false; - } - ++$this->n; - $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload); - return $this->n; - } - /** * Create a javascript PDF string. * @protected @@ -16361,1101 +13155,9 @@ class TCPDF { * @since 2.1.002 (2008-02-12) */ protected function _putjavascript() { - if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) { - return; - } - if (strpos($this->javascript, 'this.addField') > 0) { - if (!$this->ur['enabled']) { - //$this->setUserRights(); - } - // the following two lines are used to avoid form fields duplication after saving - // The addField method only works when releasing user rights (UR3) - $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1); - $jsb = "getField('tcpdfdocsaved').value='saved';"; - $this->javascript = $jsa."\n".$this->javascript."\n".$jsb; - } - $this->n_js = $this->_newobj(); - $out = ' << /Names ['; - if (!empty($this->javascript)) { - $out .= ' (EmbeddedJS) '.($this->n + 1).' 0 R'; - } - if (!empty($this->js_objects)) { - foreach ($this->js_objects as $key => $val) { - if ($val['onload']) { - $out .= ' (JS'.$key.') '.$key.' 0 R'; - } - } - } - $out .= ' ] >>'; - $out .= "\n".'endobj'; - $this->_out($out); - // default Javascript object - if (!empty($this->javascript)) { - $obj_id = $this->_newobj(); - $out = '<< /S /JavaScript'; - $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id); - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - } - // additional Javascript objects - if (!empty($this->js_objects)) { - foreach ($this->js_objects as $key => $val) { - $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj'; - $this->_out($out); - } - } + return; } - /** - * Convert color to javascript color. - * @param $color (string) color name or "#RRGGBB" - * @protected - * @author Denis Van Nuffelen, Nicola Asuni - * @since 2.1.002 (2008-02-12) - */ - protected function _JScolor($color) { - static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray'); - if (substr($color,0,1) == '#') { - return sprintf("['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255); - } - if (!in_array($color,$aColors)) { - $this->Error('Invalid color: '.$color); - } - return 'color.'.$color; - } - - /** - * Adds a javascript form field. - * @param $type (string) field type - * @param $name (string) field name - * @param $x (int) horizontal position - * @param $y (int) vertical position - * @param $w (int) width - * @param $h (int) height - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @protected - * @author Denis Van Nuffelen, Nicola Asuni - * @since 2.1.002 (2008-02-12) - */ - protected function _addfield($type, $name, $x, $y, $w, $h, $prop) { - if ($this->rtl) { - $x = $x - $w; - } - // the followind avoid fields duplication after saving the document - $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {"; - $k = $this->k; - $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n"; - $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n"; - while (list($key, $val) = each($prop)) { - if (strcmp(substr($key, -5), 'Color') == 0) { - $val = $this->_JScolor($val); - } else { - $val = "'".$val."'"; - } - $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n"; - } - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - $this->javascript .= '}'; - } - - // --- FORM FIELDS ----------------------------------------------------- - - /** - * Convert JavaScript form fields properties array to Annotation Properties array. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @return array of annotation properties - * @protected - * @author Nicola Asuni - * @since 4.8.000 (2009-09-06) - */ - protected function getAnnotOptFromJSProp($prop) { - if (isset($prop['aopt']) AND is_array($prop['aopt'])) { - // the annotation options area lready defined - return $prop['aopt']; - } - $opt = array(); // value to be returned - // alignment: Controls how the text is laid out within the text field. - if (isset($prop['alignment'])) { - switch ($prop['alignment']) { - case 'left': { - $opt['q'] = 0; - break; - } - case 'center': { - $opt['q'] = 1; - break; - } - case 'right': { - $opt['q'] = 2; - break; - } - default: { - $opt['q'] = ($this->rtl)?2:0; - break; - } - } - } - // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle. - if (isset($prop['lineWidth'])) { - $linewidth = intval($prop['lineWidth']); - } else { - $linewidth = 1; - } - // borderStyle: The border style for a field. - if (isset($prop['borderStyle'])) { - switch ($prop['borderStyle']) { - case 'border.d': - case 'dashed': { - $opt['border'] = array(0, 0, $linewidth, array(3, 2)); - $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2)); - break; - } - case 'border.b': - case 'beveled': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'B'); - break; - } - case 'border.i': - case 'inset': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'I'); - break; - } - case 'border.u': - case 'underline': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'U'); - break; - } - case 'border.s': - case 'solid': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'S'); - break; - } - default: { - break; - } - } - } - if (isset($prop['border']) AND is_array($prop['border'])) { - $opt['border'] = $prop['border']; - } - if (!isset($opt['mk'])) { - $opt['mk'] = array(); - } - if (!isset($opt['mk']['if'])) { - $opt['mk']['if'] = array(); - } - $opt['mk']['if']['a'] = array(0.5, 0.5); - // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon. - if (isset($prop['buttonAlignX'])) { - $opt['mk']['if']['a'][0] = $prop['buttonAlignX']; - } - // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon. - if (isset($prop['buttonAlignY'])) { - $opt['mk']['if']['a'][1] = $prop['buttonAlignY']; - } - // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field. - if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) { - $opt['mk']['if']['fb'] = true; - } - // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face. - if (isset($prop['buttonScaleHow'])) { - switch ($prop['buttonScaleHow']) { - case 'scaleHow.proportional': { - $opt['mk']['if']['s'] = 'P'; - break; - } - case 'scaleHow.anamorphic': { - $opt['mk']['if']['s'] = 'A'; - break; - } - } - } - // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face. - if (isset($prop['buttonScaleWhen'])) { - switch ($prop['buttonScaleWhen']) { - case 'scaleWhen.always': { - $opt['mk']['if']['sw'] = 'A'; - break; - } - case 'scaleWhen.never': { - $opt['mk']['if']['sw'] = 'N'; - break; - } - case 'scaleWhen.tooBig': { - $opt['mk']['if']['sw'] = 'B'; - break; - } - case 'scaleWhen.tooSmall': { - $opt['mk']['if']['sw'] = 'S'; - break; - } - } - } - // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face. - if (isset($prop['buttonPosition'])) { - switch ($prop['buttonPosition']) { - case 0: - case 'position.textOnly': { - $opt['mk']['tp'] = 0; - break; - } - case 1: - case 'position.iconOnly': { - $opt['mk']['tp'] = 1; - break; - } - case 2: - case 'position.iconTextV': { - $opt['mk']['tp'] = 2; - break; - } - case 3: - case 'position.textIconV': { - $opt['mk']['tp'] = 3; - break; - } - case 4: - case 'position.iconTextH': { - $opt['mk']['tp'] = 4; - break; - } - case 5: - case 'position.textIconH': { - $opt['mk']['tp'] = 5; - break; - } - case 6: - case 'position.overlay': { - $opt['mk']['tp'] = 6; - break; - } - } - } - // fillColor: Specifies the background color for a field. - if (isset($prop['fillColor'])) { - if (is_array($prop['fillColor'])) { - $opt['mk']['bg'] = $prop['fillColor']; - } else { - $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']); - } - } - // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width. - if (isset($prop['strokeColor'])) { - if (is_array($prop['strokeColor'])) { - $opt['mk']['bc'] = $prop['strokeColor']; - } else { - $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']); - } - } - // rotation: The rotation of a widget in counterclockwise increments. - if (isset($prop['rotation'])) { - $opt['mk']['r'] = $prop['rotation']; - } - // charLimit: Limits the number of characters that a user can type into a text field. - if (isset($prop['charLimit'])) { - $opt['maxlen'] = intval($prop['charLimit']); - } - if (!isset($ff)) { - $ff = 0; // default value - } - // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it. - if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) { - $ff += 1 << 0; - } - // required: Specifies whether a field requires a value. - if (isset($prop['required']) AND ($prop['required'] == 'true')) { - $ff += 1 << 1; - } - // multiline: Controls how text is wrapped within the field. - if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) { - $ff += 1 << 12; - } - // password: Specifies whether the field should display asterisks when data is entered in the field. - if (isset($prop['password']) AND ($prop['password'] == 'true')) { - $ff += 1 << 13; - } - // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect. - if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) { - $ff += 1 << 14; - } - // Radio: If set, the field is a set of radio buttons. - if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) { - $ff += 1 << 15; - } - // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value. - if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) { - $ff += 1 << 16; - } - // Combo: If set, the field is a combo box; if clear, the field is a list box. - if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) { - $ff += 1 << 17; - } - // editable: Controls whether a combo box is editable. - if (isset($prop['editable']) AND ($prop['editable'] == 'true')) { - $ff += 1 << 18; - } - // Sort: If set, the field's option items shall be sorted alphabetically. - if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) { - $ff += 1 << 19; - } - // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection). - if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) { - $ff += 1 << 20; - } - // multipleSelection: If true, indicates that a list box allows a multiple selection of items. - if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) { - $ff += 1 << 21; - } - // doNotSpellCheck: If true, spell checking is not performed on this editable text field. - if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) { - $ff += 1 << 22; - } - // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field. - if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) { - $ff += 1 << 23; - } - // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set. - if (isset($prop['comb']) AND ($prop['comb'] == 'true')) { - $ff += 1 << 24; - } - // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons. - if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) { - $ff += 1 << 25; - } - // richText: If true, the field allows rich text formatting. - if (isset($prop['richText']) AND ($prop['richText'] == 'true')) { - $ff += 1 << 25; - } - // commitOnSelChange: Controls whether a field value is committed after a selection change. - if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) { - $ff += 1 << 26; - } - $opt['ff'] = $ff; - // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset. - if (isset($prop['defaultValue'])) { - $opt['dv'] = $prop['defaultValue']; - } - $f = 4; // default value for annotation flags - // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it. - if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) { - $f += 1 << 6; - } - // display: Controls whether the field is hidden or visible on screen and in print. - if (isset($prop['display'])) { - if ($prop['display'] == 'display.visible') { - // - } elseif ($prop['display'] == 'display.hidden') { - $f += 1 << 1; - } elseif ($prop['display'] == 'display.noPrint') { - $f -= 1 << 2; - } elseif ($prop['display'] == 'display.noView') { - $f += 1 << 5; - } - } - $opt['f'] = $f; - // currentValueIndices: Reads and writes single or multiple values of a list box or combo box. - if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) { - $opt['i'] = $prop['currentValueIndices']; - } - // value: The value of the field data that the user has entered. - if (isset($prop['value'])) { - if (is_array($prop['value'])) { - $opt['opt'] = array(); - foreach ($prop['value'] AS $key => $optval) { - // exportValues: An array of strings representing the export values for the field. - if (isset($prop['exportValues'][$key])) { - $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]); - } else { - $opt['opt'][$key] = $prop['value'][$key]; - } - } - } else { - $opt['v'] = $prop['value']; - } - } - // richValue: This property specifies the text contents and formatting of a rich text field. - if (isset($prop['richValue'])) { - $opt['rv'] = $prop['richValue']; - } - // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded). - if (isset($prop['submitName'])) { - $opt['tm'] = $prop['submitName']; - } - // name: Fully qualified field name. - if (isset($prop['name'])) { - $opt['t'] = $prop['name']; - } - // userName: The user name (short description string) of the field. - if (isset($prop['userName'])) { - $opt['tu'] = $prop['userName']; - } - // highlight: Defines how a button reacts when a user clicks it. - if (isset($prop['highlight'])) { - switch ($prop['highlight']) { - case 'none': - case 'highlight.n': { - $opt['h'] = 'N'; - break; - } - case 'invert': - case 'highlight.i': { - $opt['h'] = 'i'; - break; - } - case 'push': - case 'highlight.p': { - $opt['h'] = 'P'; - break; - } - case 'outline': - case 'highlight.o': { - $opt['h'] = 'O'; - break; - } - } - } - // Unsupported options: - // - calcOrderIndex: Changes the calculation order of fields in the document. - // - delay: Delays the redrawing of a field's appearance. - // - defaultStyle: This property defines the default style attributes for the form field. - // - style: Allows the user to set the glyph style of a check box or radio button. - // - textColor, textFont, textSize - return $opt; - } - - /** - * Set default properties for form fields. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-06) - */ - public function setFormDefaultProp($prop=array()) { - $this->default_form_prop = $prop; - } - - /** - * Return the default properties for form fields. - * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-06) - */ - public function getFormDefaultProp() { - return $this->default_form_prop; - } - - /** - * Creates a text field - * @param $name (string) field name - * @param $w (float) Width of the rectangle - * @param $h (float) Height of the rectangle - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference. - * @param $x (float) Abscissa of the upper-left corner of the rectangle - * @param $y (float) Ordinate of the upper-left corner of the rectangle - * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered). - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - if ($js) { - $this->_addfield('text', $name, $x, $y, $w, $h, $prop); - return; - } - // get default style - $prop = array_merge($this->getFormDefaultProp(), $prop); - // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); - // set default appearance stream - $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; - $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); - $popt['da'] = $fontstyle; - // build appearance stream - $popt['ap'] = array(); - $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' '; - $text = ''; - if (isset($prop['value']) AND !empty($prop['value'])) { - $text = $prop['value']; - } elseif (isset($opt['v']) AND !empty($opt['v'])) { - $text = $opt['v']; - } - $tmpid = $this->startTemplate($w, $h, false); - $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false); - $this->endTemplate(); - --$this->n; - $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata']; - unset($this->xobjects[$tmpid]); - $popt['ap']['n'] .= 'Q EMC'; - // merge options - $opt = array_merge($popt, $opt); - // remove some conflicting options - unset($opt['bs']); - // set remaining annotation data - $opt['Subtype'] = 'Widget'; - $opt['ft'] = 'Tx'; - $opt['t'] = $name; - // Additional annotation's parameters (check _putannotsobj() method): - //$opt['f'] - //$opt['as'] - //$opt['bs'] - //$opt['be'] - //$opt['c'] - //$opt['border'] - //$opt['h'] - //$opt['mk']; - //$opt['mk']['r'] - //$opt['mk']['bc']; - //$opt['mk']['bg']; - unset($opt['mk']['ca']); - unset($opt['mk']['rc']); - unset($opt['mk']['ac']); - unset($opt['mk']['i']); - unset($opt['mk']['ri']); - unset($opt['mk']['ix']); - unset($opt['mk']['if']); - //$opt['mk']['if']['sw']; - //$opt['mk']['if']['s']; - //$opt['mk']['if']['a']; - //$opt['mk']['if']['fb']; - unset($opt['mk']['tp']); - //$opt['tu'] - //$opt['tm'] - //$opt['ff'] - //$opt['v'] - //$opt['dv'] - //$opt['a'] - //$opt['aa'] - //$opt['q'] - $this->Annotation($x, $y, $w, $h, $name, $opt, 0); - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - } - - /** - * Creates a RadioButton field. - * @param $name (string) Field name. - * @param $w (int) Width or the radio button. - * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference. - * @param $onvalue (string) Value to be returned if selected. - * @param $checked (boolean) Define the initial state. - * @param $x (float) Abscissa of the upper-left corner of the rectangle - * @param $y (float) Ordinate of the upper-left corner of the rectangle - * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered). - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($w, $x, $y); - if ($js) { - $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop); - return; - } - if ($this->empty_string($onvalue)) { - $onvalue = 'On'; - } - if ($checked) { - $defval = $onvalue; - } else { - $defval = 'Off'; - } - // set font - $font = 'zapfdingbats'; - $this->AddFont($font); - $tmpfont = $this->getFontBuffer($font); - // set data for parent group - if (!isset($this->radiobutton_groups[$this->page])) { - $this->radiobutton_groups[$this->page] = array(); - } - if (!isset($this->radiobutton_groups[$this->page][$name])) { - $this->radiobutton_groups[$this->page][$name] = array(); - ++$this->n; - $this->radiobutton_groups[$this->page][$name]['n'] = $this->n; - $this->radio_groups[] = $this->n; - } - $kid = ($this->n + 1); - // save object ID to be added on Kids entry on parent object - $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval); - // get default style - $prop = array_merge($this->getFormDefaultProp(), $prop); - $prop['NoToggleToOff'] = 'true'; - $prop['Radio'] = 'true'; - $prop['borderStyle'] = 'inset'; - // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); - // set additional default options - $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i']; - $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor); - $popt['da'] = $fontstyle; - // build appearance stream - $popt['ap'] = array(); - $popt['ap']['n'] = array(); - $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k); - $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(108).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); - $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(109).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); - if (!isset($popt['mk'])) { - $popt['mk'] = array(); - } - $popt['mk']['ca'] = '(l)'; - // merge options - $opt = array_merge($popt, $opt); - // set remaining annotation data - $opt['Subtype'] = 'Widget'; - $opt['ft'] = 'Btn'; - if ($checked) { - $opt['v'] = array('/'.$onvalue); - $opt['as'] = $onvalue; - } else { - $opt['as'] = 'Off'; - } - // store readonly flag - if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) { - $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false; - } - $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64); - $this->Annotation($x, $y, $w, $w, $name, $opt, 0); - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - } - - /** - * Creates a List-box field - * @param $name (string) field name - * @param $w (int) width - * @param $h (int) height - * @param $values (array) array containing the list of values. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference. - * @param $x (float) Abscissa of the upper-left corner of the rectangle - * @param $y (float) Ordinate of the upper-left corner of the rectangle - * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered). - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - if ($js) { - $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop); - $s = ''; - foreach ($values as $value) { - $s .= '\''.addslashes($value).'\','; - } - $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n"; - return; - } - // get default style - $prop = array_merge($this->getFormDefaultProp(), $prop); - // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); - // set additional default values - $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; - $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); - $popt['da'] = $fontstyle; - // build appearance stream - $popt['ap'] = array(); - $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' '; - $text = ''; - foreach($values as $item) { - $text .= $item."\n"; - } - $tmpid = $this->startTemplate($w, $h, false); - $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false); - $this->endTemplate(); - --$this->n; - $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata']; - unset($this->xobjects[$tmpid]); - $popt['ap']['n'] .= 'Q EMC'; - // merge options - $opt = array_merge($popt, $opt); - // set remaining annotation data - $opt['Subtype'] = 'Widget'; - $opt['ft'] = 'Ch'; - $opt['t'] = $name; - $opt['opt'] = $values; - unset($opt['mk']['ca']); - unset($opt['mk']['rc']); - unset($opt['mk']['ac']); - unset($opt['mk']['i']); - unset($opt['mk']['ri']); - unset($opt['mk']['ix']); - unset($opt['mk']['if']); - unset($opt['mk']['tp']); - $this->Annotation($x, $y, $w, $h, $name, $opt, 0); - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - } - - /** - * Creates a Combo-box field - * @param $name (string) field name - * @param $w (int) width - * @param $h (int) height - * @param $values (array) array containing the list of values. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference. - * @param $x (float) Abscissa of the upper-left corner of the rectangle - * @param $y (float) Ordinate of the upper-left corner of the rectangle - * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered). - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - if ($js) { - $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop); - $s = ''; - foreach ($values as $value) { - $s .= "'".addslashes($value)."',"; - } - $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n"; - return; - } - // get default style - $prop = array_merge($this->getFormDefaultProp(), $prop); - $prop['Combo'] = true; - // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); - // set additional default options - $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; - $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); - $popt['da'] = $fontstyle; - // build appearance stream - $popt['ap'] = array(); - $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' '; - $text = ''; - foreach($values as $item) { - $text .= $item[1]."\n"; - } - $tmpid = $this->startTemplate($w, $h, false); - $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false); - $this->endTemplate(); - --$this->n; - $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata']; - unset($this->xobjects[$tmpid]); - $popt['ap']['n'] .= 'Q EMC'; - // merge options - $opt = array_merge($popt, $opt); - // set remaining annotation data - $opt['Subtype'] = 'Widget'; - $opt['ft'] = 'Ch'; - $opt['t'] = $name; - $opt['opt'] = $values; - unset($opt['mk']['ca']); - unset($opt['mk']['rc']); - unset($opt['mk']['ac']); - unset($opt['mk']['i']); - unset($opt['mk']['ri']); - unset($opt['mk']['ix']); - unset($opt['mk']['if']); - unset($opt['mk']['tp']); - $this->Annotation($x, $y, $w, $h, $name, $opt, 0); - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - } - - /** - * Creates a CheckBox field - * @param $name (string) field name - * @param $w (int) width - * @param $checked (boolean) define the initial state. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference. - * @param $onvalue (string) value to be returned if selected. - * @param $x (float) Abscissa of the upper-left corner of the rectangle - * @param $y (float) Ordinate of the upper-left corner of the rectangle - * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered). - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($w, $x, $y); - if ($js) { - $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop); - return; - } - if (!isset($prop['value'])) { - $prop['value'] = array('Yes'); - } - // get default style - $prop = array_merge($this->getFormDefaultProp(), $prop); - $prop['borderStyle'] = 'inset'; - // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); - // set additional default options - $font = 'zapfdingbats'; - $this->AddFont($font); - $tmpfont = $this->getFontBuffer($font); - $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i']; - $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor); - $popt['da'] = $fontstyle; - // build appearance stream - $popt['ap'] = array(); - $popt['ap']['n'] = array(); - $fy = ((($tmpfont['desc']['Ascent'] + $tmpfont['desc']['Descent']) * $this->FontSizePt) / (1000 * $this->k)); - $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k); - $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(110).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); - $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %.2F Tf %.2F %.2F Td ('.chr(111).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); - // merge options - $opt = array_merge($popt, $opt); - // set remaining annotation data - $opt['Subtype'] = 'Widget'; - $opt['ft'] = 'Btn'; - $opt['t'] = $name; - $opt['opt'] = array($onvalue); - if ($checked) { - $opt['v'] = array('/Yes'); - $opt['as'] = 'Yes'; - } else { - $opt['v'] = array('/Off'); - $opt['as'] = 'Off'; - } - $this->Annotation($x, $y, $w, $w, $name, $opt, 0); - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - } - - /** - * Creates a button field - * @param $name (string) field name - * @param $w (int) width - * @param $h (int) height - * @param $caption (string) caption. - * @param $action (mixed) action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference. - * @param $x (float) Abscissa of the upper-left corner of the rectangle - * @param $y (float) Ordinate of the upper-left corner of the rectangle - * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered). - * @public - * @author Nicola Asuni - * @since 4.8.000 (2009-09-07) - */ - public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) { - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - if ($js) { - $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop); - $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n"; - $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n"; - $this->javascript .= 'f'.$name.".highlight='push';\n"; - $this->javascript .= 'f'.$name.".print=false;\n"; - return; - } - // get default style - $prop = array_merge($this->getFormDefaultProp(), $prop); - $prop['Pushbutton'] = 'true'; - $prop['highlight'] = 'push'; - $prop['display'] = 'display.noPrint'; - // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); - $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; - $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); - $popt['da'] = $fontstyle; - // build appearance stream - $popt['ap'] = array(); - $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' '; - $tmpid = $this->startTemplate($w, $h, false); - $bw = (2 / $this->k); // border width - $border = array( - 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)), - 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)), - 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)), - 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51))); - $this->SetFillColor(204); - $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M'); - $this->endTemplate(); - --$this->n; - $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata']; - unset($this->xobjects[$tmpid]); - $popt['ap']['n'] .= 'Q EMC'; - // set additional default options - if (!isset($popt['mk'])) { - $popt['mk'] = array(); - } - $ann_obj_id = ($this->n + 1); - if (!empty($action) AND !is_array($action)) { - $ann_obj_id = ($this->n + 2); - } - $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id); - $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id); - $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id); - // merge options - $opt = array_merge($popt, $opt); - // set remaining annotation data - $opt['Subtype'] = 'Widget'; - $opt['ft'] = 'Btn'; - $opt['t'] = $caption; - $opt['v'] = $name; - if (!empty($action)) { - if (is_array($action)) { - // form action options as on section 12.7.5 of PDF32000_2008. - $opt['aa'] = '/D <<'; - $bmode = array('SubmitForm', 'ResetForm', 'ImportData'); - foreach ($action AS $key => $val) { - if (($key == 'S') AND in_array($val, $bmode)) { - $opt['aa'] .= ' /S /'.$val; - } elseif (($key == 'F') AND (!empty($val))) { - $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id); - } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) { - $opt['aa'] .= ' /Fields ['; - foreach ($val AS $field) { - $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id); - } - $opt['aa'] .= ']'; - } elseif (($key == 'Flags')) { - $ff = 0; - if (is_array($val)) { - foreach ($val AS $flag) { - switch ($flag) { - case 'Include/Exclude': { - $ff += 1 << 0; - break; - } - case 'IncludeNoValueFields': { - $ff += 1 << 1; - break; - } - case 'ExportFormat': { - $ff += 1 << 2; - break; - } - case 'GetMethod': { - $ff += 1 << 3; - break; - } - case 'SubmitCoordinates': { - $ff += 1 << 4; - break; - } - case 'XFDF': { - $ff += 1 << 5; - break; - } - case 'IncludeAppendSaves': { - $ff += 1 << 6; - break; - } - case 'IncludeAnnotations': { - $ff += 1 << 7; - break; - } - case 'SubmitPDF': { - $ff += 1 << 8; - break; - } - case 'CanonicalFormat': { - $ff += 1 << 9; - break; - } - case 'ExclNonUserAnnots': { - $ff += 1 << 10; - break; - } - case 'ExclFKey': { - $ff += 1 << 11; - break; - } - case 'EmbedForm': { - $ff += 1 << 13; - break; - } - } - } - } else { - $ff = intval($val); - } - $opt['aa'] .= ' /Flags '.$ff; - } - } - $opt['aa'] .= ' >>'; - } else { - // Javascript action or raw action command - $js_obj_id = $this->addJavascriptObject($action); - $opt['aa'] = '/D '.$js_obj_id.' 0 R'; - } - } - $this->Annotation($x, $y, $w, $h, $name, $opt, 0); - if ($this->rtl) { - $this->x -= $w; - } else { - $this->x += $w; - } - } - - // --- END FORMS FIELDS ------------------------------------------------ - /** * Add certification signature (DocMDP or UR3) * You can set only one signature type @@ -17464,208 +13166,7 @@ class TCPDF { * @since 4.6.008 (2009-05-07) */ protected function _putsignature() { - if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) { - return; - } - $sigobjid = ($this->sig_obj_id + 1); - $out = $this->_getobj($sigobjid)."\n"; - $out .= '<< /Type /Sig'; - $out .= ' /Filter /Adobe.PPKLite'; - $out .= ' /SubFilter /adbe.pkcs7.detached'; - $out .= ' '.$this->byterange_string; - $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>'; - $out .= ' /Reference ['; // array of signature reference dictionaries - $out .= ' << /Type /SigRef'; - if ($this->signature_data['cert_type'] > 0) { - $out .= ' /TransformMethod /DocMDP'; - $out .= ' /TransformParams <<'; - $out .= ' /Type /TransformParams'; - $out .= ' /P '.$this->signature_data['cert_type']; - $out .= ' /V /1.2'; - } else { - $out .= ' /TransformMethod /UR3'; - $out .= ' /TransformParams <<'; - $out .= ' /Type /TransformParams'; - $out .= ' /V /2.2'; - if (!$this->empty_string($this->ur['document'])) { - $out .= ' /Document['.$this->ur['document'].']'; - } - if (!$this->empty_string($this->ur['form'])) { - $out .= ' /Form['.$this->ur['form'].']'; - } - if (!$this->empty_string($this->ur['signature'])) { - $out .= ' /Signature['.$this->ur['signature'].']'; - } - if (!$this->empty_string($this->ur['annots'])) { - $out .= ' /Annots['.$this->ur['annots'].']'; - } - if (!$this->empty_string($this->ur['ef'])) { - $out .= ' /EF['.$this->ur['ef'].']'; - } - if (!$this->empty_string($this->ur['formex'])) { - $out .= ' /FormEX['.$this->ur['formex'].']'; - } - } - $out .= ' >>'; // close TransformParams - // optional digest data (values must be calculated and replaced later) - //$out .= ' /Data ********** 0 R'; - //$out .= ' /DigestMethod/MD5'; - //$out .= ' /DigestLocation[********** 34]'; - //$out .= ' /DigestValue<********************************>'; - $out .= ' >>'; - $out .= ' ]'; // end of reference - if (isset($this->signature_data['info']['Name']) AND !$this->empty_string($this->signature_data['info']['Name'])) { - $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid); - } - if (isset($this->signature_data['info']['Location']) AND !$this->empty_string($this->signature_data['info']['Location'])) { - $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid); - } - if (isset($this->signature_data['info']['Reason']) AND !$this->empty_string($this->signature_data['info']['Reason'])) { - $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid); - } - if (isset($this->signature_data['info']['ContactInfo']) AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) { - $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid); - } - $out .= ' /M '.$this->_datestring($sigobjid); - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - } - - /** - * Set User's Rights for PDF Reader - * WARNING: This is experimental and currently do not work. - * Check the PDF Reference 8.7.1 Transform Methods, - * Table 8.105 Entries in the UR transform parameters dictionary - * @param $enable (boolean) if true enable user's rights on PDF reader - * @param $document (string) Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data. - * @param $annots (string) Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations. - * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate - * @param $signature (string) Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field. - * @param $ef (string) Names specifying additional usage rights for named embedded files in the document. Valid names are /Create/Delete/Modify/Import, which permit the user to perform the named operation on named embedded files - Names specifying additional embedded-files-related usage rights for the document. - * @param $formex (string) Names specifying additional form-field-related usage rights. The only valid name is BarcodePlaintext, which permits text form field data to be encoded as a plaintext two-dimensional barcode. - * @public - * @author Nicola Asuni - * @since 2.9.000 (2008-03-26) - */ - public function setUserRights( - $enable=true, - $document='/FullSave', - $annots='/Create/Delete/Modify/Copy/Import/Export', - $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate', - $signature='/Modify', - $ef='/Create/Delete/Modify/Import', - $formex='') { - $this->ur['enabled'] = $enable; - $this->ur['document'] = $document; - $this->ur['annots'] = $annots; - $this->ur['form'] = $form; - $this->ur['signature'] = $signature; - $this->ur['ef'] = $ef; - $this->ur['formex'] = $formex; - if (!$this->sign) { - $this->setSignature('', '', '', '', 0, array()); - } - } - - /** - * Enable document signature (requires the OpenSSL Library). - * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader. - * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt - * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12 - * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes - * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://') - * @param $private_key (mixed) private key (string or filename prefixed with 'file://') - * @param $private_key_password (string) password - * @param $extracerts (string) specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used. - * @param $cert_type (int) The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature. - * @param $info (array) array of option information: Name, Location, Reason, ContactInfo. - * @public - * @author Nicola Asuni - * @since 4.6.005 (2009-04-24) - */ - public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) { - // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt - // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12 - // to convert pfx certificate to pem: openssl - // OpenSSL> pkcs12 -in -out -nodes - $this->sign = true; - ++$this->n; - $this->sig_obj_id = $this->n; // signature widget - ++$this->n; // signature object ($this->sig_obj_id + 1) - $this->signature_data = array(); - if (strlen($signing_cert) == 0) { - $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.crt'; - $private_key_password = 'tcpdfdemo'; - } - if (strlen($private_key) == 0) { - $private_key = $signing_cert; - } - $this->signature_data['signcert'] = $signing_cert; - $this->signature_data['privkey'] = $private_key; - $this->signature_data['password'] = $private_key_password; - $this->signature_data['extracerts'] = $extracerts; - $this->signature_data['cert_type'] = $cert_type; - $this->signature_data['info'] = $info; - } - - /** - * Set the digital signature appearance (a cliccable rectangle area to get signature properties) - * @param $x (float) Abscissa of the upper-left corner. - * @param $y (float) Ordinate of the upper-left corner. - * @param $w (float) Width of the signature area. - * @param $h (float) Height of the signature area. - * @param $page (int) option page number (if < 0 the current page is used). - * @public - * @author Nicola Asuni - * @since 5.3.011 (2010-06-17) - */ - public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) { - $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page); - } - - /** - * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties) - * @param $x (float) Abscissa of the upper-left corner. - * @param $y (float) Ordinate of the upper-left corner. - * @param $w (float) Width of the signature area. - * @param $h (float) Height of the signature area. - * @param $page (int) option page number (if < 0 the current page is used). - * @public - * @author Nicola Asuni - * @since 5.9.101 (2011-07-06) - */ - public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) { - ++$this->n; - $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page); - } - - /** - * Get the array that defines the signature appearance (page and rectangle coordinates). - * @param $x (float) Abscissa of the upper-left corner. - * @param $y (float) Ordinate of the upper-left corner. - * @param $w (float) Width of the signature area. - * @param $h (float) Height of the signature area. - * @param $page (int) option page number (if < 0 the current page is used). - * @return (array) Array defining page and rectangle coordinates of signature appearance. - * @protected - * @author Nicola Asuni - * @since 5.9.101 (2011-07-06) - */ - protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1) { - $sigapp = array(); - if (($page < 1) OR ($page > $this->numpages)) { - $sigapp['page'] = $this->page; - } else { - $sigapp['page'] = intval($page); - } - $a = $x * $this->k; - $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k); - $c = $w * $this->k; - $d = $h * $this->k; - $sigapp['rect'] = sprintf('%.2F %.2F %.2F %.2F', $a, $b, ($a + $c), ($b + $d)); - return $sigapp; + return; } /** @@ -17821,18 +13322,6 @@ class TCPDF { return number_format((float)$num, 0, '', '.'); } - /** - * Format the page numbers on the Table Of Content. - * This method can be overriden for custom formats. - * @param $num (int) page number - * @protected - * @since 4.5.001 (2009-01-04) - * @see addTOC(), addHTMLTOC() - */ - protected function formatTOCPageNumber($num) { - return number_format((float)$num, 0, '', '.'); - } - /** * Returns the current page number formatted as a string. * @public @@ -17929,76 +13418,7 @@ class TCPDF { } } - /** - * Add transparency parameters to the current extgstate - * @param $parms (array) parameters - * @return the number of extgstates - * @protected - * @since 3.0.000 (2008-03-27) - */ - protected function addExtGState($parms) { - if ($this->pdfa_mode) { - // transparencies are not allowed in PDF/A mode - return; - } - // check if this ExtGState already exist - foreach ($this->extgstates as $i => $ext) { - if ($ext['parms'] == $parms) { - if ($this->inxobj) { - // we are inside an XObject template - $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext; - } - // return reference to existing ExtGState - return $i; - } - } - $n = (count($this->extgstates) + 1); - $this->extgstates[$n] = array('parms' => $parms); - if ($this->inxobj) { - // we are inside an XObject template - $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n]; - } - return $n; - } - /** - * Add an extgstate - * @param $gs (array) extgstate - * @protected - * @since 3.0.000 (2008-03-27) - */ - protected function setExtGState($gs) { - if ($this->pdfa_mode) { - // transparency is not allowed in PDF/A mode - return; - } - $this->_out(sprintf('/GS%d gs', $gs)); - } - - /** - * Put extgstates for object transparency - * @protected - * @since 3.0.000 (2008-03-27) - */ - protected function _putextgstates() { - if ($this->pdfa_mode) { - // transparencies are not allowed in PDF/A mode - return; - } - foreach ($this->extgstates as $i => $ext) { - $this->extgstates[$i]['n'] = $this->_newobj(); - $out = '<< /Type /ExtGState'; - foreach ($ext['parms'] as $k => $v) { - if (is_float($v)) { - $v = sprintf('%.2F', $v); - } - $out .= ' /'.$k.' '.$v; - } - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - } - } /** * Set alpha for stroking (CA) and non-stroking (ca) operations. @@ -18073,487 +13493,6 @@ class TCPDF { } } - /** - * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print. - * (see Section 8.1 of PDF reference, "Viewer Preferences"). - *
  • HideToolbar boolean (Optional) A flag specifying whether to hide the viewer application's tool bars when the document is active. Default value: false.
  • HideMenubar boolean (Optional) A flag specifying whether to hide the viewer application's menu bar when the document is active. Default value: false.
  • HideWindowUI boolean (Optional) A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed. Default value: false.
  • FitWindow boolean (Optional) A flag specifying whether to resize the document's window to fit the size of the first displayed page. Default value: false.
  • CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.
  • DisplayDocTitle boolean (Optional; PDF 1.4) A flag specifying whether the window's title bar should display the document title taken from the Title entry of the document information dictionary (see Section 10.2.1, "Document Information Dictionary"). If false, the title bar should instead display the name of the PDF file containing the document. Default value: false.
  • NonFullScreenPageMode name (Optional) The document's page mode, specifying how to display the document on exiting full-screen mode:
    • UseNone Neither document outline nor thumbnail images visible
    • UseOutlines Document outline visible
    • UseThumbs Thumbnail images visible
    • UseOC Optional content group panel visible
    This entry is meaningful only if the value of the PageMode entry in the catalog dictionary (see Section 3.6.1, "Document Catalog") is FullScreen; it is ignored otherwise. Default value: UseNone.
  • ViewArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be displayed when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:
    • MediaBox
    • CropBox (default)
    • BleedBox
    • TrimBox
    • ArtBox
  • ViewClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:
    • MediaBox
    • CropBox (default)
    • BleedBox
    • TrimBox
    • ArtBox
  • PrintArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be rendered when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:
    • MediaBox
    • CropBox (default)
    • BleedBox
    • TrimBox
    • ArtBox
  • PrintClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:
    • MediaBox
    • CropBox (default)
    • BleedBox
    • TrimBox
    • ArtBox
  • PrintScaling name (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document. Valid values are:
    • None, which indicates that the print dialog should reflect no page scaling
    • AppDefault (default), which indicates that applications should use the current print scaling
  • Duplex name (Optional; PDF 1.7) The paper handling option to use when printing the file from the print dialog. The following values are valid:
    • Simplex - Print single-sided
    • DuplexFlipShortEdge - Duplex and flip on the short edge of the sheet
    • DuplexFlipLongEdge - Duplex and flip on the long edge of the sheet
    Default value: none
  • PickTrayByPDFSize boolean (Optional; PDF 1.7) A flag specifying whether the PDF page size is used to select the input paper tray. This setting influences only the preset values used to populate the print dialog presented by a PDF viewer application. If PickTrayByPDFSize is true, the check box in the print dialog associated with input paper tray is checked. Note: This setting has no effect on Mac OS systems, which do not provide the ability to pick the input tray by size.
  • PrintPageRange array (Optional; PDF 1.7) The page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 1. Each pair consists of the first and last pages in the sub-range. An odd number of integers causes this entry to be ignored. Negative numbers cause the entire array to be ignored. Default value: as defined by PDF viewer application
  • NumCopies integer (Optional; PDF 1.7) The number of copies to be printed when the print dialog is opened for this file. Supported values are the integers 2 through 5. Values outside this range are ignored. Default value: as defined by PDF viewer application, but typically 1
- * @param $preferences (array) array of options. - * @author Nicola Asuni - * @public - * @since 3.1.000 (2008-06-09) - */ - public function setViewerPreferences($preferences) { - $this->viewer_preferences = $preferences; - } - - /** - * Paints color transition registration bars - * @param $x (float) abscissa of the top left corner of the rectangle. - * @param $y (float) ordinate of the top left corner of the rectangle. - * @param $w (float) width of the rectangle. - * @param $h (float) height of the rectangle. - * @param $transition (boolean) if true prints tcolor transitions to white. - * @param $vertical (boolean) if true prints bar vertically. - * @param $colors (string) colors to print, one letter per color separated by comma (for example 'A,W,R,G,B,C,M,Y,K'): A=black, W=white, R=red, G=green, B=blue, C=cyan, M=magenta, Y=yellow, K=black. - * @author Nicola Asuni - * @since 4.9.000 (2010-03-26) - * @public - */ - public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') { - $bars = explode(',', $colors); - $numbars = count($bars); // number of bars to print - // set bar measures - if ($vertical) { - $coords = array(0, 0, 0, 1); - $wb = $w / $numbars; // bar width - $hb = $h; // bar height - $xd = $wb; // delta x - $yd = 0; // delta y - } else { - $coords = array(1, 0, 0, 0); - $wb = $w; // bar width - $hb = $h / $numbars; // bar height - $xd = 0; // delta x - $yd = $hb; // delta y - } - $xb = $x; - $yb = $y; - foreach ($bars as $col) { - switch ($col) { - // set transition colors - case 'A': { // BLACK - $col_a = array(255); - $col_b = array(0); - break; - } - case 'W': { // WHITE - $col_a = array(0); - $col_b = array(255); - break; - } - case 'R': { // R - $col_a = array(255,255,255); - $col_b = array(255,0,0); - break; - } - case 'G': { // G - $col_a = array(255,255,255); - $col_b = array(0,255,0); - break; - } - case 'B': { // B - $col_a = array(255,255,255); - $col_b = array(0,0,255); - break; - } - case 'C': { // C - $col_a = array(0,0,0,0); - $col_b = array(100,0,0,0); - break; - } - case 'M': { // M - $col_a = array(0,0,0,0); - $col_b = array(0,100,0,0); - break; - } - case 'Y': { // Y - $col_a = array(0,0,0,0); - $col_b = array(0,0,100,0); - break; - } - case 'K': { // K - $col_a = array(0,0,0,0); - $col_b = array(0,0,0,100); - break; - } - default: { // GRAY - $col_a = array(255); - $col_b = array(0); - break; - } - } - if ($transition) { - // color gradient - $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords); - } else { - // color rectangle - $this->SetFillColorArray($col_b); - $this->Rect($xb, $yb, $wb, $hb, 'F', array()); - } - $xb += $xd; - $yb += $yd; - } - } - - /** - * Paints crop mark - * @param $x (float) abscissa of the crop mark center. - * @param $y (float) ordinate of the crop mark center. - * @param $w (float) width of the crop mark. - * @param $h (float) height of the crop mark. - * @param $type (string) type of crop mark, one sybol per type separated by comma: A = top left, B = top right, C = bottom left, D = bottom right. - * @param $color (array) crop mark color (default black). - * @author Nicola Asuni - * @since 4.9.000 (2010-03-26) - * @public - */ - public function cropMark($x, $y, $w, $h, $type='A,B,C,D', $color=array(0,0,0)) { - $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color)); - $crops = explode(',', $type); - $numcrops = count($crops); // number of crop marks to print - $dw = $w / 4; // horizontal space to leave before the intersection point - $dh = $h / 4; // vertical space to leave before the intersection point - foreach ($crops as $crop) { - switch ($crop) { - case 'A': { - $x1 = $x; - $y1 = $y - $h; - $x2 = $x; - $y2 = $y - $dh; - $x3 = $x - $w; - $y3 = $y; - $x4 = $x - $dw; - $y4 = $y; - break; - } - case 'B': { - $x1 = $x; - $y1 = $y - $h; - $x2 = $x; - $y2 = $y - $dh; - $x3 = $x + $dw; - $y3 = $y; - $x4 = $x + $w; - $y4 = $y; - break; - } - case 'C': { - $x1 = $x - $w; - $y1 = $y; - $x2 = $x - $dw; - $y2 = $y; - $x3 = $x; - $y3 = $y + $dh; - $x4 = $x; - $y4 = $y + $h; - break; - } - case 'D': { - $x1 = $x + $dw; - $y1 = $y; - $x2 = $x + $w; - $y2 = $y; - $x3 = $x; - $y3 = $y + $dh; - $x4 = $x; - $y4 = $y + $h; - break; - } - } - $this->Line($x1, $y1, $x2, $y2); - $this->Line($x3, $y3, $x4, $y4); - } - } - - /** - * Paints a registration mark - * @param $x (float) abscissa of the registration mark center. - * @param $y (float) ordinate of the registration mark center. - * @param $r (float) radius of the crop mark. - * @param $double (boolean) if true print two concentric crop marks. - * @param $cola (array) crop mark color (default black). - * @param $colb (array) second crop mark color. - * @author Nicola Asuni - * @since 4.9.000 (2010-03-26) - * @public - */ - public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) { - $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola); - $this->SetFillColorArray($cola); - $this->PieSector($x, $y, $r, 90, 180, 'F'); - $this->PieSector($x, $y, $r, 270, 360, 'F'); - $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8); - if ($double) { - $r2 = $r * 0.5; - $this->SetFillColorArray($colb); - $this->PieSector($x, $y, $r2, 90, 180, 'F'); - $this->PieSector($x, $y, $r2, 270, 360, 'F'); - $this->SetFillColorArray($cola); - $this->PieSector($x, $y, $r2, 0, 90, 'F'); - $this->PieSector($x, $y, $r2, 180, 270, 'F'); - $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8); - } - } - - /** - * Paints a linear colour gradient. - * @param $x (float) abscissa of the top left corner of the rectangle. - * @param $y (float) ordinate of the top left corner of the rectangle. - * @param $w (float) width of the rectangle. - * @param $h (float) height of the rectangle. - * @param $col1 (array) first color (Grayscale, RGB or CMYK components). - * @param $col2 (array) second color (Grayscale, RGB or CMYK components). - * @param $coords (array) array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0). - * @author Andreas Würmser, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) { - $this->Clip($x, $y, $w, $h); - $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false); - } - - /** - * Paints a radial colour gradient. - * @param $x (float) abscissa of the top left corner of the rectangle. - * @param $y (float) ordinate of the top left corner of the rectangle. - * @param $w (float) width of the rectangle. - * @param $h (float) height of the rectangle. - * @param $col1 (array) first color (Grayscale, RGB or CMYK components). - * @param $col2 (array) second color (Grayscale, RGB or CMYK components). - * @param $coords (array) array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined. - * @author Andreas Würmser, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) { - $this->Clip($x, $y, $w, $h); - $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false); - } - - /** - * Paints a coons patch mesh. - * @param $x (float) abscissa of the top left corner of the rectangle. - * @param $y (float) ordinate of the top left corner of the rectangle. - * @param $w (float) width of the rectangle. - * @param $h (float) height of the rectangle. - * @param $col1 (array) first color (lower left corner) (RGB components). - * @param $col2 (array) second color (lower right corner) (RGB components). - * @param $col3 (array) third color (upper right corner) (RGB components). - * @param $col4 (array) fourth color (upper left corner) (RGB components). - * @param $coords (array)
  • for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).
  • for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches
- * @param $coords_min (array) minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0 - * @param $coords_max (array) maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1 - * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts. - * @author Andreas Würmser, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function CoonsPatchMesh($x, $y, $w, $h, $col1=array(), $col2=array(), $col3=array(), $col4=array(), $coords=array(0.00,0.0,0.33,0.00,0.67,0.00,1.00,0.00,1.00,0.33,1.00,0.67,1.00,1.00,0.67,1.00,0.33,1.00,0.00,1.00,0.00,0.67,0.00,0.33), $coords_min=0, $coords_max=1, $antialias=false) { - if ($this->pdfa_mode) { - return; - } - $this->Clip($x, $y, $w, $h); - $n = count($this->gradients) + 1; - $this->gradients[$n] = array(); - $this->gradients[$n]['type'] = 6; //coons patch mesh - $this->gradients[$n]['coords'] = array(); - $this->gradients[$n]['antialias'] = $antialias; - $this->gradients[$n]['colors'] = array(); - $this->gradients[$n]['transparency'] = false; - //check the coords array if it is the simple array or the multi patch array - if (!isset($coords[0]['f'])) { - //simple array -> convert to multi patch array - if (!isset($col1[1])) { - $col1[1] = $col1[2] = $col1[0]; - } - if (!isset($col2[1])) { - $col2[1] = $col2[2] = $col2[0]; - } - if (!isset($col3[1])) { - $col3[1] = $col3[2] = $col3[0]; - } - if (!isset($col4[1])) { - $col4[1] = $col4[2] = $col4[0]; - } - $patch_array[0]['f'] = 0; - $patch_array[0]['points'] = $coords; - $patch_array[0]['colors'][0]['r'] = $col1[0]; - $patch_array[0]['colors'][0]['g'] = $col1[1]; - $patch_array[0]['colors'][0]['b'] = $col1[2]; - $patch_array[0]['colors'][1]['r'] = $col2[0]; - $patch_array[0]['colors'][1]['g'] = $col2[1]; - $patch_array[0]['colors'][1]['b'] = $col2[2]; - $patch_array[0]['colors'][2]['r'] = $col3[0]; - $patch_array[0]['colors'][2]['g'] = $col3[1]; - $patch_array[0]['colors'][2]['b'] = $col3[2]; - $patch_array[0]['colors'][3]['r'] = $col4[0]; - $patch_array[0]['colors'][3]['g'] = $col4[1]; - $patch_array[0]['colors'][3]['b'] = $col4[2]; - } else { - //multi patch array - $patch_array = $coords; - } - $bpcd = 65535; //16 bits per coordinate - //build the data stream - $this->gradients[$n]['stream'] = ''; - $count_patch = count($patch_array); - for ($i=0; $i < $count_patch; ++$i) { - $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit - $count_points = count($patch_array[$i]['points']); - for ($j=0; $j < $count_points; ++$j) { - //each point as 16 bit - $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd; - if ($patch_array[$i]['points'][$j] < 0) { - $patch_array[$i]['points'][$j] = 0; - } - if ($patch_array[$i]['points'][$j] > $bpcd) { - $patch_array[$i]['points'][$j] = $bpcd; - } - $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256)); - $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256)); - } - $count_cols = count($patch_array[$i]['colors']); - for ($j=0; $j < $count_cols; ++$j) { - //each color component as 8 bit - $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']); - $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']); - $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']); - } - } - //paint the gradient - $this->_out('/Sh'.$n.' sh'); - //restore previous Graphic State - $this->_out('Q'); - if ($this->inxobj) { - // we are inside an XObject template - $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n]; - } - } - - /** - * Set a rectangular clipping area. - * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode). - * @param $y (float) ordinate of the top left corner of the rectangle. - * @param $w (float) width of the rectangle. - * @param $h (float) height of the rectangle. - * @author Andreas Würmser, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @protected - */ - protected function Clip($x, $y, $w, $h) { - if ($this->rtl) { - $x = $this->w - $x - $w; - } - //save current Graphic State - $s = 'q'; - //set clipping area - $s .= sprintf(' %.2F %.2F %.2F %.2F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k); - //set up transformation matrix for gradient - $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k); - $this->_out($s); - } - - /** - * Output gradient. - * @param $type (int) type of gradient (1 Function-based shading; 2 Axial shading; 3 Radial shading; 4 Free-form Gouraud-shaded triangle mesh; 5 Lattice-form Gouraud-shaded triangle mesh; 6 Coons patch mesh; 7 Tensor-product patch mesh). (Not all types are currently supported) - * @param $coords (array) array of coordinates. - * @param $stops (array) array gradient color components: color = array of GRAY, RGB or CMYK color components; offset = (0 to 1) represents a location along the gradient vector; exponent = exponent of the exponential interpolation function (default = 1). - * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value. - * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts. - * @author Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) { - if ($this->pdfa_mode) { - return; - } - $n = count($this->gradients) + 1; - $this->gradients[$n] = array(); - $this->gradients[$n]['type'] = $type; - $this->gradients[$n]['coords'] = $coords; - $this->gradients[$n]['antialias'] = $antialias; - $this->gradients[$n]['colors'] = array(); - $this->gradients[$n]['transparency'] = false; - // color space - $numcolspace = count($stops[0]['color']); - $bcolor = array_values($background); - switch($numcolspace) { - case 4: { // CMYK - $this->gradients[$n]['colspace'] = 'DeviceCMYK'; - if (!empty($background)) { - $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F %.3F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100); - } - break; - } - case 3: { // RGB - $this->gradients[$n]['colspace'] = 'DeviceRGB'; - if (!empty($background)) { - $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255); - } - break; - } - case 1: { // Gray scale - $this->gradients[$n]['colspace'] = 'DeviceGray'; - if (!empty($background)) { - $this->gradients[$n]['background'] = sprintf('%.3F', $bcolor[0]/255); - } - break; - } - } - $num_stops = count($stops); - $last_stop_id = $num_stops - 1; - foreach ($stops as $key => $stop) { - $this->gradients[$n]['colors'][$key] = array(); - // offset represents a location along the gradient vector - if (isset($stop['offset'])) { - $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset']; - } else { - if ($key == 0) { - $this->gradients[$n]['colors'][$key]['offset'] = 0; - } elseif ($key == $last_stop_id) { - $this->gradients[$n]['colors'][$key]['offset'] = 1; - } else { - $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key); - $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep; - } - } - if (isset($stop['opacity'])) { - $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity']; - if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) { - $this->gradients[$n]['transparency'] = true; - } - } else { - $this->gradients[$n]['colors'][$key]['opacity'] = 1; - } - // exponent for the exponential interpolation function - if (isset($stop['exponent'])) { - $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent']; - } else { - $this->gradients[$n]['colors'][$key]['exponent'] = 1; - } - // set colors - $color = array_values($stop['color']); - switch($numcolspace) { - case 4: { // CMYK - $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F %.3F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100); - break; - } - case 3: { // RGB - $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255); - break; - } - case 1: { // Gray scale - $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F', $color[0]/255); - break; - } - } - } - if ($this->gradients[$n]['transparency']) { - // paint luminosity gradient - $this->_out('/TGS'.$n.' gs'); - } - //paint the gradient - $this->_out('/Sh'.$n.' sh'); - //restore previous Graphic State - $this->_out('Q'); - if ($this->inxobj) { - // we are inside an XObject template - $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n]; - } - } - /** * Output gradient shaders. * @author Nicola Asuni @@ -18561,1193 +13500,9 @@ class TCPDF { * @protected */ function _putshaders() { - if ($this->pdfa_mode) { return; - } - $idt = count($this->gradients); //index for transparency gradients - foreach ($this->gradients as $id => $grad) { - if (($grad['type'] == 2) OR ($grad['type'] == 3)) { - $fc = $this->_newobj(); - $out = '<<'; - $out .= ' /FunctionType 3'; - $out .= ' /Domain [0 1]'; - $functions = ''; - $bounds = ''; - $encode = ''; - $i = 1; - $num_cols = count($grad['colors']); - $lastcols = $num_cols - 1; - for ($i = 1; $i < $num_cols; ++$i) { - $functions .= ($fc + $i).' 0 R '; - if ($i < $lastcols) { - $bounds .= sprintf('%.3F ', $grad['colors'][$i]['offset']); - } - $encode .= '0 1 '; - } - $out .= ' /Functions ['.trim($functions).']'; - $out .= ' /Bounds ['.trim($bounds).']'; - $out .= ' /Encode ['.trim($encode).']'; - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - for ($i = 1; $i < $num_cols; ++$i) { - $this->_newobj(); - $out = '<<'; - $out .= ' /FunctionType 2'; - $out .= ' /Domain [0 1]'; - $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']'; - $out .= ' /C1 ['.$grad['colors'][$i]['color'].']'; - $out .= ' /N '.$grad['colors'][$i]['exponent']; - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - } - // set transparency fuctions - if ($grad['transparency']) { - $ft = $this->_newobj(); - $out = '<<'; - $out .= ' /FunctionType 3'; - $out .= ' /Domain [0 1]'; - $functions = ''; - $i = 1; - $num_cols = count($grad['colors']); - for ($i = 1; $i < $num_cols; ++$i) { - $functions .= ($ft + $i).' 0 R '; - } - $out .= ' /Functions ['.trim($functions).']'; - $out .= ' /Bounds ['.trim($bounds).']'; - $out .= ' /Encode ['.trim($encode).']'; - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - for ($i = 1; $i < $num_cols; ++$i) { - $this->_newobj(); - $out = '<<'; - $out .= ' /FunctionType 2'; - $out .= ' /Domain [0 1]'; - $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']'; - $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']'; - $out .= ' /N '.$grad['colors'][$i]['exponent']; - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - } - } - } - // set shading object - $this->_newobj(); - $out = '<< /ShadingType '.$grad['type']; - if (isset($grad['colspace'])) { - $out .= ' /ColorSpace /'.$grad['colspace']; - } else { - $out .= ' /ColorSpace /DeviceRGB'; - } - if (isset($grad['background']) AND !empty($grad['background'])) { - $out .= ' /Background ['.$grad['background'].']'; - } - if (isset($grad['antialias']) AND ($grad['antialias'] === true)) { - $out .= ' /AntiAlias true'; - } - if ($grad['type'] == 2) { - $out .= ' '.sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]); - $out .= ' /Domain [0 1]'; - $out .= ' /Function '.$fc.' 0 R'; - $out .= ' /Extend [true true]'; - $out .= ' >>'; - } elseif ($grad['type'] == 3) { - //x0, y0, r0, x1, y1, r1 - //at this this time radius of inner circle is 0 - $out .= ' '.sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]); - $out .= ' /Domain [0 1]'; - $out .= ' /Function '.$fc.' 0 R'; - $out .= ' /Extend [true true]'; - $out .= ' >>'; - } elseif ($grad['type'] == 6) { - $out .= ' /BitsPerCoordinate 16'; - $out .= ' /BitsPerComponent 8'; - $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]'; - $out .= ' /BitsPerFlag 8'; - $stream = $this->_getrawstream($grad['stream']); - $out .= ' /Length '.strlen($stream); - $out .= ' >>'; - $out .= ' stream'."\n".$stream."\n".'endstream'; - } - $out .= "\n".'endobj'; - $this->_out($out); - if ($grad['transparency']) { - $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out); - $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency); - } - $this->gradients[$id]['id'] = $this->n; - // set pattern object - $this->_newobj(); - $out = '<< /Type /Pattern /PatternType 2'; - $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R'; - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - $this->gradients[$id]['pattern'] = $this->n; - // set shading and pattern for transparency mask - if ($grad['transparency']) { - // luminosity pattern - $idgs = $id + $idt; - $this->_newobj(); - $this->_out($shading_transparency); - $this->gradients[$idgs]['id'] = $this->n; - $this->_newobj(); - $out = '<< /Type /Pattern /PatternType 2'; - $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R'; - $out .= ' >>'; - $out .= "\n".'endobj'; - $this->_out($out); - $this->gradients[$idgs]['pattern'] = $this->n; - // luminosity XObject - $oid = $this->_newobj(); - $this->xobjects['LX'.$oid] = array('n' => $oid); - $filter = ''; - $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q'; - if ($this->compress) { - $filter = ' /Filter /FlateDecode'; - $stream = gzcompress($stream); - } - $stream = $this->_getrawstream($stream); - $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter; - $out .= ' /Length '.strlen($stream); - $rect = sprintf('%.2F %.2F', $this->wPt, $this->hPt); - $out .= ' /BBox [0 0 '.$rect.']'; - $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>'; - $out .= ' /Resources <<'; - $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>'; - $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>'; - $out .= ' >>'; - $out .= ' >> '; - $out .= ' stream'."\n".$stream."\n".'endstream'; - $out .= "\n".'endobj'; - $this->_out($out); - // SMask - $this->_newobj(); - $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj'; - $this->_out($out); - // ExtGState - $this->_newobj(); - $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj'; - $this->_out($out); - $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id); - } - } } - /** - * Draw the sector of a circle. - * It can be used for instance to render pie charts. - * @param $xc (float) abscissa of the center. - * @param $yc (float) ordinate of the center. - * @param $r (float) radius. - * @param $a (float) start angle (in degrees). - * @param $b (float) end angle (in degrees). - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $cw: (float) indicates whether to go clockwise (default: true). - * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90. - * @author Maxime Delorme, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) { - $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o); - } - - /** - * Draw the sector of an ellipse. - * It can be used for instance to render pie charts. - * @param $xc (float) abscissa of the center. - * @param $yc (float) ordinate of the center. - * @param $rx (float) the x-axis radius. - * @param $ry (float) the y-axis radius. - * @param $a (float) start angle (in degrees). - * @param $b (float) end angle (in degrees). - * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. - * @param $cw: (float) indicates whether to go clockwise. - * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). - * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc. - * @author Maxime Delorme, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) { - if ($this->rtl) { - $xc = $this->w - $xc; - } - $op = $this->getPathPaintOperator($style); - if ($op == 'f') { - $line_style = array(); - } - if ($cw) { - $d = $b; - $b = 360 - $a + $o; - $a = 360 - $d + $o; - } else { - $b += $o; - $a += $o; - } - $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc); - $this->_out($op); - } - - /** - * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files. - * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library. - * Only vector drawing is supported, not text or bitmap. - * Although the script was successfully tested with various AI format versions, best results are probably achieved with files that were exported in the AI3 format (tested with Illustrator CS2, Freehand MX and Photoshop CS2). - * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string. - * @param $x (float) Abscissa of the upper-left corner. - * @param $y (float) Ordinate of the upper-left corner. - * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated. - * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated. - * @param $link (mixed) URL or identifier returned by AddLink(). - * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true. - * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:
  • T: top-right for LTR or top-left for RTL
  • M: middle-right for LTR or middle-left for RTL
  • B: bottom-right for LTR or bottom-left for RTL
  • N: next line
- * @param $palign (string) Allows to center or align the image on the current line. Possible values are:
  • L : left align
  • C : center
  • R : right align
  • '' : empty string : left for LTR or right for RTL
- * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:
  • 0: no border (default)
  • 1: frame
or a string containing some or all of the following characters (in any order):
  • L: left
  • T: top
  • R: right
  • B: bottom
or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) - * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions. - * @param $fixoutvals (boolean) if true remove values outside the bounding box. - * @author Valentin Schmidt, Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) { - if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) { - // convert EPS to raster image using GD or ImageMagick libraries - return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage); - } - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - $k = $this->k; - if ($file{0} === '@') { // image from string - $data = substr($file, 1); - } else { // EPS/AI file - $data = file_get_contents($file); - } - if ($data === false) { - $this->Error('EPS file not found: '.$file); - } - $regs = array(); - // EPS/AI compatibility check (only checks files created by Adobe Illustrator!) - preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator - if (count($regs) > 1) { - $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0" - if (strpos($version_str, 'Adobe Illustrator') !== false) { - $versexp = explode(' ', $version_str); - $version = (float)array_pop($versexp); - if ($version >= 9) { - $this->Error('This version of Adobe Illustrator file is not supported: '.$file); - } - } - } - // strip binary bytes in front of PS-header - $start = strpos($data, '%!PS-Adobe'); - if ($start > 0) { - $data = substr($data, $start); - } - // find BoundingBox params - preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs); - if (count($regs) > 1) { - list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1])); - } else { - $this->Error('No BoundingBox found in EPS/AI file: '.$file); - } - $start = strpos($data, '%%EndSetup'); - if ($start === false) { - $start = strpos($data, '%%EndProlog'); - } - if ($start === false) { - $start = strpos($data, '%%BoundingBox'); - } - $data = substr($data, $start); - $end = strpos($data, '%%PageTrailer'); - if ($end===false) { - $end = strpos($data, 'showpage'); - } - if ($end) { - $data = substr($data, 0, $end); - } - // calculate image width and height on document - if (($w <= 0) AND ($h <= 0)) { - $w = ($x2 - $x1) / $k; - $h = ($y2 - $y1) / $k; - } elseif ($w <= 0) { - $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k)); - } elseif ($h <= 0) { - $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k)); - } - // fit the image on available space - list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage); - if ($this->rasterize_vector_images) { - // convert EPS to raster image using GD or ImageMagick libraries - return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage); - } - // set scaling factors - $scale_x = $w / (($x2 - $x1) / $k); - $scale_y = $h / (($y2 - $y1) / $k); - // set alignment - $this->img_rb_y = $y + $h; - // set alignment - if ($this->rtl) { - if ($palign == 'L') { - $ximg = $this->lMargin; - } elseif ($palign == 'C') { - $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $ximg = $this->w - $this->rMargin - $w; - } else { - $ximg = $x - $w; - } - $this->img_rb_x = $ximg; - } else { - if ($palign == 'L') { - $ximg = $this->lMargin; - } elseif ($palign == 'C') { - $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $ximg = $this->w - $this->rMargin - $w; - } else { - $ximg = $x; - } - $this->img_rb_x = $ximg + $w; - } - if ($useBoundingBox) { - $dx = $ximg * $k - $x1; - $dy = $y * $k - $y1; - } else { - $dx = $ximg * $k; - $dy = $y * $k; - } - // save the current graphic state - $this->_out('q'.$this->epsmarker); - // translate - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1)))); - // scale - if (isset($scale_x)) { - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y))); - } - // handle pc/unix/mac line endings - $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY); - $u=0; - $cnt = count($lines); - for ($i=0; $i < $cnt; ++$i) { - $line = $lines[$i]; - if (($line == '') OR ($line{0} == '%')) { - continue; - } - $len = strlen($line); - // check for spot color names - $color_name = ''; - if (strcasecmp('x', substr(trim($line), -1)) == 0) { - if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) { - // extract spot color name - $color_name = $matches[0]; - // remove color name from string - $line = str_replace(' '.$color_name, '', $line); - // remove pharentesis from color name - $color_name = substr($color_name, 1, -1); - } - } - $chunks = explode(' ', $line); - $cmd = trim(array_pop($chunks)); - // RGB - if (($cmd == 'Xa') OR ($cmd == 'XA')) { - $b = array_pop($chunks); - $g = array_pop($chunks); - $r = array_pop($chunks); - $this->_out(''.$r.' '.$g.' '.$b.' '.($cmd=='Xa'?'rg':'RG')); //substr($line, 0, -2).'rg' -> in EPS (AI8): c m y k r g b rg! - continue; - } - $skip = false; - if ($fixoutvals) { - // check for values outside the bounding box - switch ($cmd) { - case 'm': - case 'l': - case 'L': { - // skip values outside bounding box - foreach ($chunks as $key => $val) { - if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) { - $skip = true; - } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) { - $skip = true; - } - } - } - } - } - switch ($cmd) { - case 'm': - case 'l': - case 'v': - case 'y': - case 'c': - case 'k': - case 'K': - case 'g': - case 'G': - case 's': - case 'S': - case 'J': - case 'j': - case 'w': - case 'M': - case 'd': - case 'n': { - if ($skip) { - break; - } - $this->_out($line); - break; - } - case 'x': {// custom fill color - if (empty($color_name)) { - // CMYK color - list($col_c, $col_m, $col_y, $col_k) = $chunks; - $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k'); - } else { - // Spot Color (CMYK + tint) - list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks; - $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100)); - $color_cmd = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t)); - $this->_out($color_cmd); - } - break; - } - case 'X': { // custom stroke color - if (empty($color_name)) { - // CMYK color - list($col_c, $col_m, $col_y, $col_k) = $chunks; - $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K'); - } else { - // Spot Color (CMYK + tint) - list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks; - $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100)); - $color_cmd = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t)); - $this->_out($color_cmd); - } - break; - } - case 'Y': - case 'N': - case 'V': - case 'L': - case 'C': { - if ($skip) { - break; - } - $line{$len-1} = strtolower($cmd); - $this->_out($line); - break; - } - case 'b': - case 'B': { - $this->_out($cmd . '*'); - break; - } - case 'f': - case 'F': { - if ($u > 0) { - $isU = false; - $max = min(($i + 5), $cnt); - for ($j = ($i + 1); $j < $max; ++$j) { - $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U'))); - } - if ($isU) { - $this->_out('f*'); - } - } else { - $this->_out('f*'); - } - break; - } - case '*u': { - ++$u; - break; - } - case '*U': { - --$u; - break; - } - } - } - // restore previous graphic state - $this->_out($this->epsmarker.'Q'); - if (!empty($border)) { - $bx = $this->x; - $by = $this->y; - $this->x = $ximg; - if ($this->rtl) { - $this->x += $w; - } - $this->y = $y; - $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true); - $this->x = $bx; - $this->y = $by; - } - if ($link) { - $this->Link($ximg, $y, $w, $h, $link, 0); - } - // set pointer to align the next text/objects - switch($align) { - case 'T':{ - $this->y = $y; - $this->x = $this->img_rb_x; - break; - } - case 'M':{ - $this->y = $y + round($h/2); - $this->x = $this->img_rb_x; - break; - } - case 'B':{ - $this->y = $this->img_rb_y; - $this->x = $this->img_rb_x; - break; - } - case 'N':{ - $this->SetY($this->img_rb_y); - break; - } - default:{ - break; - } - } - $this->endlinex = $this->img_rb_x; - } - - /** - * Set document barcode. - * @param $bc (string) barcode - * @public - */ - public function setBarcode($bc='') { - $this->barcode = $bc; - } - - /** - * Get current barcode. - * @return string - * @public - * @since 4.0.012 (2008-07-24) - */ - public function getBarcode() { - return $this->barcode; - } - - /** - * Print a Linear Barcode. - * @param $code (string) code to print - * @param $type (string) type of barcode (see barcodes.php for supported formats). - * @param $x (int) x position in user units (empty string = current x position) - * @param $y (int) y position in user units (empty string = current y position) - * @param $w (int) width in user units (empty string = remaining page width) - * @param $h (int) height in user units (empty string = remaining page height) - * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm) - * @param $style (array) array of options:
    - *
  • boolean $style['border'] if true prints a border
  • - *
  • int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)
  • - *
  • int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)
  • - *
  • int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)
  • - *
  • array $style['fgcolor'] color array for bars and text
  • - *
  • mixed $style['bgcolor'] color array for background (set to false for transparent)
  • - *
  • boolean $style['text'] if true prints text below the barcode
  • - *
  • string $style['label'] override default label
  • - *
  • string $style['font'] font name for text
  • int $style['fontsize'] font size for text
  • - *
  • int $style['stretchtext']: 0 = disabled; 1 = horizontal scaling only if necessary; 2 = forced horizontal scaling; 3 = character spacing only if necessary; 4 = forced character spacing.
  • - *
  • string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.
  • - *
  • string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.
  • - *
  • string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.
  • - *
  • string $style['fitwidth'] if true reduce the width to fit the barcode width + padding. When this option is enabled the 'stretch' option is automatically disabled.
  • - *
  • string $style['cellfitalign'] this option works only when 'fitwidth' is true and 'position' is unset or empty. Set the horizontal position of the containing barcode cell inside the specified rectangle: L = left; C = center; R = right.
- * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:
  • T: top-right for LTR or top-left for RTL
  • M: middle-right for LTR or middle-left for RTL
  • B: bottom-right for LTR or bottom-left for RTL
  • N: next line
- * @author Nicola Asuni - * @since 3.1.000 (2008-06-09) - * @public - */ - public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') { - if ($this->empty_string(trim($code))) { - return; - } - require_once(dirname(__FILE__).'/barcodes.php'); - // save current graphic settings - $gvars = $this->getGraphicVars(); - // create new barcode object - $barcodeobj = new TCPDFBarcode($code, $type); - $arrcode = $barcodeobj->getBarcodeArray(); - if ($arrcode === false) { - $this->Error('Error in 1D barcode string'); - } - // set default values - if (!isset($style['position'])) { - $style['position'] = ''; - } elseif ($style['position'] == 'S') { - // keep this for backward compatibility - $style['position'] = ''; - $style['stretch'] = true; - } - if (!isset($style['fitwidth'])) { - if (!isset($style['stretch'])) { - $style['fitwidth'] = true; - } else { - $style['fitwidth'] = false; - } - } - if ($style['fitwidth']) { - // disable stretch - $style['stretch'] = false; - } - if (!isset($style['stretch'])) { - if (($w === '') OR ($w <= 0)) { - $style['stretch'] = false; - } else { - $style['stretch'] = true; - } - } - if (!isset($style['fgcolor'])) { - $style['fgcolor'] = array(0,0,0); // default black - } - if (!isset($style['bgcolor'])) { - $style['bgcolor'] = false; // default transparent - } - if (!isset($style['border'])) { - $style['border'] = false; - } - $fontsize = 0; - if (!isset($style['text'])) { - $style['text'] = false; - } - if ($style['text'] AND isset($style['font'])) { - if (isset($style['fontsize'])) { - $fontsize = $style['fontsize']; - } - $this->SetFont($style['font'], '', $fontsize); - } - if (!isset($style['stretchtext'])) { - $style['stretchtext'] = 4; - } - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - if (($w === '') OR ($w <= 0)) { - if ($this->rtl) { - $w = $x - $this->lMargin; - } else { - $w = $this->w - $this->rMargin - $x; - } - } - // padding - if (!isset($style['padding'])) { - $padding = 0; - } elseif ($style['padding'] === 'auto') { - $padding = 10 * ($w / ($arrcode['maxw'] + 20)); - } else { - $padding = floatval($style['padding']); - } - // horizontal padding - if (!isset($style['hpadding'])) { - $hpadding = $padding; - } elseif ($style['hpadding'] === 'auto') { - $hpadding = 10 * ($w / ($arrcode['maxw'] + 20)); - } else { - $hpadding = floatval($style['hpadding']); - } - // vertical padding - if (!isset($style['vpadding'])) { - $vpadding = $padding; - } elseif ($style['vpadding'] === 'auto') { - $vpadding = ($hpadding / 2); - } else { - $vpadding = floatval($style['vpadding']); - } - // calculate xres (single bar width) - $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw']; - if ($style['stretch']) { - $xres = $max_xres; - } else { - if ($this->empty_string($xres)) { - $xres = (0.141 * $this->k); // default bar width = 0.4 mm - } - if ($xres > $max_xres) { - // correct xres to fit on $w - $xres = $max_xres; - } - if ((isset($style['padding']) AND ($style['padding'] === 'auto')) - OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) { - $hpadding = 10 * $xres; - if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) { - $vpadding = ($hpadding / 2); - } - } - } - if ($style['fitwidth']) { - $wold = $w; - $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding)); - if (isset($style['cellfitalign'])) { - switch ($style['cellfitalign']) { - case 'L': { - if ($this->rtl) { - $x -= ($wold - $w); - } - break; - } - case 'R': { - if (!$this->rtl) { - $x += ($wold - $w); - } - break; - } - case 'C': { - if ($this->rtl) { - $x -= (($wold - $w) / 2); - } else { - $x += (($wold - $w) / 2); - } - break; - } - default : { - break; - } - } - } - } - $text_height = ($this->cell_height_ratio * $fontsize / $this->k); - // height - if (($h === '') OR ($h <= 0)) { - // set default height - $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height; - } - $barh = $h - $text_height - (2 * $vpadding); - if ($barh <=0) { - // try to reduce font or padding to fit barcode on available height - if ($text_height > $h) { - $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio)); - $text_height = ($this->cell_height_ratio * $fontsize / $this->k); - $this->SetFont($style['font'], '', $fontsize); - } - if ($vpadding > 0) { - $vpadding = (($h - $text_height) / 4); - } - $barh = $h - $text_height - (2 * $vpadding); - } - // fit the barcode on available space - list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false); - // set alignment - $this->img_rb_y = $y + $h; - // set alignment - if ($this->rtl) { - if ($style['position'] == 'L') { - $xpos = $this->lMargin; - } elseif ($style['position'] == 'C') { - $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($style['position'] == 'R') { - $xpos = $this->w - $this->rMargin - $w; - } else { - $xpos = $x - $w; - } - $this->img_rb_x = $xpos; - } else { - if ($style['position'] == 'L') { - $xpos = $this->lMargin; - } elseif ($style['position'] == 'C') { - $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($style['position'] == 'R') { - $xpos = $this->w - $this->rMargin - $w; - } else { - $xpos = $x; - } - $this->img_rb_x = $xpos + $w; - } - $xpos_rect = $xpos; - if (!isset($style['align'])) { - $style['align'] = 'C'; - } - switch ($style['align']) { - case 'L': { - $xpos = $xpos_rect + $hpadding; - break; - } - case 'R': { - $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding; - break; - } - case 'C': - default : { - $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2); - break; - } - } - $xpos_text = $xpos; - // barcode is always printed in LTR direction - $tempRTL = $this->rtl; - $this->rtl = false; - // print background color - if ($style['bgcolor']) { - $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']); - } elseif ($style['border']) { - $this->Rect($xpos_rect, $y, $w, $h, 'D'); - } - // set foreground color - $this->SetDrawColorArray($style['fgcolor']); - $this->SetTextColorArray($style['fgcolor']); - // print bars - foreach ($arrcode['bcode'] as $k => $v) { - $bw = ($v['w'] * $xres); - if ($v['t']) { - // draw a vertical bar - $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']); - $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']); - } - $xpos += $bw; - } - // print text - if ($style['text']) { - if (isset($style['label']) AND !$this->empty_string($style['label'])) { - $label = $style['label']; - } else { - $label = $code; - } - $txtwidth = ($arrcode['maxw'] * $xres); - if ($this->GetStringWidth($label) > $txtwidth) { - $style['stretchtext'] = 2; - } - // print text - $this->x = $xpos_text; - $this->y = $y + $vpadding + $barh; - $cellpadding = $this->cell_padding; - $this->SetCellPadding(0); - $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T'); - $this->cell_padding = $cellpadding; - } - // restore original direction - $this->rtl = $tempRTL; - // restore previous settings - $this->setGraphicVars($gvars); - // set pointer to align the next text/objects - switch($align) { - case 'T':{ - $this->y = $y; - $this->x = $this->img_rb_x; - break; - } - case 'M':{ - $this->y = $y + round($h / 2); - $this->x = $this->img_rb_x; - break; - } - case 'B':{ - $this->y = $this->img_rb_y; - $this->x = $this->img_rb_x; - break; - } - case 'N':{ - $this->SetY($this->img_rb_y); - break; - } - default:{ - break; - } - } - $this->endlinex = $this->img_rb_x; - } - - /** - * This function is DEPRECATED, please use the new write1DBarcode() function. - * @param $x (int) x position in user units - * @param $y (int) y position in user units - * @param $w (int) width in user units - * @param $h (int) height position in user units - * @param $type (string) type of barcode - * @param $style (string) barcode style - * @param $font (string) font for text - * @param $xres (int) x resolution - * @param $code (string) code to print - * @deprecated deprecated since version 3.1.000 (2008-06-10) - * @public - * @see write1DBarcode() - */ - public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) { - // convert old settings for the new write1DBarcode() function. - $xres = 1 / $xres; - $newstyle = array( - 'position' => '', - 'align' => '', - 'stretch' => false, - 'fitwidth' => false, - 'cellfitalign' => '', - 'border' => false, - 'padding' => 0, - 'fgcolor' => array(0,0,0), - 'bgcolor' => false, - 'text' => true, - 'font' => $font, - 'fontsize' => 8, - 'stretchtext' => 4 - ); - if ($style & 1) { - $newstyle['border'] = true; - } - if ($style & 2) { - $newstyle['bgcolor'] = false; - } - if ($style & 4) { - $newstyle['position'] = 'C'; - } elseif ($style & 8) { - $newstyle['position'] = 'L'; - } elseif ($style & 16) { - $newstyle['position'] = 'R'; - } - if ($style & 128) { - $newstyle['text'] = true; - } - if ($style & 256) { - $newstyle['stretchtext'] = 4; - } - $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, ''); - } - - /** - * Print 2D Barcode. - * @param $code (string) code to print - * @param $type (string) type of barcode (see 2dbarcodes.php for supported formats). - * @param $x (int) x position in user units - * @param $y (int) y position in user units - * @param $w (int) width in user units - * @param $h (int) height in user units - * @param $style (array) array of options:
    - *
  • boolean $style['border'] if true prints a border around the barcode
  • - *
  • int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)
  • - *
  • int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)
  • - *
  • int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)
  • - *
  • int $style['module_width'] width of a single module in points
  • - *
  • int $style['module_height'] height of a single module in points
  • - *
  • array $style['fgcolor'] color array for bars and text
  • - *
  • mixed $style['bgcolor'] color array for background or false for transparent
  • - *
  • string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch
  • $style['module_width'] width of a single module in points
  • - *
  • $style['module_height'] height of a single module in points
- * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:
  • T: top-right for LTR or top-left for RTL
  • M: middle-right for LTR or middle-left for RTL
  • B: bottom-right for LTR or bottom-left for RTL
  • N: next line
- * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio - * @author Nicola Asuni - * @since 4.5.037 (2009-04-07) - * @public - */ - public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) { - if ($this->empty_string(trim($code))) { - return; - } - require_once(dirname(__FILE__).'/2dbarcodes.php'); - // save current graphic settings - $gvars = $this->getGraphicVars(); - // create new barcode object - $barcodeobj = new TCPDF2DBarcode($code, $type); - $arrcode = $barcodeobj->getBarcodeArray(); - if (($arrcode === false) OR empty($arrcode)) { - $this->Error('Error in 2D barcode string'); - } - // set default values - if (!isset($style['position'])) { - $style['position'] = ''; - } - if (!isset($style['fgcolor'])) { - $style['fgcolor'] = array(0,0,0); // default black - } - if (!isset($style['bgcolor'])) { - $style['bgcolor'] = false; // default transparent - } - if (!isset($style['border'])) { - $style['border'] = false; - } - // padding - if (!isset($style['padding'])) { - $style['padding'] = 0; - } elseif ($style['padding'] === 'auto') { - $style['padding'] = 4; - } - if (!isset($style['hpadding'])) { - $style['hpadding'] = $style['padding']; - } elseif ($style['hpadding'] === 'auto') { - $style['hpadding'] = 4; - } - if (!isset($style['vpadding'])) { - $style['vpadding'] = $style['padding']; - } elseif ($style['vpadding'] === 'auto') { - $style['vpadding'] = 4; - } - $hpad = (2 * $style['hpadding']); - $vpad = (2 * $style['vpadding']); - // cell (module) dimension - if (!isset($style['module_width'])) { - $style['module_width'] = 1; // width of a single module in points - } - if (!isset($style['module_height'])) { - $style['module_height'] = 1; // height of a single module in points - } - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - // number of barcode columns and rows - $rows = $arrcode['num_rows']; - $cols = $arrcode['num_cols']; - // module width and height - $mw = $style['module_width']; - $mh = $style['module_height']; - // get max dimensions - if ($this->rtl) { - $maxw = $x - $this->lMargin; - } else { - $maxw = $this->w - $this->rMargin - $x; - } - $maxh = ($this->h - $this->tMargin - $this->bMargin); - $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad)); - $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad)); - if (!$distort) { - if (($maxw * $ratioHW) > $maxh) { - $maxw = $maxh * $ratioWH; - } - if (($maxh * $ratioWH) > $maxw) { - $maxh = $maxw * $ratioHW; - } - } - // set maximum dimesions - if ($w > $maxw) { - $w = $maxw; - } - if ($h > $maxh) { - $h = $maxh; - } - // set dimensions - if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) { - $w = ($cols + $hpad) * ($mw / $this->k); - $h = ($rows + $vpad) * ($mh / $this->k); - } elseif (($w === '') OR ($w <= 0)) { - $w = $h * $ratioWH; - } elseif (($h === '') OR ($h <= 0)) { - $h = $w * $ratioHW; - } - // barcode size (excluding padding) - $bw = ($w * $cols) / ($cols + $hpad); - $bh = ($h * $rows) / ($rows + $vpad); - // dimension of single barcode cell unit - $cw = $bw / $cols; - $ch = $bh / $rows; - if (!$distort) { - if (($cw / $ch) > ($mw / $mh)) { - // correct horizontal distortion - $cw = $ch * $mw / $mh; - $bw = $cw * $cols; - $style['hpadding'] = ($w - $bw) / (2 * $cw); - } else { - // correct vertical distortion - $ch = $cw * $mh / $mw; - $bh = $ch * $rows; - $style['vpadding'] = ($h - $bh) / (2 * $ch); - } - } - // fit the barcode on available space - list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false); - // set alignment - $this->img_rb_y = $y + $h; - // set alignment - if ($this->rtl) { - if ($style['position'] == 'L') { - $xpos = $this->lMargin; - } elseif ($style['position'] == 'C') { - $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($style['position'] == 'R') { - $xpos = $this->w - $this->rMargin - $w; - } else { - $xpos = $x - $w; - } - $this->img_rb_x = $xpos; - } else { - if ($style['position'] == 'L') { - $xpos = $this->lMargin; - } elseif ($style['position'] == 'C') { - $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($style['position'] == 'R') { - $xpos = $this->w - $this->rMargin - $w; - } else { - $xpos = $x; - } - $this->img_rb_x = $xpos + $w; - } - $xstart = $xpos + ($style['hpadding'] * $cw); - $ystart = $y + ($style['vpadding'] * $ch); - // barcode is always printed in LTR direction - $tempRTL = $this->rtl; - $this->rtl = false; - // print background color - if ($style['bgcolor']) { - $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']); - } elseif ($style['border']) { - $this->Rect($xpos, $y, $w, $h, 'D'); - } - // set foreground color - $this->SetDrawColorArray($style['fgcolor']); - // print barcode cells - // for each row - for ($r = 0; $r < $rows; ++$r) { - $xr = $xstart; - // for each column - for ($c = 0; $c < $cols; ++$c) { - if ($arrcode['bcode'][$r][$c] == 1) { - // draw a single barcode cell - $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']); - } - $xr += $cw; - } - $ystart += $ch; - } - // restore original direction - $this->rtl = $tempRTL; - // restore previous settings - $this->setGraphicVars($gvars); - // set pointer to align the next text/objects - switch($align) { - case 'T':{ - $this->y = $y; - $this->x = $this->img_rb_x; - break; - } - case 'M':{ - $this->y = $y + round($h/2); - $this->x = $this->img_rb_x; - break; - } - case 'B':{ - $this->y = $this->img_rb_y; - $this->x = $this->img_rb_x; - break; - } - case 'N':{ - $this->SetY($this->img_rb_y); - break; - } - default:{ - break; - } - } - $this->endlinex = $this->img_rb_x; - } /** * Returns an array containing current margins: @@ -23305,235 +17060,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag); break; } - // Form fields (since 4.8.000 - 2009-09-07) - case 'form': { - if (isset($tag['attribute']['action'])) { - $this->form_action = $tag['attribute']['action']; - } else { - $this->form_action = K_PATH_URL.$_SERVER['SCRIPT_NAME']; - } - if (isset($tag['attribute']['enctype'])) { - $this->form_enctype = $tag['attribute']['enctype']; - } else { - $this->form_enctype = 'application/x-www-form-urlencoded'; - } - if (isset($tag['attribute']['method'])) { - $this->form_mode = $tag['attribute']['method']; - } else { - $this->form_mode = 'post'; - } - break; - } - case 'input': { - if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) { - $name = $tag['attribute']['name']; - } else { - break; - } - $prop = array(); - $opt = array(); - if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) { - $prop['readonly'] = true; - } - if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) { - $value = $tag['attribute']['value']; - } - if (isset($tag['attribute']['maxlength']) AND !$this->empty_string($tag['attribute']['maxlength'])) { - $opt['maxlen'] = intval($tag['attribute']['value']); - } - $h = $this->FontSize * $this->cell_height_ratio; - if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) { - $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2; - } else { - $w = $h; - } - if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) { - $checked = true; - } else { - $checked = false; - } - if (isset($tag['align'])) { - switch ($tag['align']) { - case 'C': { - $opt['q'] = 1; - break; - } - case 'R': { - $opt['q'] = 2; - break; - } - case 'L': - default: { - break; - } - } - } - switch ($tag['attribute']['type']) { - case 'text': { - if (isset($value)) { - $opt['v'] = $value; - } - $this->TextField($name, $w, $h, $prop, $opt, '', '', false); - break; - } - case 'password': { - if (isset($value)) { - $opt['v'] = $value; - } - $prop['password'] = 'true'; - $this->TextField($name, $w, $h, $prop, $opt, '', '', false); - break; - } - case 'checkbox': { - $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false); - break; - } - case 'radio': { - $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false); - break; - } - case 'submit': { - $w = $this->GetStringWidth($value) * 1.5; - $h *= 1.6; - $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255)); - $action = array(); - $action['S'] = 'SubmitForm'; - $action['F'] = $this->form_action; - if ($this->form_enctype != 'FDF') { - $action['Flags'] = array('ExportFormat'); - } - if ($this->form_mode == 'get') { - $action['Flags'] = array('GetMethod'); - } - $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false); - break; - } - case 'reset': { - $w = $this->GetStringWidth($value) * 1.5; - $h *= 1.6; - $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255)); - $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false); - break; - } - case 'file': { - $prop['fileSelect'] = 'true'; - $this->TextField($name, $w, $h, $prop, $opt, '', '', false); - if (!isset($value)) { - $value = '*'; - } - $w = $this->GetStringWidth($value) * 2; - $h *= 1.2; - $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255)); - $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();'; - $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false); - break; - } - case 'hidden': { - if (isset($value)) { - $opt['v'] = $value; - } - $opt['f'] = array('invisible', 'hidden'); - $this->TextField($name, 0, 0, $prop, $opt, '', '', false); - break; - } - case 'image': { - // THIS TYPE MUST BE FIXED - if (isset($tag['attribute']['src']) AND !$this->empty_string($tag['attribute']['src'])) { - $img = $tag['attribute']['src']; - } else { - break; - } - $value = 'img'; - //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false)); - if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) { - $jsaction = $tag['attribute']['onclick']; - } else { - $jsaction = ''; - } - $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false); - break; - } - case 'button': { - $w = $this->GetStringWidth($value) * 1.5; - $h *= 1.6; - $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255)); - if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) { - $jsaction = $tag['attribute']['onclick']; - } else { - $jsaction = ''; - } - $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false); - break; - } - } - break; - } - case 'textarea': { - $prop = array(); - $opt = array(); - if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) { - $prop['readonly'] = true; - } - if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) { - $name = $tag['attribute']['name']; - } else { - break; - } - if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) { - $opt['v'] = $tag['attribute']['value']; - } - if (isset($tag['attribute']['cols']) AND !$this->empty_string($tag['attribute']['cols'])) { - $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2; - } else { - $w = 40; - } - if (isset($tag['attribute']['rows']) AND !$this->empty_string($tag['attribute']['rows'])) { - $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio; - } else { - $h = 10; - } - $prop['multiline'] = 'true'; - $this->TextField($name, $w, $h, $prop, $opt, '', '', false); - break; - } - case 'select': { - $h = $this->FontSize * $this->cell_height_ratio; - if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) { - $h *= ($tag['attribute']['size'] + 1); - } - $prop = array(); - $opt = array(); - if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) { - $name = $tag['attribute']['name']; - } else { - break; - } - $w = 0; - if (isset($tag['attribute']['opt']) AND !$this->empty_string($tag['attribute']['opt'])) { - $options = explode('#!NwL!#', $tag['attribute']['opt']); - $values = array(); - foreach ($options as $val) { - if (strpos($val, '#!TaB!#') !== false) { - $opts = explode('#!TaB!#', $val); - $values[] = $opts; - $w = max($w, $this->GetStringWidth($opts[1])); - } else { - $values[] = $val; - $w = max($w, $this->GetStringWidth($val)); - } - } - } else { - break; - } - $w *= 2; - if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) { - $prop['multipleSelection'] = 'true'; - $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false); - } else { - $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false); - } - break; - } case 'tcpdf': { if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) { // Special tag used to call TCPDF methods @@ -24408,23 +17934,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } - /** - * Set the booklet mode for double-sided pages. - * @param $booklet (boolean) true set the booklet mode on, false otherwise. - * @param $inner (float) Inner page margin. - * @param $outer (float) Outer page margin. - * @public - * @since 4.2.000 (2008-10-29) - */ - public function SetBooklet($booklet=true, $inner=-1, $outer=-1) { - $this->booklet = $booklet; - if ($inner >= 0) { - $this->lMargin = $inner; - } - if ($outer >= 0) { - $this->rMargin = $outer; - } - } /** * Swap the left and right margins. @@ -24574,70 +18083,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $retval; } - /** - * Returns the Roman representation of an integer number - * @param $number (int) number to convert - * @return string roman representation of the specified number - * @since 4.4.004 (2008-12-10) - * @public - */ - public function intToRoman($number) { - $roman = ''; - while ($number >= 1000) { - $roman .= 'M'; - $number -= 1000; - } - while ($number >= 900) { - $roman .= 'CM'; - $number -= 900; - } - while ($number >= 500) { - $roman .= 'D'; - $number -= 500; - } - while ($number >= 400) { - $roman .= 'CD'; - $number -= 400; - } - while ($number >= 100) { - $roman .= 'C'; - $number -= 100; - } - while ($number >= 90) { - $roman .= 'XC'; - $number -= 90; - } - while ($number >= 50) { - $roman .= 'L'; - $number -= 50; - } - while ($number >= 40) { - $roman .= 'XL'; - $number -= 40; - } - while ($number >= 10) { - $roman .= 'X'; - $number -= 10; - } - while ($number >= 9) { - $roman .= 'IX'; - $number -= 9; - } - while ($number >= 5) { - $roman .= 'V'; - $number -= 5; - } - while ($number >= 4) { - $roman .= 'IV'; - $number -= 4; - } - while ($number >= 1) { - $roman .= 'I'; - --$number; - } - return $roman; - } - /** * Output an HTML list bullet or ordered item symbol * @param $listdepth (int) list nesting level @@ -24672,144 +18117,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $img = explode('|', $listtype); $listtype = 'img'; } - switch ($listtype) { - // unordered types - case 'none': { - break; - } - case 'disc': { - $r = $size / 6; - $lspace += (2 * $r); - if ($this->rtl) { - $this->x += $lspace; - } else { - $this->x -= $lspace; - } - $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8); - break; - } - case 'circle': { - $r = $size / 6; - $lspace += (2 * $r); - if ($this->rtl) { - $this->x += $lspace; - } else { - $this->x -= $lspace; - } - $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor; - $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color); - $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8); - $this->_out($prev_line_style); // restore line settings - break; - } - case 'square': { - $l = $size / 3; - $lspace += $l; - if ($this->rtl) {; - $this->x += $lspace; - } else { - $this->x -= $lspace; - } - $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color); - break; - } - case 'img': { - // 1=>type, 2=>width, 3=>height, 4=>image.ext - $lspace += $img[2]; - if ($this->rtl) {; - $this->x += $lspace; - } else { - $this->x -= $lspace; - } - $imgtype = strtolower($img[1]); - $prev_y = $this->y; - switch ($imgtype) { - case 'svg': { - $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false); - break; - } - case 'ai': - case 'eps': { - $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false); - break; - } - default: { - $this->Image($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], $img[1], '', 'T', false, 300, '', false, false, 0, false, false, false); - break; - } - } - $this->y = $prev_y; - break; - } - // ordered types - // $this->listcount[$this->listnum]; - // $textitem - case '1': - case 'decimal': { - $textitem = $this->listcount[$this->listnum]; - break; - } - case 'decimal-leading-zero': { - $textitem = sprintf('%02d', $this->listcount[$this->listnum]); - break; - } - case 'i': - case 'lower-roman': { - $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum])); - break; - } - case 'I': - case 'upper-roman': { - $textitem = $this->intToRoman($this->listcount[$this->listnum]); - break; - } - case 'a': - case 'lower-alpha': - case 'lower-latin': { - $textitem = chr(97 + $this->listcount[$this->listnum] - 1); - break; - } - case 'A': - case 'upper-alpha': - case 'upper-latin': { - $textitem = chr(65 + $this->listcount[$this->listnum] - 1); - break; - } - case 'lower-greek': { - $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1); - break; - } - /* - // Types to be implemented (special handling) - case 'hebrew': { - break; - } - case 'armenian': { - break; - } - case 'georgian': { - break; - } - case 'cjk-ideographic': { - break; - } - case 'hiragana': { - break; - } - case 'katakana': { - break; - } - case 'hiragana-iroha': { - break; - } - case 'katakana-iroha': { - break; - } - */ - default: { - $textitem = $this->listcount[$this->listnum]; - } - } + if (!$this->empty_string($textitem)) { // Check whether we need a new page or new column $prev_y = $this->y; @@ -25227,760 +18535,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return false; } - /** - * Move a page to a previous position. - * @param $frompage (int) number of the source page - * @param $topage (int) number of the destination page (must be less than $frompage) - * @return true in case of success, false in case of error. - * @public - * @since 4.5.000 (2009-01-02) - */ - public function movePage($frompage, $topage) { - if (($frompage > $this->numpages) OR ($frompage <= $topage)) { - return false; - } - if ($frompage == $this->page) { - // close the page before moving it - $this->endPage(); - } - // move all page-related states - $tmppage = $this->getPageBuffer($frompage); - $tmppagedim = $this->pagedim[$frompage]; - $tmppagelen = $this->pagelen[$frompage]; - $tmpintmrk = $this->intmrk[$frompage]; - $tmpbordermrk = $this->bordermrk[$frompage]; - $tmpcntmrk = $this->cntmrk[$frompage]; - if (isset($this->footerpos[$frompage])) { - $tmpfooterpos = $this->footerpos[$frompage]; - } - if (isset($this->footerlen[$frompage])) { - $tmpfooterlen = $this->footerlen[$frompage]; - } - if (isset($this->transfmrk[$frompage])) { - $tmptransfmrk = $this->transfmrk[$frompage]; - } - if (isset($this->PageAnnots[$frompage])) { - $tmpannots = $this->PageAnnots[$frompage]; - } - if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) { - for ($i = $frompage; $i > $topage; --$i) { - if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) { - --$this->pagegroups[$this->newpagegroup[$i]]; - break; - } - } - for ($i = $topage; $i > 0; --$i) { - if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) { - ++$this->pagegroups[$this->newpagegroup[$i]]; - break; - } - } - } - for ($i = $frompage; $i > $topage; --$i) { - $j = $i - 1; - // shift pages down - $this->setPageBuffer($i, $this->getPageBuffer($j)); - $this->pagedim[$i] = $this->pagedim[$j]; - $this->pagelen[$i] = $this->pagelen[$j]; - $this->intmrk[$i] = $this->intmrk[$j]; - $this->bordermrk[$i] = $this->bordermrk[$j]; - $this->cntmrk[$i] = $this->cntmrk[$j]; - if (isset($this->footerpos[$j])) { - $this->footerpos[$i] = $this->footerpos[$j]; - } elseif (isset($this->footerpos[$i])) { - unset($this->footerpos[$i]); - } - if (isset($this->footerlen[$j])) { - $this->footerlen[$i] = $this->footerlen[$j]; - } elseif (isset($this->footerlen[$i])) { - unset($this->footerlen[$i]); - } - if (isset($this->transfmrk[$j])) { - $this->transfmrk[$i] = $this->transfmrk[$j]; - } elseif (isset($this->transfmrk[$i])) { - unset($this->transfmrk[$i]); - } - if (isset($this->PageAnnots[$j])) { - $this->PageAnnots[$i] = $this->PageAnnots[$j]; - } elseif (isset($this->PageAnnots[$i])) { - unset($this->PageAnnots[$i]); - } - if (isset($this->newpagegroup[$j])) { - $this->newpagegroup[$i] = $this->newpagegroup[$j]; - unset($this->newpagegroup[$j]); - } - if ($this->currpagegroup == $j) { - $this->currpagegroup = $i; - } - } - $this->setPageBuffer($topage, $tmppage); - $this->pagedim[$topage] = $tmppagedim; - $this->pagelen[$topage] = $tmppagelen; - $this->intmrk[$topage] = $tmpintmrk; - $this->bordermrk[$topage] = $tmpbordermrk; - $this->cntmrk[$topage] = $tmpcntmrk; - if (isset($tmpfooterpos)) { - $this->footerpos[$topage] = $tmpfooterpos; - } elseif (isset($this->footerpos[$topage])) { - unset($this->footerpos[$topage]); - } - if (isset($tmpfooterlen)) { - $this->footerlen[$topage] = $tmpfooterlen; - } elseif (isset($this->footerlen[$topage])) { - unset($this->footerlen[$topage]); - } - if (isset($tmptransfmrk)) { - $this->transfmrk[$topage] = $tmptransfmrk; - } elseif (isset($this->transfmrk[$topage])) { - unset($this->transfmrk[$topage]); - } - if (isset($tmpannots)) { - $this->PageAnnots[$topage] = $tmpannots; - } elseif (isset($this->PageAnnots[$topage])) { - unset($this->PageAnnots[$topage]); - } - // adjust outlines - $tmpoutlines = $this->outlines; - foreach ($tmpoutlines as $key => $outline) { - if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) { - $this->outlines[$key]['p'] = ($outline['p'] + 1); - } elseif ($outline['p'] == $frompage) { - $this->outlines[$key]['p'] = $topage; - } - } - // adjust dests - $tmpdests = $this->dests; - foreach ($tmpdests as $key => $dest) { - if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) { - $this->dests[$key]['p'] = ($dest['p'] + 1); - } elseif ($dest['p'] == $frompage) { - $this->dests[$key]['p'] = $topage; - } - } - // adjust links - $tmplinks = $this->links; - foreach ($tmplinks as $key => $link) { - if (($link[0] >= $topage) AND ($link[0] < $frompage)) { - $this->links[$key][0] = ($link[0] + 1); - } elseif ($link[0] == $frompage) { - $this->links[$key][0] = $topage; - } - } - // adjust javascript - $tmpjavascript = $this->javascript; - global $jfrompage, $jtopage; - $jfrompage = $frompage; - $jtopage = $topage; - $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', - create_function('$matches', 'global $jfrompage, $jtopage; - $pagenum = intval($matches[3]) + 1; - if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) { - $newpage = ($pagenum + 1); - } elseif ($pagenum == $jfrompage) { - $newpage = $jtopage; - } else { - $newpage = $pagenum; - } - --$newpage; - return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); - // return to last page - $this->lastPage(true); - return true; - } - /** - * Remove the specified page. - * @param $page (int) page to remove - * @return true in case of success, false in case of error. - * @public - * @since 4.6.004 (2009-04-23) - */ - public function deletePage($page) { - if (($page < 1) OR ($page > $this->numpages)) { - return false; - } - // delete current page - unset($this->pages[$page]); - unset($this->pagedim[$page]); - unset($this->pagelen[$page]); - unset($this->intmrk[$page]); - unset($this->bordermrk[$page]); - unset($this->cntmrk[$page]); - if (isset($this->footerpos[$page])) { - unset($this->footerpos[$page]); - } - if (isset($this->footerlen[$page])) { - unset($this->footerlen[$page]); - } - if (isset($this->transfmrk[$page])) { - unset($this->transfmrk[$page]); - } - if (isset($this->PageAnnots[$page])) { - unset($this->PageAnnots[$page]); - } - if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) { - for ($i = $page; $i > 0; --$i) { - if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) { - --$this->pagegroups[$this->newpagegroup[$i]]; - break; - } - } - } - if (isset($this->pageopen[$page])) { - unset($this->pageopen[$page]); - } - if ($page < $this->numpages) { - // update remaining pages - for ($i = $page; $i < $this->numpages; ++$i) { - $j = $i + 1; - // shift pages - $this->setPageBuffer($i, $this->getPageBuffer($j)); - $this->pagedim[$i] = $this->pagedim[$j]; - $this->pagelen[$i] = $this->pagelen[$j]; - $this->intmrk[$i] = $this->intmrk[$j]; - $this->bordermrk[$i] = $this->bordermrk[$j]; - $this->cntmrk[$i] = $this->cntmrk[$j]; - if (isset($this->footerpos[$j])) { - $this->footerpos[$i] = $this->footerpos[$j]; - } elseif (isset($this->footerpos[$i])) { - unset($this->footerpos[$i]); - } - if (isset($this->footerlen[$j])) { - $this->footerlen[$i] = $this->footerlen[$j]; - } elseif (isset($this->footerlen[$i])) { - unset($this->footerlen[$i]); - } - if (isset($this->transfmrk[$j])) { - $this->transfmrk[$i] = $this->transfmrk[$j]; - } elseif (isset($this->transfmrk[$i])) { - unset($this->transfmrk[$i]); - } - if (isset($this->PageAnnots[$j])) { - $this->PageAnnots[$i] = $this->PageAnnots[$j]; - } elseif (isset($this->PageAnnots[$i])) { - unset($this->PageAnnots[$i]); - } - if (isset($this->newpagegroup[$j])) { - $this->newpagegroup[$i] = $this->newpagegroup[$j]; - unset($this->newpagegroup[$j]); - } - if ($this->currpagegroup == $j) { - $this->currpagegroup = $i; - } - if (isset($this->pageopen[$j])) { - $this->pageopen[$i] = $this->pageopen[$j]; - } elseif (isset($this->pageopen[$i])) { - unset($this->pageopen[$i]); - } - } - // remove last page - unset($this->pages[$this->numpages]); - unset($this->pagedim[$this->numpages]); - unset($this->pagelen[$this->numpages]); - unset($this->intmrk[$this->numpages]); - unset($this->bordermrk[$this->numpages]); - unset($this->cntmrk[$this->numpages]); - if (isset($this->footerpos[$this->numpages])) { - unset($this->footerpos[$this->numpages]); - } - if (isset($this->footerlen[$this->numpages])) { - unset($this->footerlen[$this->numpages]); - } - if (isset($this->transfmrk[$this->numpages])) { - unset($this->transfmrk[$this->numpages]); - } - if (isset($this->PageAnnots[$this->numpages])) { - unset($this->PageAnnots[$this->numpages]); - } - if (isset($this->newpagegroup[$this->numpages])) { - unset($this->newpagegroup[$this->numpages]); - } - if ($this->currpagegroup == $this->numpages) { - $this->currpagegroup = ($this->numpages - 1); - } - if (isset($this->pagegroups[$this->numpages])) { - unset($this->pagegroups[$this->numpages]); - } - if (isset($this->pageopen[$this->numpages])) { - unset($this->pageopen[$this->numpages]); - } - } - --$this->numpages; - $this->page = $this->numpages; - // adjust outlines - $tmpoutlines = $this->outlines; - foreach ($tmpoutlines as $key => $outline) { - if ($outline['p'] > $page) { - $this->outlines[$key]['p'] = $outline['p'] - 1; - } elseif ($outline['p'] == $page) { - unset($this->outlines[$key]); - } - } - // adjust dests - $tmpdests = $this->dests; - foreach ($tmpdests as $key => $dest) { - if ($dest['p'] > $page) { - $this->dests[$key]['p'] = $dest['p'] - 1; - } elseif ($dest['p'] == $page) { - unset($this->dests[$key]); - } - } - // adjust links - $tmplinks = $this->links; - foreach ($tmplinks as $key => $link) { - if ($link[0] > $page) { - $this->links[$key][0] = $link[0] - 1; - } elseif ($link[0] == $page) { - unset($this->links[$key]); - } - } - // adjust javascript - $tmpjavascript = $this->javascript; - global $jpage; - $jpage = $page; - $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', - create_function('$matches', 'global $jpage; - $pagenum = intval($matches[3]) + 1; - if ($pagenum >= $jpage) { - $newpage = ($pagenum - 1); - } elseif ($pagenum == $jpage) { - $newpage = 1; - } else { - $newpage = $pagenum; - } - --$newpage; - return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); - // return to last page - $this->lastPage(true); - return true; - } - - /** - * Clone the specified page to a new page. - * @param $page (int) number of page to copy (0 = current page) - * @return true in case of success, false in case of error. - * @public - * @since 4.9.015 (2010-04-20) - */ - public function copyPage($page=0) { - if ($page == 0) { - // default value - $page = $this->page; - } - if (($page < 1) OR ($page > $this->numpages)) { - return false; - } - // close the last page - $this->endPage(); - // copy all page-related states - ++$this->numpages; - $this->page = $this->numpages; - $this->setPageBuffer($this->page, $this->getPageBuffer($page)); - $this->pagedim[$this->page] = $this->pagedim[$page]; - $this->pagelen[$this->page] = $this->pagelen[$page]; - $this->intmrk[$this->page] = $this->intmrk[$page]; - $this->bordermrk[$this->page] = $this->bordermrk[$page]; - $this->cntmrk[$this->page] = $this->cntmrk[$page]; - $this->pageopen[$this->page] = false; - if (isset($this->footerpos[$page])) { - $this->footerpos[$this->page] = $this->footerpos[$page]; - } - if (isset($this->footerlen[$page])) { - $this->footerlen[$this->page] = $this->footerlen[$page]; - } - if (isset($this->transfmrk[$page])) { - $this->transfmrk[$this->page] = $this->transfmrk[$page]; - } - if (isset($this->PageAnnots[$page])) { - $this->PageAnnots[$this->page] = $this->PageAnnots[$page]; - } - if (isset($this->newpagegroup[$page])) { - // start a new group - $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1; - $this->currpagegroup = $this->newpagegroup[$this->page]; - $this->pagegroups[$this->currpagegroup] = 1; - } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) { - ++$this->pagegroups[$this->currpagegroup]; - } - // copy outlines - $tmpoutlines = $this->outlines; - foreach ($tmpoutlines as $key => $outline) { - if ($outline['p'] == $page) { - $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'y' => $outline['y'], 'p' => $this->page, 's' => $outline['s'], 'c' => $outline['c']); - } - } - // copy links - $tmplinks = $this->links; - foreach ($tmplinks as $key => $link) { - if ($link[0] == $page) { - $this->links[] = array($this->page, $link[1]); - } - } - // return to last page - $this->lastPage(true); - return true; - } - - /** - * Output a Table of Content Index (TOC). - * This method must be called after all Bookmarks were set. - * Before calling this method you have to open the page using the addTOCPage() method. - * After calling this method you have to call endTOCPage() to close the TOC page. - * You can override this method to achieve different styles. - * @param $page (int) page number where this TOC should be inserted (leave empty for current page). - * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment). - * @param $filler (string) string used to fill the space between text and page number. - * @param $toc_name (string) name to use for TOC bookmark. - * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic. - * @param $color (array) RGB color array for bookmark title (values from 0 to 255). - * @public - * @author Nicola Asuni - * @since 4.5.000 (2009-01-02) - * @see addTOCPage(), endTOCPage(), addHTMLTOC() - */ - public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) { - $fontsize = $this->FontSizePt; - $fontfamily = $this->FontFamily; - $fontstyle = $this->FontStyle; - $w = $this->w - $this->lMargin - $this->rMargin; - $spacer = $this->GetStringWidth(chr(32)) * 4; - $page_first = $this->getPage(); - $lmargin = $this->lMargin; - $rmargin = $this->rMargin; - $x_start = $this->GetX(); - $current_page = $this->page; - $current_column = $this->current_column; - if ($this->empty_string($numbersfont)) { - $numbersfont = $this->default_monospaced_font; - } - if ($this->empty_string($filler)) { - $filler = ' '; - } - if ($this->empty_string($page)) { - $gap = ' '; - } else { - $gap = ''; - if ($page < 1) { - $page = 1; - } - } - $this->SetFont($numbersfont, $fontstyle, $fontsize); - $numwidth = $this->GetStringWidth('00000'); - $maxpage = 0; //used for pages on attached documents - foreach ($this->outlines as $key => $outline) { - // check for extra pages (used for attachments) - if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) { - $outline['p'] += ($this->page - $page_first); - } - if ($this->rtl) { - $aligntext = 'R'; - $alignnum = 'L'; - } else { - $aligntext = 'L'; - $alignnum = 'R'; - } - if ($outline['l'] == 0) { - $this->SetFont($fontfamily, $fontstyle.'B', $fontsize); - } else { - $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']); - } - // check for page break - $this->checkPageBreak((2 * $this->FontSize * $this->cell_height_ratio)); - // set margins and X position - if (($this->page == $current_page) AND ($this->current_column == $current_column)) { - $this->lMargin = $lmargin; - $this->rMargin = $rmargin; - } else { - if ($this->current_column != $current_column) { - if ($this->rtl) { - $x_start = $this->w - $this->columns[$this->current_column]['x']; - } else { - $x_start = $this->columns[$this->current_column]['x']; - } - } - $lmargin = $this->lMargin; - $rmargin = $this->rMargin; - $current_page = $this->page; - $current_column = $this->current_column; - } - $this->SetX($x_start); - $indent = ($spacer * $outline['l']); - if ($this->rtl) { - $this->x -= $indent; - $this->rMargin = $this->w - $this->x; - } else { - $this->x += $indent; - $this->lMargin = $this->x; - } - $link = $this->AddLink(); - $this->SetLink($link, $outline['y'], $outline['p']); - // write the text - if ($this->rtl) { - $txt = ' '.$outline['t']; - } else { - $txt = $outline['t'].' '; - } - $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, ''); - if ($this->rtl) { - $tw = $this->x - $this->lMargin; - } else { - $tw = $this->w - $this->rMargin - $this->x; - } - $this->SetFont($numbersfont, $fontstyle, $fontsize); - if ($this->empty_string($page)) { - $pagenum = $outline['p']; - } else { - // placemark to be replaced with the correct number - $pagenum = '{#'.($outline['p']).'}'; - if ($this->isUnicodeFont()) { - $pagenum = '{'.$pagenum.'}'; - } - $maxpage = max($maxpage, $outline['p']); - } - $fw = ($tw - $this->GetStringWidth($pagenum.$filler)); - $numfills = floor($fw / $this->GetStringWidth($filler)); - if ($numfills > 0) { - $rowfill = str_repeat($filler, $numfills); - } else { - $rowfill = ''; - } - if ($this->rtl) { - $pagenum = $pagenum.$gap.$rowfill; - } else { - $pagenum = $rowfill.$gap.$pagenum; - } - // write the number - $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0); - } - $page_last = $this->getPage(); - $maxpage = max($maxpage, $page_last); - $numpages = $page_last - $page_first + 1; - if (!$this->empty_string($page)) { - for ($p = $page_first; $p <= $page_last; ++$p) { - // get page data - $temppage = $this->getPageBuffer($p); - for ($n = 1; $n <= $maxpage; ++$n) { - // update page numbers - $a = '{#'.$n.'}'; - // get page number aliases - $pnalias = $this->getInternalPageNumberAliases($a); - // calculate replacement number - if (($n >= $page) AND ($n <= $this->numpages)) { - $np = $n + $numpages; - } else { - $np = $n; - } - $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1)); - $nu = $this->UTF8ToUTF16BE($na, false); - // replace aliases with numbers - foreach ($pnalias['u'] as $u) { - $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' ')))); - if ($this->rtl) { - $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill); - } else { - $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu; - } - $temppage = str_replace($u, $nr, $temppage); - } - foreach ($pnalias['a'] as $a) { - $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' ')))); - if ($this->rtl) { - $nr = $na.' '.$sfill; - } else { - $nr = $sfill.' '.$na; - } - $temppage = str_replace($a, $nr, $temppage); - } - } - // save changes - $this->setPageBuffer($p, $temppage); - } - // move pages - $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color); - for ($i = 0; $i < $numpages; ++$i) { - $this->movePage($page_last, $page); - } - } - } - - /** - * Output a Table Of Content Index (TOC) using HTML templates. - * This method must be called after all Bookmarks were set. - * Before calling this method you have to open the page using the addTOCPage() method. - * After calling this method you have to call endTOCPage() to close the TOC page. - * @param $page (int) page number where this TOC should be inserted (leave empty for current page). - * @param $toc_name (string) name to use for TOC bookmark. - * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number. - * @param $correct_align (boolean) if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL) - * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic. - * @param $color (array) RGB color array for title (values from 0 to 255). - * @public - * @author Nicola Asuni - * @since 5.0.001 (2010-05-06) - * @see addTOCPage(), endTOCPage(), addTOC() - */ - public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) { - $filler = ' '; - $prev_htmlLinkColorArray = $this->htmlLinkColorArray; - $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle; - // set new style for link - $this->htmlLinkColorArray = array(); - $this->htmlLinkFontStyle = ''; - $page_first = $this->getPage(); - // get the font type used for numbers in each template - $current_font = $this->FontFamily; - foreach ($templates as $level => $html) { - $dom = $this->getHtmlDomArray($html); - foreach ($dom as $key => $value) { - if ($value['value'] == '#TOC_PAGE_NUMBER#') { - $this->SetFont($dom[($key - 1)]['fontname']); - $templates['F'.$level] = $this->isUnicodeFont(); - } - } - } - $this->SetFont($current_font); - $maxpage = 0; //used for pages on attached documents - foreach ($this->outlines as $key => $outline) { - // get HTML template - $row = $templates[$outline['l']]; - if ($this->empty_string($page)) { - $pagenum = $outline['p']; - } else { - // placemark to be replaced with the correct number - $pagenum = '{#'.($outline['p']).'}'; - if ($templates['F'.$outline['l']]) { - $pagenum = '{'.$pagenum.'}'; - } - $maxpage = max($maxpage, $outline['p']); - } - // replace templates with current values - $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row); - $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row); - // add link to page - $row = ''.$row.''; - // write bookmark entry - $this->writeHTML($row, false, false, true, false, ''); - } - // restore link styles - $this->htmlLinkColorArray = $prev_htmlLinkColorArray; - $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle; - // move TOC page and replace numbers - $page_last = $this->getPage(); - $maxpage = max($maxpage, $page_last); - $numpages = $page_last - $page_first + 1; - if (!$this->empty_string($page)) { - for ($p = $page_first; $p <= $page_last; ++$p) { - // get page data - $temppage = $this->getPageBuffer($p); - for ($n = 1; $n <= $maxpage; ++$n) { - // update page numbers - $a = '{#'.$n.'}'; - // get page number aliases - $pnalias = $this->getInternalPageNumberAliases($a); - // calculate replacement number - if ($n >= $page) { - $np = $n + $numpages; - } else { - $np = $n; - } - $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1)); - $nu = $this->UTF8ToUTF16BE($na, false); - // replace aliases with numbers - foreach ($pnalias['u'] as $u) { - if ($correct_align) { - $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' '))); - if ($this->rtl) { - $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill); - } else { - $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu; - } - } else { - $nr = $nu; - } - $temppage = str_replace($u, $nr, $temppage); - } - foreach ($pnalias['a'] as $a) { - if ($correct_align) { - $sfill = str_repeat($filler, (strlen($a) - strlen($na.' '))); - if ($this->rtl) { - $nr = $na.' '.$sfill; - } else { - $nr = $sfill.' '.$na; - } - } else { - $nr = $na; - } - $temppage = str_replace($a, $nr, $temppage); - } - } - // save changes - $this->setPageBuffer($p, $temppage); - } - // move pages - $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color); - for ($i = 0; $i < $numpages; ++$i) { - $this->movePage($page_last, $page); - } - } - } - - /** - * Stores a copy of the current TCPDF object used for undo operation. - * @public - * @since 4.5.029 (2009-03-19) - */ - public function startTransaction() { - if (isset($this->objcopy)) { - // remove previous copy - $this->commitTransaction(); - } - // record current page number and Y position - $this->start_transaction_page = $this->page; - $this->start_transaction_y = $this->y; - // clone current object - $this->objcopy = $this->objclone($this); - } - - /** - * Delete the copy of the current TCPDF object used for undo operation. - * @public - * @since 4.5.029 (2009-03-19) - */ - public function commitTransaction() { - if (isset($this->objcopy)) { - $this->objcopy->_destroy(true, true); - unset($this->objcopy); - } - } - - /** - * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction(). - * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value. - * @return TCPDF object. - * @public - * @since 4.5.029 (2009-03-19) - */ - public function rollbackTransaction($self=false) { - if (isset($this->objcopy)) { - if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) { - // truncate files to previous values - foreach ($this->objcopy->cache_file_length as $file => $length) { - $file = substr($file, 1); - $handle = fopen($file, 'r+'); - ftruncate($handle, $length); - } - } - $this->_destroy(true, true); - if ($self) { - $objvars = get_object_vars($this->objcopy); - foreach ($objvars as $key => $value) { - $this->$key = $value; - } - } - return $this->objcopy; - } - return $this; - } /** * Creates a copy of a class object @@ -26250,270 +18805,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->textstrokewidth = $stroke * $this->k; } - /** - * Returns an array of chars containing soft hyphens. - * @param $word (array) array of chars - * @param $patterns (array) Array of hypenation patterns. - * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm. - * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens. - * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens. - * @param $charmin (int) Minimum word length to apply the hyphenation algoritm. - * @param $charmax (int) Maximum length of broken piece of word. - * @return array text with soft hyphens - * @author Nicola Asuni - * @since 4.9.012 (2010-04-12) - * @protected - */ - protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) { - $hyphenword = array(); // hyphens positions - $numchars = count($word); - if ($numchars <= $charmin) { - return $word; - } - $word_string = $this->UTF8ArrSubString($word); - // some words will be returned as-is - $pattern = '/^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/'; - if (preg_match($pattern, $word_string) > 0) { - // email - return $word; - } - $pattern = '/(([a-zA-Z0-9\-]+\.)?)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/'; - if (preg_match($pattern, $word_string) > 0) { - // URL - return $word; - } - if (isset($dictionary[$word_string])) { - return $this->UTF8StringToArray($dictionary[$word_string]); - } - // suround word with '_' characters - $tmpword = array_merge(array(95), $word, array(95)); - $tmpnumchars = $numchars + 2; - $maxpos = $tmpnumchars - $charmin; - for ($pos = 0; $pos < $maxpos; ++$pos) { - $imax = min(($tmpnumchars - $pos), $charmax); - for ($i = $charmin; $i <= $imax; ++$i) { - $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos + $i)); - if (isset($patterns[$subword])) { - $pattern = $this->UTF8StringToArray($patterns[$subword]); - $pattern_length = count($pattern); - $digits = 1; - for ($j = 0; $j < $pattern_length; ++$j) { - // check if $pattern[$j] is a number - if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) { - if ($j == 0) { - $zero = $pos - 1; - } else { - $zero = $pos + $j - $digits; - } - if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) { - $hyphenword[$zero] = $this->unichr($pattern[$j]); - } - ++$digits; - } - } - } - } - } - $inserted = 0; - $maxpos = $numchars - $rightmin; - for ($i = $leftmin; $i <= $maxpos; ++$i) { - if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) { - // 173 = soft hyphen character - array_splice($word, $i + $inserted, 0, 173); - ++$inserted; - } - } - return $word; - } - - /** - * Returns an array of hyphenation patterns. - * @param $file (string) TEX file containing hypenation patterns. TEX pattrns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ - * @return array of hyphenation patterns - * @author Nicola Asuni - * @since 4.9.012 (2010-04-12) - * @public - */ - public function getHyphenPatternsFromTEX($file) { - // TEX patterns are available at: - // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ - $data = file_get_contents($file); - $patterns = array(); - // remove comments - $data = preg_replace('/\%[^\n]*/', '', $data); - // extract the patterns part - preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches); - $data = trim(substr($matches[0], 10, -1)); - // extract each pattern - $patterns_array = preg_split('/[\s]+/', $data); - // create new language array of patterns - $patterns = array(); - foreach($patterns_array as $val) { - if (!$this->empty_string($val)) { - $val = trim($val); - $val = str_replace('\'', '\\\'', $val); - $key = preg_replace('/[0-9]+/', '', $val); - $patterns[$key] = $val; - } - } - return $patterns; - } - - /** - * Returns text with soft hyphens. - * @param $text (string) text to process - * @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ - * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm. - * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens. - * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens. - * @param $charmin (int) Minimum word length to apply the hyphenation algoritm. - * @param $charmax (int) Maximum length of broken piece of word. - * @return array text with soft hyphens - * @author Nicola Asuni - * @since 4.9.012 (2010-04-12) - * @public - */ - public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) { - $text = $this->unhtmlentities($text); - $word = array(); // last word - $txtarr = array(); // text to be returned - $intag = false; // true if we are inside an HTML tag - if (!is_array($patterns)) { - $patterns = $this->getHyphenPatternsFromTEX($patterns); - } - // get array of characters - $unichars = $this->UTF8StringToArray($text); - // for each char - foreach ($unichars as $char) { - if ((!$intag) AND $this->unicode->uni_type[$char] == 'L') { - // letter character - $word[] = $char; - } else { - // other type of character - if (!$this->empty_string($word)) { - // hypenate the word - $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax)); - $word = array(); - } - $txtarr[] = $char; - if (chr($char) == '<') { - // we are inside an HTML tag - $intag = true; - } elseif ($intag AND (chr($char) == '>')) { - // end of HTML tag - $intag = false; - } - } - } - if (!$this->empty_string($word)) { - // hypenate the word - $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax)); - } - // convert char array to string and return - return $this->UTF8ArrSubString($txtarr); - } - - /** - * Enable/disable rasterization of vector images using ImageMagick library. - * @param $mode (boolean) if true enable rasterization, false otherwise. - * @public - * @since 5.0.000 (2010-04-27) - */ - public function setRasterizeVectorImages($mode) { - $this->rasterize_vector_images = $mode; - } - - /** - * Get the Path-Painting Operators. - * @param $style (string) Style of rendering. Possible values are: - *
    - *
  • S or D: Stroke the path.
  • - *
  • s or d: Close and stroke the path.
  • - *
  • f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.
  • - *
  • f* or F*: Fill the path, using the even-odd rule to determine the region to fill.
  • - *
  • B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.
  • - *
  • B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.
  • - *
  • b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.
  • - *
  • b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.
  • - *
  • CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.
  • - *
  • CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path
  • - *
  • n: End the path object without filling or stroking it.
  • - *
- * @param $default (string) default style - * @author Nicola Asuni - * @since 5.0.000 (2010-04-30) - * @protected - */ - protected function getPathPaintOperator($style, $default='S') { - $op = ''; - switch($style) { - case 'S': - case 'D': { - $op = 'S'; - break; - } - case 's': - case 'd': { - $op = 's'; - break; - } - case 'f': - case 'F': { - $op = 'f'; - break; - } - case 'f*': - case 'F*': { - $op = 'f*'; - break; - } - case 'B': - case 'FD': - case 'DF': { - $op = 'B'; - break; - } - case 'B*': - case 'F*D': - case 'DF*': { - $op = 'B*'; - break; - } - case 'b': - case 'fd': - case 'df': { - $op = 'b'; - break; - } - case 'b*': - case 'f*d': - case 'df*': { - $op = 'b*'; - break; - } - case 'CNZ': { - $op = 'W n'; - break; - } - case 'CEO': { - $op = 'W* n'; - break; - } - case 'n': { - $op = 'n'; - break; - } - default: { - if (!empty($default)) { - $op = $this->getPathPaintOperator($default, ''); - } else { - $op = ''; - } - } - } - return $op; - } - /** * Enable or disable default option for font subsetting. * @param $enable (boolean) if true enable font subsetting by default. @@ -26629,75 +18920,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $this->CurrentFont['fontkey']; } - /** - * Start a new XObject Template. - * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images). - * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked. - * Note: X,Y coordinates will be reset to 0,0. - * @param $w (int) Template width in user units (empty string or zero = page width less margins). - * @param $h (int) Template height in user units (empty string or zero = page height less margins). - * @param $group (mixed) Set transparency group. Can be a boolean value or an array specifying optional parameters: 'CS' (solour space name), 'I' (boolean flag to indicate isolated group) and 'K' (boolean flag to indicate knockout group). - * @return int the XObject Template ID in case of success or false in case of error. - * @author Nicola Asuni - * @public - * @since 5.8.017 (2010-08-24) - * @see endTemplate(), printTemplate() - */ - public function startTemplate($w=0, $h=0, $group=false) { - if ($this->inxobj) { - // we are already inside an XObject template - return false; - } - $this->inxobj = true; - ++$this->n; - // XObject ID - $this->xobjid = 'XT'.$this->n; - // object ID - $this->xobjects[$this->xobjid] = array('n' => $this->n); - // store current graphic state - $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars(); - // initialize data - $this->xobjects[$this->xobjid]['intmrk'] = 0; - $this->xobjects[$this->xobjid]['transfmrk'] = array(); - $this->xobjects[$this->xobjid]['outdata'] = ''; - $this->xobjects[$this->xobjid]['xobjects'] = array(); - $this->xobjects[$this->xobjid]['images'] = array(); - $this->xobjects[$this->xobjid]['fonts'] = array(); - $this->xobjects[$this->xobjid]['annotations'] = array(); - $this->xobjects[$this->xobjid]['extgstates'] = array(); - $this->xobjects[$this->xobjid]['gradients'] = array(); - $this->xobjects[$this->xobjid]['spot_colors'] = array(); - // set new environment - $this->num_columns = 1; - $this->current_column = 0; - $this->SetAutoPageBreak(false); - if (($w === '') OR ($w <= 0)) { - $w = $this->w - $this->lMargin - $this->rMargin; - } - if (($h === '') OR ($h <= 0)) { - $h = $this->h - $this->tMargin - $this->bMargin; - } - $this->xobjects[$this->xobjid]['x'] = 0; - $this->xobjects[$this->xobjid]['y'] = 0; - $this->xobjects[$this->xobjid]['w'] = $w; - $this->xobjects[$this->xobjid]['h'] = $h; - $this->w = $w; - $this->h = $h; - $this->wPt = $this->w * $this->k; - $this->hPt = $this->h * $this->k; - $this->fwPt = $this->wPt; - $this->fhPt = $this->hPt; - $this->x = 0; - $this->y = 0; - $this->lMargin = 0; - $this->rMargin = 0; - $this->tMargin = 0; - $this->bMargin = 0; - // set group mode - $this->xobjects[$this->xobjid]['group'] = $group; - return $this->xobjid; - } - /** * End the current XObject Template started with startTemplate() and restore the previous graphic state. * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images). @@ -26719,141 +18941,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $this->xobjid; } - /** - * Print an XObject Template. - * You can print an XObject Template inside the currently opened Template. - * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images). - * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked. - * @param $id (string) The ID of XObject Template to print. - * @param $x (int) X position in user units (empty string = current x position) - * @param $y (int) Y position in user units (empty string = current y position) - * @param $w (int) Width in user units (zero = remaining page width) - * @param $h (int) Height in user units (zero = remaining page height) - * @param $align (string) Indicates the alignment of the pointer next to template insertion relative to template height. The value can be:
  • T: top-right for LTR or top-left for RTL
  • M: middle-right for LTR or middle-left for RTL
  • B: bottom-right for LTR or bottom-left for RTL
  • N: next line
- * @param $palign (string) Allows to center or align the template on the current line. Possible values are:
  • L : left align
  • C : center
  • R : right align
  • '' : empty string : left for LTR or right for RTL
- * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions. - * @author Nicola Asuni - * @public - * @since 5.8.017 (2010-08-24) - * @see startTemplate(), endTemplate() - */ - public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) { - if (!isset($this->xobjects[$id])) { - $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!'); - } - if ($this->inxobj) { - if ($id == $this->xobjid) { - // close current template - $this->endTemplate(); - } else { - // use the template as resource for the template currently opened - $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id]; - } - } - // set default values - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - $ow = $this->xobjects[$id]['w']; - $oh = $this->xobjects[$id]['h']; - // calculate template width and height on document - if (($w <= 0) AND ($h <= 0)) { - $w = $ow; - $h = $oh; - } elseif ($w <= 0) { - $w = $h * $ow / $oh; - } elseif ($h <= 0) { - $h = $w * $oh / $ow; - } - // fit the template on available space - list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage); - // set page alignment - $rb_y = $y + $h; - // set alignment - if ($this->rtl) { - if ($palign == 'L') { - $xt = $this->lMargin; - } elseif ($palign == 'C') { - $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $xt = $this->w - $this->rMargin - $w; - } else { - $xt = $x - $w; - } - $rb_x = $xt; - } else { - if ($palign == 'L') { - $xt = $this->lMargin; - } elseif ($palign == 'C') { - $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $xt = $this->w - $this->rMargin - $w; - } else { - $xt = $x; - } - $rb_x = $xt + $w; - } - // print XObject Template + Transformation matrix - $this->StartTransform(); - // translate and scale - $sx = ($w / $this->xobjects[$id]['w']); - $sy = ($h / $this->xobjects[$id]['h']); - $tm = array(); - $tm[0] = $sx; - $tm[1] = 0; - $tm[2] = 0; - $tm[3] = $sy; - $tm[4] = $xt * $this->k; - $tm[5] = ($this->h - $h - $y) * $this->k; - $this->Transform($tm); - // set object - $this->_out('/'.$id.' Do'); - $this->StopTransform(); - // add annotations - if (!empty($this->xobjects[$id]['annotations'])) { - foreach ($this->xobjects[$id]['annotations'] as $annot) { - // transform original coordinates - $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k))); - $ax = ($coordlt[4] / $this->k); - $ay = ($this->h - $h - ($coordlt[5] / $this->k)); - $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k))); - $aw = ($coordrb[4] / $this->k) - $ax; - $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay; - $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']); - } - } - // set pointer to align the next text/objects - switch($align) { - case 'T': { - $this->y = $y; - $this->x = $rb_x; - break; - } - case 'M': { - $this->y = $y + round($h/2); - $this->x = $rb_x; - break; - } - case 'B': { - $this->y = $rb_y; - $this->x = $rb_x; - break; - } - case 'N': { - $this->SetY($rb_y); - break; - } - default:{ - break; - } - } - } - /** * Set the percentage of character stretching. * @param $perc (int) percentage of stretching (100 = no stretching) @@ -26898,74 +18985,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $this->font_spacing; } - /** - * Return an array of no-write page regions - * @return array of no-write page regions - * @author Nicola Asuni - * @public - * @since 5.9.003 (2010-10-13) - * @see setPageRegions(), addPageRegion() - */ - public function getPageRegions() { - return $this->page_regions; - } - - /** - * Set no-write regions on page. - * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code. - * A region is always aligned on the left or right side of the page ad is defined using a vertical segment. - * You can set multiple regions for the same page. - * @param $regions (array) array of no-write regions. For each region you can define an array as follow: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). Omit this parameter to remove all regions. - * @author Nicola Asuni - * @public - * @since 5.9.003 (2010-10-13) - * @see addPageRegion(), getPageRegions() - */ - public function setPageRegions($regions=array()) { - // empty current regions array - $this->page_regions = array(); - // add regions - foreach ($regions as $data) { - $this->addPageRegion($data); - } - } - - /** - * Add a single no-write region on selected page. - * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code. - * A region is always aligned on the left or right side of the page ad is defined using a vertical segment. - * You can set multiple regions for the same page. - * @param $region (array) array of a single no-write region array: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). - * @author Nicola Asuni - * @public - * @since 5.9.003 (2010-10-13) - * @see setPageRegions(), getPageRegions() - */ - public function addPageRegion($region) { - if (!isset($region['page']) OR empty($region['page'])) { - $region['page'] = $this->page; - } - if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0) - AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb']) - AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) { - $this->page_regions[] = $region; - } - } - - /** - * Remove a single no-write region. - * @param $key (int) region key - * @author Nicola Asuni - * @public - * @since 5.9.003 (2010-10-13) - * @see setPageRegions(), getPageRegions() - */ - public function removePageRegion($key) { - if (isset($this->page_regions[$key])) { - unset($this->page_regions[$key]); - } - } - /** * Check page for no-write regions and adapt current coordinates and page margins if necessary. * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code. @@ -27061,1684 +19080,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } return array($x, $y); } - - // --- SVG METHODS --------------------------------------------------------- - - /** - * Embedd a Scalable Vector Graphics (SVG) image. - * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library. - * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string. - * @param $x (float) Abscissa of the upper-left corner. - * @param $y (float) Ordinate of the upper-left corner. - * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated. - * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated. - * @param $link (mixed) URL or identifier returned by AddLink(). - * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:
  • T: top-right for LTR or top-left for RTL
  • M: middle-right for LTR or middle-left for RTL
  • B: bottom-right for LTR or bottom-left for RTL
  • N: next line
If the alignment is an empty string, then the pointer will be restored on the starting SVG position. - * @param $palign (string) Allows to center or align the image on the current line. Possible values are:
  • L : left align
  • C : center
  • R : right align
  • '' : empty string : left for LTR or right for RTL
- * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:
  • 0: no border (default)
  • 1: frame
or a string containing some or all of the following characters (in any order):
  • L: left
  • T: top
  • R: right
  • B: bottom
or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) - * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions. - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @public - */ - public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) { - if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) { - // convert SVG to raster image using GD or ImageMagick libraries - return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false); - } - if ($file{0} === '@') { // image from string - $this->svgdir = ''; - $svgdata = substr($file, 1); - } else { // SVG file - $this->svgdir = dirname($file); - $svgdata = file_get_contents($file); - } - if ($svgdata === false) { - $this->Error('SVG file not found: '.$file); - } - if ($x === '') { - $x = $this->x; - } - if ($y === '') { - $y = $this->y; - } - // check page for no-write regions and adapt page margins if necessary - list($x, $y) = $this->checkPageRegions($h, $x, $y); - $k = $this->k; - $ox = 0; - $oy = 0; - $ow = $w; - $oh = $h; - $aspect_ratio_align = 'xMidYMid'; - $aspect_ratio_ms = 'meet'; - $regs = array(); - // get original image width and height - preg_match('/]*)>/si', $svgdata, $regs); - if (isset($regs[1]) AND !empty($regs[1])) { - $tmp = array(); - if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) { - $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false); - } - $tmp = array(); - if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) { - $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false); - } - $tmp = array(); - if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) { - $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false); - } - $tmp = array(); - if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) { - $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false); - } - $tmp = array(); - $view_box = array(); - if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) { - if (count($tmp) == 5) { - array_shift($tmp); - foreach ($tmp as $key => $val) { - $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false); - } - $ox = $view_box[0]; - $oy = $view_box[1]; - } - // get aspect ratio - $tmp = array(); - if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) { - $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]); - switch (count($aspect_ratio)) { - case 3: { - $aspect_ratio_align = $aspect_ratio[1]; - $aspect_ratio_ms = $aspect_ratio[2]; - break; - } - case 2: { - $aspect_ratio_align = $aspect_ratio[0]; - $aspect_ratio_ms = $aspect_ratio[1]; - break; - } - case 1: { - $aspect_ratio_align = $aspect_ratio[0]; - $aspect_ratio_ms = 'meet'; - break; - } - } - } - } - } - // calculate image width and height on document - if (($w <= 0) AND ($h <= 0)) { - // convert image size to document unit - $w = $ow; - $h = $oh; - } elseif ($w <= 0) { - $w = $h * $ow / $oh; - } elseif ($h <= 0) { - $h = $w * $oh / $ow; - } - // fit the image on available space - list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage); - if ($this->rasterize_vector_images) { - // convert SVG to raster image using GD or ImageMagick libraries - return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false); - } - // set alignment - $this->img_rb_y = $y + $h; - // set alignment - if ($this->rtl) { - if ($palign == 'L') { - $ximg = $this->lMargin; - } elseif ($palign == 'C') { - $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $ximg = $this->w - $this->rMargin - $w; - } else { - $ximg = $x - $w; - } - $this->img_rb_x = $ximg; - } else { - if ($palign == 'L') { - $ximg = $this->lMargin; - } elseif ($palign == 'C') { - $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $ximg = $this->w - $this->rMargin - $w; - } else { - $ximg = $x; - } - $this->img_rb_x = $ximg + $w; - } - // store current graphic vars - $gvars = $this->getGraphicVars(); - // store SVG position and scale factors - $svgoffset_x = ($ximg - $ox) * $this->k; - $svgoffset_y = -($y - $oy) * $this->k; - if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) { - $ow = $view_box[2]; - $oh = $view_box[3]; - } else { - if ($ow <= 0) { - $ow = $w; - } - if ($oh <= 0) { - $oh = $h; - } - } - $svgscale_x = $w / $ow; - $svgscale_y = $h / $oh; - // scaling and alignment - if ($aspect_ratio_align != 'none') { - // store current scaling values - $svgscale_old_x = $svgscale_x; - $svgscale_old_y = $svgscale_y; - // force uniform scaling - if ($aspect_ratio_ms == 'slice') { - // the entire viewport is covered by the viewBox - if ($svgscale_x > $svgscale_y) { - $svgscale_y = $svgscale_x; - } elseif ($svgscale_x < $svgscale_y) { - $svgscale_x = $svgscale_y; - } - } else { // meet - // the entire viewBox is visible within the viewport - if ($svgscale_x < $svgscale_y) { - $svgscale_y = $svgscale_x; - } elseif ($svgscale_x > $svgscale_y) { - $svgscale_x = $svgscale_y; - } - } - // correct X alignment - switch (substr($aspect_ratio_align, 1, 3)) { - case 'Min': { - // do nothing - break; - } - case 'Max': { - $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x)); - break; - } - default: - case 'Mid': { - $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2); - break; - } - } - // correct Y alignment - switch (substr($aspect_ratio_align, 5)) { - case 'Min': { - // do nothing - break; - } - case 'Max': { - $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y)); - break; - } - default: - case 'Mid': { - $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2); - break; - } - } - } - // store current page break mode - $page_break_mode = $this->AutoPageBreak; - $page_break_margin = $this->getBreakMargin(); - $cell_padding = $this->cell_padding; - $this->SetCellPadding(0); - $this->SetAutoPageBreak(false); - // save the current graphic state - $this->_out('q'.$this->epsmarker); - // set initial clipping mask - $this->Rect($x, $y, $w, $h, 'CNZ', array(), array()); - // scale and translate - $e = $ox * $this->k * (1 - $svgscale_x); - $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y); - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $svgscale_x, 0, 0, $svgscale_y, $e + $svgoffset_x, $f + $svgoffset_y)); - // creates a new XML parser to be used by the other XML functions - $this->parser = xml_parser_create('UTF-8'); - // the following function allows to use parser inside object - xml_set_object($this->parser, $this); - // disable case-folding for this XML parser - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); - // sets the element handler functions for the XML parser - xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler'); - // sets the character data handler function for the XML parser - xml_set_character_data_handler($this->parser, 'segSVGContentHandler'); - // start parsing an XML document - if (!xml_parse($this->parser, $svgdata)) { - $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)); - $this->Error($error_message); - } - // free this XML parser - xml_parser_free($this->parser); - // restore previous graphic state - $this->_out($this->epsmarker.'Q'); - // restore graphic vars - $this->setGraphicVars($gvars); - $this->lasth = $gvars['lasth']; - if (!empty($border)) { - $bx = $this->x; - $by = $this->y; - $this->x = $ximg; - if ($this->rtl) { - $this->x += $w; - } - $this->y = $y; - $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true); - $this->x = $bx; - $this->y = $by; - } - if ($link) { - $this->Link($ximg, $y, $w, $h, $link, 0); - } - // set pointer to align the next text/objects - switch($align) { - case 'T':{ - $this->y = $y; - $this->x = $this->img_rb_x; - break; - } - case 'M':{ - $this->y = $y + round($h/2); - $this->x = $this->img_rb_x; - break; - } - case 'B':{ - $this->y = $this->img_rb_y; - $this->x = $this->img_rb_x; - break; - } - case 'N':{ - $this->SetY($this->img_rb_y); - break; - } - default:{ - // restore pointer to starting position - $this->x = $gvars['x']; - $this->y = $gvars['y']; - $this->page = $gvars['page']; - $this->current_column = $gvars['current_column']; - $this->tMargin = $gvars['tMargin']; - $this->bMargin = $gvars['bMargin']; - $this->w = $gvars['w']; - $this->h = $gvars['h']; - $this->wPt = $gvars['wPt']; - $this->hPt = $gvars['hPt']; - $this->fwPt = $gvars['fwPt']; - $this->fhPt = $gvars['fhPt']; - break; - } - } - $this->endlinex = $this->img_rb_x; - // restore page break - $this->SetAutoPageBreak($page_break_mode, $page_break_margin); - $this->cell_padding = $cell_padding; - } - - /** - * Get the tranformation matrix from SVG transform attribute - * @param $attribute (string) transformation - * @return array of transformations - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function getSVGTransformMatrix($attribute) { - // identity matrix - $tm = array(1, 0, 0, 1, 0, 0); - $transform = array(); - if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) { - foreach ($transform as $key => $data) { - if (!empty($data[2])) { - $a = 1; - $b = 0; - $c = 0; - $d = 1; - $e = 0; - $f = 0; - $regs = array(); - switch ($data[1]) { - case 'matrix': { - if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $a = $regs[1]; - $b = $regs[2]; - $c = $regs[3]; - $d = $regs[4]; - $e = $regs[5]; - $f = $regs[6]; - } - break; - } - case 'translate': { - if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $e = $regs[1]; - $f = $regs[2]; - } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $e = $regs[1]; - } - break; - } - case 'scale': { - if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $a = $regs[1]; - $d = $regs[2]; - } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $a = $regs[1]; - $d = $a; - } - break; - } - case 'rotate': { - if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $ang = deg2rad($regs[1]); - $x = $regs[2]; - $y = $regs[3]; - $a = cos($ang); - $b = sin($ang); - $c = -$b; - $d = $a; - $e = ($x * (1 - $a)) - ($y * $c); - $f = ($y * (1 - $d)) - ($x * $b); - } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { - $ang = deg2rad($regs[1]); - $a = cos($ang); - $b = sin($ang); - $c = -$b; - $d = $a; - $e = 0; - $f = 0; - } - break; - } - case 'skewX': { - if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { - $c = tan(deg2rad($regs[1])); - } - break; - } - case 'skewY': { - if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { - $b = tan(deg2rad($regs[1])); - } - break; - } - } - $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f)); - } - } - } - return $tm; - } - - /** - * Get the product of two SVG tranformation matrices - * @param $ta (array) first SVG tranformation matrix - * @param $tb (array) second SVG tranformation matrix - * @return transformation array - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function getTransformationMatrixProduct($ta, $tb) { - $tm = array(); - $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]); - $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]); - $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]); - $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]); - $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4]; - $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5]; - return $tm; - } - - /** - * Convert SVG transformation matrix to PDF. - * @param $tm (array) original SVG transformation matrix - * @return array transformation matrix - * @protected - * @since 5.0.000 (2010-05-02) - */ - protected function convertSVGtMatrix($tm) { - $a = $tm[0]; - $b = -$tm[1]; - $c = -$tm[2]; - $d = $tm[3]; - $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k; - $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k; - $x = 0; - $y = $this->h * $this->k; - $e = ($x * (1 - $a)) - ($y * $c) + $e; - $f = ($y * (1 - $d)) - ($x * $b) + $f; - return array($a, $b, $c, $d, $e, $f); - } - - /** - * Apply SVG graphic transformation matrix. - * @param $tm (array) original SVG transformation matrix - * @protected - * @since 5.0.000 (2010-05-02) - */ - protected function SVGTransform($tm) { - $this->Transform($this->convertSVGtMatrix($tm)); - } - - /** - * Apply the requested SVG styles (*** TO BE COMPLETED ***) - * @param $svgstyle (array) array of SVG styles to apply - * @param $prevsvgstyle (array) array of previous SVG style - * @param $x (int) X origin of the bounding box - * @param $y (int) Y origin of the bounding box - * @param $w (int) width of the bounding box - * @param $h (int) height of the bounding box - * @param $clip_function (string) clip function - * @param $clip_params (array) array of parameters for clipping function - * @return object style - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) { - $objstyle = ''; - $minlen = (0.01 / $this->k); // minimum acceptable length (3 point) - if (!isset($svgstyle['opacity'])) { - return $objstyle; - } - // clip-path - $regs = array(); - if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) { - $clip_path = $this->svgclippaths[$regs[1]]; - foreach ($clip_path as $cp) { - $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']); - } - } - // opacity - if ($svgstyle['opacity'] != 1) { - $this->SetAlpha($svgstyle['opacity']); - } - // color - $fill_color = $this->convertHTMLColorToDec($svgstyle['color']); - $this->SetFillColorArray($fill_color); - // text color - $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']); - $this->SetTextColorArray($text_color); - // clip - if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) { - $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0); - $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0); - $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0); - $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0); - $cx = $x + $left; - $cy = $y + $top; - $cw = $w - $left - $right; - $ch = $h - $top - $bottom; - if ($svgstyle['clip-rule'] == 'evenodd') { - $clip_rule = 'CNZ'; - } else { - $clip_rule = 'CEO'; - } - $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array()); - } - // fill - $regs = array(); - if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) { - // gradient - $gradient = $this->svggradients[$regs[1]]; - if (isset($gradient['xref'])) { - // reference to another gradient definition - $newgradient = $this->svggradients[$gradient['xref']]; - $newgradient['coords'] = $gradient['coords']; - $newgradient['mode'] = $gradient['mode']; - $newgradient['gradientUnits'] = $gradient['gradientUnits']; - if (isset($gradient['gradientTransform'])) { - $newgradient['gradientTransform'] = $gradient['gradientTransform']; - } - $gradient = $newgradient; - } - //save current Graphic State - $this->_out('q'); - //set clipping area - if (!empty($clip_function) AND method_exists($this, $clip_function)) { - $bbox = call_user_func_array(array($this, $clip_function), $clip_params); - if (is_array($bbox) AND (count($bbox) == 4)) { - list($x, $y, $w, $h) = $bbox; - } - } - if ($gradient['mode'] == 'measure') { - if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) { - $gtm = $gradient['gradientTransform']; - // apply transformation matrix - $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4]; - $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5]; - $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4]; - $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5]; - if (isset($gradient['coords'][4])) { - $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2)); - } - $gradient['coords'][0] = $xa; - $gradient['coords'][1] = $ya; - $gradient['coords'][2] = $xb; - $gradient['coords'][3] = $yb; - } - // convert SVG coordinates to user units - $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false); - $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false); - $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false); - $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false); - if (isset($gradient['coords'][4])) { - $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false); - } - // shift units - if ($gradient['gradientUnits'] == 'objectBoundingBox') { - // convert to SVG coordinate system - $gradient['coords'][0] += $x; - $gradient['coords'][1] += $y; - $gradient['coords'][2] += $x; - $gradient['coords'][3] += $y; - } - if ($w <= $minlen) { - $w = $minlen; - } - if ($h <= $minlen) { - $h = $minlen; - } - // calculate percentages - $gradient['coords'][0] = ($gradient['coords'][0] - $x) / $w; - $gradient['coords'][1] = ($gradient['coords'][1] - $y) / $h; - $gradient['coords'][2] = ($gradient['coords'][2] - $x) / $w; - $gradient['coords'][3] = ($gradient['coords'][3] - $y) / $h; - if (isset($gradient['coords'][4])) { - $gradient['coords'][4] /= $w; - } - } elseif ($gradient['mode'] == 'percentage') { - foreach($gradient['coords'] as $key => $val) { - $gradient['coords'][$key] = (intval($val) / 100); - } - } - // fix values - foreach($gradient['coords'] as $key => $val) { - if ($val < 0) { - $gradient['coords'][$key] = 0; - } elseif ($val > 1) { - $gradient['coords'][$key] = 1; - } - } - if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) { - // single color (no shading) - $gradient['coords'][0] = 1; - $gradient['coords'][1] = 0; - $gradient['coords'][2] = 0.999; - $gradient['coords'][3] = 0; - } - // swap Y coordinates - $tmp = $gradient['coords'][1]; - $gradient['coords'][1] = $gradient['coords'][3]; - $gradient['coords'][3] = $tmp; - // set transformation map for gradient - if ($gradient['type'] == 3) { - // gradient is always circular - $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h)); - $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $w*$this->k, $x*$this->k, $cy*$this->k)); - } else { - $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k)); - } - if (count($gradient['stops']) > 1) { - $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false); - } - } elseif ($svgstyle['fill'] != 'none') { - $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']); - if ($svgstyle['fill-opacity'] != 1) { - $this->SetAlpha($svgstyle['fill-opacity']); - } - $this->SetFillColorArray($fill_color); - if ($svgstyle['fill-rule'] == 'evenodd') { - $objstyle .= 'F*'; - } else { - $objstyle .= 'F'; - } - } - // stroke - if ($svgstyle['stroke'] != 'none') { - $stroke_style = array( - 'color' => $this->convertHTMLColorToDec($svgstyle['stroke']), - 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false), - 'cap' => $svgstyle['stroke-linecap'], - 'join' => $svgstyle['stroke-linejoin'] - ); - if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) { - $stroke_style['dash'] = $svgstyle['stroke-dasharray']; - } - $this->SetLineStyle($stroke_style); - $objstyle .= 'D'; - } - // font - $regs = array(); - if (!empty($svgstyle['font'])) { - if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) { - $font_family = $this->getFontFamilyName($regs[1]); - } else { - $font_family = $svgstyle['font-family']; - } - if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) { - $font_size = trim($regs[1]); - } else { - $font_size = $svgstyle['font-size']; - } - if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) { - $font_style = trim($regs[1]); - } else { - $font_style = $svgstyle['font-style']; - } - if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) { - $font_weight = trim($regs[1]); - } else { - $font_weight = $svgstyle['font-weight']; - } - if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) { - $font_stretch = trim($regs[1]); - } else { - $font_stretch = $svgstyle['font-stretch']; - } - if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) { - $font_spacing = trim($regs[1]); - } else { - $font_spacing = $svgstyle['letter-spacing']; - } - } else { - $font_family = $this->getFontFamilyName($svgstyle['font-family']); - $font_size = $svgstyle['font-size']; - $font_style = $svgstyle['font-style']; - $font_weight = $svgstyle['font-weight']; - $font_stretch = $svgstyle['font-stretch']; - $font_spacing = $svgstyle['letter-spacing']; - } - $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit, false) * $this->k; - $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']); - $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']); - switch ($font_style) { - case 'italic': { - $font_style = 'I'; - break; - } - case 'oblique': { - $font_style = 'I'; - break; - } - default: - case 'normal': { - $font_style = ''; - break; - } - } - switch ($font_weight) { - case 'bold': - case 'bolder': { - $font_style .= 'B'; - break; - } - } - switch ($svgstyle['text-decoration']) { - case 'underline': { - $font_style .= 'U'; - break; - } - case 'overline': { - $font_style .= 'O'; - break; - } - case 'line-through': { - $font_style .= 'D'; - break; - } - default: - case 'none': { - break; - } - } - $this->SetFont($font_family, $font_style, $font_size); - $this->setFontStretching($font_stretch); - $this->setFontSpacing($font_spacing); - return $objstyle; - } - - /** - * Draws an SVG path - * @param $d (string) attribute d of the path SVG element - * @param $style (string) Style of rendering. Possible values are: - *
    - *
  • D or empty string: Draw (default).
  • - *
  • F: Fill.
  • - *
  • F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.
  • - *
  • DF or FD: Draw and fill.
  • - *
  • DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.
  • - *
  • CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).
  • - *
  • CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).
  • - *
- * @return array of container box measures (x, y, w, h) - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function SVGPath($d, $style='') { - // set fill/stroke style - $op = $this->getPathPaintOperator($style, ''); - if (empty($op)) { - return; - } - $paths = array(); - $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d); - preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER); - $x = 0; - $y = 0; - $x1 = 0; - $y1 = 0; - $x2 = 0; - $y2 = 0; - $xmin = 2147483647; - $xmax = 0; - $ymin = 2147483647; - $ymax = 0; - $relcoord = false; - $minlen = (0.01 / $this->k); // minimum acceptable length (3 point) - $firstcmd = true; // used to print first point - // draw curve pieces - foreach ($paths as $key => $val) { - // get curve type - $cmd = trim($val[1]); - if (strtolower($cmd) == $cmd) { - // use relative coordinated instead of absolute - $relcoord = true; - $xoffset = $x; - $yoffset = $y; - } else { - $relcoord = false; - $xoffset = 0; - $yoffset = 0; - } - $params = array(); - if (isset($val[2])) { - // get curve parameters - $rawparams = preg_split('/([\,\s]+)/si', trim($val[2])); - $params = array(); - foreach ($rawparams as $ck => $cp) { - $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false); - if (abs($params[$ck]) < $minlen) { - // aproximate little values to zero - $params[$ck] = 0; - } - } - } - // store current origin point - $x0 = $x; - $y0 = $y; - switch (strtoupper($cmd)) { - case 'M': { // moveto - foreach ($params as $ck => $cp) { - if (($ck % 2) == 0) { - $x = $cp + $xoffset; - } else { - $y = $cp + $yoffset; - if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { - if ($ck == 1) { - $this->_outPoint($x, $y); - $firstcmd = false; - } else { - $this->_outLine($x, $y); - } - } - $xmin = min($xmin, $x); - $ymin = min($ymin, $y); - $xmax = max($xmax, $x); - $ymax = max($ymax, $y); - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'L': { // lineto - foreach ($params as $ck => $cp) { - if (($ck % 2) == 0) { - $x = $cp + $xoffset; - } else { - $y = $cp + $yoffset; - if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { - $this->_outLine($x, $y); - } - $xmin = min($xmin, $x); - $ymin = min($ymin, $y); - $xmax = max($xmax, $x); - $ymax = max($ymax, $y); - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'H': { // horizontal lineto - foreach ($params as $ck => $cp) { - $x = $cp + $xoffset; - if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { - $this->_outLine($x, $y); - } - $xmin = min($xmin, $x); - $xmax = max($xmax, $x); - if ($relcoord) { - $xoffset = $x; - } - } - break; - } - case 'V': { // vertical lineto - foreach ($params as $ck => $cp) { - $y = $cp + $yoffset; - if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { - $this->_outLine($x, $y); - } - $ymin = min($ymin, $y); - $ymax = max($ymax, $y); - if ($relcoord) { - $yoffset = $y; - } - } - break; - } - case 'C': { // curveto - foreach ($params as $ck => $cp) { - $params[$ck] = $cp; - if ((($ck + 1) % 6) == 0) { - $x1 = $params[($ck - 5)] + $xoffset; - $y1 = $params[($ck - 4)] + $yoffset; - $x2 = $params[($ck - 3)] + $xoffset; - $y2 = $params[($ck - 2)] + $yoffset; - $x = $params[($ck - 1)] + $xoffset; - $y = $params[($ck)] + $yoffset; - $this->_outCurve($x1, $y1, $x2, $y2, $x, $y); - $xmin = min($xmin, $x, $x1, $x2); - $ymin = min($ymin, $y, $y1, $y2); - $xmax = max($xmax, $x, $x1, $x2); - $ymax = max($ymax, $y, $y1, $y2); - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'S': { // shorthand/smooth curveto - foreach ($params as $ck => $cp) { - $params[$ck] = $cp; - if ((($ck + 1) % 4) == 0) { - if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) { - $x1 = (2 * $x) - $x2; - $y1 = (2 * $y) - $y2; - } else { - $x1 = $x; - $y1 = $y; - } - $x2 = $params[($ck - 3)] + $xoffset; - $y2 = $params[($ck - 2)] + $yoffset; - $x = $params[($ck - 1)] + $xoffset; - $y = $params[($ck)] + $yoffset; - $this->_outCurve($x1, $y1, $x2, $y2, $x, $y); - $xmin = min($xmin, $x, $x1, $x2); - $ymin = min($ymin, $y, $y1, $y2); - $xmax = max($xmax, $x, $x1, $x2); - $ymax = max($ymax, $y, $y1, $y2); - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'Q': { // quadratic Bézier curveto - foreach ($params as $ck => $cp) { - $params[$ck] = $cp; - if ((($ck + 1) % 4) == 0) { - // convert quadratic points to cubic points - $x1 = $params[($ck - 3)] + $xoffset; - $y1 = $params[($ck - 2)] + $yoffset; - $xa = ($x + (2 * $x1)) / 3; - $ya = ($y + (2 * $y1)) / 3; - $x = $params[($ck - 1)] + $xoffset; - $y = $params[($ck)] + $yoffset; - $xb = ($x + (2 * $x1)) / 3; - $yb = ($y + (2 * $y1)) / 3; - $this->_outCurve($xa, $ya, $xb, $yb, $x, $y); - $xmin = min($xmin, $x, $xa, $xb); - $ymin = min($ymin, $y, $ya, $yb); - $xmax = max($xmax, $x, $xa, $xb); - $ymax = max($ymax, $y, $ya, $yb); - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'T': { // shorthand/smooth quadratic Bézier curveto - foreach ($params as $ck => $cp) { - $params[$ck] = $cp; - if (($ck % 2) != 0) { - if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) { - $x1 = (2 * $x) - $x1; - $y1 = (2 * $y) - $y1; - } else { - $x1 = $x; - $y1 = $y; - } - // convert quadratic points to cubic points - $xa = ($x + (2 * $x1)) / 3; - $ya = ($y + (2 * $y1)) / 3; - $x = $params[($ck - 1)] + $xoffset; - $y = $params[($ck)] + $yoffset; - $xb = ($x + (2 * $x1)) / 3; - $yb = ($y + (2 * $y1)) / 3; - $this->_outCurve($xa, $ya, $xb, $yb, $x, $y); - $xmin = min($xmin, $x, $xa, $xb); - $ymin = min($ymin, $y, $ya, $yb); - $xmax = max($xmax, $x, $xa, $xb); - $ymax = max($ymax, $y, $ya, $yb); - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'A': { // elliptical arc - foreach ($params as $ck => $cp) { - $params[$ck] = $cp; - if ((($ck + 1) % 7) == 0) { - $x0 = $x; - $y0 = $y; - $rx = abs($params[($ck - 6)]); - $ry = abs($params[($ck - 5)]); - $ang = -$rawparams[($ck - 4)]; - $angle = deg2rad($ang); - $fa = $rawparams[($ck - 3)]; // large-arc-flag - $fs = $rawparams[($ck - 2)]; // sweep-flag - $x = $params[($ck - 1)] + $xoffset; - $y = $params[$ck] + $yoffset; - if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) { - // endpoints are almost identical - $xmin = min($xmin, $x); - $ymin = min($ymin, $y); - $xmax = max($xmax, $x); - $ymax = max($ymax, $y); - } else { - $cos_ang = cos($angle); - $sin_ang = sin($angle); - $a = (($x0 - $x) / 2); - $b = (($y0 - $y) / 2); - $xa = ($a * $cos_ang) - ($b * $sin_ang); - $ya = ($a * $sin_ang) + ($b * $cos_ang); - $rx2 = $rx * $rx; - $ry2 = $ry * $ry; - $xa2 = $xa * $xa; - $ya2 = $ya * $ya; - $delta = ($xa2 / $rx2) + ($ya2 / $ry2); - if ($delta > 1) { - $rx *= sqrt($delta); - $ry *= sqrt($delta); - $rx2 = $rx * $rx; - $ry2 = $ry * $ry; - } - $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2)); - if ($numerator < 0) { - $root = 0; - } else { - $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2))); - } - if ($fa == $fs){ - $root *= -1; - } - $cax = $root * (($rx * $ya) / $ry); - $cay = -$root * (($ry * $xa) / $rx); - // coordinates of ellipse center - $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2); - $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2); - // get angles - $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry)); - $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry)); - if (($fs == 0) AND ($dang > 0)) { - $dang -= (2 * M_PI); - } elseif (($fs == 1) AND ($dang < 0)) { - $dang += (2 * M_PI); - } - $angf = $angs - $dang; - if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) { - // reverse angles - $tmp = $angs; - $angs = $angf; - $angf = $tmp; - } - $angs = round(rad2deg($angs), 6); - $angf = round(rad2deg($angf), 6); - // covent angles to positive values - if (($angs < 0) AND ($angf < 0)) { - $angs += 360; - $angf += 360; - } - $pie = false; - if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) { - $pie = true; - } - list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true); - $xmin = min($xmin, $x, $axmin); - $ymin = min($ymin, $y, $aymin); - $xmax = max($xmax, $x, $axmax); - $ymax = max($ymax, $y, $aymax); - } - if ($relcoord) { - $xoffset = $x; - $yoffset = $y; - } - } - } - break; - } - case 'Z': { - $this->_out('h'); - break; - } - } - $firstcmd = false; - } // end foreach - if (!empty($op)) { - $this->_out($op); - } - return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin)); - } - - /** - * Returns the angle in radiants between two vectors - * @param $x1 (int) X coordinate of first vector point - * @param $y1 (int) Y coordinate of first vector point - * @param $x2 (int) X coordinate of second vector point - * @param $y2 (int) Y coordinate of second vector point - * @author Nicola Asuni - * @since 5.0.000 (2010-05-04) - * @protected - */ - protected function getVectorsAngle($x1, $y1, $x2, $y2) { - $dprod = ($x1 * $x2) + ($y1 * $y2); - $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1)); - $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2)); - $angle = acos($dprod / ($dist1 * $dist2)); - if (is_nan($angle)) { - $angle = M_PI; - } - if ((($x1 * $y2) - ($x2 * $y1)) < 0) { - $angle *= -1; - } - return $angle; - } - - /** - * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***) - * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler. - * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters. - * @param $attribs (array) The third parameter, attribs, contains an associative array with the element's attributes (if any). The keys of this array are the attribute names, the values are the attribute values. Attribute names are case-folded on the same criteria as element names. Attribute values are not case-folded. The original order of the attributes can be retrieved by walking through attribs the normal way, using each(). The first key in the array was the first attribute, and so on. - * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix). - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) { - // check if we are in clip mode - if ($this->svgclipmode) { - $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]); - return; - } - if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) { - if (!isset($attribs['id'])) { - $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1); - } - $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs); - return; - } - $clipping = false; - if ($parser == 'clip-path') { - // set clipping mode - $clipping = true; - } - // get styling properties - $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)]; // previous style - $svgstyle = $this->svgstyles[0]; // set default style - if (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) { - // fix style for regular expression - $attribs['style'] = ';'.$attribs['style']; - } - foreach ($prev_svgstyle as $key => $val) { - if (in_array($key, $this->svginheritprop)) { - // inherit previous value - $svgstyle[$key] = $val; - } - if (isset($attribs[$key]) AND !$this->empty_string($attribs[$key])) { - // specific attribute settings - if ($attribs[$key] == 'inherit') { - $svgstyle[$key] = $val; - } else { - $svgstyle[$key] = $attribs[$key]; - } - } elseif (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) { - // CSS style syntax - $attrval = array(); - if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) { - if ($attrval[1] == 'inherit') { - $svgstyle[$key] = $val; - } else { - $svgstyle[$key] = $attrval[1]; - } - } - } - } - // transformation matrix - if (!empty($ctm)) { - $tm = $ctm; - } else { - $tm = $this->svgstyles[(count($this->svgstyles) - 1)]['transfmatrix']; - } - if (isset($attribs['transform']) AND !empty($attribs['transform'])) { - $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform'])); - } - $svgstyle['transfmatrix'] = $tm; - $invisible = false; - if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) { - // the current graphics element is invisible (nothing is painted) - $invisible = true; - } - // process tag - switch($name) { - case 'defs': { - $this->svgdefsmode = true; - break; - } - // clipPath - case 'clipPath': { - if ($invisible) { - break; - } - $this->svgclipmode = true; - if (!isset($attribs['id'])) { - $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1); - } - $this->svgclipid = $attribs['id']; - $this->svgclippaths[$this->svgclipid] = array(); - $this->svgcliptm[$this->svgclipid] = $tm; - break; - } - case 'svg': { - // start of SVG object - break; - } - case 'g': { - // group together related graphics elements - array_push($this->svgstyles, $svgstyle); - $this->StartTransform(); - $this->setSVGStyles($svgstyle, $prev_svgstyle); - break; - } - case 'linearGradient': { - if ($this->pdfa_mode) { - break; - } - if (!isset($attribs['id'])) { - $attribs['id'] = 'GR_'.(count($this->svggradients) + 1); - } - $this->svggradientid = $attribs['id']; - $this->svggradients[$this->svggradientid] = array(); - $this->svggradients[$this->svggradientid]['type'] = 2; - $this->svggradients[$this->svggradientid]['stops'] = array(); - if (isset($attribs['gradientUnits'])) { - $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits']; - } else { - $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox'; - } - //$attribs['spreadMethod'] - $x1 = (isset($attribs['x1'])?$attribs['x1']:'0%'); - $y1 = (isset($attribs['y1'])?$attribs['y1']:'0%'); - $x2 = (isset($attribs['x2'])?$attribs['x2']:'100%'); - $y2 = (isset($attribs['y2'])?$attribs['y2']:'0%'); - if (substr($x1, -1) != '%') { - $this->svggradients[$this->svggradientid]['mode'] = 'measure'; - } else { - $this->svggradients[$this->svggradientid]['mode'] = 'percentage'; - } - if (isset($attribs['gradientTransform'])) { - $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']); - } - $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2); - if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) { - // gradient is defined on another place - $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1); - } - break; - } - case 'radialGradient': { - if ($this->pdfa_mode) { - break; - } - if (!isset($attribs['id'])) { - $attribs['id'] = 'GR_'.(count($this->svggradients) + 1); - } - $this->svggradientid = $attribs['id']; - $this->svggradients[$this->svggradientid] = array(); - $this->svggradients[$this->svggradientid]['type'] = 3; - $this->svggradients[$this->svggradientid]['stops'] = array(); - if (isset($attribs['gradientUnits'])) { - $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits']; - } else { - $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox'; - } - //$attribs['spreadMethod'] - $cx = (isset($attribs['cx'])?$attribs['cx']:0.5); - $cy = (isset($attribs['cy'])?$attribs['cy']:0.5); - $fx = (isset($attribs['fx'])?$attribs['fx']:$cx); - $fy = (isset($attribs['fy'])?$attribs['fy']:$cy); - $r = (isset($attribs['r'])?$attribs['r']:0.5); - if (isset($attribs['cx']) AND (substr($attribs['cx'], -1) != '%')) { - $this->svggradients[$this->svggradientid]['mode'] = 'measure'; - } else { - $this->svggradients[$this->svggradientid]['mode'] = 'percentage'; - } - if (isset($attribs['gradientTransform'])) { - $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']); - } - $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r); - if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) { - // gradient is defined on another place - $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1); - } - break; - } - case 'stop': { - // gradient stops - if (substr($attribs['offset'], -1) == '%') { - $offset = floatval(substr($attribs['offset'], -1)) / 100; - } else { - $offset = floatval($attribs['offset']); - if ($offset > 1) { - $offset /= 100; - } - } - $stop_color = isset($svgstyle['stop-color'])?$this->convertHTMLColorToDec($svgstyle['stop-color']):'black'; - $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1; - $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity); - break; - } - // paths - case 'path': { - if ($invisible) { - break; - } - if (isset($attribs['d'])) { - $d = trim($attribs['d']); - if (!empty($d)) { - if ($clipping) { - $this->SVGTransform($tm); - $this->SVGPath($d, 'CNZ'); - } else { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d, 'CNZ')); - if (!empty($obstyle)) { - $this->SVGPath($d, $obstyle); - } - $this->StopTransform(); - } - } - } - break; - } - // shapes - case 'rect': { - if ($invisible) { - break; - } - $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0); - $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0); - $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0); - $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0); - $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0); - $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx); - if ($clipping) { - $this->SVGTransform($tm); - $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array()); - } else { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ')); - if (!empty($obstyle)) { - $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array()); - } - $this->StopTransform(); - } - break; - } - case 'circle': { - if ($invisible) { - break; - } - $cx = (isset($attribs['cx'])?$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false):0); - $cy = (isset($attribs['cy'])?$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false):0); - $r = (isset($attribs['r'])?$this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false):0); - $x = $cx - $r; - $y = $cy - $r; - $w = 2 * $r; - $h = $w; - if ($clipping) { - $this->SVGTransform($tm); - $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8); - } else { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ')); - if (!empty($obstyle)) { - $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8); - } - $this->StopTransform(); - } - break; - } - case 'ellipse': { - if ($invisible) { - break; - } - $cx = (isset($attribs['cx'])?$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false):0); - $cy = (isset($attribs['cy'])?$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false):0); - $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0); - $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):0); - $x = $cx - $rx; - $y = $cy - $ry; - $w = 2 * $rx; - $h = 2 * $ry; - if ($clipping) { - $this->SVGTransform($tm); - $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8); - } else { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ')); - if (!empty($obstyle)) { - $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8); - } - $this->StopTransform(); - } - break; - } - case 'line': { - if ($invisible) { - break; - } - $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0); - $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0); - $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0); - $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0); - $x = $x1; - $y = $y1; - $w = abs($x2 - $x1); - $h = abs($y2 - $y1); - if (!$clipping) { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2)); - $this->Line($x1, $y1, $x2, $y2); - $this->StopTransform(); - } - break; - } - case 'polyline': - case 'polygon': { - if ($invisible) { - break; - } - $points = (isset($attribs['points'])?$attribs['points']:'0 0'); - $points = trim($points); - // note that point may use a complex syntax not covered here - $points = preg_split('/[\,\s]+/si', $points); - if (count($points) < 4) { - break; - } - $p = array(); - $xmin = 2147483647; - $xmax = 0; - $ymin = 2147483647; - $ymax = 0; - foreach ($points as $key => $val) { - $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false); - if (($key % 2) == 0) { - // X coordinate - $xmin = min($xmin, $p[$key]); - $xmax = max($xmax, $p[$key]); - } else { - // Y coordinate - $ymin = min($ymin, $p[$key]); - $ymax = max($ymax, $p[$key]); - } - } - $x = $xmin; - $y = $ymin; - $w = ($xmax - $xmin); - $h = ($ymax - $ymin); - if ($name == 'polyline') { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ')); - $this->PolyLine($p, 'D', array(), array()); - $this->StopTransform(); - } else { // polygon - if ($clipping) { - $this->SVGTransform($tm); - $this->Polygon($p, 'CNZ', array(), array(), true); - } else { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ')); - if (!empty($obstyle)) { - $this->Polygon($p, $obstyle, array(), array(), true); - } - $this->StopTransform(); - } - } - break; - } - // image - case 'image': { - if ($invisible) { - break; - } - if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) { - break; - } - $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0); - $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0); - $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0); - $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0); - $img = $attribs['xlink:href']; - if (!$clipping) { - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h); - // fix image path - if (!$this->empty_string($this->svgdir) AND (($img{0} == '.') OR (basename($img) == $img))) { - // replace relative path with full server path - $img = $this->svgdir.'/'.$img; - } - if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { - $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']); - if (($findroot === false) OR ($findroot > 1)) { - if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') { - $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img; - } else { - $img = $_SERVER['DOCUMENT_ROOT'].$img; - } - } - } - $img = urldecode($img); - $testscrtype = @parse_url($img); - if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) { - // convert URL to server path - $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img); - } - $this->Image($img, $x, $y, $w, $h); - $this->StopTransform(); - } - break; - } - // text - case 'text': - case 'tspan': { - $this->svgtextmode['invisible'] = $invisible; - if ($invisible) { - break; - } - array_push($this->svgstyles, $svgstyle); - // only basic support - advanced features must be implemented - $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):$this->x); - $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):$this->y); - $svgstyle['text-color'] = $svgstyle['fill']; - $this->svgtext = ''; - if (isset($svgstyle['text-anchor'])) { - $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor']; - } else { - $this->svgtextmode['text-anchor'] = 'start'; - } - if (isset($svgstyle['direction'])) { - if ($svgstyle['direction'] == 'rtl') { - $this->svgtextmode['rtl'] = true; - } else { - $this->svgtextmode['rtl'] = false; - } - } else { - $this->svgtextmode['rtl'] = false; - } - if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) { - $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false); - } else { - $this->svgtextmode['stroke'] = false; - } - $this->StartTransform(); - $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1); - $this->x = $x; - $this->y = $y; - break; - } - // use - case 'use': { - if (isset($attribs['xlink:href'])) { - $use = $this->svgdefs[substr($attribs['xlink:href'], 1)]; - if (isset($attribs['xlink:href'])) { - unset($attribs['xlink:href']); - } - if (isset($attribs['id'])) { - unset($attribs['id']); - } - $attribs = array_merge($use['attribs'], $attribs); - $this->startSVGElementHandler($parser, $use['name'], $use['attribs']); - } - break; - } - default: { - break; - } - } // end of switch - } - - /** - * Sets the closing SVG element handler function for the XML parser. - * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler. - * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters. - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function endSVGElementHandler($parser, $name) { - switch($name) { - case 'defs': { - $this->svgdefsmode = false; - break; - } - // clipPath - case 'clipPath': { - $this->svgclipmode = false; - break; - } - case 'g': { - // ungroup: remove last style from array - array_pop($this->svgstyles); - $this->StopTransform(); - break; - } - case 'text': - case 'tspan': { - if ($this->svgtextmode['invisible']) { - // This implementation must be fixed to following the rule: - // If the 'visibility' property is set to hidden on a 'tspan', 'tref' or 'altGlyph' element, then the text is invisible but still takes up space in text layout calculations. - break; - } - // print text - $text = $this->stringTrim($this->svgtext); - if ($this->svgtextmode['text-anchor'] != 'start') { - $textlen = $this->GetStringWidth($text); - // check if string is RTL text - if ($this->svgtextmode['text-anchor'] == 'end') { - if ($this->svgtextmode['rtl']) { - $this->x += $textlen; - } else { - $this->x -= $textlen; - } - } elseif ($this->svgtextmode['text-anchor'] == 'middle') { - if ($this->svgtextmode['rtl']) { - $this->x += ($textlen / 2); - } else { - $this->x -= ($textlen / 2); - } - } - } - $textrendermode = $this->textrendermode; - $textstrokewidth = $this->textstrokewidth; - $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false); - $this->Cell(0, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T'); - // restore previous rendering mode - $this->textrendermode = $textrendermode; - $this->textstrokewidth = $textstrokewidth; - $this->svgtext = ''; - $this->StopTransform(); - array_pop($this->svgstyles); - break; - } - default: { - break; - } - } - } - - /** - * Sets the character data handler function for the XML parser. - * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler. - * @param $data (string) The second parameter, data, contains the character data as a string. - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function segSVGContentHandler($parser, $data) { - $this->svgtext .= $data; - } - - // --- END SVG METHODS ----------------------------------------------------- - } // END OF TCPDF CLASS //============================================================+ // END OF FILE //============================================================+ + diff --git a/tools/tcpdf/unicode_data.php b/tools/tcpdf/unicode_data.php index c05cb94ec..ebbb0b371 100755 --- a/tools/tcpdf/unicode_data.php +++ b/tools/tcpdf/unicode_data.php @@ -18369,3 +18369,4 @@ public $uni_utf8tolatin = array ( //============================================================+ // END OF FILE //============================================================+ +