Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dompdf/dompdf
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislavtkachenko committed Apr 19, 2021
2 parents 6850996 + 0ccafeb commit 49f36fd
Show file tree
Hide file tree
Showing 19 changed files with 341 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* text=auto eol=lf
*.json text
*.xml text
*.php text
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 7.2
- 7.3
- 7.4
- 8.0
- nightly
- hhvm

Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Follow us on [![Twitter](http://twitter-badges.s3.amazonaws.com/twitter-a.png)](
* php-font-lib
* php-svg-lib

Note that some required dependencies may have further dependencies (notably php-svg-lib requires sabberworm/php-css-parser).
Note that some required dependencies may have further dependencies
(notably php-svg-lib requires sabberworm/php-css-parser).

### Recommendations

Expand Down Expand Up @@ -199,6 +200,18 @@ $dompdf->setOptions($options);

See [Dompdf\Options](src/Options.php) for a list of available options.

### Resource Reference Requirements

In order to protect potentially sensitive information Dompdf imposes
restrictions on files referenced from the local file system or the web.

Files accessed through web-based protocols have the following requirements:
* The Dompdf option "isRemoteEnabled" must be set to "true"
* PHP must either have the curl extension enabled or the
allow_url_fopen setting set to true

Files accessed through the local file system have the following requirement:
* The file must fall within the path(s) specified for the Dompdf "chroot" option

## Limitations (Known Issues)

Expand All @@ -221,4 +234,5 @@ See [Dompdf\Options](src/Options.php) for a list of available options.

[![Donate button](https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](http://goo.gl/DSvWf)

*If you find this project useful, please consider making a donation. Any funds donated will be used to help further development on this project.)*
*If you find this project useful, please consider making a donation.
Any funds donated will be used to help further development on this project.)*
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
}
},
"require": {
"php": "^7.1|^8.0",
"php": "^7.1 || ^8.0",
"ext-dom": "*",
"ext-mbstring": "*",
"phenx/php-font-lib": "^0.5.2",
"phenx/php-svg-lib": "^0.3.3"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"squizlabs/php_codesniffer": "^3.5",
"mockery/mockery": "^1.3"
},
Expand Down
26 changes: 7 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Dompdf Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix="php">src</directory>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="Dompdf Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
23 changes: 10 additions & 13 deletions src/Cellmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,21 @@ public function set_column_width($j, $width)
$col =& $this->get_column($j);
$col["used-width"] = $width;
$next_col =& $this->get_column($j + 1);
$next_col["x"] = $next_col["x"] + $width;
$next_col["x"] = $col["x"] + $width;
}

