-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
404 additions
and
129 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
core/core-awt/src/main/java/org/icepdf/core/pobjects/MarkupGlueAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.icepdf.core.pobjects; | ||
|
||
import org.icepdf.core.pobjects.annotations.Annotation; | ||
import org.icepdf.core.pobjects.annotations.MarkupAnnotation; | ||
import org.icepdf.core.pobjects.annotations.MarkupGluePainter; | ||
import org.icepdf.core.pobjects.annotations.PopupAnnotation; | ||
import org.icepdf.core.util.Library; | ||
|
||
import java.awt.*; | ||
import java.awt.geom.AffineTransform; | ||
import java.awt.geom.Rectangle2D; | ||
|
||
public class MarkupGlueAnnotation extends Annotation { | ||
|
||
protected MarkupAnnotation markupAnnotation; | ||
protected PopupAnnotation popupAnnotation; | ||
|
||
public MarkupGlueAnnotation(Library l, DictionaryEntries h) { | ||
super(l, h); | ||
} | ||
|
||
public MarkupGlueAnnotation(Library l, MarkupAnnotation markupAnnotation, PopupAnnotation popupAnnotation) { | ||
super(l, new DictionaryEntries()); | ||
this.markupAnnotation = markupAnnotation; | ||
this.popupAnnotation = popupAnnotation; | ||
} | ||
|
||
protected void renderAppearanceStream(Graphics2D g2d) { | ||
if (this.popupAnnotation == null || this.markupAnnotation == null) return; | ||
|
||
GraphicsConfiguration graphicsConfiguration = g2d.getDeviceConfiguration(); | ||
boolean isPrintingAllowed = this.markupAnnotation.getFlagPrint(); | ||
if (graphicsConfiguration.getDevice().getType() == GraphicsDevice.TYPE_PRINTER && | ||
this.popupAnnotation.isOpen() && isPrintingAllowed) { | ||
AffineTransform oldTransform = g2d.getTransform(); | ||
new MarkupGluePainter(markupAnnotation, popupAnnotation, this).paint(g2d); | ||
g2d.setTransform(oldTransform); | ||
} | ||
} | ||
|
||
public Rectangle2D.Float getUserSpaceRectangle() { | ||
// make sure we always update this to get the correct clip during painting | ||
if (this.markupAnnotation != null && this.popupAnnotation != null) { | ||
Rectangle rect = this.markupAnnotation.getUserSpaceRectangle().getBounds().union( | ||
this.popupAnnotation.getUserSpaceRectangle().getBounds()); | ||
userSpaceRectangle = new Rectangle2D.Float(rect.x, rect.y, rect.width, rect.height); | ||
} | ||
return userSpaceRectangle; | ||
} | ||
|
||
public boolean allowPrintNormalMode() { | ||
return allowScreenOrPrintRenderingOrInteraction() && this.markupAnnotation.getFlagPrint(); | ||
} | ||
|
||
@Override | ||
public void resetAppearanceStream(double dx, double dy, AffineTransform pageSpace, boolean isNew) { | ||
|
||
} | ||
|
||
public MarkupAnnotation getMarkupAnnotation() { | ||
return markupAnnotation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
core/core-awt/src/main/java/org/icepdf/core/pobjects/annotations/MarkupGluePainter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.icepdf.core.pobjects.annotations; | ||
|
||
import org.icepdf.core.pobjects.MarkupGlueAnnotation; | ||
|
||
import java.awt.*; | ||
import java.awt.geom.AffineTransform; | ||
import java.awt.geom.GeneralPath; | ||
|
||
/** | ||
* MarkupGluePainter allows for a visual associating between a markup annotation, and it's popup annotation | ||
* when open. This painter code is called from the component used in the Viewer RI as well as painting popups | ||
* for printing purposes. | ||
* | ||
* @since 7.1 | ||
*/ | ||
public class MarkupGluePainter { | ||
|
||
protected MarkupAnnotation markupAnnotation; | ||
protected PopupAnnotation popupAnnotation; | ||
|
||
protected MarkupGlueAnnotation markupGlueAnnotation; | ||
|
||
public MarkupGluePainter(MarkupAnnotation markupAnnotation, PopupAnnotation popupAnnotation, | ||
MarkupGlueAnnotation markupGlueAnnotation) { | ||
this.markupAnnotation = markupAnnotation; | ||
this.popupAnnotation = popupAnnotation; | ||
this.markupGlueAnnotation = markupGlueAnnotation; | ||
} | ||
|
||
public void paint(Graphics g) { | ||
if (popupAnnotation.isOpen()) { | ||
Rectangle popupBounds = popupAnnotation.getUserSpaceRectangle().getBounds(); | ||
Rectangle markupBounds = markupAnnotation.getUserSpaceRectangle().getBounds(); | ||
Rectangle glueBounds = markupGlueAnnotation.getUserSpaceRectangle().getBounds(); | ||
MarkupGluePainter.paintGlue( | ||
g, markupBounds, popupBounds, glueBounds, markupAnnotation.getColor()); | ||
} | ||
} | ||
|
||
public static void paintGlue(Graphics g, Rectangle markupBounds, Rectangle popupBounds, Rectangle glueBounds, | ||
Color color) { | ||
Graphics2D g2d = (Graphics2D) g; | ||
g2d.setColor(color); | ||
g2d.setStroke(new BasicStroke(1)); | ||
GeneralPath path = new GeneralPath(); | ||
path.moveTo(0, 0); | ||
|
||
// in order to draw the curvy shape we need to determine which of the 8 surrounding regions | ||
// the popup is relative to the markup annotation. | ||
int popupX = popupBounds.x; | ||
int popupY = popupBounds.y; | ||
int popupXC = (int) popupBounds.getCenterX(); | ||
int popupYC = (int) popupBounds.getCenterY(); | ||
int popupW = popupBounds.width; | ||
int popupH = popupBounds.height; | ||
|
||
int markupXC = (int) markupBounds.getCenterX(); | ||
int markupYC = (int) markupBounds.getCenterY(); | ||
|
||
float angle = (float) Math.toDegrees(Math.atan2(markupYC - popupYC, markupXC - popupXC)); | ||
if (angle < 0) { | ||
angle += 360; | ||
} | ||
// N | ||
if (angle >= 67.5 && angle < 112.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupXC, popupY + popupH, popupX, popupY + popupH); | ||
path.lineTo(popupX + popupW, popupY + popupH); | ||
path.quadTo(popupXC, popupY + popupH, markupXC, markupYC); | ||
} | ||
// NE | ||
else if (angle >= 112.5 && angle < 157.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupX, popupY + popupH, popupX, popupYC); | ||
path.lineTo(popupXC, popupY + popupH); | ||
path.quadTo(popupX, popupY + popupH, markupXC, markupYC); | ||
} | ||
// E | ||
else if (angle >= 157.5 && angle < 202.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupX, popupYC, popupX, popupY); | ||
path.lineTo(popupX, popupY + popupH); | ||
path.quadTo(popupX, popupYC, markupXC, markupYC); | ||
} | ||
// SE | ||
else if (angle >= 202.5 && angle < 247.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupX, popupY, popupXC, popupY); | ||
path.lineTo(popupX, popupYC); | ||
path.quadTo(popupX, popupY, markupXC, markupYC); | ||
} | ||
// S | ||
else if (angle >= 247.5 && angle < 292.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupXC, popupY, popupX, popupY); | ||
path.lineTo(popupX + popupW, popupY); | ||
path.quadTo(popupXC, popupY, markupXC, markupYC); | ||
} else if (angle >= 292.5 && angle < 315) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupX + popupW, popupY, popupXC, popupY); | ||
path.lineTo(popupX + popupW, popupYC); | ||
path.quadTo(popupX + popupW, popupY, markupXC, markupYC); | ||
} | ||
// W | ||
else if (angle >= 315 || angle < 22.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupX + popupW, popupYC, popupX + popupW, popupY); | ||
path.lineTo(popupX + popupW, popupY + popupH); | ||
path.quadTo(popupX + popupW, popupYC, markupXC, markupYC); | ||
} | ||
// NW | ||
else if (angle >= 22.5 && angle < 67.5) { | ||
path.moveTo(markupXC, markupYC); | ||
path.quadTo(popupX + popupW, popupY + popupH, popupX + popupW, popupYC); | ||
path.lineTo(popupXC, popupY + popupH); | ||
path.quadTo(popupX + popupW, popupY + popupH, markupXC, markupYC); | ||
} | ||
// translate to this components space. | ||
path.transform(new AffineTransform(1, 0, 0, 1, -glueBounds.x, -glueBounds.y)); | ||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | ||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); | ||
g2d.fill(path); | ||
} | ||
} |
Oops, something went wrong.