Skip to content

Commit 1ec96d6

Browse files
authored
Merge pull request #68 from wpj-cz/master
SVG: Add viewBox attribute to allow svg scaling
2 parents f754cbd + 483d996 commit 1ec96d6

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/BarcodeGeneratorSVG.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $c
2323
// replace table for special characters
2424
$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
2525

26+
$width = round(($barcodeData['maxWidth'] * $widthFactor), 3);
27+
2628
$svg = '<?xml version="1.0" standalone="no" ?>' . "\n";
2729
$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . "\n";
28-
$svg .= '<svg width="' . round(($barcodeData['maxWidth'] * $widthFactor),
29-
3) . '" height="' . $totalHeight . '" version="1.1" xmlns="http://www.w3.org/2000/svg">' . "\n";
30+
$svg .= '<svg width="' . $width . '" height="' . $totalHeight . '" viewBox="0 0 ' . $width . ' ' . $totalHeight . '" version="1.1" xmlns="http://www.w3.org/2000/svg">' . "\n";
3031
$svg .= "\t" . '<desc>' . strtr($barcodeData['code'], $repstr) . '</desc>' . "\n";
3132
$svg .= "\t" . '<g id="bars" fill="' . $color . '" stroke="none">' . "\n";
3233
// print bars
@@ -46,4 +47,4 @@ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $c
4647

4748
return $svg;
4849
}
49-
}
50+
}

tests/verified-files/0049000004632-ean13.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/verified-files/081231723897-ean13.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)