diff options
author | fred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local> | 2016-07-14 16:14:21 -0700 |
---|---|---|
committer | fred ross-perry <fred.ross-perry@artifex.com> | 2016-07-15 10:08:57 -0700 |
commit | 6fb868c1cdbae2864f1ad866f6c9422153dbd031 (patch) | |
tree | 08ef496983c863e2fcaace5ad404182a44d50db6 /platform/java | |
parent | cb78b5c6782f14a699f90bd5621cd3656a1e02ea (diff) | |
download | mupdf-6fb868c1cdbae2864f1ad866f6c9422153dbd031.tar.xz |
android desktop view - add a button to toggle annotations on/off.
Diffstat (limited to 'platform/java')
-rw-r--r-- | platform/java/example/PageCanvas.java | 33 | ||||
-rw-r--r-- | platform/java/example/Viewer.java | 10 |
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(); } |