Skip to content

Commit

Permalink
Release 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
finwe committed Sep 1, 2023
2 parents 146c7c1 + dd0dc60 commit 170a236
Show file tree
Hide file tree
Showing 39 changed files with 417 additions and 1,218 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,10 @@
mPDF 8.2.x
===========================

New features
------------
* Watermark text can now be colored using \Mpdf\Watermark DTO. \Mpdf\WatermarkImage DTO for images. (#1876)

mPDF 8.1.x
===========================

Expand All @@ -10,6 +17,7 @@ New features
* Set font-size to `auto` in textarea and input in active forms to resize the font-size (@ChrisB9, #1721)
* PHP 8.2 support in mPDF 8.1.3
* Added support for `psr/log` v3 without dropping v2. (@markdorison, @apotek, @greg-1-anderson, #1857)
* Added support for `psr/http-message` v2 without dropping v1. (@markdorison, @apotek, @greg-1-anderson, @NigelCunningham #1907)

Bugfixes
--------
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Expand Up @@ -24,10 +24,11 @@
"php": "^5.6 || ^7.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-gd": "*",
"ext-mbstring": "*",
"mpdf/psr-http-message-shim": "^1.0 || ^2.0",
"mpdf/psr-log-aware-trait": "^2.0 || ^3.0",
"myclabs/deep-copy": "^1.7",
"paragonie/random_compat": "^1.4|^2.0|^9.99.99",
"psr/http-message": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"setasign/fpdi": "^2.1"
},
Expand All @@ -46,7 +47,10 @@
"autoload": {
"psr-4": {
"Mpdf\\": "src/"
}
},
"files": [
"src/functions.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions src/AssetFetcher.php
Expand Up @@ -5,8 +5,8 @@
use Mpdf\File\LocalContentLoaderInterface;
use Mpdf\File\StreamWrapperChecker;
use Mpdf\Http\ClientInterface;
use Mpdf\Http\Request;
use Mpdf\Log\Context as LogContext;
use Mpdf\PsrHttpMessageShim\Request;
use Mpdf\PsrLogAwareTrait\PsrLogAwareTrait;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -83,7 +83,7 @@ public function fetchRemoteContent($path)

$this->logger->debug(sprintf('Fetching remote content of file "%s"', $path), ['context' => LogContext::REMOTE_CONTENT]);

/** @var \Mpdf\Http\Response $response */
/** @var \Mpdf\PsrHttpMessageShim\Response $response */
$response = $this->http->sendRequest(new Request('GET', $path));

if ($response->getStatusCode() !== 200) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public function fetchRemoteContent($path)

public function isPathLocal($path)
{
return strpos($path, '://') === false; // @todo More robust implementation
return str_starts_with($path, 'file://') || strpos($path, '://') === false; // @todo More robust implementation
}

}
2 changes: 1 addition & 1 deletion src/CssManager.php
Expand Up @@ -6,7 +6,7 @@
use Mpdf\Css\TextVars;
use Mpdf\File\StreamWrapperChecker;
use Mpdf\Http\ClientInterface;
use Mpdf\Http\Request;
use Mpdf\PsrHttpMessageShim\Request;
use Mpdf\Utils\Arrays;
use Mpdf\Utils\UtfString;

Expand Down
32 changes: 28 additions & 4 deletions src/Gradient.php
Expand Up @@ -53,7 +53,7 @@ public function CoonsPatchMesh($x, $y, $w, $h, $patch_array = [], $x_min = 0, $x
$this->mpdf->gradients[$n]['stream'] = '';

for ($i = 0; $i < count($patch_array); $i++) {
$this->mpdf->gradients[$n]['stream'].=chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
$this->mpdf->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit

for ($j = 0; $j < count($patch_array[$i]['points']); $j++) {

Expand Down Expand Up @@ -93,7 +93,7 @@ public function CoonsPatchMesh($x, $y, $w, $h, $patch_array = [], $x_min = 0, $x
$trans = true;
}
} elseif ($colspace === 'Gray') {
$this->mpdf->gradients[$n]['stream'].= $patch_array[$i]['colors'][$j][1];
$this->mpdf->gradients[$n]['stream'] .= $patch_array[$i]['colors'][$j][1];
if ($patch_array[$i]['colors'][$j][2] == 1) {
$trans = true;
} // transparency converted from rgba or cmyka()
Expand Down Expand Up @@ -620,15 +620,19 @@ private function parseMozLinearGradient($m, $repeat)
$g['colorspace'] = 'RGB';
$g['extend'] = ['true', 'true'];
$v = trim($m[1]);

// Change commas inside e.g. rgb(x,x,x)
while (preg_match('/(\([^\)]*?),/', $v)) {
$v = preg_replace('/(\([^\)]*?),/', '\\1@', $v);
}

// Remove spaces inside e.g. rgb(x, x, x)
while (preg_match('/(\([^\)]*?)[ ]/', $v)) {
$v = preg_replace('/(\([^\)]*?)[ ]/', '\\1', $v);
}

$bgr = preg_split('/\s*,\s*/', $v);

for ($i = 0; $i < count($bgr); $i++) {
$bgr[$i] = preg_replace('/@/', ',', $bgr[$i]);
}
Expand All @@ -645,8 +649,10 @@ private function parseMozLinearGradient($m, $repeat)
$startStops = 0;
}
}

// first part a valid point/angle?
if ($startStops === 1) { // default values

// [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i', $bgr[0], $m)) {
$angle = $m[1] + 0;
Expand All @@ -662,16 +668,19 @@ private function parseMozLinearGradient($m, $repeat)
} elseif (trim($first[count($first) - 1]) === '0') {
$angle = 0;
}

if (stripos($bgr[0], 'left') !== false) {
$startx = 0;
} elseif (stripos($bgr[0], 'right') !== false) {
$startx = 1;
} elseif (stripos($bgr[0], 'right') !== false) {
$startx = 0;
}

if (stripos($bgr[0], 'top') !== false) {
$starty = 1;
} elseif (stripos($bgr[0], 'bottom') !== false) {
$starty = 0;
}

// Check for %? ?% or %%
if (preg_match('/(\d+)[%]/i', $first[0], $m)) {
$startx = $m[1] / 100;
Expand All @@ -681,6 +690,7 @@ private function parseMozLinearGradient($m, $repeat)
$startx = $m[1];
}
}

if (isset($first[1]) && preg_match('/(\d+)[%]/i', $first[1], $m)) {
$starty = 1 - ($m[1] / 100);
} elseif (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $first[1], $m)) {
Expand All @@ -689,12 +699,15 @@ private function parseMozLinearGradient($m, $repeat)
$starty = $m[1];
}
}

if (isset($startx) && !isset($starty)) {
$starty = 0.5;
}

if (!isset($startx) && isset($starty)) {
$startx = 0.5;
}

} else {
// If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values,
// the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of
Expand All @@ -704,31 +717,41 @@ private function parseMozLinearGradient($m, $repeat)
$endy = 0;
$endx = 0.5;
}

