exit;
}
- public static function testSVG()
- {
- $test = '/home/extranet/www/fluidbook/docs/117077/html/zz%s.svg';
- echo wsTools::optimizeSVG('/home/extranet/www/fluidbook/docs/117077/html/fp11.svg', $test, [150, 300], true);
- }
-
- // public function addSearch() {
- // global $core;
- // $r = $core->con->select('SELECT book_id, parametres FROM books WHERE book_id');
- // $reset = [];
- // $error = [];
- // $skip = [];
- // while ($r->fetch()) {
- // /** @var wsBookParametres $parametres */
- // try {
- // $former =
- // $parametres = unserialize($r->parametres);
- // $order = explode(',', $parametres->navOrder);
- // $former = $parametres->navOrder;
- // $order = array_map('trim', $order);
- // if (in_array('search', $order)) {
- // $skip[] = $r->book_id;
- // continue;
- // }
- //
- // $searchLocation = 0;
- // $chaptersLocation = array_search('chapters', $order);
- // if ($chaptersLocation !== false) {
- // $searchLocation = $chaptersLocation + 1;
- // } else {
- // $indexLocation = array_search('index', $order);
- // if ($indexLocation !== false) {
- // $searchLocation = $indexLocation + 1;
- // }
- // }
- // array_splice($order, $searchLocation, 0, 'search');
- //
- // $newOrder = join(', ' , $order);
- //
- // $c = $core->con->openCursor('books');
- // $parametres->navOrder=$newOrder;
- // $c->parametres = serialize($parametres);
- // $c->changedate = TIME;
- // $c->update('WHERE book_id=' . $r->book_id);
- // $reset[] = $r->book_id . ' : ' . $former . ' -> ' . $newOrder;
- // } catch (Exception $e) {
- // $error[] = $r->book_id;
- // }
- // }
- //
- // echo 'reset : ' . implode('<br />', $reset) . '<br />';
- // echo 'skip : ' . implode(', ', $skip) . '<br />';
- // echo 'error : ' . implode(', ', $error) . '<br />';
- //
- // }
+ public static function testSVG($args)
+ {
+ global $core;
+
+ $book = $args[0];
+ $page = $args[1];
+
+ $dao = new wsDAOBook($core->con);
+ $pages = $dao->getPagesOfBook($book);
+ $p = $pages[$page];
+
+ $dir = wsDocument::getDir($p['document_id']);
+ $test = $dir . '/html/zz%s.svg';
+ wsTools::optimizeSVG($dir . '/html/fp' . $p['document_page'] . '.svg', $test, [150, 300], true);
+ }
public static function svgToFlash()
{
<?php
-class wsTools {
+class wsTools
+{
protected static $_r;
+ protected static $_i;
+ protected static $_e;
+ protected static $_u;
- public static function encodeWebVideos($file, $dir = null, $async = true, $force = false, $format = 'all') {
+ public static function encodeWebVideos($file, $dir = null, $async = true, $force = false, $format = 'all')
+ {
if (is_null($dir)) {
$dir = dirname($file);
}
$webvideo->execute();
}
- public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true) {
+ public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true)
+ {
// Init directory
if (is_string($colors)) {
$colors = array('colorize' => $colors);
}
}
- public static function optimizeSVG($original, $optimized, $resolutions = [], $force = false) {
+ public static function optimizeSVG($original, $optimized, $resolutions = [], $force = false)
+ {
if (!file_exists($original)) {
return 'doesnt exists';
foreach ($resolutions as $resolution) {
self::$_r = $resolution;
$osvg = preg_replace_callback('|\<image([^>]*)\>|', 'wsTools::optimizeRaster', $svg);
- file_put_contents(sprintf($optimized, '-' . $resolution), $osvg);
+ $ofname = sprintf($optimized, '-' . $resolution);
+ echo $ofname . "\n";
+ file_put_contents($ofname, $osvg);
}
}
return true;
return false;
}
- public static function optimizeRaster($matches) {
+ public static function optimizeRaster($matches)
+ {
+ preg_match_all('/([a-z\:\-]*)="([^"]*)"/', $matches[1], $m);
- return '<image />';
+ foreach ($m[1] as $i => $key) {
+ $attrs[$key] = $m[2][$i];
+ }
+ $e = explode(',', $attrs['xlink:href'], 2);
+ $image = imagecreatefromstring(base64_decode($e[1]));
+ $iw = imagesx($image);
+ $ih = imagesy($image);
+ $scale = 1;
+ if (isset($attrs['transform']) && strpos($attrs['transform'], 'matrix(') === 0) {
+ preg_match_all('/([\d\-\.]+)/', $attrs['transform'], $ma);
+ $values = $ma[0];
+ $scale = max($values[0], $values[1]);
+
+ }
+
+ $resolutionScale = ($iw / $attrs['width']) * $scale * (self::$_r / 72);
+ echo $resolutionScale . "\n";
+
+ $dw = round($resolutionScale * $iw);
+ $dh = round($resolutionScale * $ih);
+
+ $im = imagecreatetruecolor($dw, $dh);
+ imagecopyresampled($im, $image, 0, 0, 0, 0, $dw, $dh, $iw, $ih);
+ imagedestroy($image);
+
+ $tmp = CubeIT_Files::tempnam();
+ imagejpeg($im, $tmp, 85);
+ imagedestroy($im);
+
+ $attrs['xlink:href'] = 'data:image/jpeg;base64,' . base64_encode(file_get_contents($tmp));
+ unlink($tmp);
+
+ $res = '<image ';
+ foreach ($attrs as $k => $v) {
+ $res .= $k . '="' . $v . '" ';
+ }
+ $res .= '/>';
+ return $res;
}
- public static function copy($source, $dest) {
+ public static function copy($source, $dest)
+ {
if (!file_exists($source)) {
return;
}
touch($dest, filemtime($source));
}
- public function chiffres() {
+ public static function pages2html($book_id, $page)
+ {
+ global $core;
+ if ($page % 2 == 1) {
+ $page--;
+ }
+
+ $convert = [$page, $page + 1];
+
+ $dao = new wsDAOBook($core->con);
+ $pages = $dao->getPagesOfBook($book_id);
+ $svg = '';
+ $left = 0;
+ $css = '';
+ foreach ($convert as $item) {
+
+ if (isset($pages[$item])) {
+ $p = $pages[$item];
+ $dir = wsDocument::getDir($p['document_id']);
+ $f = $dir . '/html/fo' . $p['document_page'] . '-150.svg';
+
+ if (!isset($width)) {
+ $s = CubeIT_Image::getimagesize($f);
+ $width = $s[0];
+ $height = $s[1];
+ }
+
+ $svg .= '<div class="page" id="p' . $item . '">';
+ $svg .= self::_svg(file_get_contents($f), $item);
+ $svg .= '</div>';
+ $css .= '#p' . $item . '{left:' . $left . 'px;}';
+ $left += ($width - 1);
+ }
+ }
+
+ $res = '<html>';
+ $res .= '<head>';
+ $res .= '<meta name="width" value="' . $left . '">';
+ $res .= '<meta name="height" value="' . $height . '">';
+ $res .= '<!-- tweenmax --><script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js"></script><!-- -->';
+ $res .= '<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><!-- -->';
+ $res .= '<script src="main.js"></script>';
+ $res .= '<style type="text/css">*{padding:0;margin:0}svg{display: block;}.page{position: absolute;top: 0;}.page svg{width:' . $width . 'px;height:' . $height . 'px;}' . $css . '</style></head>';
+ $res .= '<link href="main.css" type="text/css" rel="stylesheet" />';
+ $res .= '<body>';
+ $res .= $svg;
+ $res .= '</body>';
+ $res .= '</html>';
+
+ $n = 'fb_' . $book_id . '_' . $page . '.zip';
+ $zipname = '/tmp/' . $n;
+ $zip = new ZipArchive();
+ $zip->open($zipname, ZipArchive::CREATE);
+ $zip->addFromString('index.html', $res);
+ $zip->close();
+ return ['name' => $n, 'path' => $zipname];
+ }
+
+ 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 function chiffres()
+ {
+
+ }
+
}