$docs = array();
$defaultNum = array();
foreach ($pages as $page => $info) {
+ $book->getFile($page, 'jpg', 150, true, true);
$file = WS_DOCS . '/' . $info['document_id'] . '/p' . $info['document_page'] . '.jpg';
if (!file_exists($file)) {
$info['resolution'] = 150;
$daoDoc = new wsDAODocument($core->con);
$nb_pages = count($pages);
$this->xml->addChild('pages', $nb_pages);
- $total_size = 0;
-
- foreach ($pages as $page => $info) {
- $docdir = wsDocument::getDir($info['document_id']);
- $file = $docdir . '/p' . $info['document_page'] . '.swf';
- $total_size += filesize($file);
- }
- $average_size = $total_size / $nb_pages;
- $total = self::formatSize($total_size);
- $average = self::formatSize($average_size);
$firstDoc = $daoDoc->selectById($pages[1]['document_id']);
$size = $firstDoc->generalInfos['size'];
$this->xml->addChild('width', $size[0]);
$res .= "\n";
$res .= '<b>' . __('Dimensions') . '</b> : ' . "\n";
$res .= round($size[0], 3) . ' x ' . round($size[1], 3) . ' pts' . "\n";
- $res .= "\n";
- $res .= '<b>' . __('Taille totale des pages') . '</b> : ' . "\n";
- $res .= $total . "\n";
- $res .= "\n";
- $res .= '<b>' . __('Taille moyenne des pages') . '</b> : ' . "\n";
- $res .= $average . "\n";
- $res .= "\n";
$this->xml->addChild('infos', $res);
}
global $core;
$dao = new wsDAOBook($core->con);
$dao->setComposition($this->args['book_id'], json_decode($this->args['pages']));
+ // Begin to generate files
+ $dao->compile($this->args['book_id']);
}
public function getTexts()
return;
}
- $v1 = $v2 = $html5 = false;
-
- if ($version == 'all') {
- $v1 = $v2 = $html5 = true;
- } else if ($version == '1') {
- $v1 = true;
- } else if ($version == '2') {
- $v2 = true;
- } elseif ($version == 'html5') {
- $html5 = true;
- }
-
if (null === $book) {
$book = $this->selectById($book_id);
}
$pages = $this->getPagesOfBook($book_id);
- if (!$force) {
- $v1 = $v1 && !$this->isUpToDate($book, 1);
- $v2 = $v2 && !$this->isUpToDate($book, 2);
- $html5 = $html5 && !$this->isUpToDate($book, 'html5');
- } else {
- $v1 = false;
- $html5 = true;
- $v2 = true;
- }
-
$res = '';
- if ($html5) {
- fb(time(), 'Compile HTML5');
- $this->compilePDF($book, $pages);
- $res .= $this->compileHTML5($book_id, $book, $dev, $delete);
- $this->touchCompile($book_id, 'html5');
- }
+ $this->compilePDF($book, $pages);
+ $res .= $this->compileHTML5($book_id, $book, $dev, $delete);
+ $this->touchCompile($book_id, 'html5');
- fb(time(), 'End Compile');
return $res;
}
$htmlCompiler->compile($delete);
self::$lastHTML5Compiler = $htmlCompiler;
-
}
- /* public function indexPDF($book, $pages) {
- $indexPath = WS_BOOKS . '/search/' . $book->book_id;
-
- Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
-
- if (file_exists($indexPath)) {
- files::deltree($indexPath);
- }
- $index = Zend_Search_Lucene::create($indexPath);
-
- foreach ($pages as $i => $infos) {
- $doc = new Zend_Search_Lucene_Document();
- $doc->addField(Zend_Search_Lucene_Field::Text('url', '#' . $i));
- $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', file_get_contents(wsDocument::getDir($infos['document_id']) . 'p' . $infos['document_page'] . '.txt')));
- $index->addDocument($doc);
- }
-
- $c = $this->con->openCursor('books');
- $c->lucene_time = TIME;
- $c->update('WHERE book_id=' . $book->book_id);
- } */
-
public function compilePDF($book, $pages)
{
$res = wsUtil::compilePDF($book, $pages);
<?php\r
\r
-class wsBook extends cubeMetier {\r
+class wsBook extends cubeMetier\r
+{\r
\r
- protected $book_id;\r
- protected $cid;\r
- protected $nom;\r
- protected $lang;\r
- protected $theme;\r
- protected $proprietaire;\r
- protected $proprietaire_id;\r
- protected $proprietaire_utilisateur;\r
- protected $facturable;\r
- protected $facturable_id;\r
- protected $hash;\r
- protected $compteur_visites;\r
- protected $tache;\r
- protected $projet;\r
- protected $status;\r
- protected $date_status;\r
- protected $date;\r
- protected $parametres;\r
- protected $pages;\r
- protected $chapters;\r
- protected $extras;\r
- protected $traductions;\r
- protected $numerotation;\r
- protected $specialLinks;\r
- protected $specialRulers;\r
- protected $changedate;\r
- protected $compiledate;\r
- protected $compile1date;\r
- protected $compilehtml5date;\r
- protected $composition_update;\r
- protected $version;\r
- protected $dir_references;\r
- protected $dir_hosting;\r
- protected $dir_macbook_phonegap_ios;\r
- protected $dir_phonegap_android;\r
- protected $dir_external;\r
- protected $demo_counter;\r
- protected $exportdatas;\r
+ protected $book_id;\r
+ protected $cid;\r
+ protected $nom;\r
+ protected $lang;\r
+ protected $theme;\r
+ protected $proprietaire;\r
+ protected $proprietaire_id;\r
+ protected $proprietaire_utilisateur;\r
+ protected $facturable;\r
+ protected $facturable_id;\r
+ protected $hash;\r
+ protected $compteur_visites;\r
+ protected $tache;\r
+ protected $projet;\r
+ protected $status;\r
+ protected $date_status;\r
+ protected $date;\r
+ protected $parametres;\r
+ protected $pages;\r
+ protected $chapters;\r
+ protected $extras;\r
+ protected $traductions;\r
+ protected $numerotation;\r
+ protected $specialLinks;\r
+ protected $specialRulers;\r
+ protected $changedate;\r
+ protected $compiledate;\r
+ protected $compile1date;\r
+ protected $compilehtml5date;\r
+ protected $composition_update;\r
+ protected $version;\r
+ protected $dir_references;\r
+ protected $dir_hosting;\r
+ protected $dir_macbook_phonegap_ios;\r
+ protected $dir_phonegap_android;\r
+ protected $dir_external;\r
+ protected $demo_counter;\r
+ protected $exportdatas;\r
\r
- public function __get($varname) {\r
- if (!property_exists($this, $varname)) {\r
- $msg = 'You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists';\r
- trigger_error($msg, E_USER_ERROR);\r
- throw new Exception($msg);\r
- }\r
+ protected $_docs = [];\r
\r
- $classic = array('chapters', 'specialLinks', 'specialRulers', 'traductions');\r
- $assoc = array('specialLinks', 'specialRulers');\r
+ public function __get($varname)\r
+ {\r
+ if (!property_exists($this, $varname)) {\r
+ $msg = 'You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists';\r
+ trigger_error($msg, E_USER_ERROR);\r
+ throw new Exception($msg);\r
+ }\r
\r
- if (in_array($varname, $classic)) {\r
- if (is_array($this->$varname) || is_object($this->$varname)) {\r
- return $this->$varname;\r
- }\r
- if ($this->$varname == '') {\r
- $this->$varname = array();\r
- } else {\r
- $this->$varname = json_decode($this->$varname, in_array($varname, $assoc));\r
- }\r
- return $this->$varname;\r
- }\r
- if ($varname == 'parametres') {\r
- if ($this->parametres instanceof wsBookParametres) {\r
- return $this->parametres;\r
- }\r
+ $classic = array('chapters', 'specialLinks', 'specialRulers', 'traductions');\r
+ $assoc = array('specialLinks', 'specialRulers');\r
\r
- $p = unserialize($this->parametres);\r
- if (!$p || $p->isEmpty()) {\r
- $p = new wsBookParametres($this);\r
- } else {\r
- $p->setParent($this);\r
- }\r
- $this->parametres = $p;\r
- return $this->parametres;\r
- }\r
+ if (in_array($varname, $classic)) {\r
+ if (is_array($this->$varname) || is_object($this->$varname)) {\r
+ return $this->$varname;\r
+ }\r
+ if ($this->$varname == '') {\r
+ $this->$varname = array();\r
+ } else {\r
+ $this->$varname = json_decode($this->$varname, in_array($varname, $assoc));\r
+ }\r
+ return $this->$varname;\r
+ }\r
+ if ($varname == 'parametres') {\r
+ if ($this->parametres instanceof wsBookParametres) {\r
+ return $this->parametres;\r
+ }\r
\r
- return $this->$varname;\r
- }\r
+ $p = unserialize($this->parametres);\r
+ if (!$p || $p->isEmpty()) {\r
+ $p = new wsBookParametres($this);\r
+ } else {\r
+ $p->setParent($this);\r
+ }\r
+ $this->parametres = $p;\r
+ return $this->parametres;\r
+ }\r
+\r
+ return $this->$varname;\r
+ }\r
+\r
+ public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')\r
+ {\r
+ $p = wsDAOBook::getDocumentPage($this->book_id, $page);\r
+ if (!isset($this->_docs[$p['document_id']])) {\r
+ global $core;\r
+ $dao = new wsDAODocument($core->con);\r
+ $this->_docs[$p['document_id']] = $dao->selectById($p['document_id']);\r
+ }\r
+ $doc = $this->_docs[$p['document_id']];\r
+ return $doc->getFile($p['document_page'], $format, $resolution, $withText, $withGraphics, $version);\r
+ }\r
+\r
+ public function getThumbFile($page, $format)\r
+ {\r
+ $thumbpdf = WS_BOOKS . '/working/' . $this->book_id . '/' . $this->parametres->pdfThumbnails;\r
+ if ($this->parametres->pdfThumbnails && file_exists($thumbpdf)) {\r
+\r
+ return wsPDFConvert::getThumbFromPDF($thumbpdf, $page, $format);\r
+\r
+ }\r
+ return $this->getFile($page, $format, 'thumb');\r
+ }\r
}
\ No newline at end of file
if ($format === 'jpeg') {
$format = 'jpg';
}
+ if ($format === 'svg') {
+ $version = 'html';
+ }
+
+ if ($resolution === 'thumb') {
+ $withGraphics = true;
+ $withText = true;
+ $version = '';
+ }
- $dir = $this->out . '/' . $version . '/';
+
+ $dir = rtrim($this->out . $version, '/') . '/';
if ($format === 'svg') {
$prefix = $withGraphics ? 'f' : 't';
$file = $dir . $prefix . 'o' . $page;
$file .= '.svg';
} else if ($format === 'png' || $format === 'jpg') {
$prefix = $withText ? 't' : 'h';
- $file = $dir . $prefix . $resolution . '-' . $page . '.' . $format;
+ if ($resolution === 'thumb') {
+ $file = $dir . 'p' . $page . '.' . $format;
+ } else {
+ $file = $dir . $prefix . $page . '-' . $resolution . '.' . $format;
+ }
}
if (!file_exists($file)) {
- $this->makeFile($file, $page, $format, $resolution, $withText, $version);
+ $this->makeFile($file, $page, $format, $resolution, $withText, $withGraphics, $version);
}
return $file;
}
- public function makeFile($file, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+ public function makeFile($file, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true)
{
if ($format === 'jpeg') {
$format = 'jpg';
}
if ($format === 'svg') {
-
+ if ($withGraphics) {
+ $this->makeOptimizedSVGFile($page, $resolution, $file);
+ } else {
+ $this->makeTextSVGFile($page, $file);
+ }
} else if ($format === 'png' || $format === 'jpg') {
- wsPDFConvert::makeShotPNM($this->getSplittedPDFPage($page), $file, 1, '', $resolution * $this->getResolutionRatio(), 85, 4, $withText, null, null, $format);
+ if ($resolution === 'thumb') {
+ wsPDFConvert::makeMiniShot($this->getSplittedPDFPage($page), $file, 1, $format);
+ } else {
+ $rr = version === 'html' ? $this->getResolutionRatio() : $this->getMobileFirstRatio();
+ wsPDFConvert::makeShotPNM($this->getSplittedPDFPage($page), $file, 1, '', $resolution * $rr, 85, 4, $withText, null, null, $format);
+ }
}
}
$this->makeMiniShot($page);
// Image for link editor
$this->getFile($page, 'jpg', 150, true, true);
+ // Make SVG base file
+ $this->makeSVGFile($page, false);
}
}
return 620 / $this->generalInfos['size'][0];
}
- public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM')
- {
- // Make thumbs of $w width
- // resolution 72 make 1pt=1px
- $width = $this->generalInfos['size'][0];
- $ratio = $width / $w;
- $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);
- }
-
- public function makeShotFixedHeight($page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM')
- {
- // Make thumbs of $w height
- // resolution 72 make 1pt=1px
- $height = $this->generalInfos['size'][1];
- $ratio = $height / $h;
- $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);
- }
-
- public function makeShot($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $in = null)
- {
- $error = false;
- if ($in === null) {
- $in = $this->getCroppedPDF();
- }
- // Delete all old files
- $res = $this->out . $prefix . $page . '.jpg';
- if (file_exists($res)) {
- @unlink($res);
- }
-
- if ($method == 'GS') {
- $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);
- } elseif ($method == 'PNM') {
- $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);
- }
- // Test the result by checking all files
- if (!file_exists($res)) {
- $error = true;
- }
- // If error, we try to make thumbs with other method
- if ($error) {
- if ($method == 'GS') {
- $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);
- } elseif ($method == 'PNM') {
- $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);
- }
- }
- }
-
- protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null)
- {
- if (is_null($in)) {
- $in = $this->getCroppedPDF();
- }
- // Fabrication des thumbanails avec ghostscript
- $gs = new cubeCommandLine('gs', null, true);
- $gs->setPath(CONVERTER_PATH);
- $gs->setEnv('GS_FONTPATH', FONT_PATH);
- $gs->setArg('-dBATCH');
- $gs->setArg('-dNOPAUSE');
- $gs->setArg('-dNOPROMPT');
- // Antialias
- $gs->setArg('-dDOINTERPOLATE');
- $gs->setArg('-dTextAlphaBits=' . $antialiasing);
- $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);
- // Device
- $gs->setArg('-sDEVICE=jpeg');
- // Dispotion & colors
- // $gs->setArg('-dUseCIEColor');
- $gs->setArg('-dAutoRotatePages=/None');
- $gs->setArg('-dUseCropBox');
- // Resolution & Quality
- $gs->setArg('-r' . round($resolution));
- $gs->setArg('-dJPEGQ=' . $quality);
- // Performances
- $gs->setArg('-dNumRenderingThreads=4');
- // Page range
- $gs->setArg('-dFirstPage=' . $page);
- $gs->setArg('-dLastPage=' . $page);
- // Files
- $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . $page . '.jpg');
-
- $gs->setArg(null, $in);
- $gs->execute();
- $this->addToLog($gs, true, $page);
- }
-
- protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true)
- {
- $tmp = cubeFiles::tempnam();
- $pttopx = 1;
-
- $s = $this->generalInfos['page'][$page]['size'];
- $w = floor(($s[0] * $pttopx) * ($resolution / 72));
- $h = floor(($s[1] * $pttopx) * ($resolution / 72));
-
- $antialiasing = $antialiasing ? 'yes' : 'no';
- $freetype = $texts ? 'yes' : 'no';
- // Exporte les fichiers
- $pdftoppm = new CubeIT_CommandLine('pdftoppm', null, true);
- $pdftoppm->setPath(CONVERTER_PATH);
-
- $pdftoppm->setArg('f', 1);
- $pdftoppm->setArg('l', 1);
- $pdftoppm->setArg('-cropbox');
- $pdftoppm->setArg('-freetype ' . $freetype);
- $pdftoppm->setArg('-singlefile');
- $pdftoppm->setArg('-aa ' . $antialiasing);
- $pdftoppm->setArg('-aaVector ' . $antialiasing);
- $pdftoppm->setArg('r', $resolution);
- $pdftoppm->setArg('W', $w);
- $pdftoppm->setArg('H', $h);
- $pdftoppm->setArg(null, $this->getSplittedPDFPage($page));
- $pdftoppm->setArg(null, $tmp);
- $pdftoppm->execute();
- $pdftoppm->debug();
-
- $tmp .= '.ppm';
-
- $jpegfile = $this->out . $prefix . $page . '.jpg';
- $pngfile = $this->out . $prefix . $page . '.png';
-
- if (file_exists($tmp)) {
- $cjpeg = new cubeCommandLine('/opt/mozjpeg/bin/cjpeg', null, true);
- $cjpeg->setArg('-quality ' . ($quality + 6));
- $cjpeg->setArg('-outfile ' . $jpegfile);
- $cjpeg->setArg(null, $tmp);
- $cjpeg->execute();
- $this->addToLog($cjpeg, false, $page);
-
- $pnmtopng = new CubeIT_CommandLine('pnmtopng', $pngfile, false);
- $pnmtopng->setArg('-background white');
- $pnmtopng->setArg(null, $tmp);
- $pnmtopng->execute();
-
- unlink($tmp);
- }
- }
-
protected function isCropped()
{
return $this->autocrop || $this->manualcrop || $this->autocut || $this->manualcut;
}
- public function makeHTML5Files($page)
- {
- // Then make HD background shots
- $resolutions = array(300 => 85, 150 => 85, 36 => 85);
- $rratio = $this->getResolutionRatio();
- foreach ($resolutions as $r => $q) {
- $this->makeShotPNM($page, 'html/h' . $r . '-', $r * $rratio, $q, 4, null, false);
- $this->makeShotPNM($page, 'html/t' . $r . '-', $r * $rratio, $q);
- }
- $this->makeSVGFile($page, false);
- }
-
- public function makeMobileFirstFiles($page)
- {
- // Then make HD background shots
- $resolutions = array(300 => 85, 150 => 85, 36 => 85);
- $rratio = $this->getMobileFirstRatio();
- foreach ($resolutions as $r => $q) {
- $this->makeShotPNM($page, 'mf/h' . $r . '-', $r * $rratio, $q, 4, null, false);
- $this->makeShotPNM($page, 'mf/t' . $r . '-', $r * $rratio, $q);
- }
- }
-
- public function makeSVGFile($page, $force = true)
+ public function makeSVGFile($page, $force = false)
{
$svgFile = $this->out . '/html/fp' . $page . '.svg';
if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) {
return;
}
-
- $pdftocairo = new cubeCommandLine('pdftocairo');
- $pdftocairo->setPath(CONVERTER_PATH);
- $pdftocairo->setArg('f', 1);
- $pdftocairo->setArg('l', 1);
- $pdftocairo->setArg('r', 300);
- $pdftocairo->setArg(null, '-expand');
- $pdftocairo->setArg(null, '-svg');
- $pdftocairo->setArg(null, $this->getSplittedPDFPage($page));
- $pdftocairo->setArg(null, $svgFile);
- $pdftocairo->execute();
-
- $this->addToLog($pdftocairo, true, $page);
+ wsPDFConvert::makeBaseSVGFile($this->getSplittedPDFPage($page), $svgFile, 1);
+ return $svgFile;
}
- public static function extractTexts($svgFile, $textFile, $force = false)
+ public function makeTextSVGFile($page, $out, $force = false)
{
- $do = $force || !file_exists($textFile) || filesize($textFile) < 100 || filemtime($svgFile) > filemtime($textFile) || filemtime($textFile) < filemtime(__FILE__);
+ $in = $this->makeSVGFile($page);
+ $do = $force || !file_exists($out) || filesize($out) < 100 || filemtime($in) > filemtime($out) || filemtime($out) < filemtime(__FILE__);
if (!$do) {
return;
}
+ wsPDFConvert::makeTextSVGFile($in, $out);
+ wsTools::optimizeSVG($out, $out);
+ }
- $svg = new DOMDocument();
- $svg->preserveWhiteSpace = false;
- $svg->load($svgFile, LIBXML_PARSEHUGE);
-
- // Operations to delete
- $xpath = new DOMXPath($svg);
- $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');
- $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');
- $xpath->registerNamespace("php", "http://php.net/xpath");
- $xpath->registerPhpFunctions('has_not_text');
- $toDelete = array('//svg:defs/svg:clipPath',
- '//svg:defs/svg:image',
- '//svg:defs/svg:path',
- '//svg:defs/svg:pattern',
- '//svg:defs/svg:g[starts-with(@id, "surface")]//svg:path',
- '/svg:svg/svg:g//svg:path',
- '/svg:svg/svg:g//svg:rect',
- '//svg:use[starts-with(@xlink:href, "#image")]'
- );
-
- //global $svglog;
- //$svglog = array('XPATH : ' . print_r($xpath, true));
- foreach ($toDelete as $q) {
- $list = $xpath->query($q);
- // $svglog[] = "Evaluate xpath query " . $q;
- // $svglog[] = 'Give ' . $list->length . ' results';
- // $svglog[] = 'Deleting Nodes in ' . print_r($list, true);
- if (count($list)) {
- foreach ($list as $node) {
- /* @var $node DOMNode */
- $parent = $node->parentNode;
- $parent->removeChild($node);
- }
- }
- }
- file_put_contents($textFile, $svg->saveXML());
+ public function makeOptimizedSVGFile($page, $resolution, $out)
+ {
+ $in = $this->makeSVGFile($page);
+ wsTools::optimizeSVGImages($in, $out, $resolution);
+ wsTools::optimizeSVG($out, $out);
}
protected function getSplittedPDFPage($page)
return $res;
}
- public static function makeHTML5FilesIfNotExists($document_id, $document_page, $format = 'jpg')
- {
- global $core;
-
- $path = self::getDir($document_id) . '/html/h150-' . $document_page . '.' . $format;
- if (!file_exists($path)) {
- $dao = new wsDAODocument($core->con);
- $doc = $dao->selectById($document_id);
- $doc->makeHTML5Files($document_page);
- }
- }
-
- public static function makeMobileFirstFilesIfNotExists($document_id, $document_page, $format = 'jpg')
- {
- global $core;
-
- $path = self::getDir($document_id) . '/mf/h150-' . $document_page . '.' . $format;
- if (!file_exists($path)) {
- $dao = new wsDAODocument($core->con);
- $doc = $dao->selectById($document_id);
- $doc->makeMobileFirstFiles($document_page);
- }
- }
+// public static function makeHTML5FilesIfNotExists($document_id, $document_page, $format = 'jpg')
+// {
+// global $core;
+//
+// $path = self::getDir($document_id) . '/html/h150-' . $document_page . '.' . $format;
+// if (!file_exists($path)) {
+// $dao = new wsDAODocument($core->con);
+// $doc = $dao->selectById($document_id);
+// $doc->makeHTML5Files($document_page);
+// }
+// }
+//
+// public static function makeMobileFirstFilesIfNotExists($document_id, $document_page, $format = 'jpg')
+// {
+// global $core;
+//
+// $path = self::getDir($document_id) . '/mf/h150-' . $document_page . '.' . $format;
+// if (!file_exists($path)) {
+// $dao = new wsDAODocument($core->con);
+// $doc = $dao->selectById($document_id);
+// $doc->makeMobileFirstFiles($document_page);
+// }
+// }
}
\ No newline at end of file
self::makeShot($in, $out, $page, $prefix, null, $quality, $antialiasing, $method, -1, $h, $format);\r
}\r
\r
+ public static function makeBaseSVGFile($in, $out, $page)\r
+ {\r
+ $pdftocairo = new CubeIT_CommandLine('pdftocairo');\r
+ $pdftocairo->setPath(CONVERTER_PATH);\r
+ $pdftocairo->setArg('f', $page);\r
+ $pdftocairo->setArg('l', $page);\r
+ $pdftocairo->setArg('r', 300);\r
+ $pdftocairo->setArg(null, '-expand');\r
+ $pdftocairo->setArg(null, '-svg');\r
+ $pdftocairo->setArg(null, $in);\r
+ $pdftocairo->setArg(null, $out);\r
+ $pdftocairo->execute();\r
+ }\r
+\r
+ public static function makeTextSVGFile($in,$out){\r
+ $svg = new DOMDocument();\r
+ $svg->preserveWhiteSpace = false;\r
+ $svg->load($in, LIBXML_PARSEHUGE);\r
+\r
+ // Operations to delete\r
+ $xpath = new DOMXPath($svg);\r
+ $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');\r
+ $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');\r
+ $xpath->registerNamespace("php", "http://php.net/xpath");\r
+ $xpath->registerPhpFunctions('has_not_text');\r
+ $toDelete = array('//svg:defs/svg:clipPath',\r
+ '//svg:defs/svg:image',\r
+ '//svg:defs/svg:path',\r
+ '//svg:defs/svg:pattern',\r
+ '//svg:defs/svg:g[starts-with(@id, "surface")]//svg:path',\r
+ '/svg:svg/svg:g//svg:path',\r
+ '/svg:svg/svg:g//svg:rect',\r
+ '//svg:use[starts-with(@xlink:href, "#image")]'\r
+ );\r
+\r
+ //global $svglog;\r
+ //$svglog = array('XPATH : ' . print_r($xpath, true));\r
+ foreach ($toDelete as $q) {\r
+ $list = $xpath->query($q);\r
+ // $svglog[] = "Evaluate xpath query " . $q;\r
+ // $svglog[] = 'Give ' . $list->length . ' results';\r
+ // $svglog[] = 'Deleting Nodes in ' . print_r($list, true);\r
+ if (count($list)) {\r
+ foreach ($list as $node) {\r
+ /* @var $node DOMNode */\r
+ $parent = $node->parentNode;\r
+ $parent->removeChild($node);\r
+ }\r
+ }\r
+ }\r
+ file_put_contents($out, $svg->saveXML());\r
+ }\r
+\r
public static function makeShot($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $width = null, $height = null, $format = 'jpg')\r
{\r
$error = false;\r
$antialiasing = $antialiasing ? 'yes' : 'no';\r
$freetype = $texts ? 'yes' : 'no';\r
// Exporte les fichiers\r
- $pdftoppm = new cubeCommandLine('pdftoppm', null, true);\r
+ $pdftoppm = new cubeCommandLine('/usr/local/bin/pdftoppm', null, true);\r
$pdftoppm->setPath(CONVERTER_PATH);\r
\r
$pdftoppm->setArg('f', $page);\r
$webvideo->execute();
}
- public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true)
+ public static function optimizeSVG($in, $out)
{
- // Init directory
- if (is_string($colors)) {
- $colors = array('colorize' => $colors);
- }
- $hash = sha1(json_encode($colors));
- foreach ($colors as $k => $v) {
- $colors[$k] = wsHTML5::colorToArray($colors[$k]);
- }
-
- $e = explode('-', $icon);
- $type = $e[0];
-
- if ($type == 'nav') {
- $svgRef = WS_ICONS . '/' . $iconSet . '/mobile/' . $icon . '.svg';
- if (!file_exists($svgRef)) {
- $iconSet = 1;
- $svgRef = WS_ICONS . '/' . $iconSet . '/mobile/' . $icon . '.svg';
- }
-
- $dirColorized = WS_ICONS . '/' . $iconSet . '/mobile/colorized/' . $hash . '/';
- $svgColorized = $dirColorized . '/' . $icon . '.svg';
- } else {
- $dirColorized = WS_ICONS . '/' . $type . '/colorized/' . $hash;
- $svgRef = WS_ICONS . '/' . $type . '/' . $icon . '.svg';
- $svgColorized = $dirColorized . '/' . $icon . '.svg';
- }
-
- if (!file_exists($dirColorized)) {
- mkdir($dirColorized, 0777, true);
- }
-
-
- // SVG
- $time = max(filemtime(__FILE__), filemtime($svgRef));
- if (!file_exists($svgColorized) || filemtime($svgColorized) <= $time) {
- $svg = file_get_contents($svgRef);
- // Colorize it
- foreach ($colors as $k => $v) {
- $replace = "#" . $v['hex'];
- if ($v['opacity'] < 1) {
- $replace .= '" stroke-opacity="' . $v['opacity'];
- }
- $svg = str_replace('$s' . $k, $replace, $svg);
-
-
- $replace = "#" . $v['hex'];
- if ($v['opacity'] < 1) {
- $replace .= '" fill-opacity="' . $v['opacity'];
- }
- $svg = str_replace('$' . $k, $replace, $svg);
- }
- file_put_contents($svgColorized, $svg);
- }
- self::copy($svgColorized, $dest . '/' . $icon . '.svg');
-
- // PNG
- $png = $dirColorized . '/' . $icon . '.png';
- $time = max(filemtime(__FILE__), filemtime($svgColorized));
- if (!file_exists($png) || filemtime($png) <= $time) {
- $svg = simplexml_load_file($svgColorized);
- $w = (string)$svg['width'];
- $h = (string)$svg['height'];
- $w = rtrim($w, 'px');
- $h = rtrim($h, 'px');
- // Finally rasterize it
- $batik = new cubeCommandLine('inkscape');
- $batik->setArg('z');
- $batik->setArg('e', $png);
- $batik->setArg('w', floatval($w) * $scale);
- $batik->setArg('h', floatval($h) * $scale);
- $batik->setManualArg($svgColorized);
- $batik->execute();
- }
-
- if (file_exists($png)) {
- $dim = getimagesize($png);
- $w = $dim[0] / $scale;
- $h = $dim[1] / $scale;
- }
-
- if ($makepng) {
- self::copy($png, $dest . '/' . $icon . '.png');
+ $cmd = "timeout -s 1 120 /usr/local/bin/svgcleaner --allow-bigger-file --paths-coordinates-precision 3 --copy-on-error --stdout $in";
+ $svg = `$cmd`;
+ if ($svg == '') {
+ copy($in, $out);
+ return;
}
+ file_put_contents($out, $svg);
}
- public static function optimizeSVG($original, $optimized, $resolutions = [], $force = false)
+ public static function optimizeSVGImages($in, $out, $resolution)
{
-
- if (!file_exists($original)) {
- return 'doesnt exists';
- }
-
- $baseoptimized = str_replace('%s', '', $optimized);
-
- $expireoriginallimit = max(filemtime($original), filemtime(__FILE__));
-
- $notexists = !file_exists($baseoptimized) || filesize($baseoptimized) < 60;
- if (!$notexists) {
- $cleanerexpired = filemtime($baseoptimized) < filemtime('/usr/local/bin/svgcleaner');
- $originalexpired = filemtime($baseoptimized) < $expireoriginallimit;
- } else {
- $cleanerexpired = false;
- $originalexpired = false;
- }
-
- $optimize = $force ||
- $notexists ||
- $cleanerexpired ||
- $originalexpired;
-
- if ($optimize) {
- $cmd = "timeout -s 1 120 /usr/local/bin/svgcleaner --allow-bigger-file --paths-coordinates-precision 3 --copy-on-error --stdout $original";
- $svg = `$cmd`;
- if ($svg == '') {
- $svg = file_get_contents($original);
- }
- $svg = substr_replace($svg, ' preserveAspectRatio="none" ', 5, 0);
-
- $fname = $baseoptimized;
- file_put_contents($fname, $svg);
-
- if (count($resolutions) > 0) {
- foreach ($resolutions as $resolution) {
- self::$_r = $resolution;
- $osvg = preg_replace_callback('|\<image([^>]*)\>|', 'wsTools::optimizeRaster', $svg);
- $osvg = preg_replace('/^<svg[^>]*>/', '$0<rect width="100%" height="100%" fill="white" />', $osvg);
- $ofname = sprintf($optimized, '-' . $resolution);
- file_put_contents($ofname, $osvg);
- }
- }
- return true;
- }
- return false;
+ $svg = file_get_contents($in);
+ $svg = substr_replace($svg, ' preserveAspectRatio="none" ', 5, 0);
+
+ $osvg = preg_replace_callback('|\<image([^>]*)\>|', function ($matches) use ($resolution) {
+ return wsTools::optimizeRaster($matches, $resolution);
+ }, $svg);
+ $osvg = preg_replace('/^<svg[^>]*>/', '$0<rect width="100%" height="100%" fill="white" />', $osvg);
+ file_put_contents($out, $osvg);
}
- public static function optimizeRaster($matches)
+ public static function optimizeRaster($matches, $resolution)
{
preg_match_all('/([a-z\:\-]*)="([^"]*)"/', $matches[1], $m);
$scale = max($values[0], $values[1]);
}
- $resolutionScale = ($iw / $attrs['width']) * $scale * (self::$_r / 72);
+ $resolutionScale = ($iw / $attrs['width']) * $scale * ($resolution / 72);
$dw = round($resolutionScale * $iw);
$dh = round($resolutionScale * $ih);
$svg = array('interface-back-arrow');
- foreach ($svg as $icon) {
- wsTools::colorizeAndRasterizeIcon(1, $icon, $text, $this->vdir . '/images/', 4, $w, $h);
- }
-
$caption .= "#bar{border-bottom:1px solid " . $border . "}";
$c[] = $caption;
$this->imageFormat = $this->book->parametres->imageFormat;
- wsDocument::makeHTML5FilesIfNotExists($this->pages[1]['document_id'], $this->pages[1]['document_page'], $this->imageFormat);
- $firstJpeg = wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.' . $this->imageFormat;
-
- $imagesize = CubeIT_Image::getimagesize($firstJpeg);
+ $imagesize = CubeIT_Image::getimagesize($this->book->getFile(1, 'jpg', 150));
$this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 12);
$this->linkScale = $this->cssScale = $this->z * min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height);
$res = array();
}
- protected function writeIcons()
- {
- $res = array();
- // Get the colors used to colorize graphics
- if ($this->theme->parametres->colorizeIcons) {
- $couleurI = $this->theme->parametres->couleurI;
- } else {
- $couleurI = 'FFFFFF';
- }
-
- $couleurM = $this->theme->parametres->subTextColor;
-
- $bookmarksDisabledColors = array('star' => $this->theme->parametres->bookmarkStarDisabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor);
- $bookmarksEnabledColors = array('star' => $this->theme->parametres->bookmarkStarEnabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor);
- $subTextColor = $this->theme->parametres->subTextColor;
-
- $arrowsColor = $this->theme->parametres->arrowsColor;
- // Set the icon list with the color
- $icons = array('interface-down' => $arrowsColor, 'interface-close' => $arrowsColor,
- 'interface-audio-description-on' => $arrowsColor, 'interface-audio-description-off' => $arrowsColor,
- 'help-fingers' => $couleurI, 'help-mouse' => $couleurI
- );
-
- $this->config->iconsDimensions = array();
- $makepng = !$this->supportSVG();
- $tmpdir = CubeIT_Files::tmpdir();
- foreach ($icons as $icon => $color) {
- wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $tmpdir, 4, $w, $h);
- $this->config->iconsDimensions[$icon] = array($w, $h);
- }
- $this->vdir->copyDirectory($tmpdir, 'data/images');
- $this->vdir->addTemp($tmpdir);
- return $res;
- }
-
protected function writeImages()
{
global $core;
switch ($this->book->parametres->mobileVersion) {
case 'html5-desktop':
- $this->backgroundsPrefix = array('t', 'p');
+ $this->backgroundsPrefix = array(true, false);
$this->svg = true;
break;
case 'html5-images':
- $this->backgroundsPrefix = array('t');
+ $this->backgroundsPrefix = array(true);
$this->svg = false;
break;
default:
- $this->backgroundsPrefix = array('p');
+ $this->backgroundsPrefix = array(false);
$this->svg = true;
break;
}
$this->config->pagesDimensions = [];
if ($this->book->parametres->mobileNavigationType === 'mobilefirst') {
- $makeFunction = 'makeMobileFirstFilesIfNotExists';
$imdir = 'mf';
} else {
- $makeFunction = 'makeHTML5FilesIfNotExists';
$imdir = 'html';
}
$thisrasterize = in_array($page, $rasterizePages);
$thisimagesvg = !$thisrasterize && $this->svg;
- $thisbackgroundPrefix = $thisrasterize ? ['t'] : $this->backgroundsPrefix;
-
- wsDocument::$makeFunction($infos['document_id'], $infos['document_page'], $this->imageFormat);
+ $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix;
foreach ($this->getResolutions() as $r) {
foreach ($thisbackgroundPrefix as $backgroundsPrefix) {
- $srcPrefix = $backgroundsPrefix;
- if ($backgroundsPrefix === 'p') {
- $srcPrefix = 'h';
- }
- $source = $docdir . $imdir . '/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.' . $this->imageFormat;
+ $source = $this->book->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir);
if ($r == 150 && file_exists($source)) {
$firstDoc = $daoDoc->selectById($infos['document_id']);
$d = $firstDoc->generalInfos['page'][$infos['document_page']]['size'];
$this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0]));
}
- $ok = $this->vdir->copy($source, 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.' . $this->imageFormat);
- if (!$ok && $r = 300) {
- $this->maxRes = 150;
- }
+ $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat);
}
}
if ($thisimagesvg) {
- $full = $docdir . 'html/fp' . $infos['document_page'] . '.svg';
- $fullopt = $docdir . 'html/fo' . $infos['document_page'] . '%s.svg';
- $orig = $docdir . 'html/tp' . $infos['document_page'] . '.svg';
- $opt = $docdir . 'html/to' . $infos['document_page'] . '.svg';
-
- if (!file_exists($full) || filemtime($full) < 1503671520) {
- if (!isset($doc) || $doc->document_id != $infos['document_id']) {
- $dao = new wsDAODocument($core->con);
- $doc = $dao->selectById($infos['document_id']);
- }
- $doc->makeSVGFile($infos['document_page']);
- }
- wsDocument::extractTexts($full, $orig);
- wsTools::optimizeSVG($orig, $opt);
- wsTools::optimizeSVG($full, $fullopt, [150, 300]);
-
- if (in_array($page, $this->config->vectorPages)) {
- $this->vdir->copy(str_replace('%s', '-150', $fullopt), 'data/contents/p' . $page . '.svg');
- } else {
- $this->vdir->copy($opt, 'data/contents/p' . $page . '.svg');
- }
+ $this->vdir->copy($this->book->getFile($page, 'svg', 150, true,
+ in_array($page, $this->config->vectorPages), 'html'), 'data/contents/p' . $page . '.svg');
}
- $thumb = false;
- if ($this->book->parametres->pdfThumbnails) {
- $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page, $this->imageFormat);
- }
- if (!$thumb) {
-
- $thumb = $docdir . 'p' . $infos['document_page'] . '.' . $this->imageFormat;
- if (!file_exists($thumb)) {
- $doc = $daoDoc->selectById($infos['document_id']);
- $doc->makeMiniShot($infos['document_page']);
- }
- }
- $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.' . $this->imageFormat);
+ $this->vdir->copy($this->book->getFile($page,$this->imageFormat,'thumb',true,true,'html'), 'data/thumbnails/p' . $page . '.' . $this->imageFormat);
if ($page == 1) {
$this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg');
$header .= '}';
$res[] = $header;
- //Icons
- $res = array_merge($res, $this->writeIcons());
-
// Logo
$logo = '#logo{';
if ($this->theme->parametres->logo) {