diff --git a/dompdf.php b/dompdf.php index bdc4ed944..e5e2b37c9 100755 --- a/dompdf.php +++ b/dompdf.php @@ -40,7 +40,7 @@ * @version 0.5.1 */ -/* $Id: dompdf.php,v 1.23 2008-03-12 06:35:42 benjcarson Exp $ */ +/* $Id: dompdf.php,v 1.24 2009-04-29 04:11:35 benjcarson Exp $ */ /** * Display command line usage: @@ -243,33 +243,7 @@ function getoptions() { default: - if ( isset($_GET["input_file"]) ) - $file = rawurldecode($_GET["input_file"]); - else - throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable)."); - - if ( isset($_GET["paper"]) ) - $paper = rawurldecode($_GET["paper"]); - else - $paper = DOMPDF_DEFAULT_PAPER_SIZE; - - if ( isset($_GET["orientation"]) ) - $orientation = rawurldecode($_GET["orientation"]); - else - $orientation = "portrait"; - - if ( isset($_GET["base_path"]) ) - $base_path = rawurldecode($_GET["base_path"]); - - if ( isset($_GET["output_file"]) ) - $outfile = rawurldecode($_GET["output_file"]); - else - $outfile = "dompdf_out.pdf"; - - if ( isset($_GET["save_file"]) ) - $save_file = true; - else - $save_file = false; + throw new DOMPDF_Exception("Access to dompdf.php via non-cli SAPI has been deprecated due to security concerns. Please use the dompdf class directly."); break; } diff --git a/dompdf_config.inc.php b/dompdf_config.inc.php index 325788d52..55424f002 100644 --- a/dompdf_config.inc.php +++ b/dompdf_config.inc.php @@ -37,7 +37,7 @@ * @version 0.5.1 */ -/* $Id: dompdf_config.inc.php,v 1.29 2008-03-12 06:35:43 benjcarson Exp $ */ +/* $Id: dompdf_config.inc.php,v 1.30 2009-04-29 04:11:35 benjcarson Exp $ */ //error_reporting(E_STRICT | E_ALL); @@ -83,30 +83,44 @@ */ define("DOMPDF_CHROOT", realpath(DOMPDF_DIR)); +/** + * Whether to use Unicode fonts or not. + * + * When set to true the PDF backend must be set to "CPDF" and fonts must be + * loaded via the modified ttf2ufm tool included with dompdf (see below). + * Unicode font metric files (with .ufm extensions) must be created with + * ttf2ufm. load_font.php should do this for you if the TTF2AFM define below + * points to the modified ttf2ufm tool included with dompdf. + * + * When enabled, dompdf can support all Unicode glyphs. Any glyphs used in a + * document must be present in your fonts, however. + * + */ +define("DOMPDF_UNICODE_ENABLED", false); + /** * The path to the tt2pt1 utility (used to convert ttf to afm) * * Not strictly necessary, but useful if you would like to install * additional fonts using the {@link load_font.php} utility. * + * Windows users should use something like this: + * define("TTF2AFM", "C:\\Program Files\\Ttf2Pt1\\bin\\ttf2pt1.exe"); + * * @link http://ttf2pt1.sourceforge.net/ */ define("TTF2AFM", DOMPDF_LIB_DIR ."/ttf2ufm/ttf2ufm-src/ttf2pt1"); //define("TTF2AFM", "/usr/bin/ttf2pt1"); -// Windows users should use something like this: -//define("TTF2AFM", "C:\\Program Files\\Ttf2Pt1\\bin\\ttf2pt1.exe"); /** * The PDF rendering backend to use * - * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), - * 'TCPDF' (the bundled TCPDF class), 'GD' and 'auto'. - * 'auto' will look for PDFLib and use it if found, - * or if not it will fall back on CPDF. 'TCPDF' will use the TCPDF - * library, which supports Unicode. 'GD' renders PDFs to graphic - * files. {@link Canvas_Factory} ultimately determines which - * rendering class to instantiate based on this setting. + * Valid settings are 'PDFLib', 'CPDF' (the bundled R&OS PDF class), 'GD' and + * 'auto'. 'auto' will look for PDFLib and use it if found, or if not it will + * fall back on CPDF. 'GD' renders PDFs to graphic files. {@link + * Canvas_Factory} ultimately determines which rendering class to instantiate + * based on this setting. * * Both PDFLib & CPDF rendering backends provide sufficient rendering * capabilities for dompdf, however additional features (e.g. object, @@ -126,9 +140,8 @@ * @link http://www.pdflib.com * @link http://www.ros.co.nz/pdf * @link http://www.php.net/image - * @link http://tcpdf.sf.net/ */ -define("DOMPDF_PDF_BACKEND", "cpdf"); +define("DOMPDF_PDF_BACKEND", "pdflib"); /** * PDFlib license key diff --git a/include/cpdf_adapter.cls.php b/include/cpdf_adapter.cls.php index 88857e94c..f419d342f 100644 --- a/include/cpdf_adapter.cls.php +++ b/include/cpdf_adapter.cls.php @@ -40,7 +40,7 @@ * @version 0.5.1 */ -/* $Id: cpdf_adapter.cls.php,v 1.21 2008-03-12 06:35:43 benjcarson Exp $ */ +/* $Id: cpdf_adapter.cls.php,v 1.22 2009-04-29 04:11:35 benjcarson Exp $ */ // FIXME: Need to sanity check inputs to this class require_once(DOMPDF_LIB_DIR . "/class.pdf.php"); @@ -202,11 +202,7 @@ function __construct($paper = "letter", $orientation = "portrait") { $size[2] = $a; } - // OAR - Setting isUnicode to true by default! - // Some people may not want to do this. Should we have - // a DOMPDF config variable somewhere that lets people - // choose? - $this->_pdf = new Cpdf($size, true); + $this->_pdf = new Cpdf($size, DOMPDF_UNICODE_ENABLED); $this->_pdf->addInfo("Creator", "dompdf"); // Silence pedantic warnings about missing TZ settings @@ -493,11 +489,9 @@ function line($x1, $y1, $x2, $y2, $color, $width, $style = array(), * @return string The url of the newly converted image */ protected function _convert_gif_to_png($image_url) { - global $_dompdf_warnings; if ( !function_exists("imagecreatefromgif") ) { - $_dompdf_warnings[] = "Function imagecreatefromgif() not found. Cannot convert gif image: $image_url."; - return DOMPDF_LIB_DIR . "/res/broken_image.png"; + throw new DOMPDF_Exception("Function imagecreatefromgif() not found. Cannot convert gif image: $image_url. Please install the image PHP extension."); } $old_err = set_error_handler("record_warnings"); diff --git a/include/pdflib_adapter.cls.php b/include/pdflib_adapter.cls.php index cb3bc7bea..e07bb179b 100644 --- a/include/pdflib_adapter.cls.php +++ b/include/pdflib_adapter.cls.php @@ -37,7 +37,7 @@ * @version 0.5.1 */ -/* $Id: pdflib_adapter.cls.php,v 1.25 2008-02-07 07:31:05 benjcarson Exp $ */ +/* $Id: pdflib_adapter.cls.php,v 1.26 2009-04-29 04:11:35 benjcarson Exp $ */ /** * PDF rendering interface @@ -183,7 +183,7 @@ function __construct($paper = "letter", $orientation = "portrait") { if ( is_array($paper) ) $size = $paper; else if ( isset(self::$PAPER_SIZES[mb_strtolower($paper)]) ) - $size = self::$PAPER_SIZES[$paper]; + $size = self::$PAPER_SIZES[mb_strtolower($paper)]; else $size = self::$PAPER_SIZES["letter"]; @@ -736,8 +736,8 @@ function add_link($url, $x, $y, $width, $height) { if ( $proto == "" || $proto == "file://" ) return; // Local links are not allowed $url = build_url($proto, $host, $path, $file); - $url = str_replace("=", "%3D", rawurldecode($url)); - + $url = '{' . rawurldecode($url) . '}'; + $action = $this->_pdf->create_action("URI", "url=" . $url); $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} action={activate=$action} linewidth=0"); } @@ -847,15 +847,15 @@ protected function _add_page_text() { case "text": $text = str_replace(array("{PAGE_NUM}","{PAGE_COUNT}"), - array($page_number, $this->_page_count), $text); - $this->text($x, $y, $text, $font, $size, $color, $adjust, $angle); + array($p, $this->_page_count), $text); + $this->text($x, $y, $text, $font, $size, $color, $adjust, $angle); break; case "script": if (!$eval) { $eval = new PHP_Evaluator($this); } - $eval->evaluate($code, array('PAGE_NUM' => $page_number, 'PAGE_COUNT' => $this->_page_count)); + $eval->evaluate($code, array('PAGE_NUM' => $p, 'PAGE_COUNT' => $this->_page_count)); break; } } diff --git a/lib/class.pdf.php b/lib/class.pdf.php index 2cce403cd..1691fb1ea 100644 --- a/lib/class.pdf.php +++ b/lib/class.pdf.php @@ -2576,8 +2576,6 @@ function openFont($font) { } $cc = (int)$dtmp['C']; - $glyph = $dtmp['G']; - $width = $dtmp['WX']; if ($cc >= 0) { $data['C'][$dtmp['C']] = $dtmp; @@ -2797,22 +2795,22 @@ function selectFont($fontName, $encoding = '', $set = true) { if (!$this->isUnicode) { // With Unicode, widths array isn't used - if ($lastChar>0 && $num>$lastChar+1) { + if ($lastChar>0 && $num>$lastChar+1) { - for ($i = $lastChar+1;$i<$num;$i++) { + for ($i = $lastChar+1;$i<$num;$i++) { - $widths[] = 0; + $widths[] = 0; + } } } - } $widths[] = $d['WX']; + if ($this->isUnicode) { $cid_widths[$num] = $d['WX']; } if ($firstChar == -1) { - $firstChar = $num; } @@ -2829,10 +2827,10 @@ function selectFont($fontName, $encoding = '', $set = true) { if (!$this->isUnicode) { // With Unicode, widths array isn't used - for ($i = $lastChar + 1; $i <= $charNum; $i++) { + for ($i = $lastChar + 1; $i <= $charNum; $i++) { - $widths[] = 0; - } + $widths[] = 0; + } } $lastChar = $charNum; @@ -2843,10 +2841,10 @@ function selectFont($fontName, $encoding = '', $set = true) { $widths[$charNum-$firstChar] = $this->fonts[$fontName]['C'][$charName]['WX']; if ($this->isUnicode) { $cid_widths[$charName] = $this->fonts[$fontName]['C'][$charName]['WX']; + } } } } - } if ($this->isUnicode) { $this->fonts[$fontName]['CIDWidths'] = $cid_widths; @@ -2861,20 +2859,19 @@ function selectFont($fontName, $encoding = '', $set = true) { if (!$this->isUnicode) { // With Unicode, widths array isn't used - $this->numObj++; - - $this->o_contents($this->numObj, 'new', 'raw'); + $this->numObj++; - $this->objects[$this->numObj]['c'].= '['; + $this->o_contents($this->numObj, 'new', 'raw'); - foreach($widths as $width) { + $this->objects[$this->numObj]['c'].= '['; - $this->objects[$this->numObj]['c'].= ' '.$width; - } + foreach($widths as $width) { + $this->objects[$this->numObj]['c'].= ' '.$width; + } - $this->objects[$this->numObj]['c'].= ' ]'; + $this->objects[$this->numObj]['c'].= ' ]'; - $widthid = $this->numObj; + $widthid = $this->numObj; } $missing_width = 500; diff --git a/lib/ttf2ufm/ttf2ufm.exe b/lib/ttf2ufm/ttf2ufm.exe index 673f7b4aa..ad6235927 100644 Binary files a/lib/ttf2ufm/ttf2ufm.exe and b/lib/ttf2ufm/ttf2ufm.exe differ diff --git a/test/pages.html b/test/pages.html index af1b0339c..a9f2fe028 100644 --- a/test/pages.html +++ b/test/pages.html @@ -8,7 +8,7 @@ } * { - font-family: georgia,serif; + font-family: helvetica,georgia,serif; font-weight: bold; } diff --git a/test/table.html b/test/table.html index f8eeac1a9..e74af6071 100644 --- a/test/table.html +++ b/test/table.html @@ -3,7 +3,7 @@