summaryrefslogtreecommitdiff
path: root/platform/java/PageCanvas.java
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-02-22 15:00:29 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-02-29 16:03:34 +0100
commit7609158e702ece6e182b19cec8b0192b1af598e8 (patch)
treed6611bc8243a457b2fe90bfebd72454e93601288 /platform/java/PageCanvas.java
parente1716629fd92f4580e6b213dc7be54b4935f09f9 (diff)
downloadmupdf-7609158e702ece6e182b19cec8b0192b1af598e8.tar.xz
jni: Various cleanups.
jni: Various cleanups. Fix gcc and clang warnings. Android specific functions are guarded by HAVE_ANDROID define. The java guts of the android stuff is removed for now, to be added back in later. Set up a makefile and simple tests to build for desktop java. Rerig device classes to: Device, NativeDevice, JavaDevice and DrawDevice. Add Pixmap class. Regularize naming. General cleanups and abbreviate naming. Use to_JavaClass and from_JavaClass rather than fz_mupdf_struct_from_JavaClass and JavaClass_from_fz_mupdf_struct. Check for exceptions thrown by java devices and path processor. Tweak constructors and finalizers to remove the JavaDevice subclass. Use toString when rethrowing java exceptions as fitz exceptions.
Diffstat (limited to 'platform/java/PageCanvas.java')
-rw-r--r--platform/java/PageCanvas.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/java/PageCanvas.java b/platform/java/PageCanvas.java
new file mode 100644
index 00000000..bf20afa8
--- /dev/null
+++ b/platform/java/PageCanvas.java
@@ -0,0 +1,57 @@
+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;
+
+ 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) {
+ Rect bbox = page.getBounds();
+ Pixmap pixmap = new Pixmap(ColorSpace.DeviceBGR, bbox);
+ pixmap.clear(255);
+ DrawDevice dev = new DrawDevice(pixmap);
+ page.run(dev, new Matrix());
+ 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);
+ BufferedImage image = imageFromPixmap(pixmap);
+ pixmap.destroy();
+ return image;
+ }
+
+ public PageCanvas(Page page_) {
+ this.page = page_;
+ image = imageFromPage(page, new Matrix());
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(image.getWidth(), image.getHeight());
+ }
+
+ public Dimension getMinimumSize() {
+ return getPreferredSize();
+ }
+
+ public Dimension getMaximumSize() {
+ return getPreferredSize();
+ }
+
+ public void paint(Graphics g) {
+ g.drawImage(image, 0, 0, null);
+ }
+}