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/example/PageCanvas.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/example/PageCanvas.java')
-rw-r--r-- | platform/java/example/PageCanvas.java | 33 |
1 files changed, 30 insertions, 3 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; |