Skip to content

Commit e2d94af

Browse files
committed
Merge branch 'tmbenhura'
2 parents 8fb02a5 + b3dcbcb commit e2d94af

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

include/tcpdf_colors.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'
275275
$color = strtolower($color);
276276
// check for javascript color array syntax
277277
if (strpos($color, '[') !== false) {
278-
if (preg_match('/[\[][\"\'](t|g|rgb|cmyk)[\"\'][\,]?([0-9\.]*+)[\,]?([0-9\.]*+)[\,]?([0-9\.]*+)[\,]?([0-9\.]*+)[\]]/', $color, $m) > 0) {
278+
if (preg_match('/[\[][\"\'](t|g|rgba|rgb|cmyk)[\"\'][\,]?([0-9\.]*+)[\,]?([0-9\.]*+)[\,]?([0-9\.]*+)[\,]?([0-9\.]*+)[\]]/', $color, $m) > 0) {
279279
$returncolor = array();
280280
switch ($m[1]) {
281281
case 'cmyk': {
@@ -286,7 +286,8 @@ public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'
286286
$returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100)));
287287
break;
288288
}
289-
case 'rgb': {
289+
case 'rgb':
290+
case 'rgba': {
290291
// RGB
291292
$returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255)));
292293
$returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255)));
@@ -317,6 +318,25 @@ public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'
317318
if (strlen($color) == 0) {
318319
return $defcol;
319320
}
321+
// RGBA ARRAY
322+
if (substr($color, 0, 4) == 'rgba') {
323+
$codes = substr($color, 5);
324+
$codes = str_replace(')', '', $codes);
325+
$returncolor = explode(',', $codes);
326+
// remove alpha component
327+
array_pop($returncolor);
328+
foreach ($returncolor as $key => $val) {
329+
if (strpos($val, '%') > 0) {
330+
// percentage
331+
$returncolor[$key] = (255 * intval($val) / 100);
332+
} else {
333+
$returncolor[$key] = intval($val); /* floatize */
334+
}
335+
// normalize value
336+
$returncolor[$key] = max(0, min(255, $returncolor[$key]));
337+
}
338+
return $returncolor;
339+
}
320340
// RGB ARRAY
321341
if (substr($color, 0, 3) == 'rgb') {
322342
$codes = substr($color, 4);

tcpdf.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23482,6 +23482,8 @@ protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1
2348223482
$fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
2348323483
if ($svgstyle['fill-opacity'] != 1) {
2348423484
$this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
23485+
} elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['fill'], $rgba_matches)) {
23486+
$this->setAlpha($this->alpha['CA'], 'Normal', $rgba_matches[1], false);
2348523487
}
2348623488
$this->setFillColorArray($fill_color);
2348723489
if ($svgstyle['fill-rule'] == 'evenodd') {

0 commit comments

Comments
 (0)