--- /dev/null
+<?php
+
+namespace Fluidbook\Tools\CommandLine;
+
+use Cubist\Util\CommandLine;
+use Fluidbook\Tools\FluidbookTools;
+
+class FWSTK extends CommandLine
+{
+ public function __construct($output = null, $error = true)
+ {
+ parent::__construct(FluidbookTools::tools_path('fwstk.sh', true), $output, $error);
+ }
+}
namespace Fluidbook\Tools\PDF;
use Cubist\Util\CommandLine;
+use Fluidbook\Tools\CommandLine\FWSTK;
use Fluidbook\Tools\FluidbookTools;
use Fluidbook\Tools\Jobs\ProcessFile;
use Fluidbook\Tools\Jobs\ProcessPage;
return;
}
- $fwstk = new CommandLine(FluidbookTools::tools_path('fwstk.sh',true));
+ $fwstk = new FWSTK();
$fwstk->setArg('--input ' . $this->getPDFInput());
$fwstk->setArg('--infos');
$fwstk->execute();
*/
public function processPage($page, $dest, $files, $sync = false)
{
- start_measure('Process page ' . $page . ' (doc)');
$dispatchFunction = $sync ? 'dispatchSync' : 'dispatch';
ProcessPage::$dispatchFunction($this, $page, $dest, $files);
- stop_measure('Process page ' . $page . ' (doc)');
+ }
+
+ public function processLinks($dest)
+ {
+ PDFTools::extractLinks($this->getPDFInput(), $dest);
+ }
+
+ public function processTexts($dest)
+ {
+ start_measure('Extract texts');
+ PDFTools::extractTexts($this->getPDFInput(), $dest);
+ stop_measure('Extract texts');
+ start_measure('Get highlights data');
+ PDFTools::extractHighlightsData($this->getPDFInput(), $dest);
+ stop_measure('Get highlights data');
+ start_measure('Compile search index');
+ $this->compileSearchIndex($dest);
+ stop_measure('Compile search index');
+ }
+
+ public function compileSearchIndex($dest){
+
}
public function getResolutionRatio()
use DOMDocument;
use DOMNode;
use DOMXPath;
+use Fluidbook\Tools\CommandLine\FWSTK;
class PDFTools
{
$pdf2swf->setArg('p', $page);
$pdf2swf->setArg('T', 10);
$pdf2swf->setArg('Q', 120);
- $pdf2swf->setArg('set reordertags', '0');
- $pdf2swf->setArg('fonts');
$pdf2swf->setArg('set poly2bitmap');
$pdf2swf->setArg('set storeallcharacters');
+ $pdf2swf->setArg('set reordertags', '0');
+ $pdf2swf->setArg('fonts');
$pdf2swf->setArg('set subpixels', $resolution / 72);
$pdf2swf->setArg('set jpegquality', $quality);
$pdf2swf->setArg('set disablelinks');
public static function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null, $format = 'jpg')
{
- $tmp =Files::tempnam();
+ $tmp = Files::tempnam();
$antialiasing = $antialiasing ? 'yes' : 'no';
$freetype = $texts ? 'yes' : 'no';
return $image;
}
+ public static function extractLinks($pdf, $out)
+ {
+ $out .= 'links/';
+ Files::mkdir($out);
+
+ if (file_exists($out . '/p1.csv')) {
+ return;
+ }
+ $fwstk = new FWSTK();
+ $fwstk->setArg('--input ' . $pdf);
+ $fwstk->setArg('--extractLinks ' . $out . 'p%d.csv');
+ $fwstk->setArg('--threads 1');
+ $fwstk->execute();
+ }
+
+ public static function extractTexts($pdf, $out, $ignoreSeparators = '')
+ {
+ $out .= 'texts/';
+ Files::mkdir($out);
+
+ $fwstk = new FWSTK();
+ $fwstk->setArg('--input ' . $pdf);
+ $fwstk->setArg('--extractTexts ' . $out . '%s%d.txt');
+ $fwstk->setArg('--extractTextsMethod fluidbook');
+ $fwstk->setArg('--threads 1');
+ if ($ignoreSeparators !== '') {
+ $fwstk->setArg('--ignoreSeparators ' . $ignoreSeparators);
+ }
+ $fwstk->execute();
+ }
+
+ public static function extractHighlightsData($pdf, $out)
+ {
+ $out .= 'texts/';
+ Files::mkdir($out);
+
+ $fwstk = new FWSTK();
+ $fwstk->setArg('--input ' . $pdf);
+ $fwstk->setArg('--layout ' . $out . 'p%d.fby');
+ $fwstk->setArg('--cmaps ' . $out);
+ $fwstk->setArg('--fonts' . $out . 'fonts/web/');
+ $fwstk->execute();
+ }
+
}
namespace Fluidbook\Tools\SVG;
use Cubist\Util\Files\Files;
+use Fluidbook\Tools\FluidbookTools;
class SVGTools
{
if (null === $out) {
$e = explode('.', $in);
$ext = array_pop($e);
- array_push($e, 'o');
- array_push($e, $ext);
+ $e[] = 'o';
+ $e[] = $ext;
$out = implode('.', $e);
}
public static function _optimizeSVG($in, $out)
{
- $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 == '') {
+
+ $svg = shell_exec('timeout -s 1 120 ' . FluidbookTools::tools_path('svgcleaner/svgcleaner', true) . ' --allow-bigger-file --paths-coordinates-precision 3 --copy-on-error --stdout ' . $in);
+ if (!$svg) {
$svg = file_get_contents($in);
}
$svg = self::_disablePreserveRatio($svg);
protected static function _disablePreserveRatio($in)
{
$str = 'preserveAspectRatio="none"';
- if (strpos($in, $str) !== false) {
+ if (str_contains($in, $str)) {
return $in;
}
return str_replace("<svg ", '<svg ' . $str . ' ', $in);
self::$_e = 0;
self::$_u = 0;
- $c = str_replace('id="', 'id="p' . $p . '-', $c);
- $c = str_replace('url(#', 'url(#p' . $p . '-', $c);
- $c = str_replace('xlink:href="#', 'xlink:href="#p' . $p . '-', $c);
+ $c = str_replace(array('id="', 'url(#', 'xlink:href="#'), array('id="p' . $p . '-', 'url(#p' . $p . '-', 'xlink:href="#p' . $p . '-'), $c);
$c = preg_replace_callback('/\<image([^\>]*)\>/m', function ($matches) use ($p) {
self::$_i++;
return '<g id="p' . $p . '-imageholder-' . self::$_i . '"><image id="p' . $p . '-image-' . self::$_i . '" ' . $matches[1] . '></g>';