protected $pages_log_pointers;\r
protected $infos;\r
protected $cropped;\r
- protected $uncropped;\r
protected $rgb;\r
\r
const NORMAL = 0;\r
mkdir($this->html, 0755);\r
}\r
$this->cropped = $this->out . 'crop.pdf';\r
- $this->rgb = $this->out . 'rgb.pdf';\r
- $this->uncropped = $this->out . 'uncrop.pdf';\r
$this->pages_log_pointers = array();\r
\r
if (is_null($this->conversionInfos)) {\r
\r
public function copyOriginalFromUpload($tmp_file) {\r
move_uploaded_file($tmp_file, $this->in);\r
- $this->uncropDocument();\r
}\r
\r
public function copyOriginalFromOlderVersion() {\r
if (!file_exists($this->in)) {\r
copy('http://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);\r
}\r
- $this->uncropDocument();\r
}\r
\r
public function extractFonts() {\r
if ($this->CropAndCut()) {\r
$this->getInfos($this->cropped, true);\r
}\r
- $this->performColorTransformations();\r
- $this->extractFonts();\r
+ //$this->extractFonts();\r
$this->getLinksAndTexts();\r
}\r
\r
- public function performColorTransformations() {\r
- $out = $this->out . '/rgb.pdf';\r
-\r
- /*$gs = new cubeCommandLine('gs', null, true);\r
- $gs->setPath(CONVERTER_PATH);\r
- $gs->setEnv('GS_FONTPATH', FONT_PATH);\r
- $gs->setArg('-dBATCH');\r
- $gs->setArg('-dNOPAUSE');\r
- $gs->setArg('-dNOPROMPT');\r
- // Device\r
- $gs->setArg('-sDEVICE=pdfwrite');\r
- // \r
- $gs->setArg('-dDownsampleColorImages=false');\r
- $gs->setArg('-dDownsampleGrayImages=false');\r
- $gs->setArg('-dDownsampleMonoImages=false');\r
- $gs->setArg('-dColorImageResolution=300');\r
- $gs->setArg('-dMonoImageResolution=600');\r
- $gs->setArg('-dGreyImageResolution=300');\r
- \r
- // Dispotion & colors\r
- $gs->setArg('-dConvertCMYKImagesToRGB=true');\r
- $gs->setArg('-dAutoRotatePages=/None');\r
- $gs->setArg('-dUseCropBox');\r
- $gs->setArg('-dShowAnnots=false');\r
- // Performances\r
- $gs->setArg('-dNumRenderingThreads=4');\r
- // Page range\r
- // Files\r
- $gs->setArg('-sOutputFile=' . $out);\r
-\r
- $gs->setArg(null, $this->cropped);\r
- $gs->execute();\r
- \r
- $this->addToLog($gs);*/\r
- }\r
-\r
public function CropAndCut() {\r
if (!$this->isCropped()) {\r
copy($this->in, $this->cropped);\r
$this->addToLog($fwstk);\r
}\r
\r
- public function uncropDocument() {\r
- $fwstk = new cubeCommandLine('fwstk');\r
- $fwstk->setPath(CONVERTER_PATH);\r
- $fwstk->setArg('--input ' . $this->in);\r
- $fwstk->setArg('--reset');\r
- $fwstk->setArg('--output ' . $this->uncropped);\r
- $fwstk->execute();\r
- $this->addToLog($fwstk);\r
- }\r
-\r
public function processOnePage($page, $force = true) {\r
- // $this->makeRealShot($page);\r
if ($force) {\r
$this->addToLog('Processing page #' . $page);\r
$this->makeMiniShot($page);\r
$fwstk->execute();\r
$this->addToLog($fwstk);\r
\r
- $fwstk = new cubeCommandLine('fwstk');\r
+ /*$fwstk = new cubeCommandLine('fwstk');\r
$fwstk->setPath(CONVERTER_PATH);\r
$fwstk->setArg('--input ' . $this->cropped);\r
$fwstk->setArg('--layout ' . $this->html . 'p%d.layout');\r
$fwstk->setArg('--cmaps ' . $this->html);\r
$fwstk->setArg('--fonts' . $this->out . 'fonts/web/');\r
$fwstk->execute();\r
- $this->addToLog($fwstk);\r
-\r
- /* $temp = cubeFiles::tempnam();\r
- $pdftotext = new cubeCommandLine('pdftotext', null, true);\r
- $pdftotext->setPath(CONVERTER_PATH);\r
- $pdftotext->setArg('q');\r
- $pdftotext->setArg('-eol', 'unix');\r
- $pdftotext->setArg('-enc', 'UTF-8');\r
- $pdftotext->setArg(null, $this->cropped);\r
- $pdftotext->setArg(null, $temp);\r
- $pdftotext->execute();\r
- $this->addToLog($pdftotext);\r
-\r
- $pages = explode("\f", file_get_contents($temp));\r
- foreach($pages as $i => $page) {\r
- $i++;\r
- $txt = mb_strtolower($page);\r
- $txt = cubeText::removeAccents($txt);\r
- $txt = trim($txt);\r
-\r
- file_put_contents($this->out . 'p' . $i . '.txt', $txt);\r
- }\r
-\r
- unlink($temp); */\r
+ $this->addToLog($fwstk);*/\r
}\r
\r
public function makeMiniShot($page) {\r
$this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'PNM');\r
}\r
\r
- public function makeRealShot($page) {\r
- $this->makeShot($page, 'te', 150, 60, 4, 'GS', $this->uncropped);\r
- }\r
-\r
public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM') {\r
// Make thumbs of $w width\r
// resolution 72 make 1pt=1px\r
\r
public function makeHTML5Files($page) {\r
// Then make HD background shots\r
- $resolutions = array(36 => 90, 72 => 80, 150 => 75);\r
+ $resolutions = array(150 => 75);\r
foreach ($resolutions as $r => $q) {\r
$this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, false);\r
$this->makeShotPNM($page, 'html/t' . $r . '-', $r, $q, 4, null, true);\r
}\r
- // Then get layout infos from swf\r
- file_put_contents($this->out . '/html/s' . $page . '.layout', $this->dumpSWF($page));\r
}\r
\r
protected function checkObjectsNumber($file, $maxObjects, $page) {\r
class wsHTML5Compiler {
- protected static $resolutions = array(36, 72, 150);
+ protected static $resolutions = array(150);
protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
protected static $jsFiles = array(
'js/libs/cube/fb.js',
'js/libs/jquery/jquery.hashchange.js',
'js/tester.js'
);
- protected $layouts = array();
- protected $cssSize = array();
- protected $cssColor = array();
- protected $cssOpacity = array();
- protected $cssFont = array();
- protected $cssWordSpacing = array();
- protected $cssLetterSpacing = array();
- protected $cssTransform = array();
protected $cssX = array();
protected $cssY = array();
protected $cssWidths = array();
$this->theme = $daoTheme->getThemeOfBook($book_id, true);
$this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/';
- foreach ($this->pages as $page => $infos) {
- $file = WS_DOCS . '/' . $infos['document_id'] . '/html/p' . $infos['document_page'] . '.layout';
- if (file_exists($file)) {
- $this->layouts[$page] = simplexml_load_file($file, null, LIBXML_ERR_WARNING);
- }
- }
-
$daoDoc = new wsDAODocument($core->con);
$firstDoc = $daoDoc->selectById($this->pages[1]['document_id']);
$size = $firstDoc->generalInfos['size'];
return $p + 1;
}
- protected function sortPage($layout) {
- $lines = array();
- foreach ($layout->line as $line) {
- $lines[] = $line;
- }
- usort($lines, array($this, 'compareLines'));
-
- return $lines;
- }
-
- protected function compareLines($a, $b) {
- if ((float) $a['y'] > (float) $b['y']) {
- return 1;
- } else {
- return -1;
- }
- }
-
public function compile() {
foreach ($this->layouts as $page => $layout) {
$lines = $this->sortPage($layout);
// Copy swf
copy(WS_COMPILE_ASSETS . '/_html5/swf/video.swf', $this->vdir . '/swf/video.swf');
- foreach ($this->div as $n => $page) {
- file_put_contents($this->vdir . '/data/contents/p' . $n . '.html', $this->writePage($page));
- }
- $this->writeFonts();
$this->writeImages();
$linksCSS = $this->writeLinks();
$numCSS = $this->writeCSS($this->vdir . '/data/style/style_%d.css', $linksCSS);
return 'var DATAS=' . json_encode($config) . ';' . "\n";
}
- protected function writeFonts() {
- $formats = array('ttf', 'woff', 'svg');
-
- foreach ($this->cssFont as $font => $infos) {
- $index = $infos['index'];
-
- foreach ($formats as $format) {
- $fontforge = new cubeCommandLine('convert.pe');
- $fontforge->setPath(CONVERTER_PATH);
- foreach ($this->fontDocs[$font] as $document_id => $dummy) {
- if (file_exists(WS_DOCS . '/' . $document_id . '/fonts/web/' . $font . '.otf')) {
- $fontforge->setArg(null, WS_DOCS . '/' . $document_id . '/fonts/web/' . $font . '.otf');
- } else {
- $fontforge->setArg(null, WS_DOCS . '/' . $document_id . '/fonts/web/' . $font . '.ttf');
- }
- }
- $fontforge->setArg(null, '-');
- $fontforge->setArg(null, $this->vdir . '/data/style/F' . $index . '.' . $format);
-
- $fontforge->execute();
- }
- }
- }
-
protected function writeIcons() {
$res = array();
// Get the colors used to colorize graphics
copy($s,$t);
}
- protected function writePage($page) {
- $res = '';
- $page = $this->sortPageLines($page);
- foreach ($page as $line) {
- $res .= $this->writeLine($line);
- }
- return $res;
- }
-
- protected function sortPageLines($page) {
- $cols = array();
- // On groupe par x pour tenter de regrouper les paragraphes
- foreach ($page as $line) {
- if (!count($line['groups'])) {
- continue;
- }
- $x = (string) $line['groups'][0]['x'];
- if (!isset($cols[$x])) {
- $cols[$x] = array();
- }
- $cols[$x][] = $line;
- }
- // On trie les colonnes
- usort($cols, array('wsHTML5Compiler', 'sortCols'));
- // Maintenant, on écrase tout ça
- $res = array();
- foreach ($cols as $c) {
- foreach ($c as $line) {
- $res[] = $line;
- }
- }
- return $res;
- }
-
- protected function sortCols($a, $b) {
- if ($a[0]['y'] > $b[0]['y']) {
- return 1;
- } else if ($a[0]['y'] < $b[0]['y']) {
- return -1;
- } else if ($a[0]['groups'][0]['x'] > $b[0]['groups'][0]['x']) {
- return 1;
- } else if ($a[0]['groups'][0]['x'] < $b[0]['groups'][0]['x']) {
- return -1;
- }
- return 0;
- }
-
- protected function writeLine($line) {
- $line['y'] = $this->getCSSY($line['y'] * $this->multiply);
-
- $class = array('l');
- if (!is_null($line['y'])) {
- $class[] = 'y' . $line['y'];
- }
-
- $class = implode(' ', $class);
-
- $res = '<div class="' . $class . '">';
- foreach ($line['groups'] as $group) {
- $res.=$this->writeGroup($group, $line);
- }
- $res.='</div>';
- return $res;
- }
-
- protected function writeGroup($group, $line) {
- if ($group === false) {
- return '';
- }
-
- $class = array('g');
- if (!is_null($group['color'])) {
- $class[] = 'c' . $group['color'];
- }
- if (!is_null($group['size'])) {
- $class[] = 's' . $group['size'];
- }
- if (!is_null($group['font']['index'])) {
- $class[] = 'f' . $group['font']['index'];
- }
-
- $class = implode(' ', $class);
-
- $res = '<div class="' . $class . '">';
- foreach ($group['spans'] as $span) {
- $res.=$this->writeSpan($span, $line);
- }
- $res.='</div>';
- return $res;
- }
-
- protected function writeSpan($span, $line) {
- if ($span === false) {
- return '';
- }
-
-
- $span['x'] = $this->getCSSX(($span['x']) * $this->multiply);
-
- $class = array('s');
- if ($span['text'] == ' ') {
- $class[] = 'b';
- }
- if (!is_null($span['x'])) {
- $class[] = 'x' . $span['x'];
- }
- if ($span['text'] == ' ') {
- $class[] = 'b' . $this->getCSSWidth($span['width'] * $this->multiply);
- }
- if (!is_null($line['transform'])) {
- $class[] = 't' . $line['transform'];
- }
-
- if (!is_null($span['letterspacing'])) {
- $class[] = 'l' . $span['letterspacing'];
- }
-
- $class = implode(' ', $class);
-
- $res = '<div class="' . $class . '">';
- $res.=self::escapeHTML($span['text']);
- $res.='</div>';
- return $res;
- }
-
protected function writeCSS($file, $links) {
$res = array();
$res[] = '#index .doubleThumb .overlay{height:' . $thumbh . 'px;}';
$res[] = '#index .doubleThumb .hits.yes{background-color:' . self::colorToCSS($this->theme->parametres->subSelectColor) . ';color:' . self::colorToCSS($this->theme->parametres->subTextSelectColor) . '}';
- // Pages styles
- foreach ($this->cssColor as $color => $index) {
- $res[] = '.c' . $index . '{color:#' . $color . '}';
- }
-
- foreach ($this->cssSize as $size => $index) {
- $res[] = '.s' . $index . '{font-size:' . $size . 'px}';
- }
-
- foreach ($this->cssLetterSpacing as $letterspacing => $index) {
- $res[] = '.l' . $index . '{letter-spacing:' . $letterspacing . 'em}';
- }
-
- foreach ($this->cssX as $x => $index) {
- $res[] = '.x' . $index . '{left:' . $x . 'px}';
- }
-
- foreach ($this->cssY as $y => $index) {
- $res[] = '.y' . $index . '{top:' . $y . 'px}';
- }
-
- foreach ($this->cssWidths as $w => $index) {
- $res[] = '.b' . $index . '{width:' . $w . 'px}';
- }
-
-
- foreach ($this->cssTransform as $transform => $index) {
- list($rotation, $scaleX, $scaleY, $translateX, $translateY) = explode(',', $transform);
-
- $rotation*= - 1;
-
- $t = array();
- if ($rotation != 0) {
- $t[] = 'rotate(' . $rotation . 'deg)';
- }
- if ($scaleX != 1 || $scaleY != 1) {
- $t[] = 'scale(' . $scaleX . ',' . $scaleY . ')';
- }
- if ($translateX != '0' || $translateY != '') {
- $t[] = 'translate(' . $translateX . ',' . $translateY . ')';
- }
-
- $css = '.t' . $index . '{';
- $css.=self::writeCSSUA('transform', implode(' ', $t)) . ';';
- $css.=self::writeCSSUA('transform-origin', 'left top') . ';';
- $css.='}';
- $res[] = $css;
- }
-
- foreach ($this->cssFont as $font => $infos) {
- $index = $infos['index'];
- $style = $infos['oblique'] ? 'oblique' : 'normal';
- $res[] = "@font-face{font-family:F" . $index . ";font-style:all;src:url('F" . $index . ".ttf') format('truetype'),url('F" . $index . ".woff') format('woff'),url('F" . $index . ".svg#" . $font . "') format('svg')}";
- $res[] = '.f' . $index . '{font-family:F' . $index . ',Arial,Helvetica;}';
- }
-
$res = array_chunk($res, 3500);
foreach ($res as $k => $css) {
file_put_contents(sprintf($file, $k), implode("\n", $css));
return implode(';', $res);
}
- protected function addLine($line, $document_id) {
- $res = array();
- if (count($line->a) > 1) {
- $line = $this->sortLine($line);
- }
- foreach ($line->a as $group) {
- $res[] = $this->addGroup($group, $document_id);
- }
- return array(
- 'y' => $this->normalizeFloatValue($line['y']),
- 'transform' => $this->getCSSTransform($line['rotation'], $line['scaleX'], $line['scaleY']),
- "groups" => $res);
- }
-
- protected function sortLine($line) {
- $debug = rand(1, 20) == 5;
-
-
- // Copy the current line to a new one
- $l = simplexml_load_string('<l />');
- foreach ($line->attributes() as $k => $v) {
- $l->addAttribute($k, $v);
- }
-
- // Get the s elements and sort them by x
- $tab = array();
- $allSpans = $line->xpath("a/s");
- foreach ($allSpans as $span) {
- $tab[] = $span;
- }
-
- usort($tab, array('wsHTML5Compiler', 'sortSpans'));
-
- $currentGroup = null;
- $lastParent = null;
- foreach ($tab as $span) {
- $parents = $span->xpath("..");
- $parent = array_pop($parents);
- if ($parent == $lastParent) {
- cubeXML::append($currentGroup, $span);
- continue;
- }
- if (!is_null($currentGroup)) {
- cubeXML::append($l, $currentGroup);
- }
-
- $lastParent = $parent;
- $currentGroup = simplexml_load_string('<a />');
- foreach ($parent->attributes() as $k => $v) {
- $currentGroup->addAttribute($k, $v);
- }
- cubeXML::append($currentGroup, $span);
- }
-
- if (!is_null($currentGroup)) {
- cubeXML::append($l, $currentGroup);
- }
- return $l;
- }
-
- protected static function sortSpans($a, $b) {
- $xa = floatval((string) $a['x']);
- $xb = floatval((string) $b['x']);
-
- if ($xa > $xb) {
- return 1;
- } else if ($xa < $xb) {
- return -1;
- }
- return 0;
- }
-
- protected function addGroup($group, $document_id) {
- $alpha = intval(substr($group['color'], 1, 2), 16);
- if ($alpha == 0) {
- return false;
- }
-
- $spans = array();
- foreach ($group->s as $span) {
- $spans[] = $this->addSpan($span);
- }
-
-
- return array(
- 'color' => $this->getCSSColor($group['color']),
- 'size' => $this->getCSSSize($group['size']),
- 'font' => $this->getCSSFont($group['font'], $group['oblique'] == 'true', $document_id),
- 'y' => 0,
- 'x' => $group['x'],
- 'oblique' => ($group['oblique'] == 'true'),
- 'spans' => $spans
- );
- }
-
- protected function addSpan($span) {
- return array(
- 'x' => $span['x'],
- 'width' => $span['width'],
- 'letterspacing' => $this->getCSSLetterSpacing($span['letterspacing']),
- 'text' => (string) $span
- );
- }
-
- protected function getCSSSize($size) {
- $os = $size;
- $size = $this->normalizeFloatValue($size);
- $size*=$this->multiply;
- return $this->getIndex($size, $this->cssSize);
- }
-
- protected function getCSSFont($font, $oblique, $document_id) {
- $font = (string) $font;
- $e = explode('+', $font);
- if (count($e) > 1) {
- array_shift($e);
- $font = implode('+', $e);
- }
-
- if (!isset($this->fontDocs[$font])) {
- $this->fontDocs[$font] = array();
- }
- $this->fontDocs[$font][$document_id] = true;
-
- $idx = $this->getIndex($font, $this->cssFont, array('oblique' => $oblique));
-
- return $idx;
- }
-
- protected function getCSSColor($color) {
- $color = trim($color, '#');
- if (strlen($color) > 6) {
- $color = substr($color, 2, 6);
- }
- if ($color == '000000') {
- return null;
- }
- return $this->getIndex($color, $this->cssColor);
- }
-
- protected function getCSSLetterSpacing($letterspacing) {
-
- $letterspacing = $this->normalizeFloatValue($letterspacing, 4);
-
- if ($letterspacing == 0) {
- return null;
- }
- return $this->getIndex($letterspacing, $this->cssLetterSpacing);
- }
-
- protected function getCSSWordSpacing($wordspacing) {
- $wordspacing = $this->normalizeFloatValue($wordspacing, 4);
-
- if ($wordspacing == 0) {
- return null;
- }
- return $this->getIndex($wordspacing, $this->cssWordSpacing);
- }
-
- protected function getCSSTransform($rotation, $scaleX, $scaleY) {
- $rotation = $this->normalizeFloatValue($rotation, 0);
- $scaleX = $this->normalizeFloatValue($scaleX, 3);
- $scaleY = $this->normalizeFloatValue($scaleY, 3);
- if ($scaleX < 0) {
- $scaleX*=-1;
- }
- if ($scaleY < 0) {
- $scaleY*=-1;
- }
-
- return $this->getIndex($rotation . ',' . $scaleX . ',' . $scaleY . ',0,-0.8em', $this->cssTransform);
- }
-
- protected function getCSSX($x) {
- $x = round($x);
- if ($x == 0) {
- return null;
- }
- return $this->getIndex($x, $this->cssX);
- }
-
- protected function getCSSY($y) {
- $y = round($y);
- if ($y == 0) {
- return null;
- }
- return $this->getIndex($y, $this->cssY);
- }
-
- protected function getCSSWidth($w) {
- $w = $this->normalizeFloatValue($w, 4);
- if ($w == 0) {
- return null;
- }
- return $this->getIndex($w, $this->cssWidths);
- }
-
- protected function getIndex($value, &$tab, $params = array()) {
- $value = (string) $value;
- if (isset($tab[$value])) {
- return $tab[$value];
- }
- $res = $this->base62(count($tab));
- if (!count($params)) {
- $tab[$value] = $res;
- } else {
- $tab[$value] = array_merge(array('index' => $res), $params);
- }
- return $tab[$value];
- }
-
- protected function normalizeFloatValue($value, $round = 3) {
- $value = str_replace(',', '.', $value);
- $value = (float) $value;
- $value = round($value, $round);
- return $value;
- }
-
- protected function base62($val) {
- $chars = '0123456789abcdefghijklmnopqrstuvwxyz';
- $base = strlen($chars);
- $str = '';
- do {
- $i = $val % $base;
- $str = $chars[$i] . $str;
- $val = ($val - $i) / $base;
- } while ($val > 0);
- return $str;
- }
-
public function copyLinkFile($source, $dest, $video = false) {
$origDir = WS_BOOKS . '/working/' . $this->book_id . '/';
$types = array('flv', 'mp4', 'ogv', 'webm', 'jpg');
}
}
- public static function escapeHTML($in) {
-
- //$in = htmlentities($in, ENT_NOQUOTES, "UTF-8");
- $in = str_replace(' ', '', $in);
-
-
- return $in;
- }
-
public function __destruct() {
}