Revize 1e8c793d
Přidáno uživatelem Michal Kliment před více než 9 roky(ů)
application/vendors/mpdf/classes/svg.php | ||
---|---|---|
<?php
|
||
// svg class modified for mPDF version 4.4.003 by Ian Back: based on -
|
||
// svg class modified for mPDF version 5.7.4 by Ian Back: based on -
|
||
// svg2pdf fpdf class
|
||
// sylvain briand (syb@godisaduck.com), modified by rick trevino (rtrevino1@yahoo.com)
|
||
// http://www.godisaduck.com/svg2pdf_with_fpdf
|
||
... | ... | |
// cette class etendue est open source, toute modification devra cependant etre repertori?e~
|
||
|
||
|
||
// If you wish to use "AutoFont" within SVG's. change this definition to true.
|
||
// This selects different fonts for different languages used in text.
|
||
// NB AutoFont within SVGs will only work on <text> elements, and will change the font-family for the whole element.
|
||
// This can be enabled/disabled independently of the use of AutoFont within mPDF generally.
|
||
// Choice of font is determined by the config_cp.php file, the same as for mPDF generally.
|
||
// NB The configurable variable $useLang must be set to true (in config.php or at runtime).
|
||
if (!defined("_SVG_AUTOFONT")) { define("_SVG_AUTOFONT", false); }
|
||
|
||
// Enable a limited use of classes within SVG <text> elements by setting this to true.
|
||
// This allows recognition of a "class" attribute on a <text> element.
|
||
// The CSS style for that class should be outside the SVG, and cannot use any other selectors (i.e. only .class {} can be defined)
|
||
// <style> definitions within the SVG code will be recognised if the SVG is included as an inline item within the HTML code passed to mPDF.
|
||
// The style property should be pertinent to SVG e.g. use fill:red rather than color:red
|
||
// Only the properties currently supported for SVG text can be specified:
|
||
// fill, fill-opacity, stroke, stroke-opacity, stroke-linecap, stroke-linejoin, stroke-width, stroke-dasharray, stroke-dashoffset
|
||
// font-family, font-size, font-weight, font-variant, font-style, opacity, text-anchor
|
||
if (!defined("_SVG_CLASSES")) { define("_SVG_CLASSES", false); }
|
||
|
||
|
||
|
||
// NB UNITS - Works in pixels as main units - converting to PDF units when outputing to PDF string
|
||
// and on returning size
|
||
|
||
... | ... | |
var $txt_data; // array - holds string info to write txt to image
|
||
var $txt_style; // array - current text style
|
||
var $mpdf_ref;
|
||
var $xbase; // mPDF 4.4.003
|
||
var $ybase; // mPDF 4.4.003
|
||
var $svg_error; // mPDF 4.4.003
|
||
var $subPathInit; // mPDF 4.4.003
|
||
var $spxstart; // mPDF 4.4.003
|
||
var $spystart; // mPDF 4.4.003
|
||
var $kp; // mPDF 4.4.003 convert pixels to PDF units
|
||
var $pathBBox; // mPDF 5.0.039
|
||
var $xbase;
|
||
var $ybase;
|
||
var $svg_error;
|
||
var $subPathInit;
|
||
var $spxstart;
|
||
var $spystart;
|
||
var $kp; // convert pixels to PDF units
|
||
var $pathBBox;
|
||
|
||
var $textlength; // mPDF 5.7.4
|
||
var $texttotallength; // mPDF 5.7.4
|
||
var $textoutput; // mPDF 5.7.4
|
||
var $textanchor; // mPDF 5.7.4
|
||
var $textXorigin; // mPDF 5.7.4
|
||
var $textYorigin; // mPDF 5.7.4
|
||
var $textjuststarted; // mPDF 5.7.4
|
||
var $intext; // mPDF 5.7.4
|
||
|
||
function SVG(&$mpdf){
|
||
$this->svg_gradient = array();
|
||
... | ... | |
$this->xbase = 0;
|
||
$this->ybase = 0;
|
||
$this->svg_error = false;
|
||
$this->subPathInit = false; // mPDF 4.4.003
|
||
$this->dashesUsed = false; // mPDF 5.0
|
||
$this->subPathInit = false;
|
||
$this->dashesUsed = false;
|
||
$this->mpdf_ref =& $mpdf;
|
||
|
||
$this->kp = 72 / $mpdf->img_dpi; // mPDF 4.4.003 constant To convert pixels to pts/PDF units
|
||
$this->kf = 1; // mPDF 5.0.039 constant To convert font size if re-mapped
|
||
$this->pathBBox = array(); // mPDF 5.0.039
|
||
$this->textlength = 0; // mPDF 5.7.4
|
||
$this->texttotallength = 0; // mPDF 5.7.4
|
||
$this->textoutput = ''; // mPDF 5.7.4
|
||
$this->textanchor = 'start'; // mPDF 5.7.4
|
||
$this->textXorigin = 0; // mPDF 5.7.4
|
||
$this->textYorigin = 0; // mPDF 5.7.4
|
||
$this->textjuststarted = false; // mPDF 5.7.4
|
||
$this->intext = false; // mPDF 5.7.4
|
||
|
||
$this->kp = 72 / $mpdf->img_dpi; // constant To convert pixels to pts/PDF units
|
||
$this->kf = 1; // constant To convert font size if re-mapped
|
||
$this->pathBBox = array();
|
||
|
||
$this->svg_style = array(
|
||
array(
|
||
'fill' => 'black', // mPDF 4.4.008
|
||
'fill' => 'black',
|
||
'fill-opacity' => 1, // remplissage opaque par defaut
|
||
'fill-rule' => 'nonzero', // mode de remplissage par defaut
|
||
'stroke' => 'none', // pas de trait par defaut
|
||
... | ... | |
'stroke-linejoin' => 'miter', //
|
||
'stroke-miterlimit' => 4, // limite de langle par defaut
|
||
'stroke-opacity' => 1, // trait opaque par defaut
|
||
'stroke-width' => 1, // mPDF 4.4.011
|
||
'stroke-dasharray' => 0, // mPDF 4.4.003
|
||
'stroke-dashoffset' => 0, // mPDF 4.4.003
|
||
'color' => '' // mPDF 4.4.005
|
||
'stroke-width' => 1,
|
||
'stroke-dasharray' => 0,
|
||
'stroke-dashoffset' => 0,
|
||
'color' => ''
|
||
)
|
||
);
|
||
|
||
... | ... | |
'fill-rule' => 'nonzero', // mode de remplissage par defaut
|
||
'stroke' => 'none', // pas de trait par defaut
|
||
'stroke-opacity' => 1, // trait opaque par defaut
|
||
'stroke-width' => 1, // mPDF 4.4.011
|
||
'color' => '' // mPDF 4.4.005
|
||
'stroke-width' => 1,
|
||
'color' => ''
|
||
)
|
||
);
|
||
|
||
... | ... | |
|
||
}
|
||
|
||
// mPDF 5.7.4 Embedded image
|
||
function svgImage($attribs) {
|
||
// x and y are coordinates
|
||
$x = (isset($attribs['x']) ? $attribs['x'] : 0);
|
||
$y = (isset($attribs['y']) ? $attribs['y'] : 0);
|
||
// preserveAspectRatio
|
||
$par = (isset($attribs['preserveAspectRatio']) ? $attribs['preserveAspectRatio'] : 'xMidYMid meet');
|
||
// width and height are <lengths> - Required attributes
|
||
$wset = (isset($attribs['width']) ? $attribs['width'] : 0);
|
||
$hset = (isset($attribs['height']) ? $attribs['height'] : 0);
|
||
$w = $this->mpdf_ref->ConvertSize($wset,$this->svg_info['w']*(25.4/$this->mpdf_ref->dpi),$this->mpdf_ref->FontSize,false);
|
||
$h = $this->mpdf_ref->ConvertSize($hset,$this->svg_info['h']*(25.4/$this->mpdf_ref->dpi),$this->mpdf_ref->FontSize,false);
|
||
if ($w==0 || $h==0) { return; }
|
||
// Convert to pixels = SVG units
|
||
$w *= 1/(25.4/$this->mpdf_ref->dpi);
|
||
$h *= 1/(25.4/$this->mpdf_ref->dpi);
|
||
|
||
$srcpath = $attribs['xlink:href'];
|
||
$orig_srcpath = '';
|
||
if (trim($srcpath) != '' && substr($srcpath,0,4)=='var:') {
|
||
$orig_srcpath = $srcpath;
|
||
$this->mpdf_ref->GetFullPath($srcpath);
|
||
}
|
||
|
||
// Image file (does not allow vector images i.e. WMF/SVG)
|
||
$info = $this->mpdf_ref->_getImage($srcpath, true, false, $orig_srcpath);
|
||
if(!$info) return;
|
||
|
||
// x,y,w,h define the reference rectangle
|
||
$img_h = $h;
|
||
$img_w = $w;
|
||
$img_x = $x;
|
||
$img_y = $y;
|
||
$meetOrSlice = 'meet';
|
||
|
||
// preserveAspectRatio
|
||
$ar = preg_split('/\s+/', strtolower($par));
|
||
if ($ar[0]!='none') { // If "none" need to do nothing
|
||
// Force uniform scaling
|
||
if (isset($ar[1]) && $ar[1]=='slice') { $meetOrSlice = 'slice'; }
|
||
else { $meetOrSlice = 'meet'; }
|
||
if ($info['h']/$info['w'] > $h/$w) {
|
||
if ($meetOrSlice == 'meet') { // the entire viewBox is visible within the viewport
|
||
$img_w = $img_h * $info['w']/$info['h'];
|
||
}
|
||
else { // the entire viewport is covered by the viewBox
|
||
$img_h = $img_w * $info['h']/$info['w'];
|
||
}
|
||
}
|
||
else if ($info['h']/$info['w'] < $h/$w) {
|
||
if ($meetOrSlice == 'meet') { // the entire viewBox is visible within the viewport
|
||
$img_h = $img_w * $info['h']/$info['w'];
|
||
}
|
||
else { // the entire viewport is covered by the viewBox
|
||
$img_w = $img_h * $info['w']/$info['h'];
|
||
}
|
||
}
|
||
if ($ar[0]=='xminymin') {
|
||
// do nothing to x
|
||
// do nothing to y
|
||
}
|
||
else if ($ar[0]=='xmidymin') {
|
||
$img_x += $w/2 - $img_w/2; // xMid
|
||
// do nothing to y
|
||
}
|
||
else if ($ar[0]=='xmaxymin') {
|
||
$img_x += $w - $img_w; // xMax
|
||
// do nothing to y
|
||
}
|
||
else if ($ar[0]=='xminymid') {
|
||
// do nothing to x
|
||
$img_y += $h/2 - $img_h/2; // yMid
|
||
}
|
||
else if ($ar[0]=='xmaxymid') {
|
||
$img_x += $w - $img_w; // xMax
|
||
$img_y += $h/2 - $img_h/2; // yMid
|
||
}
|
||
else if ($ar[0]=='xminymax') {
|
||
// do nothing to x
|
||
$img_y += $h - $img_h; // yMax
|
||
}
|
||
else if ($ar[0]=='xmidymax') {
|
||
$img_x += $w/2 - $img_w/2; // xMid
|
||
$img_y += $h - $img_h; // yMax
|
||
}
|
||
else if ($ar[0]=='xmaxymax') {
|
||
$img_x += $w - $img_w; // xMax
|
||
$img_y += $h - $img_h; // yMax
|
||
}
|
||
else { // xMidYMid (the default)
|
||
$img_x += $w/2 - $img_w/2; // xMid
|
||
$img_y += $h/2 - $img_h/2; // yMid
|
||
}
|
||
}
|
||
|
||
// Output
|
||
if ($meetOrSlice == 'slice') { // need to add a clipping path to reference rectangle
|
||
$s = ' q 0 w '; // Line width=0
|
||
$s .= sprintf('%.3F %.3F m ', ($x)*$this->kp, (-($y+$h))*$this->kp); // start point TL before the arc
|
||
$s .= sprintf('%.3F %.3F l ', ($x)*$this->kp, (-($y))*$this->kp); // line to BL
|
||
$s .= sprintf('%.3F %.3F l ', ($x+$w)*$this->kp, (-($y))*$this->kp); // line to BR
|
||
$s .= sprintf('%.3F %.3F l ', ($x+$w)*$this->kp, (-($y+$h))*$this->kp); // line to TR
|
||
$s .= sprintf('%.3F %.3F l ', ($x)*$this->kp, (-($y+$h))*$this->kp); // line to TL
|
||
$s .= ' W n '; // Ends path no-op & Sets the clipping path
|
||
$this->svgWriteString($s);
|
||
}
|
||
|
||
$outstring = sprintf(" q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q ",$img_w*$this->kp, $img_h*$this->kp, $img_x*$this->kp, -($img_y+$img_h)*$this->kp, $info['i'] );
|
||
$this->svgWriteString($outstring);
|
||
|
||
if ($meetOrSlice == 'slice') { // need to end clipping path
|
||
$this->svgWriteString(' Q ');
|
||
}
|
||
}
|
||
|
||
|
||
function svgGradient($gradient_info, $attribs, $element){
|
||
$n = count($this->mpdf_ref->gradients)+1;
|
||
|
||
... | ... | |
$y_offset = $mint;
|
||
}
|
||
else if ($element=='path') {
|
||
// mPDF 5.0.039
|
||
if (is_array($this->pathBBox) && $this->pathBBox[2]>0) {
|
||
$w = $this->pathBBox[2];
|
||
$h = $this->pathBBox[3];
|
||
... | ... | |
if ($x_offset==999999) { $x_offset = 0; }
|
||
if ($y_offset==999999) { $y_offset = 0; }
|
||
|
||
// mPDF 4.5.010
|
||
// TRANSFORMATIONS
|
||
$transformations = '';
|
||
if (isset($gradient_info['transform'])){
|
||
... | ... | |
|
||
$return = "";
|
||
|
||
// mPDF 5.0.039
|
||
if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
|
||
if ($transformations) { $return .= $transformations; }
|
||
}
|
||
// mPDF 5.0.040
|
||
$spread = 'P'; // pad
|
||
if (isset($gradient_info['spread'])) {
|
||
if (strtolower($gradient_info['spread'])=='reflect') { $spread = 'F'; } // reflect
|
||
... | ... | |
if (stristr($y1, '%')!== false) { $y1 = ($y1+0)/100; }
|
||
if (stristr($y2, '%')!== false) { $y2 = ($y2+0)/100; }
|
||
|
||
// mPDF 5.0.042
|
||
$bboxw = $w;
|
||
$bboxh = $h;
|
||
$usex = $x_offset;
|
||
... | ... | |
|
||
$return .= sprintf('%.3F 0 0 %.3F %.3F %.3F cm ', $a*$this->kp, $d*$this->kp, $e*$this->kp, $f*$this->kp);
|
||
|
||
// mPDF 5.0.039
|
||
if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='objectboundingbox') {
|
||
if ($transformations) { $return .= $transformations; }
|
||
}
|
||
|
||
// mPDF 5.0.020
|
||
$trans = false;
|
||
|
||
// mPDF 5.0.040
|
||
if ($spread=='R' || $spread=='F') { // Repeat / Reflect
|
||
$offs = array();
|
||
for($i=0;$i<$ns;$i++) {
|
||
... | ... | |
}
|
||
}
|
||
|
||
// mPDF 4.4.007 Gradient STOPs
|
||
// Gradient STOPs
|
||
$stops = count($gradient_info['color']);
|
||
if ($stops < 2) { return ''; }
|
||
|
||
// mPDF 5.0.042
|
||
$range = $gradient_info['color'][count($gradient_info['color'])-1]['offset']-$gradient_info['color'][0]['offset'];
|
||
$min = $gradient_info['color'][0]['offset'];
|
||
|
||
for ($i=0; $i<($stops); $i++) {
|
||
// mPDF 5.0.051
|
||
if (!$gradient_info['color'][$i]['color']) {
|
||
if ($gradient_info['colorspace']=='RGB') $gradient_info['color'][$i]['color'] = '0 0 0';
|
||
else if ($gradient_info['colorspace']=='Gray') $gradient_info['color'][$i]['color'] = '0';
|
||
... | ... | |
|
||
$this->mpdf_ref->gradients[$n]['coords']=array($grx1, $gry1, $grx2, $gry2);
|
||
|
||
$this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace']; // mPDF 5.0.051
|
||
$this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace'];
|
||
|
||
$this->mpdf_ref->gradients[$n]['type'] = 2;
|
||
$this->mpdf_ref->gradients[$n]['fo'] = true;
|
||
... | ... | |
$return .= " Q\n";
|
||
}
|
||
else if ($gradient_info['type'] == 'radial'){
|
||
// mPDF 4.4.003
|
||
if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
|
||
if ($w > $h) { $h = $w; }
|
||
else { $w = $h; }
|
||
... | ... | |
if (stristr($rx, '%')!== false) { $rx = ($rx+0)/100; }
|
||
if (stristr($ry, '%')!== false) { $ry = ($ry+0)/100; }
|
||
|
||
// mPDF 5.0.043
|
||
$bboxw = $w;
|
||
$bboxh = $h;
|
||
$usex = $x_offset;
|
||
... | ... | |
|
||
$return .= sprintf('%.3F 0 0 %.3F %.3F %.3F cm ', $a*$this->kp, $d*$this->kp, $e*$this->kp, $f*$this->kp);
|
||
|
||
// mPDF 5.0.039
|
||
if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='objectboundingbox') {
|
||
if ($transformations) { $return .= $transformations; }
|
||
}
|
||
|
||
// x1 and y1 (fx, fy) should be inside the circle defined by x0 y0 and r else error in mPDF
|
||
while (pow(($x1-$x0),2) + pow(($y1 - $y0),2) >= pow($r,2)) { $r += 0.05; }
|
||
// mPDF 5.7.4
|
||
// x1 and y1 (fx, fy) should be inside the circle defined by x0 y0 (cx, cy)
|
||
// "If the point defined by fx and fy lies outside the circle defined by cx, cy and r, then the user agent shall set
|
||
// the focal point to the intersection of the line from (cx, cy) to (fx, fy) with the circle defined by cx, cy and r."
|
||
while (pow(($x1-$x0),2) + pow(($y1 - $y0),2) >= pow($r,2)) {
|
||
// Gradually move along fx,fy towards cx,cy in 100'ths until meets criteria
|
||
$x1 -= ($x1-$x0)/100;
|
||
$y1 -= ($y1-$y0)/100;
|
||
}
|
||
|
||
// mPDF 5.0.040
|
||
if ($spread=='R' || $spread=='F') { // Repeat / Reflect
|
||
$offs = array();
|
||
for($i=0;$i<$ns;$i++) {
|
||
... | ... | |
}
|
||
}
|
||
|
||
// mPDF 4.4.007 Gradient STOPs
|
||
// Gradient STOPs
|
||
$stops = count($gradient_info['color']);
|
||
if ($stops < 2) { return ''; }
|
||
|
||
// mPDF 5.0.043
|
||
$range = $gradient_info['color'][count($gradient_info['color'])-1]['offset']-$gradient_info['color'][0]['offset'];
|
||
$min = $gradient_info['color'][0]['offset'];
|
||
|
||
for ($i=0; $i<($stops); $i++) {
|
||
// mPDF 5.0.051
|
||
if (!$gradient_info['color'][$i]['color']) {
|
||
if ($gradient_info['colorspace']=='RGB') $gradient_info['color'][$i]['color'] = '0 0 0';
|
||
else if ($gradient_info['colorspace']=='Gray') $gradient_info['color'][$i]['color'] = '0';
|
||
... | ... | |
$gry2 = $y1 + ($y0-$y1)*$last_stop;
|
||
$grir = $r*$first_stop;
|
||
$grr = $r*$last_stop;
|
||
$this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace']; // mPDF 5.0.051
|
||
$this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace'];
|
||
|
||
$this->mpdf_ref->gradients[$n]['type'] = 3;
|
||
$this->mpdf_ref->gradients[$n]['fo'] = true;
|
||
... | ... | |
$this->svg_info['y'] = $vb[1];
|
||
$this->svg_info['w'] = $vb[2];
|
||
$this->svg_info['h'] = $vb[3];
|
||
// return; // mPDF 5.0.005
|
||
}
|
||
}
|
||
|
||
... | ... | |
$svg_h = $this->mpdf_ref->ConvertSize($attribs['height']); // mm
|
||
|
||
///*
|
||
// mPDF 5.0.005
|
||
if ($this->svg_info['w']) { // if 'w' set by viewBox
|
||
if ($svg_w) { // if width also set, use these values to determine to set size of "pixel"
|
||
$this->kp *= ($svg_w/0.2645) / $this->svg_info['w'];
|
||
... | ... | |
return;
|
||
}
|
||
//*/
|
||
|
||
// Added to handle file without height or width specified
|
||
if (!$svg_w && !$svg_h) { $svg_w = $svg_h = $this->mpdf_ref->blk[$this->mpdf_ref->blklvl]['inner_width'] ; } // DEFAULT
|
||
if (!$svg_w) { $svg_w = $svg_h; }
|
||
... | ... | |
$v = trim($m[2][$i]);
|
||
$vv = preg_split('/[ ,]+/',$v);
|
||
if ($c=='matrix' && count($vv)==6) {
|
||
// mPDF 5.0.039
|
||
// Note angle of rotation is reversed (from SVG to PDF), so vv[1] and vv[2] are negated
|
||
$transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $vv[0], -$vv[1], -$vv[2], $vv[3], $vv[4]*$this->kp, -$vv[5]*$this->kp);
|
||
|
||
... | ... | |
}
|
||
|
||
if (isset($critere_style['style'])){
|
||
if (preg_match('/fill:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/',$critere_style['style'], $m)) {
|
||
if (preg_match('/fill:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/i',$critere_style['style'], $m)) { // mPDF 5.7.2
|
||
$current_style['fill'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
|
||
}
|
||
else { $tmp = preg_replace("/(.*)fill:\s*([a-z0-9#_()]*|none)(.*)/i","$2",$critere_style['style']); // mPDF 4.4.003
|
||
if ($tmp != $critere_style['style']){ $current_style['fill'] = $tmp; }
|
||
else { $tmp = preg_replace("/(.*)fill:\s*([a-z0-9#_()]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['fill'] = $tmp; }
|
||
}
|
||
|
||
// mPDF 5.7.2
|
||
if ((preg_match("/[^-]opacity:\s*([a-z0-9.]*|none)/i",$critere_style['style'], $m) ||
|
||
preg_match("/^opacity:\s*([a-z0-9.]*|none)/i",$critere_style['style'], $m)) && $m[1]!='inherit') {
|
||
$current_style['fill-opacity'] = $m[1];
|
||
$current_style['stroke-opacity'] = $m[1];
|
||
}
|
||
|
||
$tmp = preg_replace("/(.*)fill-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['fill-opacity'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['fill-opacity'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)fill-rule:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['fill-rule'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['fill-rule'] = $tmp;}
|
||
|
||
if (preg_match('/stroke:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/',$critere_style['style'], $m)) {
|
||
$current_style['stroke'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
|
||
}
|
||
else { $tmp = preg_replace("/(.*)stroke:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke'] = $tmp; }
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke'] = $tmp; }
|
||
}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-linecap:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-linecap'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-linecap'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-linejoin:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-linejoin'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-linejoin'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-miterlimit:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-miterlimit'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-miterlimit'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-opacity'] = $tmp; }
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-opacity'] = $tmp; }
|
||
|
||
$tmp = preg_replace("/(.*)stroke-width:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-width'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-width'] = $tmp;}
|
||
|
||
// mPDF 4.4.003
|
||
$tmp = preg_replace("/(.*)stroke-dasharray:\s*([a-z0-9., ]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-dasharray'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-dasharray'] = $tmp;}
|
||
|
||
// mPDF 4.4.003
|
||
$tmp = preg_replace("/(.*)stroke-dashoffset:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-dashoffset'] = $tmp;}
|
||
if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-dashoffset'] = $tmp;}
|
||
|
||
}
|
||
if(isset($critere_style['fill'])){
|
||
// mPDF 5.7.2
|
||
if(isset($critere_style['opacity']) && $critere_style['opacity']!= 'inherit'){
|
||
$current_style['fill-opacity'] = $critere_style['opacity'];
|
||
$current_style['stroke-opacity'] = $critere_style['opacity'];
|
||
}
|
||
|
||
if(isset($critere_style['fill']) && $critere_style['fill']!= 'inherit'){
|
||
$current_style['fill'] = $critere_style['fill'];
|
||
}
|
||
|
||
if(isset($critere_style['fill-opacity'])){
|
||
if(isset($critere_style['fill-opacity']) && $critere_style['fill-opacity']!= 'inherit'){
|
||
$current_style['fill-opacity'] = $critere_style['fill-opacity'];
|
||
}
|
||
|
||
if(isset($critere_style['fill-rule'])){
|
||
if(isset($critere_style['fill-rule']) && $critere_style['fill-rule']!= 'inherit'){
|
||
$current_style['fill-rule'] = $critere_style['fill-rule'];
|
||
}
|
||
|
||
if(isset($critere_style['stroke'])){
|
||
if(isset($critere_style['stroke']) && $critere_style['stroke']!= 'inherit'){
|
||
$current_style['stroke'] = $critere_style['stroke'];
|
||
}
|
||
|
||
if(isset($critere_style['stroke-linecap'])){
|
||
if(isset($critere_style['stroke-linecap']) && $critere_style['stroke-linecap']!= 'inherit'){
|
||
$current_style['stroke-linecap'] = $critere_style['stroke-linecap'];
|
||
}
|
||
|
||
if(isset($critere_style['stroke-linejoin'])){
|
||
if(isset($critere_style['stroke-linejoin']) && $critere_style['stroke-linejoin']!= 'inherit'){
|
||
$current_style['stroke-linejoin'] = $critere_style['stroke-linejoin'];
|
||
}
|
||
|
||
if(isset($critere_style['stroke-miterlimit'])){
|
||
if(isset($critere_style['stroke-miterlimit']) && $critere_style['stroke-miterlimit']!= 'inherit'){
|
||
$current_style['stroke-miterlimit'] = $critere_style['stroke-miterlimit'];
|
||
}
|
||
|
||
if(isset($critere_style['stroke-opacity'])){
|
||
if(isset($critere_style['stroke-opacity']) && $critere_style['stroke-opacity']!= 'inherit'){
|
||
$current_style['stroke-opacity'] = $critere_style['stroke-opacity'];
|
||
}
|
||
|
||
if(isset($critere_style['stroke-width'])){
|
||
if(isset($critere_style['stroke-width']) && $critere_style['stroke-width']!= 'inherit'){
|
||
$current_style['stroke-width'] = $critere_style['stroke-width'];
|
||
}
|
||
|
||
// mPDF 4.4.003
|
||
if(isset($critere_style['stroke-dasharray'])){
|
||
if(isset($critere_style['stroke-dasharray']) && $critere_style['stroke-dasharray']!= 'inherit'){
|
||
$current_style['stroke-dasharray'] = $critere_style['stroke-dasharray'];
|
||
}
|
||
if(isset($critere_style['stroke-dashoffset'])){
|
||
if(isset($critere_style['stroke-dashoffset']) && $critere_style['stroke-dashoffset']!= 'inherit'){
|
||
$current_style['stroke-dashoffset'] = $critere_style['stroke-dashoffset'];
|
||
}
|
||
|
||
// mPDF 4.4.005 Used as indirect setting for currentColor
|
||
// Used as indirect setting for currentColor
|
||
if(isset($critere_style['color']) && $critere_style['color'] != 'inherit'){
|
||
$current_style['color'] = $critere_style['color'];
|
||
}
|
||
... | ... | |
// Cette fonction ecrit le style dans le stream svg.
|
||
function svgStyle($critere_style, $attribs, $element){
|
||
$path_style = '';
|
||
if (substr_count($critere_style['fill'],'url')>0){
|
||
if (substr_count($critere_style['fill'],'url')>0 && $element != 'line'){
|
||
//
|
||
// couleur degrad?
|
||
$id_gradient = preg_replace("/url\(#([\w_]*)\)/i","$1",$critere_style['fill']);
|
||
if ($id_gradient != $critere_style['fill']) {
|
||
if (isset($this->svg_gradient[$id_gradient])) {
|
||
$fill_gradient = $this->svgGradient($this->svg_gradient[$id_gradient], $attribs, $element);
|
||
if ($fill_gradient) { // mPDF 4.4.003
|
||
if ($fill_gradient) {
|
||
$path_style = "q ";
|
||
$w = "W";
|
||
$style .= 'N';
|
||
... | ... | |
}
|
||
|
||
}
|
||
// mPDF 4.4.005 Used as indirect setting for currentColor
|
||
else if (strtolower($critere_style['fill']) == 'currentcolor'){
|
||
// Used as indirect setting for currentColor
|
||
else if (strtolower($critere_style['fill']) == 'currentcolor' && $element != 'line'){
|
||
$col = $this->mpdf_ref->ConvertColor($critere_style['color']);
|
||
if ($col) {
|
||
// mPDF 5.0.051
|
||
// mPDF 5.3.74
|
||
if ($col{0}==5) { $critere_style['fill-opacity'] = ord($col{4}/100); } // RGBa
|
||
if ($col{0}==6) { $critere_style['fill-opacity'] = ord($col{5}/100); } // CMYKa
|
||
$path_style .= $this->mpdf_ref->SetFColor($col, true).' '; // mPDF 5.0.051
|
||
$path_style .= $this->mpdf_ref->SetFColor($col, true).' ';
|
||
$style .= 'F';
|
||
}
|
||
}
|
||
else if ($critere_style['fill'] != 'none'){
|
||
else if ($critere_style['fill'] != 'none' && $element != 'line'){
|
||
$col = $this->mpdf_ref->ConvertColor($critere_style['fill']);
|
||
if ($col) {
|
||
// mPDF 5.0.051
|
||
// mPDF 5.3.74
|
||
if ($col{0}==5) { $critere_style['fill-opacity'] = ord($col{4}/100); } // RGBa
|
||
if ($col{0}==6) { $critere_style['fill-opacity'] = ord($col{5}/100); } // CMYKa
|
||
$path_style .= $this->mpdf_ref->SetFColor($col, true).' '; // mPDF 5.0.051
|
||
$path_style .= $this->mpdf_ref->SetFColor($col, true).' ';
|
||
$style .= 'F';
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
*/
|
||
}
|
||
// mPDF 4.4.005 Used as indirect setting for currentColor
|
||
// Used as indirect setting for currentColor
|
||
else if (strtolower($critere_style['stroke']) == 'currentcolor'){
|
||
$col = $this->mpdf_ref->ConvertColor($critere_style['color']);
|
||
if ($col) {
|
||
// mPDF 5.0.051
|
||
// mPDF 5.3.74
|
||
if ($col{0}==5) { $critere_style['stroke-opacity'] = ord($col{4}/100); } // RGBa
|
||
if ($col{0}==6) { $critere_style['stroke-opacity'] = ord($col{5}/100); } // CMYKa
|
||
$path_style .= $this->mpdf_ref->SetDColor($col, true).' '; // mPDF 5.0.051
|
||
... | ... | |
else if ($critere_style['stroke'] != 'none'){
|
||
$col = $this->mpdf_ref->ConvertColor($critere_style['stroke']);
|
||
if ($col) {
|
||
// mPDF 5.0.051
|
||
// mPDF 5.3.74
|
||
if ($col{0}==5) { $critere_style['stroke-opacity'] = ord($col{4}/100); } // RGBa
|
||
if ($col{0}==6) { $critere_style['stroke-opacity'] = ord($col{5}/100); } // CMYKa
|
||
$path_style .= $this->mpdf_ref->SetDColor($col, true).' '; // mPDF 5.0.051
|
||
... | ... | |
$path_style .= sprintf('%.2F M ',$critere_style['stroke-miterlimit']);
|
||
}
|
||
}
|
||
// mPDF 4.4.003
|
||
if (isset($critere_style['stroke-dasharray'])){
|
||
$off = 0;
|
||
$d = preg_split('/[ ,]/',$critere_style['stroke-dasharray']);
|
||
... | ... | |
}
|
||
}
|
||
|
||
// mPDF 4.4.003
|
||
if ($critere_style['fill-rule']=='evenodd') { $fr = '*'; }
|
||
else { $fr = ''; }
|
||
|
||
// mPDF 4.4.003
|
||
if (isset($critere_style['fill-opacity'])) {
|
||
$opacity = 1;
|
||
if ($critere_style['fill-opacity'] == 0) { $opacity = 0; }
|
||
... | ... | |
$path_style .= sprintf(' /GS%d gs ', $gs);
|
||
}
|
||
|
||
// mPDF 4.4.003
|
||
if (isset($critere_style['stroke-opacity'])) {
|
||
$opacity = 1;
|
||
if ($critere_style['stroke-opacity'] == 0) { $opacity = 0; }
|
||
... | ... | |
$op = 'n';
|
||
}
|
||
|
||
// mPDF 5.0
|
||
$prestyle = $path_style.' ';
|
||
$poststyle = $w.' '. $op.$fr.' '.$fill_gradient."\n";
|
||
return array($prestyle,$poststyle);
|
||
... | ... | |
// fonction retracant les <path />
|
||
function svgPath($command, $arguments){
|
||
$path_cmd = '';
|
||
$newsubpath = false; // mPDF 4.4.003
|
||
// mPDF 5.0.039
|
||
$newsubpath = false;
|
||
$minl = $this->pathBBox[0];
|
||
$mint = $this->pathBBox[1];
|
||
$maxr = $this->pathBBox[2]+$this->pathBBox[0];
|
||
$maxb = $this->pathBBox[3]+$this->pathBBox[1];
|
||
// mPDF 5.0.040
|
||
$start = array($this->xbase, -$this->ybase);
|
||
|
||
// mPDF 4.4.003
|
||
preg_match_all('/[\-^]?[\d.]+(e[\-]?[\d]+){0,1}/i', $arguments, $a, PREG_SET_ORDER);
|
||
|
||
// if the command is a capital letter, the coords go absolute, otherwise relative
|
||
... | ... | |
$ile_argumentow = count($a);
|
||
|
||
// each command may have different needs for arguments [1 to 8]
|
||
|
||
switch(strtolower($command)){
|
||
case 'm': // move
|
||
for($i = 0; $i<$ile_argumentow; $i+=2){
|
||
... | ... | |
$this->ybase = -$y;
|
||
}
|
||
$pdf_pt = $this->svg_overflow($pdfx,$pdfy);
|
||
// mPDF 5.0.039
|
||
$minl = min($minl,$pdf_pt['x']);
|
||
$maxr = max($maxr,$pdf_pt['x']);
|
||
$mint = min($mint,-$pdf_pt['y']);
|
||
$maxb = max($maxb,-$pdf_pt['y']);
|
||
if($i == 0) $path_cmd .= sprintf('%.3F %.3F m ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
|
||
else $path_cmd .= sprintf('%.3F %.3F l ', $pdf_pt['x']*$this->kp, $pdf_pt['y']*$this->kp);
|
||
// mPDF 4.4.003 Save start points of subpath
|
||
// Save start points of subpath
|
||
if ($this->subPathInit) {
|
||
$this->spxstart = $this->xbase;
|
||
$this->spystart = $this->ybase;
|
||
... | ... | |
$this->ybase = -$y;
|
||
}
|
||
$pdf_pt = $this->svg_overflow($pdfx,$pdfy);
|
||
// mPDF 5.0.039
|
||
$minl = min($minl,$pdf_pt['x']);
|
||
$maxr = max($maxr,$pdf_pt['x']);
|
||
$mint = min($mint,-$pdf_pt['y']);
|
||
... | ... | |
$this->ybase = -$y;
|
||
}
|
||
$pdf_pt = $this->svg_overflow($pdfx,$pdfy);
|
||
// mPDF 5.0.039
|
||
$minl = min($minl,$pdf_pt['x']);
|
||
$maxr = max($maxr,$pdf_pt['x']);
|
||
$mint = min($mint,-$pdf_pt['y']);
|
||
... | ... | |
}
|
||
break;
|
||
case 's': // bezier with first vertex equal first control
|
||
// mPDF 4.4.003
|
||
if (!($this->lastcommand == 'C' || $this->lastcommand == 'c' || $this->lastcommand == 'S' || $this->lastcommand == 's')) {
|
||
$this->lastcontrolpoints = array(0,0);
|
||
}
|
||
... | ... | |
$this->xbase = $x;
|
||
$this->ybase = -$y;
|
||
}
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // mPDF 4.4.003 always relative
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // always relative
|
||
|
||
$pdf_pt = $this->svg_overflow($pdfx,$pdfy);
|
||
|
||
// mPDF 5.0.040
|
||
$curves = array($pdfx1,-$pdfy1,$pdfx2,-$pdfy2,$pdfx,-$pdfy);
|
||
$bx = calc_bezier_bbox($start, $curves);
|
||
$minl = min($minl,$bx[0]);
|
||
... | ... | |
$this->xbase = $x;
|
||
$this->ybase = -$y;
|
||
}
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // mPDF 4.4.003 always relative
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // always relative
|
||
// $pdf_pt2 = $this->svg_overflow($pdfx2,$pdfy2);
|
||
// $pdf_pt1 = $this->svg_overflow($pdfx1,$pdfy1);
|
||
$pdf_pt = $this->svg_overflow($pdfx,$pdfy);
|
||
|
||
// mPDF 5.0.040
|
||
$curves = array($pdfx1,-$pdfy1,$pdfx2,-$pdfy2,$pdfx,-$pdfy);
|
||
$bx = calc_bezier_bbox($start, $curves);
|
||
$minl = min($minl,$bx[0]);
|
||
... | ... | |
|
||
$pdfx1 = ($this->xbase + ($x1*2/3));
|
||
$pdfy1 = ($this->ybase - ($y1*2/3));
|
||
// mPDF 4.4.003
|
||
$pdfx2 = $pdfx1 + 1/3 *($x);
|
||
$pdfy2 = $pdfy1 + 1/3 *(-$y) ;
|
||
|
||
... | ... | |
$pdfx2 = ($x+(($x1-$x)*2/3));
|
||
$pdfy2 = (-$y-(($y1-$y)*2/3));
|
||
|
||
// mPDF 4.4.003
|
||
$pdfx2 = $pdfx1 + 1/3 *($x - $this->xbase);
|
||
$pdfy2 = $pdfy1 + 1/3 *(-$y - $this->ybase) ;
|
||
|
||
$this->xbase = $x;
|
||
$this->ybase = -$y;
|
||
}
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // mPDF 4.4.003 always relative
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // always relative
|
||
|
||
$pdf_pt = $this->svg_overflow($pdfx,$pdfy);
|
||
|
||
// mPDF 5.0.040
|
||
$curves = array($pdfx1,-$pdfy1,$pdfx2,-$pdfy2,$pdfx,-$pdfy);
|
||
$bx = calc_bezier_bbox($start, $curves);
|
||
$minl = min($minl,$bx[0]);
|
||
... | ... | |
}
|
||
break;
|
||
case 't': // bezier quadratic avec point de control simetrique a lancien point de control
|
||
// mPDF 4.4.003
|
||
if (!($this->lastcommand == 'Q' || $this->lastcommand == 'q' || $this->lastcommand == 'T' || $this->lastcommand == 't')) {
|
||
$this->lastcontrolpoints = array(0,0);
|
||
}
|
||
... | ... | |
$pdfx = ($this->xbase + $x);
|
||
$pdfy = ($this->ybase - $y);
|
||
|
||
$pdfx1 = ($this->xbase + ($x1)); // mPDF 4.4.003
|
||
$pdfy1 = ($this->ybase - ($y1)); // mPDF 4.4.003
|
||
// mPDF 4.4.003
|
||
$pdfx1 = ($this->xbase + ($x1));
|
||
$pdfy1 = ($this->ybase - ($y1));
|
||
$pdfx2 = $pdfx1 + 1/3 *($x);
|
||
$pdfy2 = $pdfy1 + 1/3 *(-$y) ;
|
||
|
||
... | ... | |
$pdfx = $x;
|
||
$pdfy = -$y;
|
||
|
||
$pdfx1 = ($this->xbase + ($x1)); // mPDF 4.4.003
|
||
$pdfy1 = ($this->ybase - ($y1)); // mPDF 4.4.003
|
||
// mPDF 4.4.003
|
||
$pdfx1 = ($this->xbase + ($x1));
|
||
$pdfy1 = ($this->ybase - ($y1));
|
||
$pdfx2 = $pdfx1 + 1/3 *($x - $this->xbase);
|
||
$pdfy2 = $pdfy1 + 1/3 *(-$y - $this->ybase) ;
|
||
|
||
... | ... | |
|
||
$this->lastcontrolpoints = array(($pdfx-$pdfx2),-($pdfy-$pdfy2)); // mPDF 4.4.003 always relative
|
||
|
||
// mPDF 5.0.040
|
||
$curves = array($pdfx1,-$pdfy1,$pdfx2,-$pdfy2,$pdfx,-$pdfy);
|
||
$bx = calc_bezier_bbox($start, $curves);
|
||
$minl = min($minl,$bx[0]);
|
||
... | ... | |
$this->xbase = $x2;
|
||
$this->ybase = -$y2;
|
||
}
|
||
// mPDF 5.0.039 // mPDF 5.0.040
|
||
list($pcmd, $bounds) = $this->Arcto($x1, $y1, $x2, $y2, $rx, $ry, $angle, $largeArcFlag, $sweepFlag);
|
||
$minl = min($minl,$x2,min($bounds[0]));
|
||
$maxr = max($maxr,$x2,max($bounds[0]));
|
||
... | ... | |
break;
|
||
case'z':
|
||
$path_cmd .= 'h ';
|
||
// mPDF 4.4.003
|
||
$this->subPathInit = true;
|
||
$newsubpath = true;
|
||
$this->xbase = $this->spxstart;
|
||
... | ... | |
break;
|
||
}
|
||
|
||
if (!$newsubpath) { $this->subPathInit = false; } // mPDF 4.4.003
|
||
if (!$newsubpath) { $this->subPathInit = false; }
|
||
$this->lastcommand = $command;
|
||
// mPDF 5.0.039
|
||
$this->pathBBox[0] = $minl;
|
||
$this->pathBBox[1] = $mint;
|
||
$this->pathBBox[2] = $maxr - $this->pathBBox[0];
|
||
... | ... | |
|
||
function Arcto($x1, $y1, $x2, $y2, $rx, $ry, $angle, $largeArcFlag, $sweepFlag) {
|
||
|
||
// mPDF 5.0.040
|
||
$bounds = array(0=>array($x1,$x2),1=>array($y1,$y2));
|
||
// 1. Treat out-of-range parameters as described in
|
||
// http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
|
||
... | ... | |
// If rX = 0 or rY = 0 then this arc is treated as a straight line
|
||
// segment (a "lineto") joining the endpoints.
|
||
if ($rx == 0.0 || $ry == 0.0) {
|
||
// return array(Lineto(x2, y2), $bounds); // mPD 5.0.040
|
||
// return array(Lineto(x2, y2), $bounds);
|
||
}
|
||
|
||
// If rX or rY have negative signs, these are dropped; the absolute
|
||
... | ... | |
$bounds[0][] = $c[4];
|
||
$bounds[1][] = $c[5];
|
||
}
|
||
return array($path, $bounds); // mPD 5.0.040
|
||
return array($path, $bounds);
|
||
}
|
||
|
||
|
||
... | ... | |
}
|
||
|
||
|
||
// mPDF 4.4.003
|
||
function ConvertSVGSizePixels($size=5,$maxsize='x'){
|
||
// maxsize in pixels (user units) or 'y' or 'x'
|
||
// e.g. $w = $this->ConvertSVGSizePixels($arguments['w'],$this->svg_info['w']*(25.4/$this->mpdf_ref->dpi));
|
||
... | ... | |
return $size;
|
||
}
|
||
|
||
// mPDF 4.4.003
|
||
function ConvertSVGSizePts($size=5){
|
||
// usefontsize - setfalse for e.g. margins - will ignore fontsize for % values
|
||
// Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
|
||
... | ... | |
// fonction retracant les <rect />
|
||
function svgRect($arguments){
|
||
|
||
if ($arguments['h']==0 || $arguments['w']==0) { return ''; } // mPDF 4.4.003
|
||
if ($arguments['h']==0 || $arguments['w']==0) { return ''; }
|
||
|
||
$x = $this->ConvertSVGSizePixels($arguments['x'],'x'); // mPDF 4.4.003
|
||
$y = $this->ConvertSVGSizePixels($arguments['y'],'y'); // mPDF 4.4.003
|
||
$h = $this->ConvertSVGSizePixels($arguments['h'],'y'); // mPDF 4.4.003
|
||
$w = $this->ConvertSVGSizePixels($arguments['w'],'x'); // mPDF 4.4.003
|
||
$rx = $this->ConvertSVGSizePixels($arguments['rx'],'x'); // mPDF 4.4.003
|
||
$ry = $this->ConvertSVGSizePixels($arguments['ry'],'y'); // mPDF 4.4.003
|
||
$x = $this->ConvertSVGSizePixels($arguments['x'],'x');
|
||
$y = $this->ConvertSVGSizePixels($arguments['y'],'y');
|
||
$h = $this->ConvertSVGSizePixels($arguments['h'],'y');
|
||
$w = $this->ConvertSVGSizePixels($arguments['w'],'x');
|
||
$rx = $this->ConvertSVGSizePixels($arguments['rx'],'x');
|
||
$ry = $this->ConvertSVGSizePixels($arguments['ry'],'y');
|
||
|
||
if ($rx > $w/2) { $rx = $w/2; } // mPDF 4.4.003
|
||
if ($ry > $h/2) { $ry = $h/2; } // mPDF 4.4.003
|
||
if ($rx > $w/2) { $rx = $w/2; }
|
||
if ($ry > $h/2) { $ry = $h/2; }
|
||
|
||
if ($rx>0 and $ry == 0){$ry = $rx;}
|
||
if ($ry>0 and $rx == 0){$rx = $ry;}
|
||
... | ... | |
// le cercle est trac? grave a 4 bezier cubic, les poitn de controles
|
||
// sont deduis grace a la constante kappa * rayon
|
||
function svgEllipse($arguments){
|
||
if ($arguments['rx']==0 || $arguments['ry']==0) { return ''; } // mPDF 4.4.003
|
||
if ($arguments['rx']==0 || $arguments['ry']==0) { return ''; }
|
||
|
||
$kappa = 4*(sqrt(2)-1)/3;
|
||
|
||
... | ... | |
$ybase = - $arguments[1] ;
|
||
}
|
||
else {
|
||
if ($arguments[0]==$arguments[2] && $arguments[1]==$arguments[3]) { return ''; } // mPDF 4.4.003 Zero length line
|
||
$xbase = $this->ConvertSVGSizePixels($arguments[0],'x'); // mPDF 4.4.003
|
||
$ybase = - $this->ConvertSVGSizePixels($arguments[1],'y'); // mPDF 4.4.003
|
||
if ($arguments[0]==$arguments[2] && $arguments[1]==$arguments[3]) { return ''; } // Zero length line
|
||
$xbase = $this->ConvertSVGSizePixels($arguments[0],'x');
|
||
$ybase = - $this->ConvertSVGSizePixels($arguments[1],'y');
|
||
}
|
||
$path_cmd = sprintf('%.3F %.3F m ', $xbase*$this->kp, $ybase*$this->kp);
|
||
for ($i = 2; $i<count($arguments);$i += 2) {
|
||
... | ... | |
$tmp_y = - $arguments[($i+1)] ;
|
||
}
|
||
else {
|
||
$tmp_x = $this->ConvertSVGSizePixels($arguments[$i],'x') ; // mPDF 4.4.003
|
||
$tmp_y = - $this->ConvertSVGSizePixels($arguments[($i+1)],'y') ; // mPDF 4.4.003
|
||
$tmp_x = $this->ConvertSVGSizePixels($arguments[$i],'x') ;
|
||
$tmp_y = - $this->ConvertSVGSizePixels($arguments[($i+1)],'y') ;
|
||
}
|
||
$path_cmd .= sprintf('%.3F %.3F l ', $tmp_x*$this->kp, $tmp_y*$this->kp);
|
||
}
|
||
|
||
// $path_cmd .= 'h '; // ?? In error - don't close subpath here
|
||
return $path_cmd;
|
||
|
||
}
|
||
|
||
//
|
||
// fonction retracant les <polygone />
|
||
function svgPolygon($arguments){
|
||
$xbase = $arguments[0] ;
|
||
... | ... | |
|
||
}
|
||
|
||
//
|
||
// write string to image
|
||
function svgText() {
|
||
// $tmp = count($this->txt_style)-1;
|
||
$current_style = array_pop($this->txt_style);
|
||
$current_style = $this->txt_style[count($this->txt_style)-1]; // mPDF 5.7.4
|
||
$style = '';
|
||
$render = -1;
|
||
if(isset($this->txt_data[2]))
|
||
... | ... | |
// select font
|
||
$style .= ($current_style['font-weight'] == 'bold')?'B':'';
|
||
$style .= ($current_style['font-style'] == 'italic')?'I':'';
|
||
$size = $current_style['font-size']*$this->kf; // mPDF 5.0.039
|
||
$size = $current_style['font-size']*$this->kf;
|
||
|
||
// mPDF 5.0
|
||
$current_style['font-family'] = $this->mpdf_ref->SetFont($current_style['font-family'],$style,$size,false);
|
||
$this->mpdf_ref->CurrentFont['fo'] = true; // mPDF 5.0.039
|
||
$this->mpdf_ref->CurrentFont['fo'] = true;
|
||
|
||
|
||
// mPDF 5.0.041
|
||
$opacitystr = '';
|
||
$opacity = 1;
|
||
if (isset($current_style['fill-opacity'])) {
|
||
... | ... | |
$this->mpdf_ref->extgstates[$gs]['fo'] = true; // mPDF 5.0.039
|
||
$opacitystr = sprintf(' /GS%d gs ', $gs);
|
||
|
||
// mPDF 5.0.051
|
||
$fillstr = '';
|
||
if (isset($current_style['fill']) && $current_style['fill']!='none') {
|
||
$col = $this->mpdf_ref->ConvertColor($current_style['fill']);
|
||
... | ... | |
if (isset($current_style['stroke-width']) && $current_style['stroke-width']>0 && $current_style['stroke']!='none') {
|
||
$scol = $this->mpdf_ref->ConvertColor($current_style['stroke']);
|
||
if ($scol) {
|
||
$strokestr .= $this->mpdf_ref->SetDColor($scol, true).' '; // mPDF 5.0.051
|
||
$strokestr .= $this->mpdf_ref->SetDColor($scol, true).' ';
|
||
}
|
||
$linewidth = $this->ConvertSVGSizePixels($current_style['stroke-width']);
|
||
if ($linewidth > 0) {
|
||
... | ... | |
}
|
||
if ($render == -1) { return ''; }
|
||
|
||
$x = $this->ConvertSVGSizePixels($this->txt_data[0],'x'); // mPDF 4.4.003
|
||
$y = $this->ConvertSVGSizePixels($this->txt_data[1],'y'); // mPDF 4.4.003
|
||
$x = $this->txt_data[0]; // mPDF 5.7.4
|
||
$y = $this->txt_data[1]; // mPDF 5.7.4
|
||
$txt = $this->txt_data[2];
|
||
|
||
// mPDF 4.4.003
|
||
$txt = preg_replace('/\f/','',$txt);
|
||
$txt = preg_replace('/\r/','',$txt);
|
||
$txt = preg_replace('/\n/',' ',$txt);
|
||
$txt = preg_replace('/\t/',' ',$txt);
|
||
$txt = preg_replace("/[ ]+/u",' ',$txt);
|
||
|
||
$txt = trim($txt);
|
||
if ($this->textjuststarted) { $txt = ltrim($txt); } // mPDF 5.7.4
|
||
$this->textjuststarted = false; // mPDF 5.7.4
|
||
|
||
$txt = $this->mpdf_ref->purify_utf8_text($txt);
|
||
if ($this->mpdf_ref->text_input_as_HTML) {
|
||
$txt = $this->mpdf_ref->all_entities_to_utf8($txt);
|
||
}
|
||
|
||
// mPDF 5.0
|
||
if ($this->mpdf_ref->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mpdf_ref->mb_enc,'UTF-8'); }
|
||
if (preg_match("/([".$this->mpdf_ref->pregRTLchars."])/u", $txt)) { $this->mpdf_ref->biDirectional = true; } // mPDF 4.4.003
|
||
if (preg_match("/([".$this->mpdf_ref->pregRTLchars."])/u", $txt)) { $this->mpdf_ref->biDirectional = true; }
|
||
|
||
$this->mpdf_ref->magic_reverse_dir($txt, true, 'ltr'); // mPDF 5.0.054
|
||
$this->mpdf_ref->magic_reverse_dir($txt, true, 'ltr');
|
||
$this->mpdf_ref->ConvertIndic($txt);
|
||
|
||
|
||
if ($current_style['text-anchor']=='middle') {
|
||
$tw = $this->mpdf_ref->GetStringWidth($txt)*_MPDFK/2; // mPDF 4.4.003 // mPDF 5.4.09
|
||
}
|
||
else if ($current_style['text-anchor']=='end') {
|
||
$tw = $this->mpdf_ref->GetStringWidth($txt)*_MPDFK; // mPDF 4.4.003 // mPDF 5.4.09
|
||
}
|
||
else $tw = 0;
|
||
// mPDF 5.7.4
|
||
$this->textlength = $this->mpdf_ref->GetStringWidth($txt) * 1/(25.4/$this->mpdf_ref->dpi);
|
||
$this->texttotallength += $this->textlength;
|
||
|
||
if (!$this->mpdf_ref->usingCoreFont) {
|
||
$this->mpdf_ref->UTF8StringToArray($txt); // mPDF 5.0 adds chars to subset list
|
||
$this->mpdf_ref->UTF8StringToArray($txt);
|
||
$txt= $this->mpdf_ref->UTF8ToUTF16BE($txt, false);
|
||
}
|
||
$txt='('.$this->mpdf_ref->_escape($txt).')';
|
||
$this->mpdf_ref->CurrentFont['used']= true;
|
||
|
||
$pdfx = $x - $tw/$this->kp; // mPDF 4.4.009
|
||
$pdfy = -$y ;
|
||
$xbase = $x;
|
||
$ybase = -$y;
|
||
|
||
// mPDF 5.0.041
|
||
// mPDF 5.0.051
|
||
$path_cmd = sprintf('q BT /F%d %s %.3F Tf %.3F %.3F Td %s Tr %s %s %s Tj ET Q ',$this->mpdf_ref->CurrentFont['i'],$opacitystr, $this->mpdf_ref->FontSizePt,$pdfx*$this->kp,$pdfy*$this->kp,$render,$fillstr,$strokestr,$txt)."\n";
|
||
// mPDF 5.7.2 // mPDF 5.7.4
|
||
$path_cmd = sprintf('q BT /F%d %.3F Tf %s mPDF-AXS(%.3F) %.3F Td %s Tr %s %s %s Tj ET Q ',$this->mpdf_ref->CurrentFont['i'], $this->mpdf_ref->FontSizePt, $opacitystr, $x*$this->kp,-$y*$this->kp,$render,$fillstr,$strokestr,$txt)."\n";
|
||
unset($this->txt_data[0], $this->txt_data[1],$this->txt_data[2]);
|
||
|
||
// mPDF 5.4.12
|
||
if (isset($current_style['font-size-parent'])) {
|
||
$this->mpdf_ref->SetFontSize($current_style['font-size-parent']);
|
||
}
|
||
... | ... | |
{
|
||
return ' ';
|
||
}
|
||
// $path_cmd .= 'h '; // mPDF 5.0
|
||
// Reset font // mPDF 5.7.4
|
||
$prev_style = $this->txt_style[count($this->txt_style)-1];
|
||
$style = '';
|
||
$style .= ($prev_style['font-weight'] == 'bold')?'B':'';
|
||
$style .= ($prev_style['font-style'] == 'italic')?'I':'';
|
||
$size = $prev_style['font-size']*$this->kf;
|
||
$this->mpdf_ref->SetFont($prev_style['font-family'],$style,$size,false);
|
||
|
||
return $path_cmd;
|
||
}
|
||
|
||
... | ... | |
$current_style['fill'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
|
||
}
|
||
else { $tmp = preg_replace("/(.*)fill:\s*([a-z0-9#_()]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['fill'] = $tmp; }
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['fill'] = $tmp; }
|
||
}
|
||
|
||
$tmp = preg_replace("/(.*)fill-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['fill-opacity'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['fill-opacity'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)fill-rule:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['fill-rule'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['fill-rule'] = $tmp;}
|
||
|
||
if (preg_match('/stroke:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/',$critere_style['style'], $m)) {
|
||
$current_style['stroke'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
|
||
}
|
||
else { $tmp = preg_replace("/(.*)stroke:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke'] = $tmp; }
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke'] = $tmp; }
|
||
}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-linecap:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-linecap'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-linecap'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-linejoin:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-linejoin'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-linejoin'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-miterlimit:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-miterlimit'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-miterlimit'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-opacity'] = $tmp; }
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-opacity'] = $tmp; }
|
||
|
||
$tmp = preg_replace("/(.*)stroke-width:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-width'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-width'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-dasharray:\s*([a-z0-9., ]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-dasharray'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-dasharray'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)stroke-dashoffset:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $current_style['stroke-dashoffset'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-dashoffset'] = $tmp;}
|
||
|
||
// mPDF 5.0.039
|
||
$tmp = preg_replace("/(.*)font-family:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $critere_style['font-family'] = $tmp;}
|
||
// mPDF 5.7.2
|
||
$tmp = preg_replace("/(.*)font-family:\s*([a-z0-9.\"' ,\-]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $critere_style['font-family'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)font-size:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $critere_style['font-size'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $critere_style['font-size'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)font-weight:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $critere_style['font-weight'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $critere_style['font-weight'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)font-style:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp != $critere_style['style']){ $critere_style['font-style'] = $tmp;}
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $critere_style['font-style'] = $tmp;}
|
||
|
||
$tmp = preg_replace("/(.*)text-anchor:\s*(start|middle|end)(.*)/i","$2",$critere_style['style']);
|
||
if ($tmp && $tmp != 'inherit' && $tmp!=$critere_style['style']){ $critere_style['text-anchor'] = $tmp;}
|
||
|
||
}
|
||
|
||
... | ... | |
|
||
}
|
||
|
||
if(isset($critere_style['fill'])){
|
||
if(isset($critere_style['fill']) && $critere_style['fill']!='inherit'){
|
||
$current_style['fill'] = $critere_style['fill'];
|
||
}
|
||
if(isset($critere_style['stroke'])){
|
||
if(isset($critere_style['stroke']) && $critere_style['stroke']!='inherit'){
|
||
$current_style['stroke'] = $critere_style['stroke'];
|
||
}
|
||
if(isset($critere_style['stroke-width'])){
|
||
if(isset($critere_style['stroke-width']) && $critere_style['stroke-width']!='inherit'){
|
||
$current_style['stroke-width'] = $critere_style['stroke-width'];
|
||
}
|
||
|
||
if(isset($critere_style['font-style'])){
|
||
if(isset($critere_style['font-style']) && $critere_style['font-style']!='inherit'){
|
||
if(strtolower($critere_style['font-style']) == 'oblique')
|
||
{
|
||
$critere_style['font-style'] = 'italic';
|
||
... | ... | |
$current_style['font-style'] = $critere_style['font-style'];
|
||
}
|
||
|
||
if(isset($critere_style['font-weight'])){
|
||
if(isset($critere_style['font-weight']) && $critere_style['font-weight']!='inherit'){
|
||
if(strtolower($critere_style['font-weight']) == 'bolder')
|
||
{
|
||
$critere_style['font-weight'] = 'bold';
|
||
... | ... | |
$current_style['font-weight'] = $critere_style['font-weight'];
|
||
}
|
||
|
||
if(isset($critere_style['font-size'])){
|
||
// mPDF 5.4.12
|
||
if(isset($critere_style['font-size']) && $critere_style['font-size']!='inherit'){
|
||
if (strpos($critere_style['font-size'], '%')!==false) {
|
||
$current_style['font-size-parent'] = $current_style['font-size'];
|
||
}
|
||
... | ... | |
$this->mpdf_ref->SetFont('','',$current_style['font-size'],false);
|
||
}
|
||
|
||
if(isset($critere_style['font-family'])){
|
||
if(isset($critere_style['font-family']) && $critere_style['font-family']!='inherit'){
|
||
$v = $critere_style['font-family'];
|
||
$aux_fontlist = explode(",",$v);
|
||
$found = 0;
|
||
... | ... | |
}
|
||
}
|
||
|
||
if(isset($critere_style['text-anchor'])){
|
||
if(isset($critere_style['text-anchor']) && $critere_style['text-anchor']!='inherit'){
|
||
$current_style['text-anchor'] = $critere_style['text-anchor'];
|
||
}
|
||
|
||
... | ... | |
|
||
|
||
|
||
//
|
||
// fonction ajoutant un gradient
|
||
function svgAddGradient($id,$array_gradient){
|
||
|
||
$this->svg_gradient[$id] = $array_gradient;
|
||
|
||
}
|
||
//
|
||
// Ajoute une couleur dans le gradient correspondant
|
||
|
||
//
|
||
// function ecrivant dans le svgstring
|
||
function svgWriteString($content){
|
||
|
||
function svgWriteString($content){
|
||
$this->svg_string .= $content;
|
||
|
||
}
|
||
|
||
|
||
|
||
// analise le svg et renvoie aux fonctions precedente our le traitement
|
||
function ImageSVG($data){
|
||
$data = preg_replace('/^.*?<svg([> ])/is', '<svg\\1', $data); // mPDF 5.7.4
|
||
|
||
$data = preg_replace('/<!--.*?-->/is', '', $data); // mPDF 5.7.4
|
||
|
||
// Converts < to < when not a tag
|
||
$data = preg_replace('/<([^!?\/a-zA-Z_:])/i','<\\1',$data ); // mPDF 5.7.4
|
||
|
||
if (_SVG_AUTOFONT) { $data = $this->AutoFont($data); }
|
||
$this->svg_info = array();
|
||
|
||
// mPDF 4.4.006
|
||
if (preg_match('/<!ENTITY/si',$data)) {
|
||
// Get User-defined entities
|
||
preg_match_all('/<!ENTITY\s+([a-z]+)\s+\"(.*?)\">/si',$data, $ent);
|
||
... | ... | |
}
|
||
|
||
|
||
// mPDF 4.4.003
|
||
if (preg_match('/xlink:href=/si',$data)) {
|
||
if (preg_match('/xlink:href\s*=/si',$data)) {
|
||
// GRADIENTS
|
||
// Get links
|
||
preg_match_all('/(<(linearGradient|radialgradient)[^>]*)xlink:href=["\']#(.*?)["\'](.*?)\/>/si',$data, $links);
|
||
if (count($links[0])) { $links[5] = array(); } // mPDF 4.5.010
|
||
preg_match_all('/(<(linearGradient|radialgradient)[^>]*)xlink:href\s*=\s*["\']#(.*?)["\'](.*?)\/>/si',$data, $links);
|
||
if (count($links[0])) { $links[5] = array(); }
|
||
// Delete links from data - keeping in $links
|
||
for ($i=0; $i<count($links[0]); $i++) {
|
||
$links[5][$i] = 'tmpLink'.RAND(100000,9999999); // mPDF 4.5.010
|
||
$data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', '<MYLINKS'.$links[5][$i].'>' , $data); // mPDF 4.5.010
|
||
$links[5][$i] = 'tmpLink'.RAND(100000,9999999);
|
||
$data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', '<MYLINKS'.$links[5][$i].'>' , $data);
|
||
}
|
||
// Get targets
|
||
preg_match_all('/<(linearGradient|radialgradient)([^>]*)id=["\'](.*?)["\'](.*?)>(.*?)<\/(linearGradient|radialgradient)>/si',$data, $m);
|
||
preg_match_all('/<(linearGradient|radialgradient)([^>]*)id\s*=\s*["\'](.*?)["\'](.*?)>(.*?)<\/(linearGradient|radialgradient)>/si',$data, $m);
|
||
$targets = array();
|
||
$stops = array();
|
||
// keeping in $targets
|
||
... | ... | |
}
|
||
// Add back links this time as targets (gradients)
|
||
for ($i=0; $i<count($links[0]); $i++) {
|
||
$def = $links[1][$i] .' '.$links[4][$i].'>'. $stops[$links[3][$i]].'</'.$links[2][$i] .'>' ; // mPDF 4.5.010
|
||
$data = preg_replace('/<MYLINKS'.$links[5][$i].'>/is', $def , $data); // mPDF 4.5.010
|
||
$def = $links[1][$i] .' '.$links[4][$i].'>'. $stops[$links[3][$i]].'</'.$links[2][$i] .'>' ;
|
||
$data = preg_replace('/<MYLINKS'.$links[5][$i].'>/is', $def , $data);
|
||
}
|
||
|
||
|
||
// mPDF 5.7.4
|
||
// <TREF>
|
||
preg_match_all('/<tref ([^>]*)xlink:href\s*=\s*["\']#([^>]*?)["\']([^>]*)\/>/si',$data, $links);
|
||
for ($i=0; $i<count($links[0]); $i++) {
|
||
|
||
// Get the item to use from defs
|
||
$insert = '';
|
||
if (preg_match('/<text [^>]*id\s*=\s*["\']'.$links[2][$i].'["\'][^>]*>(.*?)<\/text>/si',$data, $m)) {
|
||
$insert = $m[1];
|
||
}
|
||
if ($insert) {
|
||
$data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', $insert, $data);
|
||
}
|
||
}
|
||
|
||
// mPDF 5.7.2
|
||
// <USE>
|
||
preg_match_all('/<use ([^>]*)xlink:href\s*=\s*["\']#([^>]*?)["\']([^>]*)\/>/si',$data, $links);
|
||
for ($i=0; $i<count($links[0]); $i++) {
|
||
|
||
// Get the item to use from defs
|
||
$insert = '';
|
||
if (preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']'.$links[2][$i].'["\'][^>]*\/>/si',$data, $m)) {
|
||
$insert = $m[0];
|
||
}
|
||
if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']'.$links[2][$i].'["\']/si',$data, $m)) {
|
||
|
||
if (preg_match('/<'.$m[1].'[^>]*id\s*=\s*["\']'.$links[2][$i].'["\'][^>]*>.*?<\/'.$m[1].'>/si',$data, $m)) {
|
||
$insert = $m[0];
|
||
}
|
||
}
|
||
|
||
if ($insert) {
|
||
|
||
$inners = $links[1][$i] . ' ' . $links[3][$i];
|
||
// Change x,y coords to translate()
|
||
if (preg_match('/y\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) { $y = $m[1]; }
|
||
else { $y = 0; }
|
||
if (preg_match('/x\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) { $x = $m[1]; }
|
||
else { $x = 0; }
|
||
if ($x || $y) {
|
||
$inners = preg_replace('/(y|x)\s*=\s*["\']([^>]*?)["\']/', '', $inners);
|
||
if (preg_match('/transform\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
|
||
if (preg_match('/translate\(\s*([0-9\.]+)\s*,\s*([0-9\.]+)\s*\)/', $m[1], $mm)) {
|
||
$transform = $m[1]; // transform="...."
|
||
$x += $mm[1];
|
||
$y += $mm[2];
|
||
$transform = preg_replace('/'.preg_quote($mm[0],'/').'/', '', $transform);
|
||
$transform = 'transform="'.$transform.' translate('.$x.', '.$y.')"';
|
||
$inners = preg_replace('/'.preg_quote($m[0],'/').'/is', $transform, $inners);
|
||
}
|
||
else {
|
||
$inners = preg_replace('/'.preg_quote($m[0],'/').'/is', 'transform="'.$m[1].' translate('.$x.', '.$y.')"', $inners);
|
||
}
|
||
}
|
||
else {
|
||
$inners .= ' transform="translate('.$x.', '.$y.')"';
|
||
}
|
||
}
|
||
}
|
||
$replacement = '<g '.$inners.'>'.$insert.'</g>';
|
||
$data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', $replacement, $data);
|
||
}
|
||
preg_match_all('/<use ([^>]*)xlink:href\s*=\s*["\']#([^>]*?)["\']([^>]*)>\s*<\/use>/si',$data, $links);
|
||
for ($i=0; $i<count($links[0]); $i++) {
|
||
|
||
// Get the item to use from defs
|
||
$insert = '';
|
||
if (preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']'.$links[2][$i].'["\'][^>]*\/>/si',$data, $m)) {
|
||
$insert = $m[0];
|
||
}
|
||
if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']'.$links[2][$i].'["\']/si',$data, $m)) {
|
||
|
||
if (preg_match('/<'.$m[1].'[^>]*id\s*=\s*["\']'.$links[2][$i].'["\'][^>]*>.*?<\/'.$m[1].'>/si',$data, $m)) {
|
||
$insert = $m[0];
|
||
}
|
||
}
|
||
|
||
if ($insert) {
|
||
|
||
$inners = $links[1][$i] . ' ' . $links[3][$i];
|
||
// Change x,y coords to translate()
|
||
if (preg_match('/y\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) { $y = $m[1]; }
|
||
else { $y = 0; }
|
||
if (preg_match('/x\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) { $x = $m[1]; }
|
||
else { $x = 0; }
|
||
if ($x || $y) {
|
||
$inners = preg_replace('/(y|x)\s*=\s*["\']([^>]*?)["\']/', '', $inners);
|
||
if (preg_match('/transform\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
|
||
if (preg_match('/translate\(\s*([0-9\.]+)\s*,\s*([0-9\.]+)\s*\)/', $m[1], $mm)) {
|
||
$transform = $m[1]; // transform="...."
|
||
$x += $mm[1];
|
||
$y += $mm[2];
|
||
$transform = preg_replace('/'.preg_quote($mm[0],'/').'/', '', $transform);
|
||
$transform = 'transform="'.$transform.' translate('.$x.', '.$y.')"';
|
||
$inners = preg_replace('/'.preg_quote($m[0],'/').'/is', $transform, $inners);
|
||
}
|
||
else {
|
||
$inners = preg_replace('/'.preg_quote($m[0],'/').'/is', 'transform="'.$m[1].' translate('.$x.', '.$y.')"', $inners);
|
||
}
|
||
}
|
||
else {
|
||
$inners .= ' transform="translate('.$x.', '.$y.')"';
|
||
}
|
||
}
|
||
$replacement = '<g '.$inners.'>'.$insert.'</g>';
|
||
$data = preg_replace('/'.preg_quote($links[0][$i],'/').'/is', $replacement, $data);
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
// mPDF 4.4.003 - Removes <pattern>
|
||
// Removes <pattern>
|
||
$data = preg_replace('/<pattern.*?<\/pattern>/is', '', $data);
|
||
// mPDF 4.4.003 - Removes <marker>
|
||
// Removes <marker>
|
||
$data = preg_replace('/<marker.*?<\/marker>/is', '', $data);
|
||
|
||
$this->svg_info['data'] = $data;
|
||
|
||
$this->svg_string = '';
|
||
|
||
//
|
||
// chargement unique des fonctions
|
||
if(!function_exists("xml_svg2pdf_start")){ // mPDF 5.3.76
|
||
if(!function_exists("xml_svg2pdf_start")){
|
||
|
||
function xml_svg2pdf_start($parser, $name, $attribs){
|
||
//
|
||
// definition
|
||
global $svg_class, $last_gradid;
|
||
|
||
// mPDF 4.4.003
|
||
// mPDF 5.7.2
|
||
if (strtolower($name) == 'lineargradient'){
|
||
$tmp_gradient = array(
|
||
'type' => 'linear',
|
||
'info' => array(
|
||
'x1' => $attribs['x1'],
|
||
'y1' => $attribs['y1'],
|
||
'x2' => $attribs['x2'],
|
||
'y2' => $attribs['y2']
|
||
),
|
||
'transform' => $attribs['gradientTransform'],
|
||
'units' => $attribs['gradientUnits'],
|
||
'spread' => $attribs['spreadMethod'],
|
||
'color' => array()
|
||
);
|
||
$last_gradid = $attribs['id'];
|
||
$svg_class->svgAddGradient($attribs['id'],$tmp_gradient);
|
||
return;
|
||
}
|
||
else if (strtolower($name) == 'radialgradient'){
|
||
$tmp_gradient = array(
|
||
'type' => 'radial',
|
||
'info' => array(
|
||
'x0' => $attribs['cx'],
|
||
'y0' => $attribs['cy'],
|
||
'x1' => $attribs['fx'],
|
||
'y1' => $attribs['fy'],
|
||
'r' => $attribs['r']
|
||
),
|
||
'transform' => $attribs['gradientTransform'],
|
||
'units' => $attribs['gradientUnits'],
|
||
'spread' => $attribs['spreadMethod'],
|
||
'color' => array()
|
||
);
|
||
$last_gradid = $attribs['id'];
|
||
$svg_class->svgAddGradient($attribs['id'],$tmp_gradient);
|
||
return;
|
||
}
|
||
else if (strtolower($name) == 'stop'){
|
||
if (!$last_gradid) break;
|
||
if (isset($attribs['style']) AND preg_match('/stop-color:\s*([^;]*)/i',$attribs['style'],$m)) {
|
Také k dispozici: Unified diff
Release 1.1.8