if (!isset($startx)) {
$startx = false;
}

if (!isset($starty)) {
$starty = false;
}

if (!isset($endx)) {
$endx = false;
}

if (!isset($endy)) {
$endy = false;
}

if (!isset($angle)) {
$angle = false;
}

$g['coords'] = [$startx, $starty, $endx, $endy, $angle, $repeat];
$g['stops'] = [];

for ($i = $startStops; $i < count($bgr); $i++) {

// parse stops
$el = preg_split('/\s+/', trim($bgr[$i]));
// mPDF 5.3.74
$col = $this->colorConverter->convert($el[0], $this->mpdf->PDFAXwarnings);

if (!$col) {
$col = $this->colorConverter->convert(255, $this->mpdf->PDFAXwarnings);
}

if ($col[0] == 1) {
$g['colorspace'] = 'Gray';
} elseif ($col[0] == 4 || $col[0] == 6) {
Expand All @@ -737,6 +760,7 @@ private function parseMozLinearGradient($m, $repeat)

$g['stops'][] = $this->getStop($col, $el, true);
}

return $g;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Http/CurlHttpClient.php
Expand Up @@ -4,6 +4,8 @@

use Mpdf\Log\Context as LogContext;
use Mpdf\Mpdf;
use Mpdf\PsrHttpMessageShim\Response;
use Mpdf\PsrHttpMessageShim\Stream;
use Mpdf\PsrLogAwareTrait\PsrLogAwareTrait;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;
Expand Down

0 comments on commit 170a236

Please sign in to comment.