From 2a74a7da33044464d616afac9796cc5250283b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20T=C3=A2che?= Date: Mon, 13 Nov 2023 06:38:45 +0100 Subject: [PATCH 1/2] GH-315 Uses reference of annotation instead of annotation object in annotationToComponent (#315) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guillaume Tâche --- .../ri/common/views/PageViewComponentImpl.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewComponentImpl.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewComponentImpl.java index 7652ffbaf..3a04531f3 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewComponentImpl.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewComponentImpl.java @@ -1,6 +1,11 @@ package org.icepdf.ri.common.views; -import org.icepdf.core.pobjects.*; +import org.icepdf.core.pobjects.Catalog; +import org.icepdf.core.pobjects.Destination; +import org.icepdf.core.pobjects.NameTree; +import org.icepdf.core.pobjects.Page; +import org.icepdf.core.pobjects.PageTree; +import org.icepdf.core.pobjects.Reference; import org.icepdf.core.pobjects.annotations.Annotation; import org.icepdf.core.pobjects.annotations.ChoiceWidgetAnnotation; import org.icepdf.core.pobjects.annotations.FreeTextAnnotation; @@ -43,7 +48,7 @@ public class PageViewComponentImpl extends AbstractPageViewComponent implements // annotations component for this pageViewComp. protected final Object annotationComponentsLock = new Object(); protected ArrayList annotationComponents; - protected Map annotationToComponent; + protected Map annotationToComponent; protected ArrayList destinationComponents; private Set searchHitComponents = new HashSet<>(); @@ -230,7 +235,7 @@ public AnnotationComponent getComponentFor(Annotation annot) { if (annotationToComponent == null) { initializeAnnotationsComponent(getPage()); } - return annotationToComponent.get(annot); + return annotationToComponent.get(annot.getPObjectReference()); } /** @@ -440,7 +445,7 @@ public void addAnnotation(AnnotationComponent annotation) { annotationToComponent = new HashMap<>(); } annotationComponents.add((AbstractAnnotationComponent) annotation); - annotationToComponent.put(annotation.getAnnotation(), annotation); + annotationToComponent.put(annotation.getAnnotation().getPObjectReference(), annotation); if (annotation instanceof PopupAnnotationComponent) { addPopupAnnotationComponent((PopupAnnotationComponent) annotation); } else if (annotation instanceof MarkupAnnotationComponent) { @@ -463,7 +468,7 @@ public void addAnnotation(AnnotationComponent annotation) { public void removeAnnotation(AnnotationComponent annotationComp) { annotationComponents.remove(annotationComp); if (annotationComp.getAnnotation() != null) { - annotationToComponent.remove(annotationComp.getAnnotation()); + annotationToComponent.remove(annotationComp.getAnnotation().getPObjectReference()); } else { annotationToComponent.entrySet().stream().filter(e -> e.getValue().equals(annotationComp)).findFirst() .ifPresent(e -> annotationToComponent.remove(e.getKey())); @@ -560,7 +565,7 @@ private void initializeAnnotationsComponent(Page page) { if (comp != null) { // add for painting annotationComponents.add(comp); - annotationToComponent.put(annotation, comp); + annotationToComponent.put(annotation.getPObjectReference(), comp); // add to layout if (comp instanceof PopupAnnotationComponent) { PopupAnnotationComponent popupAnnotationComponent = (PopupAnnotationComponent) comp; From 50c8d6013449274f382056725573cfac5fc936f2 Mon Sep 17 00:00:00 2001 From: Patrick Corless Date: Tue, 14 Nov 2023 21:21:02 -0700 Subject: [PATCH 2/2] GH-316 fix print issue with documents that do not have annotations. (#317) Co-authored-by: Patrick Corless --- .../org/icepdf/ri/common/print/PrintHelperImpl.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/print/PrintHelperImpl.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/print/PrintHelperImpl.java index f1165ffbc..be36c3214 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/print/PrintHelperImpl.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/print/PrintHelperImpl.java @@ -183,11 +183,14 @@ public int print(Graphics printGraphics, PageFormat pageFormat, int pageIndex) { Dimension dim = pageDim.toDimension(); Rectangle2D.Float rect = new Rectangle2D.Float(0, 0, dim.width, dim.height); List annotations = currentPage.getAnnotations(); - for (Annotation annot : annotations) { - Rectangle2D.union( - rect, - annot.calculatePageSpaceRectangle(currentPage, Page.BOUNDARY_MEDIABOX, rotation, zoomFactor), - rect); + if (annotations != null) { + for (Annotation annot : annotations) { + Rectangle2D.union( + rect, + annot.calculatePageSpaceRectangle(currentPage, Page.BOUNDARY_MEDIABOX, rotation, + zoomFactor), + rect); + } } // Get location of imageable area from PageFormat object