use Cubist\PDF\PDFTools;
use Fluidbook\Tools\SVG\SVGTools;
-class ProcessFile
-{
+class ProcessFile {
protected $format = 'jpg';
/**
* @var int|string
*/
protected $job;
- public function __construct($format = 'jpg', $resolution = 150, $withGraphics = true, $withTexts = true, $version = 'html')
- {
+ public function __construct($format = 'jpg', $resolution = 150, $withGraphics = true, $withTexts = true, $version = 'html') {
$this->format = $format;
$this->resolution = $resolution;
$this->withGraphics = $withGraphics;
/**
* @param string $format
*/
- public function setFormat(string $format)
- {
+ public function setFormat(string $format) {
$this->format = $format;
}
/**
* @return string
*/
- public function getFormat(): string
- {
+ public function getFormat(): string {
if ($this->format === 'jpeg') {
return 'jpg';
}
/**
* @param int|string $resolution
*/
- public function setResolution(int|string $resolution)
- {
+ public function setResolution(int|string $resolution) {
$this->resolution = $resolution;
}
/**
* @return int|string
*/
- public function getResolution(): int|string
- {
+ public function getResolution(): int|string {
return $this->resolution;
}
/**
* @return bool
*/
- public function isWithGraphics(): bool
- {
+ public function isWithGraphics(): bool {
return $this->withGraphics;
}
/**
* @param bool $withGraphics
*/
- public function setWithGraphics(bool $withGraphics)
- {
+ public function setWithGraphics(bool $withGraphics) {
$this->withGraphics = $withGraphics;
}
/**
* @return bool
*/
- public function isWithTexts(): bool
- {
+ public function isWithTexts(): bool {
return $this->withTexts;
}
/**
* @param bool $withTexts
*/
- public function setWithTexts(bool $withTexts)
- {
+ public function setWithTexts(bool $withTexts) {
$this->withTexts = $withTexts;
}
/**
* @return int
*/
- public function getPage(): int
- {
+ public function getPage(): int {
return $this->job->getPage();
}
/**
* @return mixed
*/
- public function getOut()
- {
+ public function getOut() {
return $this->job->getOut();
}
/**
* @return string
*/
- public function getVersion(): string
- {
+ public function getVersion(): string {
if ($this->getFormat() === 'svg') {
return 'html';
} else if ($this->getFormat() === 'swf') {
/**
* @param string $version
*/
- public function setVersion(string $version)
- {
+ public function setVersion(string $version) {
$this->version = $version;
}
/**
* @return ProcessPage
*/
- public function getJob(): ProcessPage
- {
+ public function getJob(): ProcessPage {
return $this->job;
}
/**
* @param ProcessPage $job
*/
- public function setJob(ProcessPage $job)
- {
+ public function setJob(ProcessPage $job) {
$this->job = $job;
return $this;
}
- public function getPath($force = false)
- {
+ public function getPath($force = false) {
$dir = rtrim($this->getOut() . $this->getVersion(), '/') . '/';
$minsize = 1;
$res = '';
return $res;
}
- public function makeFile($file)
- {
+ public function makeFile($file) {
$lock = $file . '.lock';
if (file_exists($lock) && filemtime($lock) > time() - 300) {
sleep(10);
}
}
- public function makeSVGFile($force = false)
- {
+ public function makeSVGFile($force = false) {
$svgFile = $this->getOut() . '/html/fp' . $this->getPage() . '.svg';
if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) {
return $svgFile;
return $svgFile;
}
- public function makeTextSVGFile($out)
- {
+ public function makeTextSVGFile($out) {
$in = $this->makeSVGFile();
$inter = str_replace('/to', '/tp', $out);
PDFTools::makeTextSVGFile($in, $inter);
SVGTools::optimizeSVG($inter, $out);
}
- public function getResolutionRatio(): float
- {
+ public function getResolutionRatio(): float {
return $this->getJob()->getResolutionRatio();
}
- public function getMobileRatio(): float
- {
+ public function getMobileRatio(): float {
return $this->getJob()->getMobileFirstRatio();
}
- public function makeOptimizedSVGFile($out)
- {
+ public function makeOptimizedSVGFile($out) {
$in = $this->makeSVGFile();
SVGTools::optimizeSVGImages($in, $out, $this->getResolution());
+ $beforeOpt = str_replace('.svg', '.orig.svg', $out);
+ copy($out, $beforeOpt);
SVGTools::optimizeSVG($out, $out);
}
- public function getSplittedPDFPage()
- {
+ public function getSplittedPDFPage() {
$res = $this->getOut() . 'pdf/p' . $this->getPage() . '.pdf';
if (!file_exists($res)) {
$this->getJob()->splitDoc();