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:
- *
$arrcode['code'] code to be printed on text label
- *
$arrcode['num_rows'] required number of rows
- *
$arrcode['num_cols'] required number of columns
- *
$arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)
- * @param $code (string) code to print
- * @param $type (string) type of barcode:
DATAMATRIX : Datamatrix (ISO/IEC 16022)
PDF417 : PDF417 (ISO/IEC 15438:2006)
PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".
QRCODE : QRcode Low error correction
QRCODE,L : QRcode Low error correction
QRCODE,M : QRcode Medium error correction
QRCODE,Q : QRcode Better error correction
QRCODE,H : QR-CODE Best error correction
RAW: raw mode - comma-separad list of array rows
RAW2: raw mode - array rows are surrounded by square parenthesis.
TEST : Test matrix
- */
- 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";
- 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";
- 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:
DATAMATRIX : Datamatrix (ISO/IEC 16022)
PDF417 : PDF417 (ISO/IEC 15438:2006)
PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".
QRCODE : QRcode Low error correction
QRCODE,L : QRcode Low error correction
QRCODE,M : QRcode Medium error correction
QRCODE,Q : QRcode Better error correction
QRCODE,H : QR-CODE Best error correction
RAW: raw mode - comma-separad list of array rows
RAW2: raw mode - array rows are surrounded by square parenthesis.
TEST : Test matrix
- * @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:
- *
$arrcode['code'] code to be printed on text label
- *
$arrcode['maxh'] max barcode height
- *
$arrcode['maxw'] max barcode width
- *
$arrcode['bcode'][$k] single bar or space in $k position
- *
$arrcode['bcode'][$k]['t'] bar type: true = bar, false = space.
- *
$arrcode['bcode'][$k]['w'] bar width in units.
- *
$arrcode['bcode'][$k]['h'] bar height in units.
- *
$arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)
- * @param $code (string) code to print
- * @param $type (string) type of barcode:
RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
KIX : KIX (Klant index - Customer index)
IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
CODABAR : CODABAR
CODE11 : CODE 11
PHARMA : PHARMACODE
PHARMA2T : PHARMACODE TWO-TRACKS
- * @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";
- 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 = '
The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0–4. The allowable encoding ranges shall be 00–04, 10–14, 20–24, 30–34, 40–44, 50–54, 60–64, 70–74, 80–84, and 90–94.
The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000http://it2.php.net/manual/en/function.dechex.php–999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.
The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.
The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000–999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999, 000000000–999999999, and 00000000000–99999999999.
- * @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:
- *
total matrix rows (including finder pattern)
- *
total matrix cols (including finder pattern)
- *
total matrix rows (without finder pattern)
- *
total matrix cols (without finder pattern)
- *
region data rows (with finder pattern)
- *
region data col (with finder pattern)
- *
region data rows (without finder pattern)
- *
region data col (without finder pattern)
- *
horizontal regions
- *
vertical regions
- *
regions
- *
data codewords
- *
error codewords
- *
blocks
- *
data codewords per block
- *
error codewords per block
- *
- * @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:
.
- */
- 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:
mm = Bits per symbol;
nn = Symbols per block;
alpha_to = log lookup table array;
index_of = Antilog lookup table array;
genpoly = Generator polynomial array;
nroots = Number of generator;
roots = number of parity symbols;
fcr = First consecutive root, index form;
prim = Primitive element, index form;
iprim = prim-th root of 1, index form;
pad = Padding bytes in shortened block;
gfpoly
.
- */
- 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:
- *
ISO 216 A Series + 2 SIS 014711 extensions
- *
A0 (841x1189 mm ; 33.11x46.81 in)
- *
A1 (594x841 mm ; 23.39x33.11 in)
- *
A2 (420x594 mm ; 16.54x23.39 in)
- *
A3 (297x420 mm ; 11.69x16.54 in)
- *
A4 (210x297 mm ; 8.27x11.69 in)
- *
A5 (148x210 mm ; 5.83x8.27 in)
- *
A6 (105x148 mm ; 4.13x5.83 in)
- *
A7 (74x105 mm ; 2.91x4.13 in)
- *
A8 (52x74 mm ; 2.05x2.91 in)
- *
A9 (37x52 mm ; 1.46x2.05 in)
- *
A10 (26x37 mm ; 1.02x1.46 in)
- *
A11 (18x26 mm ; 0.71x1.02 in)
- *
A12 (13x18 mm ; 0.51x0.71 in)
- *
ISO 216 B Series + 2 SIS 014711 extensions
- *
B0 (1000x1414 mm ; 39.37x55.67 in)
- *
B1 (707x1000 mm ; 27.83x39.37 in)
- *
B2 (500x707 mm ; 19.69x27.83 in)
- *
B3 (353x500 mm ; 13.90x19.69 in)
- *
B4 (250x353 mm ; 9.84x13.90 in)
- *
B5 (176x250 mm ; 6.93x9.84 in)
- *
B6 (125x176 mm ; 4.92x6.93 in)
- *
B7 (88x125 mm ; 3.46x4.92 in)
- *
B8 (62x88 mm ; 2.44x3.46 in)
- *
B9 (44x62 mm ; 1.73x2.44 in)
- *
B10 (31x44 mm ; 1.22x1.73 in)
- *
B11 (22x31 mm ; 0.87x1.22 in)
- *
B12 (15x22 mm ; 0.59x0.87 in)
- *
ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
- *
C0 (917x1297 mm ; 36.10x51.06 in)
- *
C1 (648x917 mm ; 25.51x36.10 in)
- *
C2 (458x648 mm ; 18.03x25.51 in)
- *
C3 (324x458 mm ; 12.76x18.03 in)
- *
C4 (229x324 mm ; 9.02x12.76 in)
- *
C5 (162x229 mm ; 6.38x9.02 in)
- *
C6 (114x162 mm ; 4.49x6.38 in)
- *
C7 (81x114 mm ; 3.19x4.49 in)
- *
C8 (57x81 mm ; 2.24x3.19 in)
- *
C9 (40x57 mm ; 1.57x2.24 in)
- *
C10 (28x40 mm ; 1.10x1.57 in)
- *
C11 (20x28 mm ; 0.79x1.10 in)
- *
C12 (14x20 mm ; 0.55x0.79 in)
- *
C76 (81x162 mm ; 3.19x6.38 in)
- *
DL (110x220 mm ; 4.33x8.66 in)
- *
SIS 014711 E Series
- *
E0 (879x1241 mm ; 34.61x48.86 in)
- *
E1 (620x879 mm ; 24.41x34.61 in)
- *
E2 (440x620 mm ; 17.32x24.41 in)
- *
E3 (310x440 mm ; 12.20x17.32 in)
- *
E4 (220x310 mm ; 8.66x12.20 in)
- *
E5 (155x220 mm ; 6.10x8.66 in)
- *
E6 (110x155 mm ; 4.33x6.10 in)
- *
E7 (78x110 mm ; 3.07x4.33 in)
- *
E8 (55x78 mm ; 2.17x3.07 in)
- *
E9 (39x55 mm ; 1.54x2.17 in)
- *
E10 (27x39 mm ; 1.06x1.54 in)
- *
E11 (19x27 mm ; 0.75x1.06 in)
- *
E12 (13x19 mm ; 0.51x0.75 in)
- *
SIS 014711 G Series
- *
G0 (958x1354 mm ; 37.72x53.31 in)
- *
G1 (677x958 mm ; 26.65x37.72 in)
- *
G2 (479x677 mm ; 18.86x26.65 in)
- *
G3 (338x479 mm ; 13.31x18.86 in)
- *
G4 (239x338 mm ; 9.41x13.31 in)
- *
G5 (169x239 mm ; 6.65x9.41 in)
- *
G6 (119x169 mm ; 4.69x6.65 in)
- *
G7 (84x119 mm ; 3.31x4.69 in)
- *
G8 (59x84 mm ; 2.32x3.31 in)
- *
G9 (42x59 mm ; 1.65x2.32 in)
- *
G10 (29x42 mm ; 1.14x1.65 in)
- *
G11 (21x29 mm ; 0.83x1.14 in)
- *
G12 (14x21 mm ; 0.55x0.83 in)
- *
ISO Press
- *
RA0 (860x1220 mm ; 33.86x48.03 in)
- *
RA1 (610x860 mm ; 24.02x33.86 in)
- *
RA2 (430x610 mm ; 16.93x24.02 in)
- *
RA3 (305x430 mm ; 12.01x16.93 in)
- *
RA4 (215x305 mm ; 8.46x12.01 in)
- *
SRA0 (900x1280 mm ; 35.43x50.39 in)
- *
SRA1 (640x900 mm ; 25.20x35.43 in)
- *
SRA2 (450x640 mm ; 17.72x25.20 in)
- *
SRA3 (320x450 mm ; 12.60x17.72 in)
- *
SRA4 (225x320 mm ; 8.86x12.60 in)
- *
German DIN 476
- *
4A0 (1682x2378 mm ; 66.22x93.62 in)
- *
2A0 (1189x1682 mm ; 46.81x66.22 in)
- *
Variations on the ISO Standard
- *
A2_EXTRA (445x619 mm ; 17.52x24.37 in)
- *
A3+ (329x483 mm ; 12.95x19.02 in)
- *
A3_EXTRA (322x445 mm ; 12.68x17.52 in)
- *
A3_SUPER (305x508 mm ; 12.01x20.00 in)
- *
SUPER_A3 (305x487 mm ; 12.01x19.17 in)
- *
A4_EXTRA (235x322 mm ; 9.25x12.68 in)
- *
A4_SUPER (229x322 mm ; 9.02x12.68 in)
- *
SUPER_A4 (227x356 mm ; 8.94x14.02 in)
- *
A4_LONG (210x348 mm ; 8.27x13.70 in)
- *
F4 (210x330 mm ; 8.27x12.99 in)
- *
SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)
- *
A5_EXTRA (173x235 mm ; 6.81x9.25 in)
- *
ANSI Series
- *
ANSI_E (864x1118 mm ; 34.00x44.00 in)
- *
ANSI_D (559x864 mm ; 22.00x34.00 in)
- *
ANSI_C (432x559 mm ; 17.00x22.00 in)
- *
ANSI_B (279x432 mm ; 11.00x17.00 in)
- *
ANSI_A (216x279 mm ; 8.50x11.00 in)
- *
Traditional 'Loose' North American Paper Sizes
- *
LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)
- *
TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)
- *
LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)
- *
LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)
- *
GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)
- *
JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)
- *
Other North American Paper Sizes
- *
QUADDEMY (889x1143 mm ; 35.00x45.00 in)
- *
SUPER_B (330x483 mm ; 13.00x19.00 in)
- *
QUARTO (229x279 mm ; 9.00x11.00 in)
- *
FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)
- *
EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)
- *
MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)
- *
FOOLSCAP (210x330 mm ; 8.27x13.00 in)
- *
COMPACT (108x171 mm ; 4.25x6.75 in)
- *
ORGANIZERJ (70x127 mm ; 2.75x5.00 in)
- *
Canadian standard CAN 2-9.60M
- *
P1 (560x860 mm ; 22.05x33.86 in)
- *
P2 (430x560 mm ; 16.93x22.05 in)
- *
P3 (280x430 mm ; 11.02x16.93 in)
- *
P4 (215x280 mm ; 8.46x11.02 in)
- *
P5 (140x215 mm ; 5.51x8.46 in)
- *
P6 (107x140 mm ; 4.21x5.51 in)
- *
North American Architectural Sizes
- *
ARCH_E (914x1219 mm ; 36.00x48.00 in)
- *
ARCH_E1 (762x1067 mm ; 30.00x42.00 in)
- *
ARCH_D (610x914 mm ; 24.00x36.00 in)
- *
ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)
- *
ARCH_B (305x457 mm ; 12.00x18.00 in)
- *
ARCH_A (229x305 mm ; 9.00x12.00 in)
- *
Announcement Envelopes
- *
ANNENV_A2 (111x146 mm ; 4.37x5.75 in)
- *
ANNENV_A6 (121x165 mm ; 4.75x6.50 in)
- *
ANNENV_A7 (133x184 mm ; 5.25x7.25 in)
- *
ANNENV_A8 (140x206 mm ; 5.50x8.12 in)
- *
ANNENV_A10 (159x244 mm ; 6.25x9.62 in)
- *
ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)
- *
Commercial Envelopes
- *
COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)
- *
COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)
- *
COMMENV_N8 (98x191 mm ; 3.87x7.50 in)
- *
COMMENV_N9 (98x225 mm ; 3.87x8.87 in)
- *
COMMENV_N10 (105x241 mm ; 4.12x9.50 in)
- *
COMMENV_N11 (114x263 mm ; 4.50x10.37 in)
- *
COMMENV_N12 (121x279 mm ; 4.75x11.00 in)
- *
COMMENV_N14 (127x292 mm ; 5.00x11.50 in)
- *
Catalogue Envelopes
- *
CATENV_N1 (152x229 mm ; 6.00x9.00 in)
- *
CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)
- *
CATENV_N2 (165x254 mm ; 6.50x10.00 in)
- *
CATENV_N3 (178x254 mm ; 7.00x10.00 in)
- *
CATENV_N6 (191x267 mm ; 7.50x10.50 in)
- *
CATENV_N7 (203x279 mm ; 8.00x11.00 in)
- *
CATENV_N8 (210x286 mm ; 8.25x11.25 in)
- *
CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)
- *
CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)
- *
CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)
- *
CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)
- *
CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)
- *
CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)
- *
CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)
- *
Japanese (JIS P 0138-61) Standard B-Series
- *
JIS_B0 (1030x1456 mm ; 40.55x57.32 in)
- *
JIS_B1 (728x1030 mm ; 28.66x40.55 in)
- *
JIS_B2 (515x728 mm ; 20.28x28.66 in)
- *
JIS_B3 (364x515 mm ; 14.33x20.28 in)
- *
JIS_B4 (257x364 mm ; 10.12x14.33 in)
- *
JIS_B5 (182x257 mm ; 7.17x10.12 in)
- *
JIS_B6 (128x182 mm ; 5.04x7.17 in)
- *
JIS_B7 (91x128 mm ; 3.58x5.04 in)
- *
JIS_B8 (64x91 mm ; 2.52x3.58 in)
- *
JIS_B9 (45x64 mm ; 1.77x2.52 in)
- *
JIS_B10 (32x45 mm ; 1.26x1.77 in)
- *
JIS_B11 (22x32 mm ; 0.87x1.26 in)
- *
JIS_B12 (16x22 mm ; 0.63x0.87 in)
- *
PA Series
- *
PA0 (840x1120 mm ; 33.07x44.09 in)
- *
PA1 (560x840 mm ; 22.05x33.07 in)
- *
PA2 (420x560 mm ; 16.54x22.05 in)
- *
PA3 (280x420 mm ; 11.02x16.54 in)
- *
PA4 (210x280 mm ; 8.27x11.02 in)
- *
PA5 (140x210 mm ; 5.51x8.27 in)
- *
PA6 (105x140 mm ; 4.13x5.51 in)
- *
PA7 (70x105 mm ; 2.76x4.13 in)
- *
PA8 (52x70 mm ; 2.05x2.76 in)
- *
PA9 (35x52 mm ; 1.38x2.05 in)
- *
PA10 (26x35 mm ; 1.02x1.38 in)
- *
Standard Photographic Print Sizes
- *
PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)
- *
E (82x120 mm ; 3.25x4.72 in)
- *
3R, L (89x127 mm ; 3.50x5.00 in)
- *
4R, KG (102x152 mm ; 4.02x5.98 in)
- *
4D (120x152 mm ; 4.72x5.98 in)
- *
5R, 2L (127x178 mm ; 5.00x7.01 in)
- *
6R, 8P (152x203 mm ; 5.98x7.99 in)
- *
8R, 6P (203x254 mm ; 7.99x10.00 in)
- *
S8R, 6PW (203x305 mm ; 7.99x12.01 in)
- *
10R, 4P (254x305 mm ; 10.00x12.01 in)
- *
S10R, 4PW (254x381 mm ; 10.00x15.00 in)
- *
11R (279x356 mm ; 10.98x14.02 in)
- *
S11R (279x432 mm ; 10.98x17.01 in)
- *
12R (305x381 mm ; 12.01x15.00 in)
- *
S12R (305x456 mm ; 12.01x17.95 in)
- *
Common Newspaper Sizes
- *
NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)
- *
NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)
- *
NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)
- *
Business Cards
- *
CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)
- *
BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)
- *
BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)
- *
BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)
- *
BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)
- *
BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)
- *
BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)
- *
BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)
- *
Billboards
- *
4SHEET (1016x1524 mm ; 40.00x60.00 in)
- *
6SHEET (1200x1800 mm ; 47.24x70.87 in)
- *
12SHEET (3048x1524 mm ; 120.00x60.00 in)
- *
16SHEET (2032x3048 mm ; 80.00x120.00 in)
- *
32SHEET (4064x3048 mm ; 160.00x120.00 in)
- *
48SHEET (6096x3048 mm ; 240.00x120.00 in)
- *
64SHEET (8128x3048 mm ; 320.00x120.00 in)
- *
96SHEET (12192x3048 mm ; 480.00x120.00 in)
- *
Old Imperial English (some are still used in USA)
- *
EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)
- *
EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)
- *
EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)
- *
EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)
- *
EN_ATLAS (660x864 mm ; 26.00x34.00 in)
- *
EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)
- *
EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)
- *
EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)
- *
EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)
- *
EN_PRINCESS (546x711 mm ; 21.50x28.00 in)
- *
EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)
- *
EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)
- *
EN_ROYAL (508x635 mm ; 20.00x25.00 in)
- *
EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)
- *
EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)
- *
EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)
- *
EN_MEDIUM (445x584 mm ; 17.50x23.00 in)
- *
EN_DEMY (445x572 mm ; 17.50x22.50 in)
- *
EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)
- *
EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)
- *
EN_POST (394x489 mm ; 15.50x19.25 in)
- *
EN_CROWN (381x508 mm ; 15.00x20.00 in)
- *
EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)
- *
EN_BRIEF (343x406 mm ; 13.50x16.00 in)
- *
EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)
- *
EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)
- *
EN_POTT (318x381 mm ; 12.50x15.00 in)
- *
Old Imperial Belgian
- *
BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)
- *
BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)
- *
BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)
- *
BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)
- *
BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)
- *
BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)
- *
BE_JESUS (540x730 mm ; 21.26x28.74 in)
- *
BE_RAISIN (500x650 mm ; 19.69x25.59 in)
- *
BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)
- *
BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)
- *
BE_COQUILLE (430x560 mm ; 16.93x22.05 in)
- *
BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)
- *
BE_RUCHE (360x460 mm ; 14.17x18.11 in)
- *
BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)
- *
BE_LYS (317x397 mm ; 12.48x15.63 in)
- *
BE_POT (307x384 mm ; 12.09x15.12 in)
- *
BE_ROSETTE (270x347 mm ; 10.63x13.66 in)
- *
Old Imperial French
- *
FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)
- *
FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)
- *
FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)
- *
FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)
- *
FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)
- *
FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)
- *
FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)
- *
FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)
- *
FR_JOURNAL (650x940 mm ; 25.59x37.01 in)
- *
FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)
- *
FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)
- *
FR_CLOCHE (600x800 mm ; 23.62x31.50 in)
- *
FR_SOLEIL (600x800 mm ; 23.62x31.50 in)
- *
FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)
- *
FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)
- *
FR_JESUS (560x760 mm ; 22.05x29.92 in)
- *
FR_RAISIN (500x650 mm ; 19.69x25.59 in)
- *
FR_CAVALIER (460x620 mm ; 18.11x24.41 in)
- *
FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)
- *
FR_CARRE (450x560 mm ; 17.72x22.05 in)
- *
FR_COQUILLE (440x560 mm ; 17.32x22.05 in)
- *
FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)
- *
FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)
- *
FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)
- *
FR_ECU (400x520 mm ; 15.75x20.47 in)
- *
FR_COURONNE (360x460 mm ; 14.17x18.11 in)
- *
FR_TELLIERE (340x440 mm ; 13.39x17.32 in)
- *
FR_POT (310x400 mm ; 12.20x15.75 in)
- *
- * @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):
P or Portrait (default)
L or Landscape
'' (empty string) for automatic orientation
@@ -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:
- *
- *
width (float): Width of the line in user units.
- *
cap (string): Type of cap to put on the line. Possible values are:
- * butt, round, square. The difference between "square" and "butt" is that
- * "square" projects a flat end past the end of the line.
- *
join (string): Type of join. Possible values are: miter, round,
- * bevel.
- *
dash (mixed): Dash pattern. Is 0 (without dash) or string with
- * series of length values, which are the lengths of the on and off dashes.
- * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
- * 1 off, 2 on, 1 off, ...
- *
phase (integer): Modifier on the dash pattern which is used to shift
- * the point at which the pattern starts.
- *
color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).
- *
- * @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:
- *
- *
all: Line style of all borders. Array like for SetLineStyle().
- *
L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().
- *
- * 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:
- *
- *
all: Line style of all lines. Array like for SetLineStyle().
- *
0 to ($np - 1): Line style of each line. Array like for SetLineStyle().
- *
- * 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:
- *
- *
all: Line style of all lines. Array like for SetLineStyle().
- *
0 to ($np - 1): Line style of each line. Array like for SetLineStyle().
- *
- * 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:
- *
- *
all: Line style of all sides. Array like for SetLineStyle().
- *
0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().
- *
- * 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:
- *
- *
D or empty string: Draw (default).
- *
F: Fill.
- *
DF or FD: Draw and 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).
- *
- * @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:
- *
- *
all: Line style of all sides. Array like for
- * SetLineStyle().
- *
0 to (n - 1): Line style of each side. Array like for SetLineStyle().
- *
- * 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:
- *
- *
D or empty string: Draw (default).
- *
F: Fill.
- *
DF or FD: Draw and 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).
- *
- * @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('/