From: vincent@cubedesigners.com Date: Sat, 17 Mar 2012 15:00:13 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=fca56c35e53e86d89d7658da89665b8a43f2319d;p=cubeextranet.git --- diff --git a/fluidbook/tools/fwstk/nbproject/private/private.properties b/fluidbook/tools/fwstk/nbproject/private/private.properties index 12e72ab29..a3838e51e 100644 --- a/fluidbook/tools/fwstk/nbproject/private/private.properties +++ b/fluidbook/tools/fwstk/nbproject/private/private.properties @@ -4,4 +4,4 @@ do.depend=false do.jar=true javac.debug=true javadoc.preview=true -user.properties.file=C:\\Users\\Vincent\\.netbeans\\7.1\\build.properties +user.properties.file=C:\\Users\\Cube\\.netbeans\\7.1\\build.properties diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 62fe16b55..547341dbc 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -39,7 +39,6 @@ class wsDocument extends cubeMetier { protected $pages_log_pointers; protected $infos; protected $cropped; - protected $uncropped; protected $rgb; const NORMAL = 0; @@ -73,8 +72,6 @@ class wsDocument extends cubeMetier { mkdir($this->html, 0755); } $this->cropped = $this->out . 'crop.pdf'; - $this->rgb = $this->out . 'rgb.pdf'; - $this->uncropped = $this->out . 'uncrop.pdf'; $this->pages_log_pointers = array(); if (is_null($this->conversionInfos)) { @@ -84,14 +81,12 @@ class wsDocument extends cubeMetier { public function copyOriginalFromUpload($tmp_file) { move_uploaded_file($tmp_file, $this->in); - $this->uncropDocument(); } public function copyOriginalFromOlderVersion() { if (!file_exists($this->in)) { copy('http://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in); } - $this->uncropDocument(); } public function extractFonts() { @@ -264,47 +259,10 @@ class wsDocument extends cubeMetier { if ($this->CropAndCut()) { $this->getInfos($this->cropped, true); } - $this->performColorTransformations(); - $this->extractFonts(); + //$this->extractFonts(); $this->getLinksAndTexts(); } - public function performColorTransformations() { - $out = $this->out . '/rgb.pdf'; - - /*$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'); - // Device - $gs->setArg('-sDEVICE=pdfwrite'); - // - $gs->setArg('-dDownsampleColorImages=false'); - $gs->setArg('-dDownsampleGrayImages=false'); - $gs->setArg('-dDownsampleMonoImages=false'); - $gs->setArg('-dColorImageResolution=300'); - $gs->setArg('-dMonoImageResolution=600'); - $gs->setArg('-dGreyImageResolution=300'); - - // Dispotion & colors - $gs->setArg('-dConvertCMYKImagesToRGB=true'); - $gs->setArg('-dAutoRotatePages=/None'); - $gs->setArg('-dUseCropBox'); - $gs->setArg('-dShowAnnots=false'); - // Performances - $gs->setArg('-dNumRenderingThreads=4'); - // Page range - // Files - $gs->setArg('-sOutputFile=' . $out); - - $gs->setArg(null, $this->cropped); - $gs->execute(); - - $this->addToLog($gs);*/ - } - public function CropAndCut() { if (!$this->isCropped()) { copy($this->in, $this->cropped); @@ -343,18 +301,7 @@ class wsDocument extends cubeMetier { $this->addToLog($fwstk); } - public function uncropDocument() { - $fwstk = new cubeCommandLine('fwstk'); - $fwstk->setPath(CONVERTER_PATH); - $fwstk->setArg('--input ' . $this->in); - $fwstk->setArg('--reset'); - $fwstk->setArg('--output ' . $this->uncropped); - $fwstk->execute(); - $this->addToLog($fwstk); - } - public function processOnePage($page, $force = true) { - // $this->makeRealShot($page); if ($force) { $this->addToLog('Processing page #' . $page); $this->makeMiniShot($page); @@ -384,47 +331,20 @@ class wsDocument extends cubeMetier { $fwstk->execute(); $this->addToLog($fwstk); - $fwstk = new cubeCommandLine('fwstk'); + /*$fwstk = new cubeCommandLine('fwstk'); $fwstk->setPath(CONVERTER_PATH); $fwstk->setArg('--input ' . $this->cropped); $fwstk->setArg('--layout ' . $this->html . 'p%d.layout'); $fwstk->setArg('--cmaps ' . $this->html); $fwstk->setArg('--fonts' . $this->out . 'fonts/web/'); $fwstk->execute(); - $this->addToLog($fwstk); - - /* $temp = cubeFiles::tempnam(); - $pdftotext = new cubeCommandLine('pdftotext', null, true); - $pdftotext->setPath(CONVERTER_PATH); - $pdftotext->setArg('q'); - $pdftotext->setArg('-eol', 'unix'); - $pdftotext->setArg('-enc', 'UTF-8'); - $pdftotext->setArg(null, $this->cropped); - $pdftotext->setArg(null, $temp); - $pdftotext->execute(); - $this->addToLog($pdftotext); - - $pages = explode("\f", file_get_contents($temp)); - foreach($pages as $i => $page) { - $i++; - $txt = mb_strtolower($page); - $txt = cubeText::removeAccents($txt); - $txt = trim($txt); - - file_put_contents($this->out . 'p' . $i . '.txt', $txt); - } - - unlink($temp); */ + $this->addToLog($fwstk);*/ } public function makeMiniShot($page) { $this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'PNM'); } - public function makeRealShot($page) { - $this->makeShot($page, 'te', 150, 60, 4, 'GS', $this->uncropped); - } - public function makeShotFixedWidth($page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM') { // Make thumbs of $w width // resolution 72 make 1pt=1px @@ -618,13 +538,11 @@ class wsDocument extends cubeMetier { public function makeHTML5Files($page) { // Then make HD background shots - $resolutions = array(36 => 90, 72 => 80, 150 => 75); + $resolutions = array(150 => 75); foreach ($resolutions as $r => $q) { $this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, false); $this->makeShotPNM($page, 'html/t' . $r . '-', $r, $q, 4, null, true); } - // Then get layout infos from swf - file_put_contents($this->out . '/html/s' . $page . '.layout', $this->dumpSWF($page)); } protected function checkObjectsNumber($file, $maxObjects, $page) { diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index a288d089a..2dfb6c4fc 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -2,7 +2,7 @@ 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', @@ -30,14 +30,6 @@ class wsHTML5Compiler { '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(); @@ -97,13 +89,6 @@ class wsHTML5Compiler { $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']; @@ -145,24 +130,6 @@ class wsHTML5Compiler { 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); @@ -194,10 +161,6 @@ class wsHTML5Compiler { // 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); @@ -368,30 +331,6 @@ class wsHTML5Compiler { 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 @@ -437,131 +376,6 @@ class wsHTML5Compiler { 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 = '
'; - foreach ($line['groups'] as $group) { - $res.=$this->writeGroup($group, $line); - } - $res.='
'; - 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 = '
'; - foreach ($group['spans'] as $span) { - $res.=$this->writeSpan($span, $line); - } - $res.='
'; - 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 = '
'; - $res.=self::escapeHTML($span['text']); - $res.='
'; - return $res; - } - protected function writeCSS($file, $links) { $res = array(); @@ -732,62 +546,6 @@ class wsHTML5Compiler { $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)); @@ -803,236 +561,6 @@ class wsHTML5Compiler { 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(''); - 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(''); - 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'); @@ -1066,15 +594,6 @@ class wsHTML5Compiler { } } - public static function escapeHTML($in) { - - //$in = htmlentities($in, ENT_NOQUOTES, "UTF-8"); - $in = str_replace(' ', '', $in); - - - return $in; - } - public function __destruct() { }