public function __construct($params = array())
{
/* Default parameters. */
$defaults = array('orientation' => 'P', 'unit' => 'mm', 'format' => 'A4');
$params = array_merge($defaults, $params);
/* Scale factor. */
if ($params['unit'] == 'pt') {
$this->_scale = 1;
} elseif ($params['unit'] == 'mm') {
$this->_scale = 72 / 25.4;
} elseif ($params['unit'] == 'cm') {
$this->_scale = 72 / 2.54;
} elseif ($params['unit'] == 'in') {
$this->_scale = 72;
} else {
throw new Horde_Pdf_Exception(sprintf('Incorrect units: %s', $params['unit']));
}
/* Page format. */
if (is_string($params['format'])) {
$params['format'] = Horde_String::lower($params['format']);
if ($params['format'] == 'a3') {
$params['format'] = array(841.89, 1190.55);
} elseif ($params['format'] == 'a4') {
$params['format'] = array(595.28, 841.89);
} elseif ($params['format'] == 'a5') {
$params['format'] = array(420.94, 595.28);
} elseif ($params['format'] == 'letter') {
$params['format'] = array(612, 792);
} elseif ($params['format'] == 'legal') {
$params['format'] = array(612, 1008);
} else {
throw new Horde_Pdf_Exception(sprintf('Unknown page format: %s', $params['format']));
}
$this->fwPt = $params['format'][0];
$this->fhPt = $params['format'][1];
} else {
$this->fwPt = $params['format'][0] * $this->_scale;
$this->fhPt = $params['format'][1] * $this->_scale;
}
$this->fw = $this->fwPt / $this->_scale;
$this->fh = $this->fhPt / $this->_scale;
/* Page orientation. */
$params['orientation'] = Horde_String::lower($params['orientation']);
if ($params['orientation'] == 'p' || $params['orientation'] == 'portrait') {
$this->_default_orientation = 'P';
$this->wPt = $this->fwPt;
$this->hPt = $this->fhPt;
} elseif ($params['orientation'] == 'l' || $params['orientation'] == 'landscape') {
$this->_default_orientation = 'L';
$this->wPt = $this->fhPt;
$this->hPt = $this->fwPt;
} else {
throw new Horde_Pdf_Exception(sprintf('Incorrect orientation: %s', $params['orientation']));
}
$this->_current_orientation = $this->_default_orientation;
$this->w = $this->wPt / $this->_scale;
$this->h = $this->hPt / $this->_scale;
/* Page margins (1 cm) */
$margin = 28.35 / $this->_scale;
$this->setMargins($margin, $margin);
/* Interior cell margin (1 mm) */
$this->_cell_margin = $margin / 10;
/* Line width (0.2 mm) */
$this->_line_width = 0.5669999999999999 / $this->_scale;
/* Automatic page break */
$this->setAutoPageBreak(true, 2 * $margin);
/* Full width display mode */
$this->setDisplayMode('fullwidth');
/* Compression */
$this->setCompression(true);
}