Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Fit width given document with various page formats #135

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.icepdf.ri.common.views;

import org.icepdf.core.pobjects.PDimension;
import org.icepdf.core.pobjects.PageTree;
import org.icepdf.core.util.ColorUtil;
import org.icepdf.core.util.Defs;
import org.icepdf.core.util.PropertyConstants;
Expand Down Expand Up @@ -351,6 +353,21 @@ protected boolean isTextSelectionTool() {
getCurrentToolHandler() instanceof HighLightAnnotationHandler);
}

protected PDimension getMaxPageDimension() {
final PDimension dimension = new PDimension(0, 0);
final PageTree pt = documentViewModel.getDocument().getPageTree();
for (int i = 0; i < pt.getNumberOfPages(); ++i) {
final PDimension dim = pt.getPage(i).getSize(0f, 1f);
if (dim.getHeight() > dimension.getHeight()) {
dimension.set((float) dimension.getWidth(), (float) dim.getHeight());
}
if (dim.getWidth() > dimension.getWidth()) {
dimension.set((float) dim.getWidth(), (float) dimension.getHeight());
}
}
return dimension;
}

/**
* Checks to see if the mouse has exited the scroll pane viewport on the vertical plane.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.icepdf.ri.common.views;

import org.icepdf.core.pobjects.PDimension;
import org.icepdf.ri.common.CurrentPageChanger;
import org.icepdf.ri.common.KeyListenerPageColumnChanger;

Expand Down Expand Up @@ -124,19 +125,9 @@ public void dispose() {
}

public Dimension getDocumentSize() {
// still used by page fit code
float pageViewWidth = 0;
float pageViewHeight = 0;
int currCompIndex = documentViewController.getCurrentPageIndex();
Rectangle bounds = documentViewModel.getPageBounds(currCompIndex);
if (bounds != null) {
pageViewWidth = bounds.width;
pageViewHeight = bounds.height;
}
// normalize the dimensions to a zoom level of zero.
float currentZoom = documentViewController.getDocumentViewModel().getViewZoom();
pageViewWidth = Math.abs(pageViewWidth / currentZoom);
pageViewHeight = Math.abs(pageViewHeight / currentZoom);
final PDimension dimension = getMaxPageDimension();
float pageViewWidth = (float) dimension.getWidth();
float pageViewHeight = (float) dimension.getHeight();

// add any horizontal padding from layout manager
pageViewWidth += PAGE_SPACING_HORIZONTAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.icepdf.ri.common.views;

import org.icepdf.core.pobjects.PDimension;
import org.icepdf.ri.common.KeyListenerPageChanger;
import org.icepdf.ri.common.MouseWheelListenerPageChanger;

Expand Down Expand Up @@ -132,18 +133,9 @@ public void dispose() {
}

public Dimension getDocumentSize() {
float pageViewWidth = 0;
float pageViewHeight = 0;
int currCompIndex = documentViewController.getCurrentPageIndex();
Rectangle bounds = documentViewModel.getPageBounds(currCompIndex);
if (bounds != null) {
pageViewWidth = bounds.width;
pageViewHeight = bounds.height;
}
// normalize the dimensions to a zoom level of zero.
float currentZoom = documentViewController.getDocumentViewModel().getViewZoom();
pageViewWidth = Math.abs(pageViewWidth / currentZoom);
pageViewHeight = Math.abs(pageViewHeight / currentZoom);
final PDimension maxDimension = getMaxPageDimension();
float pageViewWidth = (float) maxDimension.getWidth();
float pageViewHeight = (float) maxDimension.getHeight();

// add any horizontal padding from layout manager
pageViewWidth += PAGE_SPACING_HORIZONTAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.icepdf.ri.common.views;

import org.icepdf.core.pobjects.PDimension;
import org.icepdf.ri.common.CurrentPageChanger;
import org.icepdf.ri.common.KeyListenerPageColumnChanger;

Expand Down Expand Up @@ -139,58 +140,9 @@ public void dispose() {
}

public Dimension getDocumentSize() {
float pageViewWidth = 0;
float pageViewHeight = 0;
// The page index and corresponding component index are approximately equal
// If the first page is on the right, then there's a spacer on the left,
// bumping indexes up by one.
int currPageIndex = documentViewController.getCurrentPageIndex();
int currCompIndex = currPageIndex;
int numComponents = getComponentCount();
boolean foundCurrent = false;
while (currCompIndex >= 0 && currCompIndex < numComponents) {
Component comp = getComponent(currCompIndex);
if (comp instanceof PageViewDecorator) {
PageViewDecorator pvd = (PageViewDecorator) comp;
PageViewComponent pvc = pvd.getPageViewComponent();
if (pvc.getPageIndex() == currPageIndex) {
Dimension dim = pvd.getPreferredSize();
pageViewWidth = dim.width;
pageViewHeight = dim.height;
foundCurrent = true;
break;
}
}
currCompIndex++;
}
if (foundCurrent) {
// Determine if the page at (currPageIndex,currCompIndex) was
// on the left or right, so that if there's a page next to
// it, whether it's earlier or later in the component list,
// so we can get it's pageViewHeight and use that for our pageViewHeight
// calculation.
// If the other component is past the ends of the component
// list, or not a PageViewDecorator, then current was either
// the first or last page in the document
boolean evenPageIndex = ((currPageIndex & 0x1) == 0);
boolean bumpedIndex = (currCompIndex != currPageIndex);
boolean onLeft = evenPageIndex ^ bumpedIndex; // XOR
int otherCompIndex = onLeft ? (currCompIndex + 1) : (currCompIndex - 1);
if (otherCompIndex >= 0 && otherCompIndex < numComponents) {
Component comp = getComponent(otherCompIndex);
if (comp instanceof PageViewDecorator) {
PageViewDecorator pvd = (PageViewDecorator) comp;
Dimension dim = pvd.getPreferredSize();
pageViewWidth = dim.width;
pageViewHeight = dim.height;
}
}
}

// normalize the dimensions to a zoom level of zero.
float currentZoom = documentViewController.getDocumentViewModel().getViewZoom();
pageViewWidth = Math.abs(pageViewWidth / currentZoom);
pageViewHeight = Math.abs(pageViewHeight / currentZoom);
final PDimension dimension = getMaxPageDimension();
float pageViewWidth = (float) dimension.getWidth();
float pageViewHeight = (float) dimension.getHeight();

// two pages wide, generalization, pages are usually the same size we
// don't bother to look at the second pages size for the time being.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.icepdf.ri.common.views;

import org.icepdf.core.pobjects.PDimension;
import org.icepdf.ri.common.CurrentPageChanger;
import org.icepdf.ri.common.KeyListenerPageChanger;
import org.icepdf.ri.common.MouseWheelListenerPageChanger;
Expand Down Expand Up @@ -172,27 +173,12 @@ public void dispose() {
}

public Dimension getDocumentSize() {
float pageViewWidth = 0;
float pageViewHeight = 0;
int count = getComponentCount();
Component comp;
for (int i = 0; i < count; i++) {
comp = getComponent(i);
if (comp instanceof PageViewDecorator) {
PageViewDecorator pvd = (PageViewDecorator) comp;
Dimension dim = pvd.getPreferredSize();
pageViewWidth = dim.width;
pageViewHeight = dim.height;
break;
}
}
// normalize the dimensions to a zoom level of zero.
float currentZoom = documentViewController.getDocumentViewModel().getViewZoom();
pageViewWidth = Math.abs(pageViewWidth / currentZoom);
pageViewHeight = Math.abs(pageViewHeight / currentZoom);
final PDimension dimension = getMaxPageDimension();
float pageViewWidth = (float) dimension.getWidth();
float pageViewHeight = (float) dimension.getHeight();

// two pages wide, generalization, pages are usually the same size we
// don't bother to look at the second pages size for the time being.
// don't bother to look at the second pages size for the time being.
pageViewWidth *= 2;

// add any horizontal padding from layout manager
Expand Down