summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/java/example/PageCanvas.java33
-rw-r--r--platform/java/example/Viewer.java10
2 files changed, 39 insertions, 4 deletions
diff --git a/platform/java/example/PageCanvas.java b/platform/java/example/PageCanvas.java
index cca57dc5..b6471f3d 100644
--- a/platform/java/example/PageCanvas.java
+++ b/platform/java/example/PageCanvas.java
@@ -12,6 +12,8 @@ public class PageCanvas extends java.awt.Canvas
protected float mScale = 1.0f;
private float mRetinaScale = 1.0f;
+ private static boolean mShowAnnots = false;
+
public static BufferedImage imageFromPixmap(Pixmap pixmap) {
int w = pixmap.getWidth();
int h = pixmap.getHeight();
@@ -21,15 +23,35 @@ public class PageCanvas extends java.awt.Canvas
}
public static BufferedImage imageFromPageWithDevice(Page page, Matrix ctm) {
+ // make a blank pixmap
Rect bbox = page.getBounds();
bbox.transform(ctm);
- Pixmap pixmap = new Pixmap(ColorSpace.DeviceBGR, bbox);
+ Pixmap pixmap = new Pixmap(ColorSpace.DeviceBGR, bbox, true);
pixmap.clear(255);
+
+ // make a device
DrawDevice dev = new DrawDevice(pixmap);
- page.run(dev, ctm);
+
+ // run page contents (without annotations)
+ page.runPageContents(dev, ctm, new Cookie());
+
+ // run annotations
+ if (mShowAnnots)
+ {
+ Annotation annotations[] = page.getAnnotations();
+ if (annotations != null && annotations.length>0)
+ {
+ for (Annotation annot : annotations) {
+ annot.run(dev, ctm, new Cookie());
+ }
+ }
+ }
+
dev.destroy();
+
BufferedImage image = imageFromPixmap(pixmap);
pixmap.destroy();
+
return image;
}
@@ -51,7 +73,7 @@ public class PageCanvas extends java.awt.Canvas
{
Matrix ctm = new Matrix();
ctm.scale(mScale);
- image = imageFromPage(page, ctm);
+ image = imageFromPageWithDevice(page, ctm);
repaint();
}
@@ -81,6 +103,11 @@ public class PageCanvas extends java.awt.Canvas
}
}
+ public void toggleAnnots() {
+ mShowAnnots = !mShowAnnots;
+ run();
+ }
+
public void paint(Graphics g)
{
float scale = 1.0f;
diff --git a/platform/java/example/Viewer.java b/platform/java/example/Viewer.java
index d70a82e3..abd13067 100644
--- a/platform/java/example/Viewer.java
+++ b/platform/java/example/Viewer.java
@@ -29,7 +29,7 @@ public class Viewer extends Frame implements WindowListener, ActionListener
protected Panel toolbar;
protected PageCanvas pageCanvas;
protected Label pageLabel;
- protected Button firstButton, prevButton, nextButton, lastButton, zoomInButton, zoomOutButton, fontIncButton, fontDecButton;
+ protected Button firstButton, prevButton, nextButton, lastButton, zoomInButton, zoomOutButton, fontIncButton, fontDecButton, toggleAnnotsButton;
protected int pageCount;
protected int pageNumber;
protected int layoutWidth;
@@ -70,6 +70,9 @@ public class Viewer extends Frame implements WindowListener, ActionListener
zoomOutButton = new Button("-");
zoomOutButton.addActionListener(this);
+ toggleAnnotsButton = new Button("toggle annots");
+ toggleAnnotsButton.addActionListener(this);
+
if (doc.isReflowable()) {
fontIncButton = new Button("FONT");
fontIncButton.addActionListener(this);
@@ -85,6 +88,7 @@ public class Viewer extends Frame implements WindowListener, ActionListener
toolbar.add(lastButton);
toolbar.add(zoomInButton);
toolbar.add(zoomOutButton);
+ toolbar.add(toggleAnnotsButton);
if (doc.isReflowable()) {
toolbar.add(fontIncButton);
toolbar.add(fontDecButton);
@@ -147,6 +151,10 @@ public class Viewer extends Frame implements WindowListener, ActionListener
if (layoutEm != oldLayoutEm)
doc.layout(layoutWidth, layoutHeight, layoutEm);
+ if (source == toggleAnnotsButton) {
+ pageCanvas.toggleAnnots();
+ }
+
if (pageNumber != oldPageNumber || layoutEm != oldLayoutEm)
stuff();
}