Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
- unicode changes and security fix, pushing leftover local changes fo…
Browse files Browse the repository at this point in the history
…r use by others

git-svn-id: http://dompdf.googlecode.com/svn/trunk/dompdf@97 8e70de24-3a84-11de-b438-597f59cd7555
  • Loading branch information
Benj Carson committed Apr 29, 2009
1 parent be6a3bf commit 2df4fb9
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 91 deletions.
30 changes: 2 additions & 28 deletions dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down
37 changes: 25 additions & 12 deletions dompdf_config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
12 changes: 3 additions & 9 deletions include/cpdf_adapter.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
14 changes: 7 additions & 7 deletions include/pdflib_adapter.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"];

Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
37 changes: 17 additions & 20 deletions lib/class.pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Binary file modified lib/ttf2ufm/ttf2ufm.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion test/pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

* {
font-family: georgia,serif;
font-family: helvetica,georgia,serif;
font-weight: bold;
}

Expand Down
2 changes: 1 addition & 1 deletion test/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
<style>

body { font-family: verdana;}
table {
margin-top: 2em;
}
Expand Down
23 changes: 23 additions & 0 deletions www/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
...
</a></li>

<li><a href="#headers_sent">I'm getting the following error:<br/>
Unable to stream pdf: headers already sent</a></li>

</ol>

<div class="divider1">&nbsp;</div>
Expand Down Expand Up @@ -373,4 +376,24 @@
<a href="#FAQ">[back to top]</a>
<div class="divider2" style="background-position: 130px 0%">&nbsp;</div>

<a name="headers_sent"> </a>
<h3>I'm getting the following error:<br/>Unable to stream pdf: headers already
sent</h3>

<p>This error occurs when PHP has already sent data to the browser. Check
whether your script <code>echo</code>s or <code>print</code>s any output before streaming your PDF, or if
it has text outside of &lt;?php ?&gt; tags (including whitespace at the
beginning or end of a file).</p>

<p>Try deleting or removing the echo/print statements or the offending text.
Alternatively, you can use the <a
href="http://www.php.net/manual/en/function.ob-start.php">ob_start()</a> and <a
href="http://www.php.net/manual/en/function.ob-get-contents.php">ob_get_contents()</a>
functions.</p>


<a href="#FAQ">[back to top]</a> <div class="divider1"
style="background-position: 666px 0%">&nbsp;</div>


</div> <?php include "foot.inc" ?>
7 changes: 4 additions & 3 deletions www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

<li style="list-style-image: url('images/star_02.gif');">inline PHP
support. See the section on <a href="usage.php#inline">inline PHP</a> for details.</li>

<li style="list-style-image: url('images/star_04.gif');">version 0.5.2 includes
full unicode support when using the R&amp;OS backend</li>

</ul>


Expand All @@ -74,9 +78,6 @@

<ul>

<li style="list-style-image: url('images/star_04.gif');">tables can not be
nested</li>

<li style="list-style-image: url('images/star_02.gif');">ordered lists are
currently unsupported.</li>

Expand Down
Loading

0 comments on commit 2df4fb9

Please sign in to comment.