$y = $this->top;
$w = $this->width;
$h = $this->height;
+ $page = $this->page;
+ $maxWidth = $this->compiler->getWidthForLinks();
+ if ($this->compiler->isDoublePage() && $x >= $maxWidth && $page % 2 === 0) {
+ $x -= $maxWidth;
+ $page++;
+ }
+
+ if ($this->page % 2 === 0 && $this->compiler->isDoublePage()) {
+ $maxWidth *= 2;
+ }
+
+ $maxHeight = $this->compiler->getHeightForLinks();
if ($x < 0) {
- $w -= $x;
+ $w += $x;
$x = 0;
}
if ($y < 0) {
- $h -= $y;
+ $h += $y;
$y = 0;
}
- $maxWidth = $this->compiler->getWidthForLinks();
-
- if ($this->page % 2 === 0 && !$this->compiler->isOnePage()) {
- $maxWidth *= 2;
- }
- $maxHeight = $this->compiler->getHeightForLinks();
-
if ($x + $w > $maxWidth) {
$w -= ($x + $w - $maxWidth);
}
$h -= ($y + $h - $maxHeight);
}
- return [
- 'id' => $this->id,
- 'page' => $this->page,
+ $res = [
+ 'id' => $this->uid,
+ 'page' => $page,
'maxzoom' => $this->compiler->getSetting('downloadPortionZoom', '8'),
'group' => '',
'group-count' => 0,
- 'width' => round($w),
- 'height' => round($h),
- 'x' => round($x),
- 'y' => round($y),
+ 'width' => $w,
+ 'height' => $h,
+ 'x' => $x,
+ 'y' => $y,
'pdf' => $pdf,
'border' => $this->border,
'borderColor' => $this->borderColor,
+ 'quality' => 80,
];
+
+ return $res;
}
public function getAdditionnalContent() {
namespace Fluidbook\Tools\Links;
use Cubist\Util\CommandLine\Imagemagick;
+use Cubist\Util\CommandLine\Poppler;
use Cubist\Util\Graphics\PDF;
use Cubist\Util\Text;
use Fluidbook\Tools\Compiler\CompilerInterface;
// 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' => 72 * 2 * $maxzoom
+ 'resolution' => Poppler::RESOLUTION_FACTOR * 2 * $maxzoom,
];
+ if (isset($attributes['quality'])) {
+ $extractOptions['quality'] = $attributes['quality'];
+ }
- // Round all link co-ordinates because there seems to be a problem with the the Workshop link editor
- // where link "left" values (and maybe others) change fractionally upon saves. This causes problems later when
- // extracting the zoom images from the PDF because it causes a cache-miss and the images are regenerated again.
$x = $attributes['x'];
$y = $attributes['y'];
$w = $attributes['width'];
$h = $attributes['height'];
- $bookwidth = round($compiler->getWidthForLinks());
+ $bookwidth = $compiler->getWidthForLinks();
+
+ if ($compiler->isDoublePage() && $x >= $bookwidth) {
+ $x -= $bookwidth;
+ $attributes['page']++;
+ }
if (!isset($attributes['pdf']) || !$attributes['pdf']) {
$pdfpath = $compiler->getPagePDFSource($attributes['page']);
$cache = $compiler->getCacheDir("zoomarea/" . $cachedir);
+ $leftArea = ['x' => $x, 'y' => $y, 'width' => $w, 'height' => $h];
$leftfile = PDF::extractArea($pdfpath,
$extractPage,
- array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h),
+ $leftArea,
null, $extractOptions, $cache);
-
- if (($x + $w) > $bookwidth && !$compiler->isOnePage()) {
+ if (($x + $w) >= $bookwidth && $compiler->isDoublePage()) {
if (!isset($attributes['pdf']) || !$attributes['pdf']) {
$pdfpath = $compiler->getPagePDFSource($attributes['page'] + 1);
$extractPage = 1;
$diff = ($w + $x) - $bookwidth;
$rightfile = PDF::extractArea($pdfpath,
$extractPage,
- array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h),
+ ['x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h],
null, $extractOptions, $cache);
if (!file_exists($rightfile)) {