]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Sat, 17 Sep 2011 13:58:08 +0000 (13:58 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Sat, 17 Sep 2011 13:58:08 +0000 (13:58 +0000)
fluidbook/tools/convert.pe
inc/ws/Util/_common.php
inc/ws/Util/class.ws.pdf.fontextractor.php [deleted file]
inc/ws/Util/fontextractor/class.ws.pdf.font.php [new file with mode: 0644]
inc/ws/Util/fontextractor/class.ws.pdf.fontextractor.php [new file with mode: 0644]
inc/ws/Util/html5/class.ws.html5.compiler.php

index 6a0eab3520584729f6ab34016f7ba0c82d6da64f..1ef60a3a0c5d4da94e50a96cec05d41099a43797 100644 (file)
@@ -10,6 +10,7 @@ endloop
 
 //
 if($argv[i]!="-")
+       Print("Rewrite font with CMAP ",$argv[i]);
        cmap=LoadStringFromFile($argv[i])
        glyphs=StrSplit(cmap,"\\n");
        j=0
index 65010ba508544ba8d36e0f10cf1ccb700f57335a..5edcef271422758e09c2d588058817c596fb1002 100644 (file)
@@ -11,5 +11,6 @@ $__autoload['wsSecureSWF'] = dirname(__FILE__) . '/class.ws.secure.swf.php';
 $__autoload['wsTools'] = dirname(__FILE__) . '/class.ws.tools.php';\r
 $__autoload['wsHTML5Compiler'] = dirname(__FILE__) . '/html5/class.ws.html5.compiler.php';\r
 $__autoload['wsHTML5Link'] = dirname(__FILE__) . '/html5/class.ws.html5.links.php';\r
-$__autoload['wsPDFFontExtractor'] = dirname(__FILE__) . '/class.ws.pdf.fontextractor.php';\r
+$__autoload['wsPDFFontExtractor'] = dirname(__FILE__) . '/fontextractor/class.ws.pdf.fontextractor.php';\r
+$__autoload['wsPDFFont'] = dirname(__FILE__) . '/fontextractor/class.ws.pdf.font.php';\r
 ?>
\ No newline at end of file
diff --git a/inc/ws/Util/class.ws.pdf.fontextractor.php b/inc/ws/Util/class.ws.pdf.fontextractor.php
deleted file mode 100644 (file)
index 3d2bbc6..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-<?php
-
-class wsPDFFontExtractor {
-
-       protected $in;
-       protected $outpdf;
-       protected $outweb;
-       protected $fonts = array();
-       protected $cmaps = array();
-       protected $descendants = array();
-       protected $descendantNames = array();
-       protected $doc;
-
-       public function __construct($in, $doc=null) {
-               $this->doc = $doc;
-               $this->in = $in . '/original.pdf';
-               $this->outpdf = $in . '/fonts/pdf';
-               $this->outweb = $in . '/fonts/web';
-       }
-
-       public function extract() {
-               $this->clean();
-
-               $this->getFonts();
-               $this->getFontsDescriptors();
-               $this->extractFonts();
-               $this->extractCmaps();
-               $this->convertToTTF();
-       }
-
-       public function convertToTTF() {
-
-
-
-               $dr = opendir($this->outpdf);
-               while ($file = readdir($dr)) {
-                       if ($file == '.' || $file == '..' || files::getExtension($file) == 'cmap') {
-                               continue;
-                       }
-
-                       $e = explode('.', $file);
-                       array_pop($e);
-                       $fname = implode('.', $e);
-
-                       $e = explode('-', $fname);
-                       array_pop($e);
-                       $fname = implode('-', $e);
-
-                       if (!isset($collections[$fname])) {
-                               $collections[$fname] = array();
-                       }
-                       $collections[$fname][] = $file;
-               }
-
-               foreach ($collections as $fontname => $files) {
-                       $descendant = array_keys($this->descendantNames, $fontname);
-                       if (count($descendant)) {
-                               $f = array_keys($this->descendants, $descendant[0]);
-                               $fontname = $f[0];
-                       }
-
-
-                       $fontforge = new cubeCommandLine('convert.pe');
-                       $fontforge->setPath(CONVERTER_PATH);
-                       foreach ($files as $file) {
-                               $fontforge->setArg(null, $this->outpdf . '/' . $file);
-                       }
-                       $cmapFile = $this->outpdf . '/' . $fontname . '.cmap';
-                       if (!file_exists($cmapFile)) {
-                               $fontforge->setArg(null, '-');
-                       } else {
-                               $fontforge->setArg(null, $cmapFile);
-                       }
-                       $fontforge->setArg(null, $this->outweb . '/' . $fontname . '.ttf');
-                       $fontforge->execute();
-                       $this->addToLog($fontforge);
-               }
-       }
-
-       public function getFonts() {
-               $pdfinfo = $this->getCommandLine('pdfinfo');
-               $pdfinfo->setArg('f');
-               $pdfinfo->setArg(null, $this->in);
-               $pdfinfo->execute();
-
-               $this->addToLog($pdfinfo);
-
-               /*
-                * /home/extranet/www/fluidbook/docs/100376/original.pdf:
-
-                 PDF-1.7
-                 Info object (9177 0 R):
-                 <<
-                 /CreationDate (D:20110831090005+02'00')
-                 /Creator (Adobe InDesign CS5 \(7.0\))
-                 /ModDate (D:20110901144502+02'00')
-                 /Producer (Adobe PDF Library 9.9)
-                 /Trapped /False
-                 >>
-
-                 Pages: 116
-
-                 Retrieving info from pages 1-116...
-                 Fonts (201):
-                 1 (   9180 0 R): Type1 'QGNYEE+AvantGarde-Book' (9193 0 R)
-                 1 (   9180 0 R): Type1 'QGNYEE+AvantGarde-ExtraLight' (9195 0 R)
-                 2 (      1 0 R): Type1 'QGNYEE+DIN-Light' (7605 0 R)
-                 2 (      1 0 R): Type1 'QGNYEE+AvantGarde-ExtraLightObl' (7608 0 R)
-                 2 (      1 0 R): Type1 'QGNYEE+AvantGarde-MediumObl' (7601 0 R)
-
-                */
-
-               if (preg_match_all("|\s+\d+\s+\(\s+\d+\s+\d+\s+\w+\):\s+\w+\s+'([A-Za-z-+]+)'\s+\((\d+)\s+\d+\s+\w+\)\s|", $pdfinfo->output, $matches)) {
-                       foreach ($matches[1] as $k => $name) {
-                               $this->fonts[$matches[2][$k]] = array('name' => $name);
-                       }
-               }
-       }
-
-       protected function getFontsDescriptors() {
-               $pdfshow = $this->getCommandLine('pdfshow');
-               $pdfshow->setArg(null, $this->in);
-               $pdfshow->setManualArg(implode(' ', array_keys($this->fonts)));
-               $pdfshow->execute();
-               $this->doc->addToLog($pdfshow);
-
-               /*
-                 8677 0 obj
-                 <<
-                 /BaseFont /YIKUMO+Futura-Condensed
-                 /Encoding /WinAnsiEncoding
-                 /FirstChar 32
-                 /FontDescriptor 7690 0 R
-                 /LastChar 119
-                 /Subtype /Type1
-                 /Type /Font
-                 /Widths [ 205 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-                 0 0 0 0 0 0 0 0 0 414 418 0 466 0 342 0 0 0 303 0 0 561 0
-                 0 388 0 0 354 0 0 0 0 0 0 0 0 0 0 0 0 0 380 380 0 380 361
-                 0 382 388 180 0 395 180 590 388 375 380 0 269 276 221 389
-                 0 487 ]
-                 >>
-                 endobj
-
-                 9193 0 obj
-                 <<
-                 /BaseFont /QGNYEE+AvantGarde-Book
-                 /Encoding /WinAnsiEncoding
-                 /FirstChar 32
-                 /FontDescriptor 9192 0 R
-                 /LastChar 201
-                 /Subtype /Type1
-                 /ToUnicode 9185 0 R
-                 /Type /Font
-                 /Widths [ 277 0 0 0 0 0 0 0 0 0 0 0 277 332 0 0 554 554 554
-                 0 0 0 554 554 0 0 0 0 0 0 0 0 0 740 574 813 744 536 485 872
-                 683 226 482 0 462 919 740 869 592 0 607 498 426 655 702 0
-                 0 592 480 0 0 0 0 0 0 683 0 0 0 650 0 0 0 200 0 0 200 0 610
-                 655 0 0 301 388 339 0 554 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000
-                 0 0 0 0 0 0 0 0 0 0 0 0 351 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-                 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-                 0 740 0 0 0 0 0 0 0 0 536 ]
-                 >>
-                 endobj
-                * 
-                 10 0 obj
-                 <<
-                 /BaseFont /FuturaLT-Bold--Identity-H
-                 /DescendantFonts [ 11 0 R ]
-                 /Encoding /Identity-H
-                 /Name /F0
-                 /Subtype /Type0
-                 /ToUnicode 3881 0 R
-                 /Type /Font
-                 >>
-                 endobj
-
-                */
-
-               $lines = explode("\n", $pdfshow->output);
-               $currentFont = null;
-               foreach ($lines as $line) {
-                       $line = trim($line);
-                       if ($line == '' || $line == '<<' || $line == '>>') {
-                               continue;
-                       }
-                       if ($line == 'endobj') {
-                               $currentFont = null;
-                               continue;
-                       }
-                       $e = explode(' ', $line);
-                       if (count($e) == 3 && $e[2] == 'obj') {
-                               $currentFont = $e[0];
-                               continue;
-                       }
-
-                       if (is_null($currentFont)) {
-                               continue;
-                       }
-
-                       $fontname = $this->fonts[$currentFont]['name'];
-
-                       if ($e[0] == '/ToUnicode') {
-                               $this->fonts[$currentFont]['cmap'] = $e[1];
-                               $this->cmaps[$fontname] = $e[1];
-                       }
-
-                       if ($e[0] == '/DescendantFonts') {
-                               $this->fonts[$currentFont]['descendant'] = $e[2];
-                               $this->descendants[$fontname] = $e[2];
-                       }
-               }
-
-               $this->manageDescendants();
-
-               $this->addToLog(print_r($this->fonts, true));
-       }
-
-       protected function manageDescendants() {
-               if (!count($this->descendants)) {
-                       return;
-               }
-
-               $pdfshow = $this->getCommandLine('pdfshow');
-               $pdfshow->setArg(null, $this->in);
-               $pdfshow->setManualArg(implode(' ', $this->descendants));
-               $pdfshow->execute();
-               $this->doc->addToLog($pdfshow);
-
-               /*
-                 11 0 obj
-                 <<
-                 /BaseFont /EHLOJB+FuturaLT-Bold-OV-JVKOJB
-                 /CIDSystemInfo <<
-                 /Ordering (Identity)
-                 /Registry (Adobe)
-                 /Supplement 0
-                 >>
-                 /DW 343
-                 /FontDescriptor 3878 0 R
-                 /Name /F0
-                 /Subtype /CIDFontType0
-                 /Type /Font
-                 /W [ 1 [ 781 ] 4 [ 781 ] 9 [ 677 660 ] 12 [ 752 550 550 550 ]
-                 17 [ 550 ] 20 [ 542 842 803 324 ] 26 [ 324 ] 28 [ 489 ] 30
-                 [ 495 ] 32 [ 983 881 ] 35 [ 887 ] 43 [ 661 887 680 616 ]
-                 48 [ 533 ] 50 [ 778 ] 55 [ 761 ] 57 [ 789 ] 61 [ 707 ] 63
-                 [ 682 ] 77 [ 682 ] 87 [ 483 ] 93 [ 343 343 ] 97 [ 682 ] 106
-                 [ 610 610 610 ] 111 [ 686 ] 119 [ 388 ] 121 [ 689 ] 124 [
-                 686 ] 126 [ 677 ] 134 [ 661 ] 136 [ 392 ] 138 [ 302 ] 140
-                 [ 302 302 ] 149 [ 989 ] 154 [ 661 ] 156 [ 686 ] 159 [ 662 ]
-                 167 [ 686 ] 175 [ 682 ] 180 [ 343 ] 193 [ 372 ] 196 [ 453 ]
-                 199 [ 513 ] 203 [ 686 686 ] 208 [ 360 ] 210 [ 686 ] 215 [
-                 686 ] 217 [ 659 ] 232 [ 686 ] ]
-                 >>
-                 endobj
-
-                */
-
-               $currentDescendant = null;
-               $lines = explode("\n", $pdfshow->output);
-               foreach ($lines as $line) {
-                       $line = trim($line);
-                       $e = explode(' ', $line);
-                       if (count($e) == 3 && $e[2] == "obj") {
-                               $currentDescendant = $e[0];
-                       }
-                       if ($line == 'endobj') {
-                               $currentDescendant = null;
-                       }
-
-                       if (is_null($currentDescendant)) {
-                               continue;
-                       }
-
-                       if ($e[0] == '/BaseFont') {
-                               $this->descendantNames[$currentDescendant] = trim($e[1], "/");
-                       }
-               }
-
-               $this->addToLog('Descendant names : ' . print_r($this->descendantNames, true));
-       }
-
-       protected function extractFonts() {
-               $descriptors = $this->getUniqueId('descriptor');
-
-               $pdfextract = $this->getCommandLine('pdfextract');
-               $pdfextract->setArg(null, $this->in);
-               $pdfextract->execute();
-               $this->addToLog($pdfextract);
-
-
-               $formats = array('pnm', 'pam', 'pgm', 'jpg', 'gif', 'jpeg', 'png');
-               foreach ($formats as $f) {
-                       `rm $this->outpdf/*.$f`;
-               }
-       }
-
-       protected function extractCmaps() {
-               $cmaps = array_unique($this->cmaps);
-
-               $pdfshow = $this->getCommandLine('pdfshow');
-               $pdfshow->setArg(null, $this->in);
-               $pdfshow->setManualArg(implode(' ', $cmaps));
-               $pdfshow->execute();
-               $this->addToLog($pdfshow);
-
-
-               /* 5266 0 obj
-                 <<
-                 /Filter /FlateDecode
-                 /Length 583
-                 >>
-                 stream
-                 /CIDInit /ProcSet findresource begin
-                 12 dict begin
-                 begincmap
-                 /CIDSystemInfo
-                 << /Registry (Adobe)
-                 /Ordering (UCS) /Supplement 0 >> def
-                 /CMapName /Adobe-Identity-UCS def
-                 /CMapType 2 def
-                 1 begincodespacerange
-                 <0000> <FFFF>
-                 endcodespacerange
-                 81 beginbfchar
-                 <0000> <0020>
-                 <0001> <0021>
-                 <0005> <0025>
-                 <0007> <2019>
-                 <0008> <0028>
-                 <0009> <0029>
-                 <000C> <002C>
-                 <000D> <002D>
-                 <000E> <002E>
-                 <000F> <002F>
-                 endbfchar
-                 endcmap CMapName currentdict /CMap defineresource pop end end
-                 endstream
-                 endobj
-
-                */
-
-               $finalCmaps = array();
-
-               $lines = explode("\n", $pdfshow->output);
-               $currentCmap = null;
-               $inMap = false;
-               foreach ($lines as $line) {
-                       $line = trim($line);
-                       if ($line == '') {
-                               continue;
-                       }
-                       if ($line == 'endobj') {
-                               $currentCmap = null;
-                               continue;
-                       } elseif ($line == 'endbfchar') {
-                               $inMap = false;
-                       }
-
-                       $e = explode(' ', $line);
-                       if (count($e) == 3 && $e[2] == 'obj') {
-                               $currentCmap = $e[0];
-                               continue;
-                       }
-
-                       if (count($e) == 2 && $e[1] == 'beginbfchar') {
-                               $inMap = true;
-                               continue;
-                       }
-
-                       if (!$inMap || is_null($currentCmap)) {
-                               continue;
-                       }
-
-                       $fonts = array_keys($this->cmaps, $currentCmap);
-
-                       $from = trim($e[0], '<>');
-                       $to = trim($e[1], '<>');
-
-                       foreach ($fonts as $fontname) {
-                               if (!isset($finalCmaps[$fontname])) {
-                                       $finalCmaps[$fontname] = array();
-                               }
-
-                               if (strlen($to) >= 8) {
-                                       $toc = $to;
-                                       $to = $this->manageLigatures($to);
-                                       $this->addToLog('Correct ligature ' . $toc . ' -> ' . $to);
-                               }
-
-                               $finalCmaps[$fontname][$from] = $to;
-                       }
-               }
-
-               foreach ($finalCmaps as $fontname => $cmap) {
-                       arsort($cmap);
-                       $data = '';
-                       foreach ($cmap as $from => $to) {
-                               $data.=$from . "\t" . $to . "\n";
-                       }
-
-                       $this->addToLog('Write cmap for font ' . $fontname . ' in ' . $this->outpdf . '/' . $fontname . '.cmap');
-
-                       file_put_contents($this->outpdf . '/' . $fontname . '.cmap', $data);
-               }
-       }
-
-       protected function manageLigatures($code) {
-               $codes = str_split($code, 4);
-               $str = '';
-               foreach ($codes as $c) {
-                       $str.=chr(intval($c, 16));
-               }
-
-               $ligatures = array('AE' => '00C6', 'ae' => '00E6',
-                       'OE' => '0152', 'oe' => '0152',
-                       'IJ' => '0132', 'ij' => '0133',
-                       'ff' => 'fb00',
-                       'fi' => 'fb01',
-                       'fl' => 'fb02',
-                       'ffi' => 'fb03',
-                       'ffl' => 'fb04');
-
-               // Si un couple est une ligature standard
-               if (isset($ligatures[$str])) {
-                       return $ligatures[$str];
-               }
-               // Sinon, on ne retourne que le premier code
-               return $codes[0];
-       }
-
-       protected function getUniqueId($param) {
-               $res = array();
-               foreach ($this->fonts as $f) {
-                       if (isset($f[$param])) {
-                               $res[$id] = $f[$param];
-                       }
-               }
-               return array_unique($res);
-       }
-
-       protected function clean() {
-               `rm -rf $this->outpdf`;
-               `rm -rf $this->outweb`;
-               mkdir($this->outweb, 0777, true);
-               mkdir($this->outpdf, 0777, true);
-       }
-
-       protected function getCommandLine($program) {
-               $res = new cubeCommandLine('/usr/local/mupdf/' . $program);
-               $res->cd($this->outpdf);
-               $res->setPath(CONVERTER_PATH);
-               return $res;
-       }
-
-       protected function addToLog($tolog) {
-               if (!is_null($this->doc)) {
-                       $this->doc->addToLog($tolog);
-               } elseif ($tolog instanceof cubeCommandLine) {
-                       echo $tolog->commande . "\n\n";
-                       echo $tolog->output . "\n\n";
-               } else {
-                       echo $tolog . "\n\n";
-               }
-       }
-
-}
-
-?>
diff --git a/inc/ws/Util/fontextractor/class.ws.pdf.font.php b/inc/ws/Util/fontextractor/class.ws.pdf.font.php
new file mode 100644 (file)
index 0000000..9d0f2a9
--- /dev/null
@@ -0,0 +1,303 @@
+<?php
+
+class wsPDFFont {
+
+       protected $id;
+       protected $name;
+       protected $descendant = null;
+       protected $extractor;
+       protected $cmap_id = null;
+       protected $descriptor_id = null;
+       protected $font_file_id = null;
+       protected static $ligatures = array('AE' => '00C6', 'ae' => '00E6',
+               'OE' => '0152', 'oe' => '0152',
+               'IJ' => '0132', 'ij' => '0133',
+               'ff' => 'fb00',
+               'fi' => 'fb01',
+               'fl' => 'fb02',
+               'ffi' => 'fb03',
+               'ffl' => 'fb04');
+
+       public function __construct(&$extractor, $id, $name='') {
+               $this->extractor = $extractor;
+               $this->id = $id;
+               $this->name = $name;
+
+               $this->getInfos();
+               $this->getDescriptor();
+       }
+
+       public function getDescriptor() {
+               if (is_null($this->getDescriptorId())) {
+                       return;
+               }
+               /*
+                 213 0 obj
+                 <<
+                 /Ascent 951
+                 /CapHeight 714
+                 /CharSet (/period/A/B/D/E/G/L/M/O/U)
+                 /Descent -216
+                 /Flags 32
+                 /FontBBox [ -164 -216 1031 951 ]
+                 /FontFamily (HelveticaNeue MediumCond)
+                 /FontFile3 212 0 R
+                 /FontName /LYOXCO+HelveticaNeue-MediumCond
+                 /FontStretch /Condensed
+                 /FontWeight 500
+                 /ItalicAngle 0
+                 /StemV 108
+                 /Type /FontDescriptor
+                 /XHeight 538
+                 >>
+                 endobj
+
+                */
+
+               $lines = $this->showObject($this->getDescriptorId());
+               foreach ($lines as $line) {
+                       $e = explode(" ", $line);
+                       if (strpos($e[0], "/FontFile") !== false) {
+                               $this->font_file_id = $e[1];
+                       }
+               }
+       }
+
+       public function getInfos() {
+               $lines = $this->showObject($this->id);
+               // Test redirection
+               while (count($lines) == 1) {
+                       $e = explode(' ', $lines[0]);
+                       if ($e[0] == '[' && $e[4] == ']') {
+                               // Change id and get infos again
+                               $this->id=$e[1];
+                               return $this->getInfos();
+                       } else {
+                               return;
+                       }
+               }
+
+
+               foreach ($lines as $line) {
+                       $e = explode(' ', $line);
+                       if ($line == '' || $line == '<<' || $line == '>>') {
+                               continue;
+                       }
+
+                       if ($e[0] == '/ToUnicode') {
+                               $this->cmap_id = $e[1];
+                       }
+
+                       if ($e[0] == '/DescendantFonts') {
+                               $this->descendant = new wsPDFFont($this->extractor, $e[1]);
+                       }
+
+                       if ($e[0] == '/BaseFont') {
+                               $this->name = ltrim($e[1], '/');
+                       }
+
+                       if ($e[0] == '/FontDescriptor') {
+                               $this->descriptor_id = $e[1];
+                       }
+               }
+
+
+
+
+               /*
+                 8677 0 obj
+                 <<
+                 /BaseFont /YIKUMO+Futura-Condensed
+                 /Encoding /WinAnsiEncoding
+                 /FirstChar 32
+                 /FontDescriptor 7690 0 R
+                 /LastChar 119
+                 /Subtype /Type1
+                 /Type /Font
+                 /Widths [ 205 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+                 0 0 0 0 0 0 0 0 0 414 418 0 466 0 342 0 0 0 303 0 0 561 0
+                 0 388 0 0 354 0 0 0 0 0 0 0 0 0 0 0 0 0 380 380 0 380 361
+                 0 382 388 180 0 395 180 590 388 375 380 0 269 276 221 389
+                 0 487 ]
+                 >>
+                 endobj
+
+                 9193 0 obj
+                 <<
+                 /BaseFont /QGNYEE+AvantGarde-Book
+                 /Encoding /WinAnsiEncoding
+                 /FirstChar 32
+                 /FontDescriptor 9192 0 R
+                 /LastChar 201
+                 /Subtype /Type1
+                 /ToUnicode 9185 0 R
+                 /Type /Font
+                 /Widths [ 277 0 0 0 0 0 0 0 0 0 0 0 277 332 0 0 554 554 554
+                 0 0 0 554 554 0 0 0 0 0 0 0 0 0 740 574 813 744 536 485 872
+                 683 226 482 0 462 919 740 869 592 0 607 498 426 655 702 0
+                 0 592 480 0 0 0 0 0 0 683 0 0 0 650 0 0 0 200 0 0 200 0 610
+                 655 0 0 301 388 339 0 554 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000
+                 0 0 0 0 0 0 0 0 0 0 0 0 351 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+                 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+                 0 740 0 0 0 0 0 0 0 0 536 ]
+                 >>
+                 endobj
+                * 
+                 10 0 obj
+                 <<
+                 /BaseFont /FuturaLT-Bold--Identity-H
+                 /DescendantFonts [ 11 0 R ]
+                 /Encoding /Identity-H
+                 /Name /F0
+                 /Subtype /Type0
+                 /ToUnicode 3881 0 R
+                 /Type /Font
+                 >>
+                 endobj
+                * 
+                 11 0 obj
+                 <<
+                 /BaseFont /EHLOJB+FuturaLT-Bold-OV-JVKOJB
+                 /CIDSystemInfo <<
+                 /Ordering (Identity)
+                 /Registry (Adobe)
+                 /Supplement 0
+                 >>
+                 /DW 343
+                 /FontDescriptor 3878 0 R
+                 /Name /F0
+                 /Subtype /CIDFontType0
+                 /Type /Font
+                 /W [ 1 [ 781 ] 4 [ 781 ] 9 [ 677 660 ] 12 [ 752 550 550 550 ]
+                 17 [ 550 ] 20 [ 542 842 803 324 ] 26 [ 324 ] 28 [ 489 ] 30
+                 [ 495 ] 32 [ 983 881 ] 35 [ 887 ] 43 [ 661 887 680 616 ]
+                 48 [ 533 ] 50 [ 778 ] 55 [ 761 ] 57 [ 789 ] 61 [ 707 ] 63
+                 [ 682 ] 77 [ 682 ] 87 [ 483 ] 93 [ 343 343 ] 97 [ 682 ] 106
+                 [ 610 610 610 ] 111 [ 686 ] 119 [ 388 ] 121 [ 689 ] 124 [
+                 686 ] 126 [ 677 ] 134 [ 661 ] 136 [ 392 ] 138 [ 302 ] 140
+                 [ 302 302 ] 149 [ 989 ] 154 [ 661 ] 156 [ 686 ] 159 [ 662 ]
+                 167 [ 686 ] 175 [ 682 ] 180 [ 343 ] 193 [ 372 ] 196 [ 453 ]
+                 199 [ 513 ] 203 [ 686 686 ] 208 [ 360 ] 210 [ 686 ] 215 [
+                 686 ] 217 [ 659 ] 232 [ 686 ] ]
+                 >>
+                 endobj
+
+                 248 0 obj
+                 [ 247 0 R ]
+                 endobj */
+       }
+
+       public function showObject($obj) {
+               return $this->extractor->showObject($obj);
+       }
+
+       public function getDescriptorId() {
+               if (!is_null($this->descendant)) {
+                       return $this->descendant->getDescriptorId();
+               }
+               return $this->descriptor_id;
+       }
+
+       public function getCMAP() {
+               if (is_null($this->cmap_id)) {
+                       if (!is_null($this->descendant)) {
+                               return $this->descendant->getCMAP();
+                       }
+                       return array();
+               }
+               $res = array();
+               $lines = $this->showObject($this->cmap_id);
+
+               $inMap = false;
+               foreach ($lines as $line) {
+                       $line = trim($line);
+                       if ($line == '') {
+                               continue;
+                       }
+
+                       $e = explode(' ', $line);
+
+                       if (count($e) == 2 && $e[1] == 'beginbfchar') {
+                               $inMap = true;
+                               continue;
+                       }
+
+                       if (!$inMap) {
+                               continue;
+                       }
+
+                       $from = trim($e[0], '<>');
+                       $to = trim($e[1], '<>');
+
+                       $res[$from] = $to;
+               }
+               return true;
+       }
+
+       protected function manageLigatures($code) {
+               $codes = str_split($code, 4);
+               $str = '';
+               foreach ($codes as $c) {
+                       $str.=chr(intval($c, 16));
+               }
+
+
+
+               // Si un couple est une ligature standard
+               if (isset(self::$ligatures[$str])) {
+                       return self::$ligatures[$str];
+               }
+               // Sinon, on ne retourne que le premier code
+               return $codes[0];
+       }
+
+       protected function getFontFileId() {
+               if (is_null($this->font_file_id)) {
+                       if (!is_null($this->descendant)) {
+                               return $this->descendant->getFontFileId();
+                       }
+                       return null;
+               }
+               return $this->font_file_id;
+       }
+
+       public function writeTTF($dir) {
+               $cmap = $this->writeCMAP();
+               $file = $this->writeFont();
+
+               $fontforge = new cubeCommandLine('convert.pe');
+               $fontforge->setPath(CONVERTER_PATH);
+               $fontforge->setArg(null, $file);
+               $fontforge->setArg(null, $cmap);
+               $fontforge->setArg(null, $dir . '/' . $this->name . '-' . $this->id . '.ttf');
+               $fontforge->execute();
+               $this->addToLog($fontforge);
+
+               unlink($cmap);
+               unlink($file);
+       }
+
+       protected function writeFont() {
+               $tmp = cubeFiles::tempnam();
+               $this->extractor->writeObject($this->getFontFileId(), $tmp);
+               return $tmp;
+       }
+
+       protected function writeCMAP() {
+               $tmp = cubeFiles::tempnam() . '.cmap';
+               $fp = fopen($tmp, 'wb');
+               $cmap = $this->getCMAP();
+               foreach ($cmap as $from => $to) {
+                       fwrite($fp, $from . "\t" . $to . "\n");
+               }
+               fclose($fp);
+               return $tmp;
+       }
+
+       protected function addToLog($toLog) {
+               $this->extractor->addToLog($toLog);
+       }
+
+}
+
+?>
diff --git a/inc/ws/Util/fontextractor/class.ws.pdf.fontextractor.php b/inc/ws/Util/fontextractor/class.ws.pdf.fontextractor.php
new file mode 100644 (file)
index 0000000..a6ad65d
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+
+class wsPDFFontExtractor {
+
+       protected $in;
+       protected $outpdf;
+       protected $outweb;
+       protected $fonts = array();
+       protected $cmaps = array();
+       protected $descendants = array();
+       protected $descendantNames = array();
+       protected $doc;
+
+       public function __construct($in, $doc=null) {
+               $this->doc = $doc;
+               $this->in = $in . '/original.pdf';
+               $this->outpdf = $in . '/fonts/pdf';
+               $this->outweb = $in . '/fonts/web';
+       }
+
+       public function extract() {
+               $this->clean();
+
+               $this->getFonts();
+               $this->convertToTTF();
+               
+               $this->addToLog(print_r($this,true));
+       }
+
+       public function convertToTTF() {
+               foreach ($this->fonts as $font) {
+                       $font->writeTTF($this->outpdf);
+               }
+       }
+
+       public function getFonts() {
+               $pdfinfo = $this->getCommandLine('pdfinfo');
+               $pdfinfo->setArg('f');
+               $pdfinfo->setArg(null, $this->in);
+               $pdfinfo->execute();
+
+               $this->addToLog($pdfinfo);
+
+               /*
+                * /home/extranet/www/fluidbook/docs/100376/original.pdf:
+
+                 PDF-1.7
+                 Info object (9177 0 R):
+                 <<
+                 /CreationDate (D:20110831090005+02'00')
+                 /Creator (Adobe InDesign CS5 \(7.0\))
+                 /ModDate (D:20110901144502+02'00')
+                 /Producer (Adobe PDF Library 9.9)
+                 /Trapped /False
+                 >>
+
+                 Pages: 116
+
+                 Retrieving info from pages 1-116...
+                 Fonts (201):
+                 1 (   9180 0 R): Type1 'QGNYEE+AvantGarde-Book' (9193 0 R)
+                 1 (   9180 0 R): Type1 'QGNYEE+AvantGarde-ExtraLight' (9195 0 R)
+                 2 (      1 0 R): Type1 'QGNYEE+DIN-Light' (7605 0 R)
+                 2 (      1 0 R): Type1 'QGNYEE+AvantGarde-ExtraLightObl' (7608 0 R)
+                 2 (      1 0 R): Type1 'QGNYEE+AvantGarde-MediumObl' (7601 0 R)
+
+                */
+
+               if (preg_match_all("|\s+\d+\s+\(\s+\d+\s+\d+\s+\w+\):\s+\w+\s+'([A-Za-z-+]+)'\s+\((\d+)\s+\d+\s+\w+\)\s|", $pdfinfo->output, $matches)) {
+                       foreach ($matches[1] as $k => $name) {
+                               $this->fonts[$matches[2][$k]] = new wsPDFFont($this, $matches[2][$k], $name);
+                       }
+               }
+       }
+
+       protected function clean() {
+               `rm -rf $this->outpdf`;
+               `rm -rf $this->outweb`;
+               mkdir($this->outweb, 0777, true);
+               mkdir($this->outpdf, 0777, true);
+       }
+
+       protected function getCommandLine($program) {
+               $res = new cubeCommandLine('/usr/local/mupdf/' . $program);
+               $res->cd($this->outpdf);
+               $res->setPath(CONVERTER_PATH);
+               return $res;
+       }
+
+       public function showObject($object, $binary=null) {
+               $pdfshow = $this->getCommandLine('pdfshow');
+               $pdfshow->setArg(null, $this->in);
+               $pdfshow->setArg(null, $object);
+               $pdfshow->execute();
+               
+               $this->addToLog($pdfshow);
+               
+               $obj = $pdfshow->output;
+               $obj = explode("\n", $obj);
+               $res = array();
+               foreach ($obj as $o) {
+                       $o=trim($o);
+                       if($o==''){
+                               continue;
+                       }
+                       $res[] = trim($o);
+                       
+               }
+               array_shift($res);
+               array_pop($res);
+               
+               $this->addToLog(print_r($res,true));
+               
+               return $res;
+       }
+
+       public function writeObject($obj, $to) {
+               $pdfshow = new cubeCommandLine('/usr/local/mupdf/pdfshow', $to, false);
+               $pdfshow->cd($this->outpdf);
+               $pdfshow->setPath(CONVERTER_PATH);
+               $pdfshow->setArg('b');
+               $pdfshow->setArg(null, $this->in);
+               $pdfshow->setArg(null, $obj);
+               $pdfshow->execute();
+               
+               $this->addToLog($pdfshow->commande);
+       }
+
+       public function addToLog($tolog) {
+               if (!is_null($this->doc)) {
+                       $this->doc->addToLog($tolog);
+               } elseif ($tolog instanceof cubeCommandLine) {
+                       echo $tolog->commande . "\n\n";
+                       echo $tolog->output . "\n\n";
+               } else {
+                       echo $tolog . "\n\n";
+               }
+       }
+
+}
+
+?>
index 4370b5c3c04e028e842bc4a74fca18032a0f9494..52aac6046c0c1c1bcf5a6813c4bfa43807a74a8a 100644 (file)
@@ -357,6 +357,7 @@ class wsHTML5Compiler {
                $formats = array('ttf', 'woff', 'svg');
 
                foreach ($this->cssFont as $font => $infos) {
+                       fb($infos, $font);
                        $index = $infos['index'];
 
                        foreach ($formats as $format) {
@@ -465,7 +466,7 @@ class wsHTML5Compiler {
 
                $res = '<div class="' . $class . '">';
                foreach ($line['groups'] as $group) {
-                       $res.=$this->writeGroup($group, $line, $ox);
+                       $res.=$this->writeGroup($group, $line);
                }
                $res.='</div>';
                return $res;
@@ -749,7 +750,7 @@ class wsHTML5Compiler {
                foreach ($this->cssFont as $font => $infos) {
                        $index = $infos['index'];
                        $style = $infos['oblique'] ? 'oblique' : 'normal';
-                       $res[] = "@font-face{font-family:F" . $index . ";font-style:" . $style . ";src:url('F" . $index . ".ttf') format('truetype'),url('F" . $index . ".woff') format('woff'),url('F" . $index . ".svg#" . $font . "') format('svg')}";
+                       $res[] = "@font-face{font-family:F" . $index . ";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}';
                }