/**
* @var string
*/
- protected $dest;
+ protected $out;
/**
* @param $document Document
* @param $page integer
- * @param $dest string
+ * @param $out string
*/
- public function __construct($document, $page, $dest)
+ public function __construct($document, $page, $out, $files = [])
{
$this->document = $document;
$this->page = $page;
- $this->dest = $dest;
+ $this->out = $out;
+ $this->files = $files;
}
public function handle()
{
-
+ foreach ($this->files as $file) {
+ $this->getFile($this->page, $file['format'], $file['resolution'], $file['withText'], $file['withGraphics'], 'html', false);
+ }
}
/**
* @param $dest string
*/
- public function processPages($dest)
+ public function processPages($dest, $files)
{
for ($i = 1; $i <= $this->getPages(); $i++) {
- $this->processPage($i, $dest);
+ $this->processPage($i, $dest, $files);
}
}
* @param $i
* @param $dest
*/
- public function processPage($page, $dest)
+ public function processPage($page, $dest, $files)
{
- dispatch(new ProcessPage($this, $page, $dest));
+ dispatch(new ProcessPage($this, $page, $dest, $files));
}
}
class SVGTools
{
+ protected static $_r;
+ protected static $_i;
+ protected static $_e;
+ protected static $_u;
+
public static function optimizeSVG($in, $out = null)
{
if (null === $out) {
file_put_contents($out, $osvg);
}
+ protected static function _svg($c, $p)
+ {
+ self::$_i = 0;
+ self::$_e = 0;
+ self::$_u = 0;
+
+ $c = str_replace('id="', 'id="p' . $p . '-', $c);
+ $c = str_replace('url(#', 'url(#p' . $p . '-', $c);
+ $c = str_replace('xlink:href="#', 'xlink:href="#p' . $p . '-', $c);
+ $c = preg_replace_callback('/\<image([^\>]*)\>/m', function ($matches) use ($p) {
+ self::$_i++;
+ return '<g id="p' . $p . '-imageholder-' . self::$_i . '"><image id="p' . $p . '-image-' . self::$_i . '" ' . $matches[1] . '></g>';
+ }, $c);
+ $c = str_replace('</image>', '</image></g></g>', $c);
+
+ $c = preg_replace_callback('/<path /', function () use ($p) {
+ self::$_e++;
+ return '<path id="p' . $p . '-e-' . self::$_e . '" ';
+ }, $c);
+ $c = preg_replace_callback('/<use /', function () use ($p) {
+ self::$_u++;
+ return '<use id="p' . $p . '-u-' . self::$_u . '" ';
+ }, $c);
+
+ return $c;
+ }
+
public static function optimizeRaster($matches, $resolution)
{
preg_match_all('/([a-z\:\-]*)="([^"]*)"/', $matches[1], $m);