/**
  *   $type        : { 'none' | 'color' | 'colour' | 'image' }
  *   $options     : if type == 'color' or 'colour':
  *                    $options[0] = red-component   of backgroundcolour ( 0 <= r <= 1)
  *                    $options[1] = green-component of backgroundcolour ( 0 <= g <= 1)
  *                    $options[2] = blue-component  of backgroundcolour ( 0 <= b <= 1)
  *                   if type == 'image':
  *                    $options['img']     = location of image file; URI's are allowed if allow_url_open is enabled in php.ini
  *                    $options['width']   = width of background image; default is width of page
  *                    $options['height']  = height of background image; default is height of page
  *                    $options['xpos']    = horizontal position of background image; default is 0
  *                    $options['ypos']    = vertical position of background image; default is 0
  *           *new*    $options['repeat']  = repeat image horizontally (1), repeat image vertically (2) or full in both directions (3); default is 0
  *                                          highly recommend to set this->hashed to true when using repeat function
  *
  * Assuming that people don't want to specify the paper size using the absolute coordinates
  * allow a couple of options:
  * orientation can be 'portrait' or 'landscape'
  * or, to actually set the coordinates, then pass an array in as the first parameter.
  * the defaults are as shown.
  *
  * 2002-07-24 - Nicola Asuni (info@tecnick.com):
  * Added new page formats (45 standard ISO paper formats and 4 american common formats)
  * paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm
  *
  * Now you may also pass a 2 values array containing the page width and height in centimeters
  *
  * @param $paper
  * @param $orientation
  * @param $type
  * @param $options
  * @return unknown_type
  */
 public function __construct($paper = 'a4', $orientation = 'portrait', $type = 'none', $options = array())
 {
     if (!is_array($paper)) {
         switch (strtoupper($paper)) {
             case '4A0':
                 $size = array(0, 0, 4767.87, 6740.79);
                 break;
             case '2A0':
                 $size = array(0, 0, 3370.39, 4767.87);
                 break;
             case 'A0':
                 $size = array(0, 0, 2383.94, 3370.39);
                 break;
             case 'A1':
                 $size = array(0, 0, 1683.78, 2383.94);
                 break;
             case 'A2':
                 $size = array(0, 0, 1190.55, 1683.78);
                 break;
             case 'A3':
                 $size = array(0, 0, 841.89, 1190.55);
                 break;
             case 'A4':
             default:
                 $size = array(0, 0, 595.28, 841.89);
                 break;
             case 'A5':
                 $size = array(0, 0, 419.53, 595.28);
                 break;
             case 'A6':
                 $size = array(0, 0, 297.64, 419.53);
                 break;
             case 'A7':
                 $size = array(0, 0, 209.76, 297.64);
                 break;
             case 'A8':
                 $size = array(0, 0, 147.4, 209.76);
                 break;
             case 'A9':
                 $size = array(0, 0, 104.88, 147.4);
                 break;
             case 'A10':
                 $size = array(0, 0, 73.7, 104.88);
                 break;
             case 'B0':
                 $size = array(0, 0, 2834.65, 4008.19);
                 break;
             case 'B1':
                 $size = array(0, 0, 2004.09, 2834.65);
                 break;
             case 'B2':
                 $size = array(0, 0, 1417.32, 2004.09);
                 break;
             case 'B3':
                 $size = array(0, 0, 1000.63, 1417.32);
                 break;
             case 'B4':
                 $size = array(0, 0, 708.66, 1000.63);
                 break;
             case 'B5':
                 $size = array(0, 0, 498.9, 708.66);
                 break;
             case 'B6':
                 $size = array(0, 0, 354.33, 498.9);
                 break;
             case 'B7':
                 $size = array(0, 0, 249.45, 354.33);
                 break;
             case 'B8':
                 $size = array(0, 0, 175.75, 249.45);
                 break;
             case 'B9':
                 $size = array(0, 0, 124.72, 175.75);
                 break;
             case 'B10':
                 $size = array(0, 0, 87.87, 124.72);
                 break;
             case 'C0':
                 $size = array(0, 0, 2599.37, 3676.54);
                 break;
             case 'C1':
                 $size = array(0, 0, 1836.85, 2599.37);
                 break;
             case 'C2':
                 $size = array(0, 0, 1298.27, 1836.85);
                 break;
             case 'C3':
                 $size = array(0, 0, 918.4299999999999, 1298.27);
                 break;
             case 'C4':
                 $size = array(0, 0, 649.13, 918.4299999999999);
                 break;
             case 'C5':
                 $size = array(0, 0, 459.21, 649.13);
                 break;
             case 'C6':
                 $size = array(0, 0, 323.15, 459.21);
                 break;
             case 'C7':
                 $size = array(0, 0, 229.61, 323.15);
                 break;
             case 'C8':
                 $size = array(0, 0, 161.57, 229.61);
                 break;
             case 'C9':
                 $size = array(0, 0, 113.39, 161.57);
                 break;
             case 'C10':
                 $size = array(0, 0, 79.37, 113.39);
                 break;
             case 'RA0':
                 $size = array(0, 0, 2437.8, 3458.27);
                 break;
             case 'RA1':
                 $size = array(0, 0, 1729.13, 2437.8);
                 break;
             case 'RA2':
                 $size = array(0, 0, 1218.9, 1729.13);
                 break;
             case 'RA3':
                 $size = array(0, 0, 864.5700000000001, 1218.9);
                 break;
             case 'RA4':
                 $size = array(0, 0, 609.45, 864.5700000000001);
                 break;
             case 'SRA0':
                 $size = array(0, 0, 2551.18, 3628.35);
                 break;
             case 'SRA1':
                 $size = array(0, 0, 1814.17, 2551.18);
                 break;
             case 'SRA2':
                 $size = array(0, 0, 1275.59, 1814.17);
                 break;
             case 'SRA3':
                 $size = array(0, 0, 907.09, 1275.59);
                 break;
             case 'SRA4':
                 $size = array(0, 0, 637.8, 907.09);
                 break;
             case 'LETTER':
                 $size = array(0, 0, 612.0, 792.0);
                 break;
             case 'LEGAL':
                 $size = array(0, 0, 612.0, 1008.0);
                 break;
             case 'EXECUTIVE':
                 $size = array(0, 0, 521.86, 756.0);
                 break;
             case 'FOLIO':
                 $size = array(0, 0, 612.0, 936.0);
                 break;
         }
         switch (strtolower($orientation)) {
             case 'landscape':
                 $a = $size[3];
                 $size[3] = $size[2];
                 $size[2] = $a;
                 break;
         }
     } else {
         if (count($paper) > 2) {
             // then an array was sent it to set the size
             $size = $paper;
         } else {
             //size in centimeters has been passed
             $size[0] = 0;
             $size[1] = 0;
             $size[2] = $paper[0] / 2.54 * 72;
             $size[3] = $paper[1] / 2.54 * 72;
         }
     }
     parent::__construct($size);
     $this->ez['pageWidth'] = $size[2];
     $this->ez['pageHeight'] = $size[3];
     // also set the margins to some reasonable defaults
     $this->ez['topMargin'] = 30;
     $this->ez['bottomMargin'] = 30;
     $this->ez['leftMargin'] = 30;
     $this->ez['rightMargin'] = 30;
     // set the current writing position to the top of the first page
     $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
     // and get the ID of the page that was created during the instancing process.
     $this->ezPages[1] = $this->getFirstPageId();
     $this->ezPageCount = 1;
     switch ($type) {
         case 'color':
         case 'colour':
             $this->ezBackground['type'] = 'color';
             $this->ezBackground['color'] = $options;
             break;
         case 'image':
             if (!isset($options['img'])) {
                 $errormsg = "Background Image not set.";
                 break;
             }
             if (!file_exists($options['img'])) {
                 $errormsg = "Background Image does not exists: '" . $options['img'] . "'";
                 break;
             }
             $im = getimagesize($options['img']);
             if ($im === false) {
                 $errormsg = "Background Image is invalid: '" . $options['img'] . "'";
                 break;
             }
             $this->ezBackground['type'] = 'image';
             $this->ezBackground['image'] = $options['img'];
             $this->ezBackground['format'] = $im[2];
             $this->ezBackground['repeat'] = $options['repeat'];
             if (isset($options['width']) && is_numeric($options['width'])) {
                 $this->ezBackground['width'] = $options['width'];
             } else {
                 $this->ezBackground['width'] = $this->ez['pageWidth'];
             }
             if (isset($options['height']) && is_numeric($options['height'])) {
                 $this->ezBackground['height'] = $options['height'];
             } else {
                 $this->ezBackground['height'] = $this->ez['pageHeight'];
             }
             if (isset($options['xpos']) && is_numeric($options['xpos'])) {
                 $this->ezBackground['xpos'] = $options['xpos'];
             } else {
                 $this->ezBackground['xpos'] = 0;
             }
             if (isset($options['ypos']) && is_numeric($options['ypos'])) {
                 $this->ezBackground['ypos'] = $options['ypos'];
             } else {
                 $this->ezBackground['ypos'] = 0;
             }
             break;
         case 'none':
         default:
             $this->ezBackground['type'] = 'none';
             break;
     }
     $this->setBackground();
 }
 function __construct($paper = 'a4', $orientation = 'portrait')
 {
     // Assuming that people don't want to specify the paper size using the absolute coordinates
     // allow a couple of options:
     // orientation can be 'portrait' or 'landscape'
     // or, to actually set the coordinates, then pass an array in as the first parameter.
     // the defaults are as shown.
     //
     // -------------------------
     // 2002-07-24 - Nicola Asuni (info@tecnick.com):
     // Added new page formats (45 standard ISO paper formats and 4 american common formats)
     // paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm
     //
     // Now you may also pass a 2 values array containing the page width and height in centimeters
     // -------------------------
     if (!is_array($paper)) {
         switch (strtoupper($paper)) {
             case '4A0':
                 $size = array(0, 0, 4767.87, 6740.79);
                 break;
             case '2A0':
                 $size = array(0, 0, 3370.39, 4767.87);
                 break;
             case 'A0':
                 $size = array(0, 0, 2383.94, 3370.39);
                 break;
             case 'A1':
                 $size = array(0, 0, 1683.78, 2383.94);
                 break;
             case 'A2':
                 $size = array(0, 0, 1190.55, 1683.78);
                 break;
             case 'A3':
                 $size = array(0, 0, 841.89, 1190.55);
                 break;
             case 'A4':
             default:
                 $size = array(0, 0, 595.28, 841.89);
                 break;
             case 'A5':
                 $size = array(0, 0, 419.53, 595.28);
                 break;
             case 'A6':
                 $size = array(0, 0, 297.64, 419.53);
                 break;
             case 'A7':
                 $size = array(0, 0, 209.76, 297.64);
                 break;
             case 'A8':
                 $size = array(0, 0, 147.4, 209.76);
                 break;
             case 'A9':
                 $size = array(0, 0, 104.88, 147.4);
                 break;
             case 'A10':
                 $size = array(0, 0, 73.7, 104.88);
                 break;
             case 'B0':
                 $size = array(0, 0, 2834.65, 4008.19);
                 break;
             case 'B1':
                 $size = array(0, 0, 2004.09, 2834.65);
                 break;
             case 'B2':
                 $size = array(0, 0, 1417.32, 2004.09);
                 break;
             case 'B3':
                 $size = array(0, 0, 1000.63, 1417.32);
                 break;
             case 'B4':
                 $size = array(0, 0, 708.66, 1000.63);
                 break;
             case 'B5':
                 $size = array(0, 0, 498.9, 708.66);
                 break;
             case 'B6':
                 $size = array(0, 0, 354.33, 498.9);
                 break;
             case 'B7':
                 $size = array(0, 0, 249.45, 354.33);
                 break;
             case 'B8':
                 $size = array(0, 0, 175.75, 249.45);
                 break;
             case 'B9':
                 $size = array(0, 0, 124.72, 175.75);
                 break;
             case 'B10':
                 $size = array(0, 0, 87.87, 124.72);
                 break;
             case 'C0':
                 $size = array(0, 0, 2599.37, 3676.54);
                 break;
             case 'C1':
                 $size = array(0, 0, 1836.85, 2599.37);
                 break;
             case 'C2':
                 $size = array(0, 0, 1298.27, 1836.85);
                 break;
             case 'C3':
                 $size = array(0, 0, 918.4299999999999, 1298.27);
                 break;
             case 'C4':
                 $size = array(0, 0, 649.13, 918.4299999999999);
                 break;
             case 'C5':
                 $size = array(0, 0, 459.21, 649.13);
                 break;
             case 'C6':
                 $size = array(0, 0, 323.15, 459.21);
                 break;
             case 'C7':
                 $size = array(0, 0, 229.61, 323.15);
                 break;
             case 'C8':
                 $size = array(0, 0, 161.57, 229.61);
                 break;
             case 'C9':
                 $size = array(0, 0, 113.39, 161.57);
                 break;
             case 'C10':
                 $size = array(0, 0, 79.37, 113.39);
                 break;
             case 'RA0':
                 $size = array(0, 0, 2437.8, 3458.27);
                 break;
             case 'RA1':
                 $size = array(0, 0, 1729.13, 2437.8);
                 break;
             case 'RA2':
                 $size = array(0, 0, 1218.9, 1729.13);
                 break;
             case 'RA3':
                 $size = array(0, 0, 864.5700000000001, 1218.9);
                 break;
             case 'RA4':
                 $size = array(0, 0, 609.45, 864.5700000000001);
                 break;
             case 'SRA0':
                 $size = array(0, 0, 2551.18, 3628.35);
                 break;
             case 'SRA1':
                 $size = array(0, 0, 1814.17, 2551.18);
                 break;
             case 'SRA2':
                 $size = array(0, 0, 1275.59, 1814.17);
                 break;
             case 'SRA3':
                 $size = array(0, 0, 907.09, 1275.59);
                 break;
             case 'SRA4':
                 $size = array(0, 0, 637.8, 907.09);
                 break;
             case 'LETTER':
                 $size = array(0, 0, 612.0, 792.0);
                 break;
             case 'LEGAL':
                 $size = array(0, 0, 612.0, 1008.0);
                 break;
             case 'EXECUTIVE':
                 $size = array(0, 0, 521.86, 756.0);
                 break;
             case 'FOLIO':
                 $size = array(0, 0, 612.0, 936.0);
                 break;
         }
         switch (strtolower($orientation)) {
             case 'landscape':
                 $a = $size[3];
                 $size[3] = $size[2];
                 $size[2] = $a;
                 break;
         }
     } else {
         if (count($paper) > 2) {
             // then an array was sent it to set the size
             $size = $paper;
         } else {
             //size in centimeters has been passed
             $size[0] = 0;
             $size[1] = 0;
             $size[2] = $paper[0] / 2.54 * 72;
             $size[3] = $paper[1] / 2.54 * 72;
         }
     }
     parent::__construct($size);
     $this->ez['pageWidth'] = $size[2];
     $this->ez['pageHeight'] = $size[3];
     // also set the margins to some reasonable defaults
     $config = eZINI::instance('pdf.ini');
     $this->ez['topMargin'] = $config->variable('PDFGeneral', 'TopMargin');
     $this->ez['bottomMargin'] = $config->variable('PDFGeneral', 'BottomMargin');
     $this->ez['leftMargin'] = $config->variable('PDFGeneral', 'LeftMargin');
     $this->ez['rightMargin'] = $config->variable('PDFGeneral', 'RightMargin');
     // set the current writing position to the top of the first page
     $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
     $this->ez['xOffset'] = 0;
     // set current text justification
     $this->ez['justification'] = 'left';
     $this->ez['lineSpace'] = 1;
     // and get the ID of the page that was created during the instancing process.
     $this->ezPages[1] = $this->getFirstPageId();
     $this->ezPageCount = 1;
 }