summaryrefslogtreecommitdiff
path: root/platform/java/example/PageCanvas.java
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-01-04 13:19:33 +0100
committerTor Andersson <tor.andersson@artifex.com>2017-01-09 17:45:35 +0100
commit18d95a4ee602435899eae941ed0215fa1f71a01b (patch)
tree19f087faf7e24c62bc343a3cfea06dfb4c5ff87a /platform/java/example/PageCanvas.java
parent5d92615f37303041a473e8a25860860601a8dcfe (diff)
downloadmupdf-18d95a4ee602435899eae941ed0215fa1f71a01b.tar.xz
java: Clean up and simplify example viewer.
Don't pull in swing classes for simple desktop AWT viewer. Use inner classes for helper classes. Add list of zoom levels. Add table of content list. Make page canvas flicker free.
Diffstat (limited to 'platform/java/example/PageCanvas.java')
-rw-r--r--platform/java/example/PageCanvas.java122
1 files changed, 0 insertions, 122 deletions
diff --git a/platform/java/example/PageCanvas.java b/platform/java/example/PageCanvas.java
deleted file mode 100644
index b6471f3d..00000000
--- a/platform/java/example/PageCanvas.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package example;
-
-import com.artifex.mupdf.fitz.*;
-import java.awt.*;
-import java.awt.image.*;
-
-public class PageCanvas extends java.awt.Canvas
-{
- protected Page page;
- protected BufferedImage image;
-
- 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();
- BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- image.setRGB(0, 0, w, h, pixmap.getPixels(), 0, w);
- return image;
- }
-
- 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, true);
- pixmap.clear(255);
-
- // make a device
- DrawDevice dev = new DrawDevice(pixmap);
-
- // 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;
- }
-
- public static BufferedImage imageFromPage(Page page, Matrix ctm) {
- Pixmap pixmap = page.toPixmap(ctm, ColorSpace.DeviceBGR, true);
- BufferedImage image = imageFromPixmap(pixmap);
- pixmap.destroy();
- return image;
- }
-
- public PageCanvas(Page page_, float nativeScale) {
- mRetinaScale = nativeScale;
- mScale = mRetinaScale;
- this.page = page_;
- run();
- }
-
- private void run()
- {
- Matrix ctm = new Matrix();
- ctm.scale(mScale);
- image = imageFromPageWithDevice(page, ctm);
- repaint();
- }
-
- public Dimension getPreferredSize() {
- return new Dimension(image.getWidth(), image.getHeight());
- }
-
- public Dimension getMinimumSize() {
- return getPreferredSize();
- }
-
- public Dimension getMaximumSize() {
- return getPreferredSize();
- }
-
- public void zoomIn() {
- if (mScale < 10) {
- mScale += 0.25f;
- run();
- }
- }
-
- public void zoomOut() {
- if (mScale > 0.25f) {
- mScale -= 0.25f;
- run();
- }
- }
-
- public void toggleAnnots() {
- mShowAnnots = !mShowAnnots;
- run();
- }
-
- public void paint(Graphics g)
- {
- float scale = 1.0f;
- scale = 1/mRetinaScale;
-
- final Graphics2D g2d = (Graphics2D)g.create(0, 0, image.getWidth(), image.getHeight());
- g2d.scale(scale, scale);
- g2d.drawImage(image, 0, 0, null);
- g2d.dispose();
- }
-
-}