use JsonException;
use stdClass;
-class Compiler implements ShouldQueue, ShouldBeUnique
-{
+class Compiler implements ShouldQueue, ShouldBeUnique {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use Links;
*/
protected $stub = '';
- public function addSource($document, $start = 1, $pages = null)
- {
+ /**
+ * @var int[]
+ */
+ protected $resolutions = [150, 300];
+
+ public function addSource($document, $start = 1, $pages = null) {
$source = new Source(new Document($document), $start, $pages);
$this->sources[] = $source;
foreach ($source->getRange() as $sourcePage) {
}
}
- public function getVirtualDirectory()
- {
+ public function getVirtualDirectory() {
return $this->vdir;
}
*
* @return void
*/
- public function handle()
- {
+ public function handle() {
$sync = ($this->job instanceof SyncJob);
if ($sync) {
PHP::neverStop(false);
stop_measure('Process Fluidbook');
}
- public function processPages($sync = false)
- {
+ public function processPages($sync = false) {
start_measure('Process Pages');
foreach ($this->sources as $source) {
$source->getDocument()->processPages($this->getProcessFiles(), $source->getRange(), $sync);
stop_measure('Process Pages');
}
- public function getTexts()
- {
+ public function getTexts() {
start_measure('Process texts');
foreach ($this->sources as $source) {
$source->getDocument()->processTexts();
/**
* @return ProcessFile[]
*/
- public function getProcessFiles()
- {
- return [
+ public function getProcessFiles() {
+ $res = [
'thumb' => new ProcessFile('jpg', 'thumb'),
- 'back150' => new ProcessFile('jpg', 150, true, false),
'text' => new ProcessFile('svg', 150, false, true),
];
+ foreach ($this->resolutions as $resolution) {
+ $res['back' . $resolution] = new ProcessFile('jpg', $resolution, true, false),
+ }
}
/**
* @return ProcessFile
* @throws Exception
*/
- public function getProcessFile($name, $page = null)
- {
+ public function getProcessFile($name, $page = null) {
$files = $this->getProcessFiles();
if (isset($files[$name])) {
$res = $files[$name];
* @return SourcePage
* @throws Exception
*/
- public function getSourceOfPage($page)
- {
+ public function getSourceOfPage($page) {
if (isset($this->pages[$page - 1])) {
return $this->pages[$page - 1];
}
/**
* @throws JsonException
*/
- protected function compileFluidbook()
- {
+ protected function compileFluidbook() {
start_measure('Compile fluidbook');
if ($this->wdir === '') {
stop_measure('Compile fluidbook');
}
- public function prepareStub()
- {
+ public function prepareStub() {
if ($this->stub !== '') {
$this->vdir->copyDirectory($this->stub, '/');
}
}
- public function compileContents()
- {
+ public function compileContents() {
for ($i = 1; $i <= $this->getPageCount(); $i++) {
$this->vdir->copy($this->getProcessFile('back150', $i)->getPath(), 'data/background/150/p' . $i . '.jpg');
}
}
- public function getPageCount()
- {
+ public function getPageCount() {
$res = 0;
foreach ($this->sources as $source) {
$res += $source->getPages();
/**
* @throws \JsonException
*/
- public function compileSearch()
- {
+ public function compileSearch() {
$index = new SearchIndex();
foreach ($this->pages as $i => $page) {
/**
* @throws JsonException
*/
- public function compileConfig()
- {
+ public function compileConfig() {
$settings = mb_substr(file_get_contents($this->stub . '/data/datas.js'), 13, -2);
$this->config = json_decode($settings, false, 512, JSON_THROW_ON_ERROR);
$this->config->maxResolution = 150;
$this->vdir->file_put_contents('data/datas.js', $c);
}
- protected function compileDimensions()
- {
+ protected function compileDimensions() {
$firstPageDoc = $this->getSourceOfPage(1)->getSource()->getDocument();
$width = round($firstPageDoc->getWidth(), 8);
}
}
- protected function compilePageNumbers()
- {
+ protected function compilePageNumbers() {
$this->config->numerotation = [];
foreach ($this->sources as $source) {
}
}
- protected function compileChapters()
- {
+ protected function compileChapters() {
$this->config->chaptersPagesNumber = 'physical';
$this->config->chapters = [];
foreach ($this->sources as $source) {
}
}
- public function getBookSurface()
- {
+ public function getBookSurface() {
return $this->getWidth() * $this->getHeight();
}
- public function getWidth()
- {
+ public function getWidth() {
return $this->getSourceOfPage(1)->getSource()->getDocument()->getWidth();
}
- public function getHeight()
- {
+ public function getHeight() {
return $this->getSourceOfPage(1)->getSource()->getDocument()->getHeight();
}
- public function addVideoJs()
- {
+ public function addVideoJs() {
$this->addLess('videojs/videojs');
}
- public function addSlideshowLibrary($inline = true)
- {
+ public function addSlideshowLibrary($inline = true) {
$l = ($inline ? $this->config->inlineSlideshowLibrary : $this->config->popupSlideshowLibrary);
$this->addLess('slideshow/' . $l);
}