use Cubist\Util\Graphics\PDF;
use Cubist\Util\Text;
use Fluidbook\Tools\Compiler\Compiler;
+use Fluidbook\Tools\Compiler\CompilerInterface;
-class ZoomLink extends NormalLink
-{
+class ZoomLink extends NormalLink {
protected $maxzoom_default = 2;
protected $_groups = null;
- public function ignore()
- {
+ public function ignore() {
return parent::ignore() || $this->isOutsidePage();
}
- public function getGroups()
- {
+ public function getGroups() {
if (null === $this->_groups) {
$this->_groups = [];
$groups = explode(',', $this->group);
return $this->_groups;
}
- public function init()
- {
+ public function init() {
$this->compiler->addJsLib('fluidbook-zoom', 'js/libs/fluidbook/links/fluidbook.links.zoom.js');
$this->maxzoom_default = $this->compiler->getSetting('zoomAreaDefaultZoomLevel', 2);
parent::init();
}
- public function getHTMLContainerClass()
- {
+ public function getHTMLContainerClass() {
$class = ' zoomarea';
$groups = $this->getGroups();
return parent::getHTMLContainerClass() . $class;
}
- public function getDefaultTooltip()
- {
+ public function getDefaultTooltip() {
return 'zoom in';
}
- public function getAdditionnalContent()
- {
+ public function getAdditionnalContent() {
$res = parent::getAdditionnalContent();
$res .= ' id="' . $this->uid . '"';
return $res;
}
- public function getZoomAttributes()
- {
+ public function getZoomAttributes() {
return [
'id' => $this->uid,
'page' => $this->page,
/**
* @param $attributes
- * @param $compiler Compiler
+ * @param $compiler CompilerInterface
* @param $cachedir
* @param $save
* @return void
*/
- public static function generateImage($attributes, $compiler, $cachedir, $save)
- {
+ public static function generateImage($attributes, $compiler, $cachedir, $save) {
$maxzoom = $attributes['maxzoom']; // Max zoom level might not always be set in the link editor
$maxzoom = max(2, min($maxzoom, 20));
$maxzoom = 2;
}
- // TODO: Consider generating higher-res images (eg. 2x) for HiDPI screens. Maybe some extra optimisations can be done on the larger images...
-
$extractOptions = [
// The Poppler::extractArea function accepts a resolution setting and uses that to determine the
// scale factor on the extracted images. It does so by dividing by 72, so we can pass our own scale
// factor by setting the resolution to 72 * $maxzoom
- 'resolution' => 150 * $maxzoom
+ 'resolution' => 72 * 2 * $maxzoom
];
// Round all link co-ordinates because there seems to be a problem with the the Workshop link editor
$h = $attributes['height'];
$bookwidth = round($compiler->getSetting('width'));
- //error_log("--- Book Width: $bookwidth ---");
-
if (!isset($attributes['pdf']) || !$attributes['pdf']) {
$pdfpath = $compiler->getPagePDFSource($attributes['page']);
$extractPage = 1;
$extractPage = $attributes['page'];
}
- $cache = storage_path('fluidbook/cache/zoomarea');
+ $cache = $compiler->getCacheDir("zoomarea/" . $cachedir);
- $left = Files::tempnam();
$leftfile = PDF::extractArea($pdfpath,
$extractPage,
array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h),
- $left, $extractOptions, $cache);
+ null, $extractOptions, $cache);
- if (($x + $w) > $bookwidth) {
+ if (($x + $w) > $bookwidth && !$compiler->isOnePage()) {
if (!isset($attributes['pdf']) || !$attributes['pdf']) {
-
$pdfpath = $compiler->getPagePDFSource($attributes['page'] + 1);
$extractPage = 1;
} else {
}
$diff = ($w + $x) - $bookwidth;
- $right = Files::tempnam();
$rightfile = PDF::extractArea($pdfpath,
$extractPage,
array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h),
- $right, $extractOptions, $cache);
+ null, $extractOptions, $cache);
if (!file_exists($rightfile)) {
die('Error generating right part ' . $rightfile);
}
- $both = Files::tempnam() . '.jpg';
- Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal');
+ $both = $cache . hash('sha256', $leftfile . $rightfile) . '.jpg';
+ if (!file_exists($both)) {
+ Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal');
+ }
if (!file_exists($both)) {
throw new \Exception('Error glueing ' . $leftfile . ' and ' . $rightfile);
}
$both = $leftfile;
}
- if (isset($attributes['border']) && $attributes['border'] > 0) {
- $tmp = Files::tempnam() . '.jpg';
- Imagemagick::addBorder($both, $tmp, $attributes['border'], $attributes['borderColor']);
- $compiler->getVirtualDirectory()->addTemp($both);
- $both = $tmp;
- }
+ // if (isset($attributes['border']) && $attributes['border'] > 0) {
+ // $tmp = Files::tempnam() . '.jpg';
+ // Imagemagick::addBorder($both, $tmp, $attributes['border'], $attributes['borderColor']);
+ // $compiler->getVirtualDirectory()->addTemp($both);
+ // $both = $tmp;
+ // }
+ // dd($both);
- $compiler->simpleCopyLinkFile($both, 'data/links/' . $save . '_' . $attributes['id'] . '.jpg');
- // Perform tidy up and delete temporary files if they exist
- $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both'];
- foreach ($files_to_delete as $file) {
- if (isset($$file)) {
- $compiler->getVirtualDirectory()->addTemp($$file);
- }
- }
+ $dest = 'data/links/' . $save . '_' . $attributes['id'] . '.jpg';
+ $compiler->simpleCopyLinkFile($both, $dest);
}
- public function getClasses()
- {
+ public function getClasses() {
// Assign CSS classes for all groups so we can match and group them via JS
$groups = $this->getGroups();
$group_classes = [];
foreach ($groups as $group) {
- if (empty($group)) continue;
+ if (empty($group))
+ continue;
$group_classes[] = 'zoom-group-' . trim(Text::str2URL($group));
}