/**
* @param int $i
* @param mixed $height
* @param long $height
*/
public function set_row_height($i, $height)
{
$row =& $this->get_row($i);

if ($row["height"] !== null && $height <= $row["height"]) {
return;
if ($height > $row["height"]) {
$row["height"] = $height;
}

$row["height"] = $height;
$next_row =& $this->get_row($i + 1);
$next_row["y"] = $row["y"] + $height;
$next_row["y"] = $row["y"] + $row["height"];
}

/**
Expand Down Expand Up @@ -647,12 +644,12 @@ public function add_frame(Frame $frame)
$width = $style->width;

$val = null;
if (Helpers::is_percent($width)) {
if (Helpers::is_percent($width) && $colspan === 1) {
$var = "percent";
$val = (float)rtrim($width, "% ") / $colspan;
} else if ($width !== "auto") {
} else if ($width !== "auto" && $colspan === 1) {
$var = "absolute";
$val = $style->length_in_pt($frame_min) / $colspan;
$val = $style->length_in_pt($frame_min);
}

$min = 0;
Expand All @@ -674,10 +671,10 @@ public function add_frame(Frame $frame)
$max += $col["max-width"];
}

if ($frame_min > $min) {
if ($frame_min > $min && $colspan === 1) {
// The frame needs more space. Expand each sub-column
// FIXME try to avoid putting this dummy value when table-layout:fixed
$inc = ($this->is_layout_fixed() ? 10e-10 : ($frame_min - $min) / $colspan);
$inc = ($this->is_layout_fixed() ? 10e-10 : ($frame_min - $min));
for ($c = 0; $c < $colspan; $c++) {
$col =& $this->get_column($this->__col + $c);
$col["min-width"] += $inc;
Expand Down
10 changes: 7 additions & 3 deletions src/Css/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static function parse($color)
static $cache = [];

$color = strtolower($color);
$alpha = 1.0;

if (isset($cache[$color])) {
return $cache[$color];
Expand All @@ -203,14 +204,18 @@ static function parse($color)
return $cache[$color] = self::getArray($color[1] . $color[1] . $color[2] . $color[2] . $color[3] . $color[3]);
} // #rgba format
else if ($length == 5 && $color[0] === "#") {
$alpha = round(hexdec($color[4] . $color[4])/255, 2);
if (ctype_xdigit($color[4])) {
$alpha = round(hexdec($color[4] . $color[4])/255, 2);
}
return $cache[$color] = self::getArray($color[1] . $color[1] . $color[2] . $color[2] . $color[3] . $color[3], $alpha);
} // #rrggbb format
else if ($length == 7 && $color[0] === "#") {
return $cache[$color] = self::getArray(mb_substr($color, 1, 6));
} // #rrggbbaa format
else if ($length == 9 && $color[0] === "#") {
$alpha = round(hexdec(mb_substr($color, 7, 2))/255, 2);
if (ctype_xdigit(mb_substr($color, 7, 2))) {
$alpha = round(hexdec(mb_substr($color, 7, 2))/255, 2);
}
return $cache[$color] = self::getArray(mb_substr($color, 1, 6), $alpha);
} // rgb( r,g,b ) / rgba( r,g,b,α ) format
else if (mb_strpos($color, "rgb") !== false) {
Expand All @@ -226,7 +231,6 @@ static function parse($color)

// alpha transparency
// FIXME: not currently using transparency
$alpha = 1.0;
if (count($triplet) == 4) {
$alpha = (trim(array_pop($triplet)));
if (Helpers::is_percent($alpha)) {
Expand Down
63 changes: 39 additions & 24 deletions src/Css/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function __construct(Stylesheet $stylesheet, $origin = Stylesheet::ORIG_A
$d["src"] = "";
$d["unicode_range"] = "";

// vendor-previxed properties
// vendor-prefixed properties
$d["_dompdf_background_image_resolution"] = &$d["background_image_resolution"];
$d["_dompdf_image_resolution"] = &$d["image_resolution"];
$d["_dompdf_keep"] = "";
Expand Down Expand Up @@ -794,7 +794,13 @@ function merge(Style $style)
unset($this->_prop_cache[$shorthand]);
}
}
$this->__set($prop, $val);
//FIXME: temporary hack around lack of persistence of base href for URLs
if (($prop === "background_image" || $prop === "list_style_image") && isset($style->_props_computed[$prop])) {
$this->__set($prop, $style->_props_computed[$prop]);
} else {
// computed value not set, recompute use the specified value
$this->__set($prop, $val);
}
}
}
}
Expand Down Expand Up @@ -1808,7 +1814,7 @@ protected function _image($val)

if (empty($val) || $val === "none") {
$path = "none";
} else if (mb_strpos($val, "url") === false) {
} elseif (mb_strpos($val, "url") === false) {
$path = "none"; //Don't resolve no image -> otherwise would prefix path and no longer recognize as none
} else {
$val = preg_replace("/url\(\s*['\"]?([^'\")]+)['\"]?\s*\)/", "\\1", trim($val));
Expand All @@ -1819,7 +1825,7 @@ protected function _image($val)
$this->_stylesheet->get_host(),
$this->_stylesheet->get_base_path(),
$val);
if ($parsed_url["protocol"] == "" && $this->_stylesheet->get_protocol() == "") {
if (($parsed_url["protocol"] == "" || $parsed_url["protocol"] == "file://") && ($this->_stylesheet->get_protocol() == "" || $this->_stylesheet->get_protocol() == "file://")) {
$path = realpath($path);
// If realpath returns FALSE then specifically state that there is no background image
if (!$path) {
Expand Down Expand Up @@ -1886,7 +1892,12 @@ function set_background_color($color)
function set_background_image($val)
{
$this->_props["background_image"] = $val;
$this->_props_computed["background_image"] = "url(" . $this->_image($val) . ")";
$parsed_val = $this->_image($val);
if ($parsed_val === "none") {
$this->_props_computed["background_image"] = "none";
} else {
$this->_props_computed["background_image"] = "url(" . $parsed_val . ")";
}
$this->_prop_cache["background_image"] = null;
}

Expand Down Expand Up @@ -2488,30 +2499,29 @@ function set_padding($val)
protected function _set_border($side, $border_spec, $important)
{
$border_spec = preg_replace("/\s*\,\s*/", ",", $border_spec);
//$border_spec = str_replace(",", " ", $border_spec); // Why did we have this ?? rbg(10, 102, 10) > rgb(10 102 10)
$arr = explode(" ", $border_spec);

// FIXME: handle partial values
//For consistency of individual and combined properties, and with ie8 and firefox3
//reset all attributes, even if only partially given
//$this->_set_style_side_type('border', $side, 'style', self::$_defaults['border_' . $side . '_style'], $important);
//$this->_set_style_side_type('border', $side, 'width', self::$_defaults['border_' . $side . '_width'], $important);
//$this->_set_style_side_type('border', $side, 'color', self::$_defaults['border_' . $side . '_color'], $important);

foreach ($arr as $value) {
$value = trim($value);
if (in_array($value, self::$BORDER_STYLES)) {
$this->_set_style_side_type('border', $side, 'style', $value, $important);
} elseif (preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:thin|medium|thick)/", $value)) {
$this->_set_style_side_type('border', $side, 'width', $value, $important);
} elseif ($value === "inherit") {
$this->_set_style_side_type('border', $side, 'style', $value, $important);
$this->_set_style_side_type('border', $side, 'width', $value, $important);
$this->_set_style_side_type('border', $side, 'color', $value, $important);
$prop = "";
if (strtolower($value) === "inherit") {
$this->__set("border_${side}_color", "inherit");
$this->__set("border_${side}_style", "inherit");
$this->__set("border_${side}_width", "inherit");
continue;
} elseif (in_array($value, self::$BORDER_STYLES)) {
$prop = "border_${side}_style";
} elseif ($value === "0" || preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:thin|medium|thick)/", $value)) {
$prop = "border_${side}_width";
} else {
// must be color
$this->_set_style_side_type('border', $side, 'color', $this->munge_color($value), $important);
$prop = "border_${side}_color";
}

if ($important) {
$this->_important_props[$prop] = true;
}
$this->__set($prop, $value);
}
}

Expand Down Expand Up @@ -2837,7 +2847,7 @@ function set_outline($val)

if (in_array($value, self::$BORDER_STYLES)) {
$this->__set("outline_style", $value);
} else if (preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:thin|medium|thick)/", $value)) {
} else if ($value === "0" || preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:thin|medium|thick)/", $value)) {
$this->__set("outline_width", $value);
} else {
// must be color
Expand Down Expand Up @@ -2913,7 +2923,12 @@ function set_border_spacing($val)
function set_list_style_image($val)
{
$this->_props["list_style_image"] = $val;
$this->_props_computed["list_style_image"] = "url(" . $this->_image($val) . ")";
$parsed_val = $this->_image($val);
if ($parsed_val === "none") {
$this->_props_computed["list_style_image"] = "none";
} else {
$this->_props_computed["list_style_image"] = "url(" . $parsed_val . ")";
}
$this->_prop_cache["list_style_image"] = null;
}

Expand Down
Loading

0 comments on commit 49f36fd

Please sign in to comment.