PDF View: Improve _getMostVisiblePart function.

Signed-off-by: Gökay ŞATIR <gokaysatir@gmail.com>
Change-Id: I877a2f5bac09bb81088b1aae9539cb0847f0fc50
This commit is contained in:
Gökay ŞATIR 2021-07-29 14:16:25 +03:00
parent 87b98a4b59
commit eff77c75ad

View file

@ -5490,20 +5490,28 @@ L.CanvasTileLayer = L.Layer.extend({
}
}
if (!found)
parts.push({part: queue[i].part, tileCount: 0});
parts.push({part: queue[i].part});
found = false;
}
var maxTileCount = 0;
var ratio = this._tileSize / this._tileHeightTwips;
var partHeightPixels = Math.round((this._partHeightTwips + this._spaceBetweenParts) * ratio);
var partWidthPixels = Math.round(this._partWidthTwips * ratio);
var rectangle;
var maxArea = -1;
var mostVisiblePart = 0;
var docBoundsRectangle = app.sectionContainer.getDocumentBounds();
docBoundsRectangle[2] = docBoundsRectangle[2] - docBoundsRectangle[0];
docBoundsRectangle[3] = docBoundsRectangle[3] - docBoundsRectangle[1];
for (i = 0; i < parts.length; i++) {
for (var j = 0; j < queue.length; j++) {
if (queue[j].part === parts[i].part)
parts[i].tileCount++;
}
if (parts[i].tileCount > maxTileCount) {
maxTileCount = parts[i].tileCount;
mostVisiblePart = parts[i].part;
rectangle = [0, partHeightPixels * parts[i].part, partWidthPixels, partHeightPixels];
rectangle = L.LOUtil._getIntersectionRectangle(rectangle, docBoundsRectangle);
if (rectangle) {
if (rectangle[2] * rectangle[3] > maxArea) {
maxArea = rectangle[2] * rectangle[3];
mostVisiblePart = parts[i].part;
}
}
}
return mostVisiblePart;