diff options
34 files changed, 4263 insertions, 2274 deletions
diff --git a/platform/android/src/com/artifex/mupdf/fitz/AndroidDrawDevice.java b/platform/android/src/com/artifex/mupdf/fitz/AndroidDrawDevice.java index 1537f62a..4a8daaa7 100644 --- a/platform/android/src/com/artifex/mupdf/fitz/AndroidDrawDevice.java +++ b/platform/android/src/com/artifex/mupdf/fitz/AndroidDrawDevice.java @@ -2,18 +2,21 @@ package com.artifex.mupdf.fitz; import android.graphics.Bitmap; -public final class AndroidDrawDevice extends CDevice +public final class AndroidDrawDevice extends NativeDevice { + // NOT static. + private native long newNative(Bitmap bitmap, int pageX0, int pageY0, int pageX1, int pageY1, int patchX0, int patchY0, int patchX1, int patchY1); + // Construction public AndroidDrawDevice(Bitmap bitmap, int pageX0, int pageY0, int pageX1, int pageY1, int patchX0, int patchY0, int patchX1, int patchY1) { - nativeDevice = newNative(bitmap, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); + super(0); + pointer = newNative(bitmap, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); } public AndroidDrawDevice(Bitmap bitmap, RectI page, RectI patch) { - nativeDevice = newNative(bitmap, page.x0, page.y0, page.x1, page.y1, patch.x0, patch.y0, patch.x1, patch.y1); + super(0); + pointer = newNative(bitmap, page.x0, page.y0, page.x1, page.y1, patch.x0, patch.y0, patch.x1, patch.y1); } - - private native long newNative(Bitmap bitmap, int pageX0, int pageY0, int pageX1, int pageY1, int patchX0, int patchY0, int patchX1, int patchY1); } 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); + } +} diff --git a/platform/java/TraceDevice.java b/platform/java/TraceDevice.java new file mode 100644 index 00000000..879a453b --- /dev/null +++ b/platform/java/TraceDevice.java @@ -0,0 +1,138 @@ +import com.artifex.mupdf.fitz.*; + +public class TraceDevice extends Device implements PathWalker, TextWalker +{ + public String traceColor(ColorSpace cs, float color[], float alpha) { + String s = cs + " ["; + int i; + for (i = 0; i < color.length; ++i) { + if (i > 0) s += " "; + s += color[i]; + } + return s + "] " + alpha; + } + public String traceStroke(StrokeState stroke) { + return "c=" + stroke.getStartCap() + "," + stroke.getDashCap() + "," + stroke.getEndCap() + + " j=" + stroke.getLineJoin() + + " m=" + stroke.getMiterLimit() + + " l=" + stroke.getLineWidth(); + } + + public void moveTo(float x, float y) { + System.out.println("moveto " + x + " " + y); + } + public void lineTo(float x, float y) { + System.out.println("lineto " + x + " " + y); + } + public void curveTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey) { + System.out.println("curveto " + cx1 + " " + cy1 + " " + cx2 + " " + cy2 + " " + ex + " " + ey); + } + public void closePath() { + System.out.println("closepath"); + } + + public void showGlyph(Font font, boolean vertical, Matrix trm, int glyph, int unicode) { + System.out.println("glyph '" + (char)unicode + "' " + glyph + "\t" + font + " " + trm); + } + + public void tracePath(Path path) { + path.walk(this); + } + public void traceText(Text text) { + text.walk(this); + } + + public void beginPage(Rect r, Matrix m) { + System.out.println("beginPage " + r + " " + m); + } + + public void endPage() { + System.out.println("endPage"); + } + + public void fillPath(Path path, boolean evenOdd, Matrix ctm, ColorSpace cs, float color[], float alpha) { + System.out.println("fillPath " + evenOdd + " " + ctm + " " + traceColor(cs, color, alpha)); + tracePath(path); + } + public void strokePath(Path path, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha) { + System.out.println("strokePath " + traceStroke(stroke) + " " + ctm + " " + traceColor(cs, color, alpha)); + tracePath(path); + } + public void clipPath(Path path, Rect rect, boolean evenOdd, Matrix ctm) { + System.out.println("clipPath " + evenOdd + " " + ctm); + tracePath(path); + } + public void clipStrokePath(Path path, Rect rect, StrokeState stroke, Matrix ctm) { + System.out.println("clipStrokePath " + traceStroke(stroke) + " " + ctm); + tracePath(path); + } + + public void fillText(Text text, Matrix ctm, ColorSpace cs, float color[], float alpha) { + System.out.println("fillText " + ctm + " " + traceColor(cs, color, alpha)); + traceText(text); + } + public void strokeText(Text text, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha) { + System.out.println("strokeText " + ctm + " " + traceStroke(stroke) + " " + traceColor(cs, color, alpha)); + traceText(text); + } + public void clipText(Text text, Matrix ctm) { + System.out.println("clipText " + ctm); + traceText(text); + } + public void clipStrokeText(Text text, StrokeState stroke, Matrix ctm) { + System.out.println("clipStrokeText " + ctm + " " + traceStroke(stroke)); + traceText(text); + } + public void ignoreText(Text text, Matrix ctm) { + System.out.println("ignoreText " + ctm); + traceText(text); + } + public void fillShade(Shade shade, Matrix ctm, float alpha) { + System.out.println("fillShade " + ctm + " " + alpha); + } + public void fillImage(Image img, Matrix ctm, float alpha) { + System.out.println("fillImage " + ctm + " " + alpha); + } + public void fillImageMask(Image img, Matrix ctm, ColorSpace cs, float color[], float alpha) { + System.out.println("fillImageMask " + ctm + " " + traceColor(cs, color, alpha)); + } + public void clipImageMask(Image img, Rect rect, Matrix ctm) { + System.out.println("clipImageMask " + ctm + " " + rect); + } + public void popClip() { + System.out.println("popClip"); + } + + public void beginMask(Rect rect, boolean luminosity, ColorSpace cs, float bc[]) { + System.out.println("beginMask r=" + rect + + " l=" + luminosity + + " " + traceColor(cs, bc, 1)); + } + public void endMask() { + System.out.println("endMask"); + } + public void beginGroup(Rect rect, boolean isolated, boolean knockout, int blendmode, float alpha) { + System.out.println("beginGroup r=" + rect + + " i=" + isolated + + " k=" + knockout + + " bm=" + blendmode + + " a=" + alpha); + } + public void endGroup() { + System.out.println("endGroup"); + } + public int beginTile(Rect area, Rect view, float xstep, float ystep, Matrix ctm, int id) { + System.out.println("beginTile"); + return 0; + } + public void endTile() { + System.out.println("endTile"); + } + + public static void main(String[] args) { + Document doc = new Document("pdfref17.pdf"); + Page page = doc.loadPage(1144); + TraceDevice dev = new TraceDevice(); + page.run(dev, new Matrix()); + } +} diff --git a/platform/java/Viewer.java b/platform/java/Viewer.java new file mode 100644 index 00000000..e0d6290b --- /dev/null +++ b/platform/java/Viewer.java @@ -0,0 +1,67 @@ +import com.artifex.mupdf.fitz.*; +import java.awt.Frame; +import java.awt.Label; +import java.awt.BorderLayout; +import java.awt.event.*; + +public class Viewer extends Frame implements WindowListener +{ + protected Document doc; + protected PageCanvas pageCanvas; + protected Label pageLabel; + protected int count; + + public Viewer(Document doc_) { + super("MuPDF"); + + this.doc = doc_; + this.count = doc.countPages(); + + setSize(600, 900); + + pageCanvas = new PageCanvas(doc.loadPage(1144)); + pageLabel = new Label("page " + 1); + + add(pageLabel, BorderLayout.NORTH); + add(pageCanvas, BorderLayout.CENTER); + + addWindowListener(this); + + { + Page page = doc.loadPage(0); + Device dev = new Device() { + public void beginPage(Rect r, Matrix m) { + System.out.println("beginPage " + r + m); + } + public void fillText(Text text, Matrix ctm, ColorSpace cs, float color[], float alpha) { + System.out.println("fillText " + text); + text.walk(new TextWalker() { + public void showGlyph(Font f, boolean v, Matrix m, int g, int c) { + System.out.println(f + " " + m + " " + g + " " + (char)c); + } + }); + } + }; + page.run(dev, new Matrix(), null); + } + } + + // WindowListener + + public void windowClosing(WindowEvent event) { + System.exit(0); + } + + public void windowActivated(WindowEvent event) { } + public void windowDeactivated(WindowEvent event) { } + public void windowIconified(WindowEvent event) { } + public void windowDeiconified(WindowEvent event) { } + public void windowOpened(WindowEvent event) { } + public void windowClosed(WindowEvent event) { } + + public static void main(String[] args) { + Document doc = new Document("pdfref17.pdf"); + Viewer app = new Viewer(doc); + app.setVisible(true); + } +} diff --git a/platform/java/com/artifex/mupdf/fitz/Annotation.java b/platform/java/com/artifex/mupdf/fitz/Annotation.java index 6e6dd1c1..5f652246 100644 --- a/platform/java/com/artifex/mupdf/fitz/Annotation.java +++ b/platform/java/com/artifex/mupdf/fitz/Annotation.java @@ -2,26 +2,20 @@ package com.artifex.mupdf.fitz; public class Annotation { - // Private data - private long nativeAnnot = 0; + private long pointer; - // Construction - private Annotation(long ptr) - { - nativeAnnot = ptr; - } - - // Operation - public native void run(Device dev, Matrix ctm, Cookie cookie); - - // FIXME: Write accessors + protected native void finalize(); - // Destruction - public void destroy() - { + public void destroy() { finalize(); - nativeAnnot = 0; + pointer = 0; } - protected native void finalize(); + private Annotation(long p) { + pointer = p; + } + + public native void run(Device dev, Matrix ctm, Cookie cookie); + + private native long advance(); } diff --git a/platform/java/com/artifex/mupdf/fitz/AwtDrawDevice.java b/platform/java/com/artifex/mupdf/fitz/AwtDrawDevice.java deleted file mode 100644 index 4e6fb33d..00000000 --- a/platform/java/com/artifex/mupdf/fitz/AwtDrawDevice.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.artifex.mupdf.fitz; - -public final class AwtDrawDevice extends CDevice -{ - // Construction - public AwtDrawDevice(int rgba[], int width, int height) - { - nativeDevice = newNative(rgba, width, height); - } - - private native long newNative(int rgba[], int width, int height); -} diff --git a/platform/java/com/artifex/mupdf/fitz/ColorSpace.java b/platform/java/com/artifex/mupdf/fitz/ColorSpace.java index cad952c0..b7822161 100644 --- a/platform/java/com/artifex/mupdf/fitz/ColorSpace.java +++ b/platform/java/com/artifex/mupdf/fitz/ColorSpace.java @@ -2,33 +2,44 @@ package com.artifex.mupdf.fitz; public class ColorSpace { - // Private data - private long nativeColorSpace; - - // Statics - public static ColorSpace DeviceGray = new ColorSpace(newDeviceGray()); - public static ColorSpace DeviceRGB = new ColorSpace(newDeviceRGB()); - public static ColorSpace DeviceCMYK = new ColorSpace(newDeviceCMYK()); - - private static native long newDeviceGray(); - private static native long newDeviceRGB(); - private static native long newDeviceCMYK(); - - // Construction - private ColorSpace(long l) - { - nativeColorSpace = l; - } + private long pointer; - // Accessors - public native int getNumComponents(); + protected native void finalize(); - // Destruction - public final void destroy() - { + public void destroy() { finalize(); - nativeColorSpace = 0; + pointer = 0; + } + + private ColorSpace(long p) { + pointer = p; } - protected final native void finalize(); + private static native long nativeDeviceGray(); + private static native long nativeDeviceRGB(); + private static native long nativeDeviceBGR(); + private static native long nativeDeviceCMYK(); + + protected static ColorSpace fromPointer(long p) { + if (p == DeviceGray.pointer) return DeviceGray; + if (p == DeviceRGB.pointer) return DeviceRGB; + if (p == DeviceBGR.pointer) return DeviceBGR; + if (p == DeviceCMYK.pointer) return DeviceCMYK; + return new ColorSpace(p); + } + + public static ColorSpace DeviceGray = new ColorSpace(nativeDeviceGray()); + public static ColorSpace DeviceRGB = new ColorSpace(nativeDeviceRGB()); + public static ColorSpace DeviceBGR = new ColorSpace(nativeDeviceBGR()); + public static ColorSpace DeviceCMYK = new ColorSpace(nativeDeviceCMYK()); + + public native int getNumberOfComponents(); + + public String toString() { + if (this == DeviceGray) return "DeviceGray"; + if (this == DeviceRGB) return "DeviceRGB"; + if (this == DeviceBGR) return "DeviceBGR"; + if (this == DeviceCMYK) return "DeviceCMYK"; + return "ColorSpace(" + getNumberOfComponents() + ")"; + } } diff --git a/platform/java/com/artifex/mupdf/fitz/Context.java b/platform/java/com/artifex/mupdf/fitz/Context.java index 1baafb01..3614e65f 100644 --- a/platform/java/com/artifex/mupdf/fitz/Context.java +++ b/platform/java/com/artifex/mupdf/fitz/Context.java @@ -8,12 +8,20 @@ package com.artifex.mupdf.fitz; // function. public class Context { - // Load our native library - static - { - System.loadLibrary("mupdf"); + private static boolean inited = false; + private static native int initNative(); + + public static void init() { + if (!inited) { + inited = true; + System.loadLibrary("mupdf_java"); + if (initNative() < 0) + throw new RuntimeException("cannot initialize mupdf library"); + } } + static { init(); } + // FIXME: We should support the store size being changed dynamically. // This requires changes within the MuPDF core. //public native static void setStoreSize(long newSize); diff --git a/platform/java/com/artifex/mupdf/fitz/Cookie.java b/platform/java/com/artifex/mupdf/fitz/Cookie.java index b6761b42..f866f99e 100644 --- a/platform/java/com/artifex/mupdf/fitz/Cookie.java +++ b/platform/java/com/artifex/mupdf/fitz/Cookie.java @@ -2,29 +2,20 @@ package com.artifex.mupdf.fitz; public class Cookie { - // Private data - private long nativeCookie = 0; + private long pointer; - // Construction - public Cookie() - { - nativeCookie = newNative(); + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; } private native long newNative(); - // Operation - public native void abort(); - - //FIXME: Cookie accessors - - // Destruction - protected native void finalize(); - - public void destroy() - { - finalize(); - nativeCookie = 0; + public Cookie() { + pointer = newNative(); } + public native void abort(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Device.java b/platform/java/com/artifex/mupdf/fitz/Device.java index 366022e9..c8bf23d4 100644 --- a/platform/java/com/artifex/mupdf/fitz/Device.java +++ b/platform/java/com/artifex/mupdf/fitz/Device.java @@ -1,7 +1,66 @@ package com.artifex.mupdf.fitz; -public abstract class Device +public class Device { + protected long pointer; + + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; + } + + private native long newNative(); + + protected Device() { + pointer = newNative(); + } + + protected Device(long p) { + pointer = p; + } + + /* An accessor for device hints */ + public native int getHints(); + public native void enableDeviceHints(int hints); + public native void disableDeviceHints(int hints); + + /* To implement your own device in Java, you should define your own + * class that extends Device, and override as many of the following + * functions as is appropriate. For example: + * + * class ImageTraceDevice extends Device + * { + * void fillImage(Image img, Matrix ctx, float alpha) { + * System.out.println("Image!"); + * } + * }; + */ + + public void beginPage(Rect rect, Matrix ctm) {} + public void endPage() {} + public void fillPath(Path path, boolean evenOdd, Matrix ctm, ColorSpace cs, float color[], float alpha) {} + public void strokePath(Path path, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha) {} + public void clipPath(Path path, Rect rect, boolean evenOdd, Matrix ctm) {} + public void clipStrokePath(Path path, Rect rect, StrokeState stroke, Matrix ctm) {} + public void fillText(Text text, Matrix ctm, ColorSpace cs, float color[], float alpha) {} + public void strokeText(Text text, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha) {} + public void clipText(Text text, Matrix ctm) {} + public void clipStrokeText(Text text, StrokeState stroke, Matrix ctm) {} + public void ignoreText(Text text, Matrix ctm) {} + public void fillShade(Shade shade, Matrix ctm, float alpha) {} + public void fillImage(Image img, Matrix ctm, float alpha) {} + public void fillImageMask(Image img, Matrix ctm, ColorSpace cs, float color[], float alpha) {} + public void clipImageMask(Image img, Rect rect, Matrix ctm) {} + public void popClip() {} + public void beginMask(Rect rect, boolean luminosity, ColorSpace cs, float bc[]) {} + public void endMask() {} + public void beginGroup(Rect rect, boolean isolated, boolean knockout, int blendmode, float alpha) {} + public void endGroup() {} + public int beginTile(Rect area, Rect view, float xstep, float ystep, Matrix ctm, int id) { return 0; } + public void endTile() {} + /* Flags */ public static final int FZ_DEVFLAG_MASK = 1; public static final int FZ_DEVFLAG_COLOR = 2; @@ -40,133 +99,7 @@ public abstract class Device public static final int FZ_BLEND_ISOLATED = 16; public static final int FZ_BLEND_KNOCKOUT = 32; - /* To implement your own device in Java, you should define your own - * class that extends this one, and override as many of the following - * functions as is appropriate. For example: - * - * class ImageTraceDevice extends Device - * { - * void fillImage(Image img, Matrix ctx, float alpha) { - * Debug.Log("Image!"); - * } - * }; - * - * There is no constructor here, as no one will ever construct a - * Device without subclassing. - */ - - /* Everything under here is private implementation details. - * Ideally we'd like to hide these from prying eyes, but Java doesn't - * allow that. - */ - + /* Device hints */ public static final int FZ_IGNORE_IMAGE = 1; public static final int FZ_IGNORE_SHADE = 2; - - /* None of our device functions do anything. Anyone interested will - * override them in a subclass either in Java, or (as a subclass of - * CDevice) in C. - */ - public void beginPage(Rect rect, Matrix ctm) - { - } - - public void endPage() - { - } - - public void fillPath(Path path, int even_odd, Matrix ctm, ColorSpace cs, float color[], float alpha) - { - } - - public void strokePath(long ctx, Path path, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha) - { - } - - public void clipPath(Path path, Rect rect, int even_odd, Matrix ctm) - { - } - - public void clipStrokePath(Path path, Rect rect, StrokeState stroke, Matrix ctm) - { - } - - public void fillText(Text text, Matrix ctm, ColorSpace cs, float color[], float alpha) - { - } - - public void strokeText(Text text, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha) - { - } - - public void clipText(Text text, Matrix ctm) - { - } - - public void clipStrokeText(Text text, StrokeState stroke, Matrix ctm) - { - } - - public void ignoreText(Text text, Matrix ctm) - { - } - - public void fillShade(Shade shade, Matrix ctm, float alpha) - { - } - - public void fillImage(Image img, Matrix ctm, float alpha) - { - } - - public void fillImageMask(Image img, Matrix ctm, ColorSpace cs, float color[], float alpha) - { - } - - public void clipImageMask(Image img, Rect rect, Matrix ctm) - { - } - - public void popClip() - { - } - - public void beginMask(Rect rect, int luminosity, ColorSpace cs, float bc[]) - { - } - - public void endMask() - { - } - - public void beginGroup(Rect rect, int isolated, int knockout, int blendmode, float alpha) - { - } - - public void endGroup() - { - } - - public int beginTile(Rect area, Rect view, float xstep, float ystep, Matrix ctm, int id) - { - return 0; - } - - public void endTile() - { - } - - /* An accessor for device hints */ - final native int getHints(); - final native void enableDeviceHints(int hints); - final native void disableDeviceHints(int hints); - - // Destruction - public void destroy() - { - } - - // Private data. - // All java devices MUST leave this as 0. - protected long nativeDevice; } diff --git a/platform/java/com/artifex/mupdf/fitz/DisplayList.java b/platform/java/com/artifex/mupdf/fitz/DisplayList.java index 8a2515e4..3f36fa3d 100644 --- a/platform/java/com/artifex/mupdf/fitz/DisplayList.java +++ b/platform/java/com/artifex/mupdf/fitz/DisplayList.java @@ -2,31 +2,24 @@ package com.artifex.mupdf.fitz; public class DisplayList { - // Private data - protected long nativeDisplayList; + protected long pointer; - // Constructions - public DisplayList() - { - nativeDisplayList = newNative(); + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; } private native long newNative(); - // Operation + public DisplayList() { + pointer = newNative(); + } + public native void run(Device device, Matrix ctm, Rect scissor, Cookie cookie); - public void run(Device device, Matrix ctm, Cookie cookie) - { + public void run(Device device, Matrix ctm, Cookie cookie) { run(device, ctm, null, cookie); } - - // Destruction - public void destroy() - { - finalize(); - nativeDisplayList = 0; - } - - protected native void finalize(); } diff --git a/platform/java/com/artifex/mupdf/fitz/DisplayListDevice.java b/platform/java/com/artifex/mupdf/fitz/DisplayListDevice.java index de3142dc..c7f7c935 100644 --- a/platform/java/com/artifex/mupdf/fitz/DisplayListDevice.java +++ b/platform/java/com/artifex/mupdf/fitz/DisplayListDevice.java @@ -1,14 +1,10 @@ package com.artifex.mupdf.fitz; -import android.graphics.Bitmap; - -public final class DisplayListDevice extends CDevice +public final class DisplayListDevice extends NativeDevice { - // Construction - public DisplayListDevice(DisplayList list) - { - nativeDevice = newNative(list); - } + private static native long newNative(DisplayList list); - private native long newNative(DisplayList list); + public DisplayListDevice(DisplayList list) { + super(newNative(list)); + } } diff --git a/platform/java/com/artifex/mupdf/fitz/Document.java b/platform/java/com/artifex/mupdf/fitz/Document.java index 8c3136df..efa2a425 100644 --- a/platform/java/com/artifex/mupdf/fitz/Document.java +++ b/platform/java/com/artifex/mupdf/fitz/Document.java @@ -1,60 +1,44 @@ package com.artifex.mupdf.fitz; -import java.lang.ref.WeakReference; - public class Document { - // Private data - private long nativeDocument = 0; - - // Construction - public Document(String filename) throws Exception - { - nativeDocument = newNative(filename); - if (nativeDocument == 0) - throw(new Exception("Failed to load Document")); - } - private native final long newNative(String filename); - - // FIXME: Should support opening java streams and from byte buffers etc. - // Streams would need to be seekable. - public Document(byte buffer[], String magic) throws Exception - { - nativeDocument = 0;//newFromBufferNative(buffer, magic); - if (nativeDocument == 0) - throw(new Exception("Failed to load Document")); + static { + Context.init(); } - //private native final long newFromBufferNative(byte buffer[], String magic); - //public Document(SeekableStream stream, String magic) throws Exception - //{ - // nativeDocument = newFromStreamNative(stream, magic); - // if (nativeDocument == 0) - // throw(new Exception("Failed to load Document")); - //} - //private native final long newFromBufferNative(SeekableStream stream, String magic); + public static final String META_FORMAT = "format"; + public static final String META_ENCRYPTION = "encryption"; + public static final String META_INFO_AUTHOR = "info:Author"; + public static final String META_INFO_TITLE = "info:Title"; - // Operation - public native boolean needsPassword(); + protected long pointer; - public native boolean authenticatePassword(String password); + protected native void finalize(); - public native int countPages(); + public void destroy() { + finalize(); + pointer = 0; + } - public native Page getPage(int n); + private native long newNativeWithPath(String filename); + private native long newNativeWithBuffer(byte buffer[], String magic); + // private native long newNativeWithRandomAccessFile(RandomAccessFile file, String magic); - public native String getFileFormat(); + public Document(String filename) { + pointer = newNativeWithPath(filename); + } - public native boolean isUnencryptedPDF(); + public Document(byte buffer[], String magic) { + pointer = newNativeWithBuffer(buffer, magic); + } - public native Outline getOutline(); + public native boolean needsPassword(); + public native boolean authenticatePassword(String password); - // Destruction - public void destroy() - { - finalize(); - nativeDocument = 0; - } + public native int countPages(); + public native Page loadPage(int number); + public native Outline loadOutline(); + public native String getMetaData(String key); - protected native void finalize(); + public native boolean isUnencryptedPDF(); } diff --git a/platform/java/com/artifex/mupdf/fitz/DrawDevice.java b/platform/java/com/artifex/mupdf/fitz/DrawDevice.java new file mode 100644 index 00000000..e022be10 --- /dev/null +++ b/platform/java/com/artifex/mupdf/fitz/DrawDevice.java @@ -0,0 +1,10 @@ +package com.artifex.mupdf.fitz; + +public final class DrawDevice extends NativeDevice +{ + private static native long newNative(Pixmap pixmap); + + public DrawDevice(Pixmap pixmap) { + super(newNative(pixmap)); + } +} diff --git a/platform/java/com/artifex/mupdf/fitz/Font.java b/platform/java/com/artifex/mupdf/fitz/Font.java index 7630dfa5..5b9cd8c5 100644 --- a/platform/java/com/artifex/mupdf/fitz/Font.java +++ b/platform/java/com/artifex/mupdf/fitz/Font.java @@ -2,21 +2,22 @@ package com.artifex.mupdf.fitz; public class Font { - // Private data - private long nativeFont; + private long pointer; - // Construction - private Font(long font) - { - nativeFont = font; - } + protected native void finalize(); - // Destruction - public void destroy() - { + public void destroy() { finalize(); - nativeFont = 0; + pointer = 0; } - protected native void finalize(); + private Font(long p) { + pointer = p; + } + + public native String getName(); + + public String toString() { + return "Font(" + getName() + ")"; + } } diff --git a/platform/java/com/artifex/mupdf/fitz/Image.java b/platform/java/com/artifex/mupdf/fitz/Image.java index a736ce5f..4964053e 100644 --- a/platform/java/com/artifex/mupdf/fitz/Image.java +++ b/platform/java/com/artifex/mupdf/fitz/Image.java @@ -1,40 +1,23 @@ package com.artifex.mupdf.fitz; -import android.graphics.Bitmap; public class Image { - // Private data - private long nativeImage = 0; + private long pointer; - // Construction - Image(Bitmap bm) throws Exception - { - if (bm == null) - throw new Exception("null Bitmap passed to Image"); - nativeImage = newFromBitmapNative(bm, null); - } + protected native void finalize(); - Image(Bitmap bm, Image mask) throws Exception - { - if (bm == null) - throw new Exception("null Bitmap passed to Image"); - nativeImage = newFromBitmapNative(bm, mask); + public void destroy() { + finalize(); + pointer = 0; } - private native final long newFromBitmapNative(Bitmap bm, Image mask); - - // Private constructor for the C to use. Any objects created by the - // C are done for purposes of calling back to a java device, and - // should therefore be considered const. - private Image(long l) - { - nativeImage = l; + private Image(long p) { + pointer = p; } - // Accessors public native int getWidth(); public native int getHeight(); - public native int getNumComponents(); + public native int getNumberOfComponents(); public native int getBitsPerComponent(); public native int getXResolution(); public native int getYResolution(); @@ -44,13 +27,4 @@ public class Image // FIXME: Get data back? // FIXME: Create images from data or java streams? - - // Destruction - public void destroy() - { - finalize(); - nativeImage = 0; - } - - protected native void finalize(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Link.java b/platform/java/com/artifex/mupdf/fitz/Link.java index 7c63fcf9..0ecd8307 100644 --- a/platform/java/com/artifex/mupdf/fitz/Link.java +++ b/platform/java/com/artifex/mupdf/fitz/Link.java @@ -2,26 +2,18 @@ package com.artifex.mupdf.fitz; public class Link { - // Private data - private long nativeLink = 0; + private long pointer; - // Construction - private Link(long l) - { - nativeLink = l; - } - - // Operation - public native Link getNext(); - - //FIXME: Accessors + protected native void finalize(); - // Destruction - public void destroy() - { + public void destroy() { finalize(); - nativeLink = 0; + pointer = 0; } - protected native void finalize(); + private Link(long p) { + pointer = p; + } + + public native Link getNext(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Matrix.java b/platform/java/com/artifex/mupdf/fitz/Matrix.java index ede57ccc..80da84fc 100644 --- a/platform/java/com/artifex/mupdf/fitz/Matrix.java +++ b/platform/java/com/artifex/mupdf/fitz/Matrix.java @@ -2,15 +2,9 @@ package com.artifex.mupdf.fitz; public class Matrix { - public float a; - public float b; - public float c; - public float d; - public float e; - public float f; - - public Matrix(float a, float b, float c, float d, float e, float f) - { + public float a, b, c, d, e, f; + + public Matrix(float a, float b, float c, float d, float e, float f) { this.a = a; this.b = b; this.c = c; @@ -19,28 +13,32 @@ public class Matrix this.f = f; } - public Matrix(float a, float d) - { - this.a = a; - this.b = 0; - this.c = 0; - this.d = d; - this.e = 0; - this.f = 0; + public Matrix(float a, float b, float c, float d) { + this(a, b, c, d, 0, 0); } - public Matrix(float a) - { - this.a = a; - this.b = 0; - this.c = 0; - this.d = a; - this.e = 0; - this.f = 0; + public Matrix(float a, float d) { + this(a, 0, 0, d, 0, 0); + } + + public Matrix(float a) { + this(a, 0, 0, a, 0, 0); + } + + public Matrix() { + this(1, 0, 0, 1, 0, 0); + } + + public Matrix(Matrix one, Matrix two) { + a = one.a * two.a + one.b * two.c; + b = one.a * two.b + one.b * two.d; + c = one.c * two.a + one.d * two.c; + d = one.c * two.b + one.d * two.d; + e = one.e * two.a + one.f * two.c + two.e; + f = one.e * two.b + one.f * two.d + two.f; } - public Matrix concat(Matrix m) - { + public Matrix concat(Matrix m) { float a = this.a * m.a + this.b * m.c; float b = this.a * m.b + this.b * m.d; float c = this.c * m.a + this.d * m.c; @@ -56,4 +54,110 @@ public class Matrix return this; } + + public Matrix scale(float sx, float sy) { + a *= sx; + b *= sx; + c *= sy; + d *= sy; + return this; + } + + public Matrix scale(float s) { + return scale(s, s); + } + + public Matrix translate(float tx, float ty) { + e += tx * a + ty * c; + f += tx * b + ty * d; + return this; + } + + public Matrix rotate(float degrees) { + while (degrees < 0) + degrees += 360; + while (degrees >= 360) + degrees -= 360; + + if (Math.abs(0 - degrees) < 0.0001) { + // Nothing to do + } else if (Math.abs(90 - degrees) < 0.0001) { + float save_a = a; + float save_b = b; + a = c; + b = d; + c = -save_a; + d = -save_b; + } else if (Math.abs(180 - degrees) < 0.0001) { + a = -a; + b = -b; + c = -c; + d = -d; + } else if (Math.abs(270 - degrees) < 0.0001) { + float save_a = a; + float save_b = b; + a = -c; + b = -d; + c = save_a; + d = save_b; + } else { + float sin = (float)Math.sin(degrees * Math.PI / 180.0); + float cos = (float)Math.cos(degrees * Math.PI / 180.0); + float save_a = a; + float save_b = b; + a = cos * save_a + sin * c; + b = cos * save_b + sin * d; + c = -sin * save_a + cos * c; + d = -sin * save_b + cos * d; + } + return this; + } + + public String toString() { + return "[" + a + " " + b + " " + c + " " + d + " " + e + " " + f + "]"; + } + + public static Matrix Identity() { + return new Matrix(1, 0, 0, 1, 0, 0); + } + + public static Matrix Scale(float x) { + return new Matrix(x, 0, 0, x, 0, 0); + } + + public static Matrix Scale(float x, float y) { + return new Matrix(x, 0, 0, y, 0, 0); + } + + public static Matrix Translate(float x, float y) { + return new Matrix(1, 0, 0, 1, x, y); + } + + public static Matrix Rotate(float degrees) { + float sin, cos; + + while (degrees < 0) + degrees += 360; + while (degrees >= 360) + degrees -= 360; + + if (Math.abs(0 - degrees) < 0.0001) { + sin = 0; + cos = 1; + } else if (Math.abs(90 - degrees) < 0.0001) { + sin = 1; + cos = 0; + } else if (Math.abs(180 - degrees) < 0.0001) { + sin = 0; + cos = -1; + } else if (Math.abs(270 - degrees) < 0.0001) { + sin = -1; + cos = 0; + } else { + sin = (float)Math.sin(degrees * Math.PI / 180.0); + cos = (float)Math.cos(degrees * Math.PI / 180.0); + } + + return new Matrix(cos, sin, -sin, cos, 0, 0); + } } diff --git a/platform/java/com/artifex/mupdf/fitz/CDevice.java b/platform/java/com/artifex/mupdf/fitz/NativeDevice.java index 3bfe9c70..6786688f 100644 --- a/platform/java/com/artifex/mupdf/fitz/CDevice.java +++ b/platform/java/com/artifex/mupdf/fitz/NativeDevice.java @@ -1,23 +1,33 @@ package com.artifex.mupdf.fitz; -public abstract class CDevice extends Device +public class NativeDevice extends Device { - // Private data - private Object nativeResource = null; - protected long nativeInfo = 0; + private long nativeInfo; + private Object nativeResource; + + protected native void finalize(); + + public void destroy() { + super.destroy(); + nativeInfo = 0; + nativeResource = null; + } + + protected NativeDevice(long p) { + super(p); + } - // Operation public native final void beginPage(Rect rect, Matrix ctm); public native final void endPage(); - public native final void fillPath(Path path, int even_odd, Matrix ctm, ColorSpace cs, float color[], float alpha); + public native final void fillPath(Path path, boolean evenOdd, Matrix ctm, ColorSpace cs, float color[], float alpha); public native final void strokePath(Path path, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha); - public native final void clipPath(Path path, Rect rect, int even_odd, Matrix ctm); + public native final void clipPath(Path path, Rect rect, boolean evenOdd, Matrix ctm); public native final void clipStrokePath(Path path, Rect rect, StrokeState stroke, Matrix ctm); public native final void fillText(Text text, Matrix ctm, ColorSpace cs, float color[], float alpha); public native final void strokeText(Text text, StrokeState stroke, Matrix ctm, ColorSpace cs, float color[], float alpha); - public native final void clipText(Text text, Matrix ctm, int accumulate); + public native final void clipText(Text text, Matrix ctm); public native final void clipStrokeText(Text text, StrokeState stroke, Matrix ctm); public native final void ignoreText(Text text, Matrix ctm); @@ -28,22 +38,11 @@ public abstract class CDevice extends Device public native final void popClip(); - public native final void beginMask(Rect rect, int luminosity, ColorSpace cs, float bc[]); + public native final void beginMask(Rect rect, boolean luminosity, ColorSpace cs, float bc[]); public native final void endMask(); - public native final void beginGroup(Rect rect, int isolated, int knockout, int blendmode, float alpha); + public native final void beginGroup(Rect rect, boolean isolated, boolean knockout, int blendmode, float alpha); public native final void endGroup(); public native final int beginTile(Rect area, Rect view, float xstep, float ystep, Matrix ctm, int id); public native final void endTile(); - - // Destruction - public final void destroy() - { - finalize(); - nativeDevice = 0; - nativeResource = null; - nativeInfo = 0; - } - - protected native final void finalize(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Outline.java b/platform/java/com/artifex/mupdf/fitz/Outline.java index 1b808d7f..98a11b79 100644 --- a/platform/java/com/artifex/mupdf/fitz/Outline.java +++ b/platform/java/com/artifex/mupdf/fitz/Outline.java @@ -2,21 +2,16 @@ package com.artifex.mupdf.fitz; public class Outline { - // Private data - private long nativeOutline = 0; + private long pointer; - // Construction - private Outline(long out) - { - nativeOutline = out; - } + protected native void finalize(); - // Destruction - public void destroy() - { + public void destroy() { finalize(); - nativeOutline = 0; + pointer = 0; } - protected native void finalize(); + private Outline(long p) { + pointer = p; + } } diff --git a/platform/java/com/artifex/mupdf/fitz/Page.java b/platform/java/com/artifex/mupdf/fitz/Page.java index 46d598ee..befbe1c7 100644 --- a/platform/java/com/artifex/mupdf/fitz/Page.java +++ b/platform/java/com/artifex/mupdf/fitz/Page.java @@ -2,36 +2,37 @@ package com.artifex.mupdf.fitz; public class Page { - // Private data - private long nativePage = 0; + private long pointer; private Annotation nativeAnnots[]; - // Construction - private Page(long page) - { - nativePage = page; + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; + nativeAnnots = null; + } + + private Page(long p) { + pointer = p; nativeAnnots = null; } - // Operation - public native Rect bound(); + public native Rect getBounds(); + + public native Pixmap toPixmap(Matrix ctm, ColorSpace colorspace); + public native void run(Device dev, Matrix ctm, Cookie cookie); public native void runPageContents(Device dev, Matrix ctm, Cookie cookie); public native Annotation[] getAnnotations(); + public void run(Device dev, Matrix ctm) { + run(dev, ctm, null); + } + // FIXME: Later public native Link[] getLinks(); // FIXME: Later. Much later. //fz_transition *fz_page_presentation(fz_document *doc, fz_page *page, float *duration); - - // Destruction - public void destroy() - { - finalize(); - nativePage = 0; - nativeAnnots = null; - } - - protected native void finalize(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Path.java b/platform/java/com/artifex/mupdf/fitz/Path.java index 17257f10..fa925bab 100644 --- a/platform/java/com/artifex/mupdf/fitz/Path.java +++ b/platform/java/com/artifex/mupdf/fitz/Path.java @@ -1,82 +1,63 @@ package com.artifex.mupdf.fitz; -public class Path implements PathProcessor +public class Path implements PathWalker { - // Private data - private long nativePath = 0; + private long pointer; - // Construction - public Path() - { - nativePath = newNative(); + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; } private native long newNative(); + private native long cloneNative(); - private Path(long path) - { - nativePath = path; + public Path() { + pointer = newNative(); } - public Path(Path old) - { - nativePath = clone(old); + private Path(long p) { + pointer = p; } - private native long clone(Path old); + public Path(Path old) { + pointer = old.cloneNative(); + } - // Operation public native Point currentPoint(); - public void moveTo(Point xy) - { + public native void moveTo(float x, float y); + public native void lineTo(float x, float y); + public native void curveTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey); + public native void curveToV(float cx, float cy, float ex, float ey); + public native void curveToY(float cx, float cy, float ex, float ey); + public native void closePath(); + + public void moveTo(Point xy) { moveTo(xy.x, xy.y); } - public native void moveTo(float x, float y); - - public void lineTo(Point xy) - { + public void lineTo(Point xy) { lineTo(xy.x, xy.y); } - public native void lineTo(float x, float y); - - public void curveTo(Point c1, Point c2, Point e) - { + public void curveTo(Point c1, Point c2, Point e) { curveTo(c1.x, c1.y, c2.x, c2.y, e.x, e.y); } - public native void curveTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey); - - public void curveToV(Point c, Point e) - { + public void curveToV(Point c, Point e) { curveToV(c.x, c.y, e.x, e.y); } - public native void curveToV(float cx, float cy, float ex, float ey); - - public void curveToY(Point c, Point e) - { + public void curveToY(Point c, Point e) { curveToY(c.x, c.y, e.x, e.y); } - public native void curveToY(float cx, float cy, float ex, float ey); - - public native void close(); - public native void transform(Matrix mat); - public native Rect bound(StrokeState stroke, Matrix ctm); - - public native void process(PathProcessor proc); - - // Destruction - public void destroy() - { - finalize(); - nativePath = 0; - } + public native Rect getBounds(StrokeState stroke, Matrix ctm); - protected native void finalize(); + public native void walk(PathWalker walker); } diff --git a/platform/java/com/artifex/mupdf/fitz/PathProcessor.java b/platform/java/com/artifex/mupdf/fitz/PathWalker.java index 71d03c50..66d1b49b 100644 --- a/platform/java/com/artifex/mupdf/fitz/PathProcessor.java +++ b/platform/java/com/artifex/mupdf/fitz/PathWalker.java @@ -1,9 +1,9 @@ package com.artifex.mupdf.fitz; -public interface PathProcessor +public interface PathWalker { public void moveTo(float x, float y); public void lineTo(float x, float y); public void curveTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey); - public void close(); + public void closePath(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Pixmap.java b/platform/java/com/artifex/mupdf/fitz/Pixmap.java new file mode 100644 index 00000000..61c833ff --- /dev/null +++ b/platform/java/com/artifex/mupdf/fitz/Pixmap.java @@ -0,0 +1,60 @@ +package com.artifex.mupdf.fitz; + +public class Pixmap +{ + private long pointer; + + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; + } + + private native long newNative(ColorSpace cs, int x, int y, int w, int h); + + private Pixmap(long p) { + pointer = p; + } + + public Pixmap(ColorSpace colorspace, int x, int y, int w, int h) { + pointer = newNative(colorspace, x, y, w, h); + } + + public Pixmap(ColorSpace colorspace, int w, int h) { + this(colorspace, 0, 0, w, h); + } + + public Pixmap(ColorSpace colorspace, Rect rect) { + this(colorspace, (int)rect.x0, (int)rect.y0, (int)(rect.x1 - rect.x0), (int)(rect.y1 - rect.y0)); + } + + public native void clear(); + public native void clearWithValue(int value); + + public native void saveAsPNG(String filename, boolean saveAlpha); + + public native int getX(); + public native int getY(); + public native int getWidth(); + public native int getHeight(); + public native int getStride(); + public native int getNumberOfComponents(); + public native ColorSpace getColorSpace(); + public native byte[] getSamples(); + public native int[] getPixels(); /* only valid for RGB or BGR pixmaps */ + + public void clear(int value) { + clearWithValue(value); + } + + public String toString() { + return "Pixmap(w=" + getWidth() + + " h=" + getHeight() + + " x=" + getX() + + " y=" + getY() + + " n=" + getNumberOfComponents() + + " cs=" + getColorSpace() + + ")"; + } +} diff --git a/platform/java/com/artifex/mupdf/fitz/Point.java b/platform/java/com/artifex/mupdf/fitz/Point.java index 08989dd7..b32198bc 100644 --- a/platform/java/com/artifex/mupdf/fitz/Point.java +++ b/platform/java/com/artifex/mupdf/fitz/Point.java @@ -5,20 +5,21 @@ public class Point public float x; public float y; - public Point(float x, float y) - { + public Point(float x, float y) { this.x = x; this.y = y; } - public Point(Point p) - { + public Point(Point p) { this.x = p.x; this.y = p.y; } - public Point transform(Matrix tm) - { + public String toString() { + return "[" + x + " " + y + "]"; + } + + public Point transform(Matrix tm) { float old_x = this.x; this.x = old_x * tm.a + y * tm.c + tm.e; diff --git a/platform/java/com/artifex/mupdf/fitz/Rect.java b/platform/java/com/artifex/mupdf/fitz/Rect.java index eb9138cf..819646e8 100644 --- a/platform/java/com/artifex/mupdf/fitz/Rect.java +++ b/platform/java/com/artifex/mupdf/fitz/Rect.java @@ -7,29 +7,30 @@ public class Rect public float x1; public float y1; - public Rect(float x0, float y0, float x1, float y1) - { + public Rect(float x0, float y0, float x1, float y1) { this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1; } - public Rect(Rect r) - { - this.x0 = r.x0; - this.y0 = r.y0; - this.x1 = r.x1; - this.y1 = r.y1; + public Rect(Rect r) { + this(r.x0, r.y0, r.x1, r.y1); } - public Rect transform(Matrix tm) - { + public Rect(RectI r) { + this(r.x0, r.y0, r.x1, r.y1); + } + + public String toString() { + return "[" + x0 + " " + y0 + " " + x1 + " " + y1 + "]"; + } + + public Rect transform(Matrix tm) { float ax0 = x0 * tm.a; float ax1 = x1 * tm.a; - if (ax0 > ax1) - { + if (ax0 > ax1) { float t = ax0; ax0 = ax1; ax1 = t; @@ -38,8 +39,7 @@ public class Rect float cy0 = y0 * tm.c; float cy1 = y1 * tm.c; - if (cy0 > cy1) - { + if (cy0 > cy1) { float t = cy0; cy0 = cy1; cy1 = t; @@ -50,8 +50,7 @@ public class Rect float bx0 = x0 * tm.b; float bx1 = x1 * tm.b; - if (bx0 > bx1) - { + if (bx0 > bx1) { float t = bx0; bx0 = bx1; bx1 = t; @@ -60,8 +59,7 @@ public class Rect float dy0 = y0 * tm.d; float dy1 = y1 * tm.d; - if (dy0 > dy1) - { + if (dy0 > dy1) { float t = dy0; dy0 = dy1; dy1 = t; diff --git a/platform/java/com/artifex/mupdf/fitz/RectI.java b/platform/java/com/artifex/mupdf/fitz/RectI.java index 1f91c778..8e46a3f2 100644 --- a/platform/java/com/artifex/mupdf/fitz/RectI.java +++ b/platform/java/com/artifex/mupdf/fitz/RectI.java @@ -7,29 +7,33 @@ public class RectI public int x1; public int y1; - public RectI(int x0, int y0, int x1, int y1) - { + public RectI(int x0, int y0, int x1, int y1) { this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1; } - public RectI(Rect r) - { + public RectI(RectI r) { + this(r.x0, r.y0, r.x1, r.y1); + } + + public RectI(Rect r) { this.x0 = (int)Math.floor(r.x0); this.y0 = (int)Math.ceil(r.y0); this.x1 = (int)Math.floor(r.x1); this.y1 = (int)Math.ceil(r.y1); } - public RectI transform(Matrix tm) - { + public String toString() { + return "[" + x0 + " " + y0 + " " + x1 + " " + y1 + "]"; + } + + public RectI transform(Matrix tm) { float ax0 = x0 * tm.a; float ax1 = x1 * tm.a; - if (ax0 > ax1) - { + if (ax0 > ax1) { float t = ax0; ax0 = ax1; ax1 = t; @@ -38,8 +42,7 @@ public class RectI float cy0 = y0 * tm.c; float cy1 = y1 * tm.c; - if (cy0 > cy1) - { + if (cy0 > cy1) { float t = cy0; cy0 = cy1; cy1 = t; @@ -50,8 +53,7 @@ public class RectI float bx0 = x0 * tm.b; float bx1 = x1 * tm.b; - if (bx0 > bx1) - { + if (bx0 > bx1) { float t = bx0; bx0 = bx1; bx1 = t; @@ -60,8 +62,7 @@ public class RectI float dy0 = y0 * tm.d; float dy1 = y1 * tm.d; - if (dy0 > dy1) - { + if (dy0 > dy1) { float t = dy0; dy0 = dy1; dy1 = t; diff --git a/platform/java/com/artifex/mupdf/fitz/Shade.java b/platform/java/com/artifex/mupdf/fitz/Shade.java index bfadebc7..35182cb8 100644 --- a/platform/java/com/artifex/mupdf/fitz/Shade.java +++ b/platform/java/com/artifex/mupdf/fitz/Shade.java @@ -2,27 +2,16 @@ package com.artifex.mupdf.fitz; public class Shade { - // Private data - private long nativeShade = 0; + private long pointer; - // Construction - // Private constructor for the C to use. Any objects created by the - // C are done for purposes of calling back to a java device, and - // should therefore be considered const. - private Shade(long l) - { - nativeShade = l; - } - - // FIXME: Constructors for the different types of shade - // FIXME: Accessors for shade data + protected native void finalize(); - // Destruction - public void destroy() - { + public void destroy() { finalize(); - nativeShade = 0; + pointer = 0; } - protected native void finalize(); + private Shade(long p) { + pointer = p; + } } diff --git a/platform/java/com/artifex/mupdf/fitz/StrokeState.java b/platform/java/com/artifex/mupdf/fitz/StrokeState.java index 2f2fcf96..7f333f76 100644 --- a/platform/java/com/artifex/mupdf/fitz/StrokeState.java +++ b/platform/java/com/artifex/mupdf/fitz/StrokeState.java @@ -1,7 +1,5 @@ package com.artifex.mupdf.fitz; -import android.graphics.Rect; - public class StrokeState { public static final int FZ_LINECAP_BUTT = 0; @@ -14,36 +12,38 @@ public class StrokeState public static final int FZ_LINEJOIN_BEVEL = 2; public static final int FZ_LINEJOIN_MITER_XPS = 3; - // Private data - private long nativeStroke; + private long pointer; - // Construction - StrokeState(int startCap, int endCap, int lineJoin, float lineWidth, float miterLimit) - { - nativeStroke = newNative(startCap, 0, endCap, lineJoin, lineWidth, miterLimit, 0, null); - } + protected native void finalize(); - StrokeState(int startCap, int dashCap, int endCap, int lineJoin, float lineWidth, float miterLimit, float dashPhase, float dash[]) - { - nativeStroke = newNative(startCap, dashCap, endCap, lineJoin, lineWidth, miterLimit, dashPhase, dash); + public void destroy() { + finalize(); + pointer = 0; } - private native long newNative(int startCap, int dashCap, int endCap, int lineJoin, float lineWidth, float miterLimit, float dashPhase, float dash[]); + private native long newNative(int startCap, int dashCap, int endCap, int lineJoin, float lineWidth, float miterLimit, + float dashPhase, float dash[]); // Private constructor for the C to use. Any objects created by the // C are done for purposes of calling back to a java device, and // should therefore be considered const. This is fine as we don't // currently provide mechanisms for changing individual elements // of the StrokeState. - private StrokeState(long l) - { - nativeStroke = l; + private StrokeState(long p) { + pointer = p; + } + + public StrokeState(int startCap, int endCap, int lineJoin, float lineWidth, float miterLimit) { + pointer = newNative(startCap, 0, endCap, lineJoin, lineWidth, miterLimit, 0, null); + } + + public StrokeState(int startCap, int dashCap, int endCap, int lineJoin, float lineWidth, float miterLimit, + float dashPhase, float dash[]) { + pointer = newNative(startCap, dashCap, endCap, lineJoin, lineWidth, miterLimit, dashPhase, dash); } - // Operation public native void adjustRectForStroke(Rect rect, Matrix ctm); - // Accessors public native int getStartCap(); public native int getDashCap(); public native int getEndCap(); @@ -52,13 +52,4 @@ public class StrokeState public native float getMiterLimit(); public native float getDashPhase(); public native float[] getDashes(); - - // Destruction - public void destroy() - { - finalize(); - nativeStroke = 0; - } - - protected native void finalize(); } diff --git a/platform/java/com/artifex/mupdf/fitz/Text.java b/platform/java/com/artifex/mupdf/fitz/Text.java index eada4635..d5d9a836 100644 --- a/platform/java/com/artifex/mupdf/fitz/Text.java +++ b/platform/java/com/artifex/mupdf/fitz/Text.java @@ -1,46 +1,34 @@ package com.artifex.mupdf.fitz; -public class Text +public class Text implements TextWalker { - // Private data - private long nativeText = 0; - private boolean isConst = false; - - // Cloning - public Text(Text old) - { - nativeText = cloneNative(old); + private long pointer; + + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; } + private native long newNative(); private native long cloneNative(Text old); - //public Text(Font font, Matrix trm, int wmode) - //{ - // nativeText = newNative(font, trm, wmode); - //} - - // Private method used for creating Text entries for a - // device implemented in java. These entries should be - // immutable. - private Text(long ptr) - { - nativeText = ptr; - isConst = true; + private Text(long p) { + pointer = p; } - // Operation - public native Rect bound(StrokeState stroke, Matrix ctm); + public Text(Text old) { + pointer = cloneNative(old); + } - //public native void add(int gid, int ucs, float x, float y); + public Text() { + pointer = newNative(); + } - // FIXME: Write accessors + public native void showGlyph(Font font, boolean vertical, Matrix trm, int glyph, int unicode); - // Destruction - public void destroy() - { - finalize(); - nativeText = 0; - } + public native Rect getBounds(StrokeState stroke, Matrix ctm); - protected native void finalize(); + public native void walk(TextWalker walker); } diff --git a/platform/java/com/artifex/mupdf/fitz/TextWalker.java b/platform/java/com/artifex/mupdf/fitz/TextWalker.java new file mode 100644 index 00000000..99d3e150 --- /dev/null +++ b/platform/java/com/artifex/mupdf/fitz/TextWalker.java @@ -0,0 +1,6 @@ +package com.artifex.mupdf.fitz; + +public interface TextWalker +{ + public void showGlyph(Font font, boolean vertical, Matrix trm, int glyph, int unicode); +} diff --git a/platform/java/com/artifex/mupdf/fitz/TryLaterException.java b/platform/java/com/artifex/mupdf/fitz/TryLaterException.java index 644c6af1..e2d1b88e 100644 --- a/platform/java/com/artifex/mupdf/fitz/TryLaterException.java +++ b/platform/java/com/artifex/mupdf/fitz/TryLaterException.java @@ -2,8 +2,7 @@ package com.artifex.mupdf.fitz; public class TryLaterException extends Exception { - TryLaterException(String message) - { + TryLaterException(String message) { super(message); } } diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index c1931702..653735aa 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -1,12 +1,5 @@ #include <jni.h> -#include <time.h> #include <pthread.h> -#include <android/log.h> -#include <android/bitmap.h> - -#include <stdio.h> -#include <stdlib.h> -#include <math.h> #ifdef NDK_PROFILER #include "prof.h" @@ -15,191 +8,270 @@ #include "mupdf/fitz.h" #include "mupdf/pdf.h" -#define MY_JNI_VERSION JNI_VERSION_1_6 - -#define JNI_FN(A) Java_com_artifex_mupdf_fitz_ ## A -#define PACKAGENAME "com.artifex.mupdf.fitz" -#define PACKAGEPATH "com/artifex/mupdf/fitz/" +#include "mupdf_native.h" /* javah generated prototypes */ +#ifdef HAVE_ANDROID +#include <android/log.h> +#include <android/bitmap.h> #define LOG_TAG "libmupdf" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) #define LOGT(...) __android_log_print(ANDROID_LOG_INFO,"alert",__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) +#else +#undef LOGI +#undef LOGE +#define LOGI(...) do{printf(__VA_ARGS__);putchar('\n');}while(0) +#define LOGE(...) do{printf(__VA_ARGS__);putchar('\n');}while(0) +#endif + +#define MY_JNI_VERSION JNI_VERSION_1_6 + +#define FUN(A) Java_com_artifex_mupdf_fitz_ ## A +#define PKG "com/artifex/mupdf/fitz/" + +/* Do our best to avoid type casting warnings. */ + +#define CAST(type, var) (type)pointer_cast(var) + +static inline void *pointer_cast(jlong l) +{ + return (void *)(intptr_t)l; +} + +static inline jlong jlong_cast(const void *p) +{ + return (jlong)(intptr_t)p; +} -/* Set to 1 to enable debug log traces. */ -#define DEBUG 0 - -/* All the cached classes/mids/fids we need */ - -static jclass annot_class; -static jfieldID annot_fid; -static jmethodID annot_const_mid; -static jclass cdevice_class; -static jfieldID cdevice_nativeresource_fid; -static jfieldID cdevice_nativeinfo_fid; -static jclass colorspace_class; -static jfieldID colorspace_fid; -static jmethodID colorspace_const_mid; -static jclass cookie_class; -static jfieldID cookie_fid; -static jclass device_class; -static jfieldID device_fid; -static jmethodID device_begin_page_mid; -static jmethodID device_end_page_mid; -static jmethodID device_fill_path_mid; -static jmethodID device_stroke_path_mid; -static jmethodID device_clip_path_mid; -static jmethodID device_clip_stroke_path_mid; -static jmethodID device_fill_text_mid; -static jmethodID device_stroke_text_mid; -static jmethodID device_clip_text_mid; -static jmethodID device_clip_stroke_text_mid; -static jmethodID device_ignore_text_mid; -static jmethodID device_fill_shade_mid; -static jmethodID device_fill_image_mid; -static jmethodID device_fill_image_mask_mid; -static jmethodID device_clip_image_mask_mid; -static jmethodID device_pop_clip_mid; -static jmethodID device_begin_mask_mid; -static jmethodID device_end_mask_mid; -static jmethodID device_begin_group_mid; -static jmethodID device_end_group_mid; -static jmethodID device_begin_tile_mid; -static jmethodID device_end_tile_mid; -static jclass displaylist_class; -static jfieldID displaylist_fid; -static jclass document_class; -static jfieldID document_fid; -static jclass exception_class; -static jclass font_class; -static jfieldID font_fid; -//static jfieldID font_isconst_fid; -static jclass image_class; -static jfieldID image_fid; -static jmethodID image_const_mid; -static jclass link_class; -static jfieldID link_fid; -static jclass matrix_class; -static jfieldID matrix_a_fid; -static jfieldID matrix_b_fid; -static jfieldID matrix_c_fid; -static jfieldID matrix_d_fid; -static jfieldID matrix_e_fid; -static jfieldID matrix_f_fid; -static jmethodID matrix_const_mid; -static jclass outline_class; -static jfieldID outline_fid; -static jmethodID outline_const_mid; -static jclass page_class; -static jfieldID page_fid; -static jmethodID page_const_mid; -static jfieldID page_document_fid; -static jfieldID page_annots_fid; -static jclass path_class; -static jfieldID path_fid; -static jmethodID path_const_mid; -static jclass pathproc_class; -static jmethodID pathproc_moveto_mid; -static jmethodID pathproc_lineto_mid; -static jmethodID pathproc_curveto_mid; -static jmethodID pathproc_close_mid; -static jclass point_class; -static jfieldID point_fid; -static jmethodID point_const_mid; -static jclass rect_class; -static jfieldID rect_x0_fid; -static jfieldID rect_x1_fid; -static jfieldID rect_y0_fid; -static jfieldID rect_y1_fid; -static jmethodID rect_const_mid; -static jclass shade_class; -static jfieldID shade_fid; -static jmethodID shade_const_mid; -static jclass stroke_class; -static jfieldID stroke_fid; -static jmethodID stroke_const_mid; -static jclass text_class; -static jfieldID text_fid; -static jmethodID text_const_mid; -static jclass trylaterexception_class; +/* All the cached classes/mids/fids we need. */ + +static jclass cls_Annot; +static jclass cls_ColorSpace; +static jclass cls_Cookie; +static jclass cls_Device; +static jclass cls_DisplayList; +static jclass cls_Document; +static jclass cls_Exception; +static jclass cls_Font; +static jclass cls_Image; +static jclass cls_Link; +static jclass cls_Matrix; +static jclass cls_NativeDevice; +static jclass cls_Object; +static jclass cls_OutOfMemoryError; +static jclass cls_Outline; +static jclass cls_Page; +static jclass cls_Path; +static jclass cls_PathWalker; +static jclass cls_Pixmap; +static jclass cls_Point; +static jclass cls_Rect; +static jclass cls_Shade; +static jclass cls_StrokeState; +static jclass cls_Text; +static jclass cls_TextWalker; +static jclass cls_TryLaterException; + +static jfieldID fid_Annot_pointer; +static jfieldID fid_ColorSpace_pointer; +static jfieldID fid_Cookie_pointer; +static jfieldID fid_Device_pointer; +static jfieldID fid_DisplayList_pointer; +static jfieldID fid_Document_pointer; +static jfieldID fid_Font_pointer; +static jfieldID fid_Image_pointer; +static jfieldID fid_Link_pointer; +static jfieldID fid_Matrix_a; +static jfieldID fid_Matrix_b; +static jfieldID fid_Matrix_c; +static jfieldID fid_Matrix_d; +static jfieldID fid_Matrix_e; +static jfieldID fid_Matrix_f; +static jfieldID fid_NativeDevice_nativeInfo; +static jfieldID fid_NativeDevice_nativeResource; +static jfieldID fid_Outline_pointer; +static jfieldID fid_Page_nativeAnnots; +static jfieldID fid_Page_pointer; +static jfieldID fid_Path_pointer; +static jfieldID fid_Pixmap_pointer; +static jfieldID fid_Rect_x0; +static jfieldID fid_Rect_x1; +static jfieldID fid_Rect_y0; +static jfieldID fid_Rect_y1; +static jfieldID fid_Shade_pointer; +static jfieldID fid_StrokeState_pointer; +static jfieldID fid_Text_pointer; + +static jmethodID mid_Annot_init; +static jmethodID mid_ColorSpace_fromPointer; +static jmethodID mid_ColorSpace_init; +static jmethodID mid_Device_beginGroup; +static jmethodID mid_Device_beginMask; +static jmethodID mid_Device_beginPage; +static jmethodID mid_Device_beginTile; +static jmethodID mid_Device_clipImageMask; +static jmethodID mid_Device_clipPath; +static jmethodID mid_Device_clipStrokePath; +static jmethodID mid_Device_clipStrokeText; +static jmethodID mid_Device_clipText; +static jmethodID mid_Device_endGroup; +static jmethodID mid_Device_endMask; +static jmethodID mid_Device_endPage; +static jmethodID mid_Device_endTile; +static jmethodID mid_Device_fillImage; +static jmethodID mid_Device_fillImageMask; +static jmethodID mid_Device_fillPath; +static jmethodID mid_Device_fillShade; +static jmethodID mid_Device_fillText; +static jmethodID mid_Device_ignoreText; +static jmethodID mid_Device_popClip; +static jmethodID mid_Device_strokePath; +static jmethodID mid_Device_strokeText; +static jmethodID mid_Font_init; +static jmethodID mid_Image_init; +static jmethodID mid_Matrix_init; +static jmethodID mid_Object_toString; +static jmethodID mid_Outline_init; +static jmethodID mid_Page_init; +static jmethodID mid_PathWalker_closePath; +static jmethodID mid_PathWalker_curveTo; +static jmethodID mid_PathWalker_lineTo; +static jmethodID mid_PathWalker_moveTo; +static jmethodID mid_Path_init; +static jmethodID mid_Pixmap_init; +static jmethodID mid_Point_init; +static jmethodID mid_Rect_init; +static jmethodID mid_Shade_init; +static jmethodID mid_StrokeState_init; +static jmethodID mid_Text_init; +static jmethodID mid_TextWalker_showGlyph; static pthread_key_t context_key; static fz_context *base_context; -static void -throwOutOfMemoryError(JNIEnv *env, const char *info) +/* Helper functions to set the java exception flag. */ + +static void jni_throw(JNIEnv *env, int type, const char *mess) { - jclass oomCls = (*env)->FindClass(env, "java/lang/OutOfMemoryError"); + if (type == FZ_ERROR_TRYLATER) + (*env)->ThrowNew(env, cls_TryLaterException, mess); + else + (*env)->ThrowNew(env, cls_Exception, mess); +} - if (oomCls == NULL) - return; /* Well, what hope have we got! */ +static void jni_throw_oom(JNIEnv *env, const char *info) +{ + (*env)->ThrowNew(env, cls_OutOfMemoryError, info); +} - (*env)->ExceptionClear(env); - (*env)->ThrowNew(env, oomCls, info); +static void jni_rethrow(JNIEnv *env, fz_context *ctx) +{ + jni_throw(env, fz_caught(ctx), fz_caught_message(ctx)); } -static const char *last_class_obtained = NULL; +/* Convert a java exception and throw into fitz. */ -static jclass -get_class(int *failed, JNIEnv *env, const char *str) +static void fz_throw_java(fz_context *ctx, JNIEnv *env) { - jclass local, global; + jthrowable ex = (*env)->ExceptionOccurred(env); + if (ex) + { + jobject msg = (*env)->CallObjectMethod(env, ex, mid_Object_toString); + if (msg) + { + const char *p = (*env)->GetStringUTFChars(env, msg, NULL); + if (p) + { + char buf[256]; + fz_strlcpy(buf, p, sizeof buf); + (*env)->ReleaseStringUTFChars(env, msg, p); + fz_throw(ctx, FZ_ERROR_GENERIC, "%s", buf); + } + } + } + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown java error"); +} + + +/* Load classes, field and method IDs. */ + +static const char *current_class_name = NULL; +static jclass current_class = NULL; + +static jclass get_class(int *failed, JNIEnv *env, const char *name) +{ + jclass local; if (*failed) return NULL; - last_class_obtained = str; - local = (*env)->FindClass(env, str); + current_class_name = name; + local = (*env)->FindClass(env, name); if (local == NULL) { - LOGI("Failed to find class %s", str); + LOGI("Failed to find class %s", name); *failed = 1; return NULL; } - global = (*env)->NewGlobalRef(env, local); - if (global == NULL) + current_class = (*env)->NewGlobalRef(env, local); + if (current_class == NULL) { - LOGI("Failed to make global ref for %s", str); + LOGI("Failed to make global ref for %s", name); *failed = 1; return NULL; } (*env)->DeleteLocalRef(env, local); - return global; + return current_class; } -static jfieldID -get_field(int *failed, JNIEnv *env, jclass cla, const char *field, const char *sig) +static jfieldID get_field(int *failed, JNIEnv *env, const char *field, const char *sig) { jfieldID fid; - if (*failed || cla == NULL) + if (*failed || current_class == NULL) return NULL; - fid = (*env)->GetFieldID(env, cla, field, sig); - if (fid == (jfieldID)0) + fid = (*env)->GetFieldID(env, current_class, field, sig); + if (fid == 0) { - LOGI("Failed to get field for %s %s %s", last_class_obtained ? last_class_obtained : "<noclass>", field, sig); + LOGI("Failed to get field for %s %s %s", current_class_name, field, sig); *failed = 1; } return fid; } -static jmethodID -get_method(int *failed, JNIEnv *env, jclass cla, const char *method, const char *sig) +static jmethodID get_method(int *failed, JNIEnv *env, const char *method, const char *sig) +{ + jmethodID mid; + + if (*failed || current_class == NULL) + return NULL; + + mid = (*env)->GetMethodID(env, current_class, method, sig); + if (mid == 0) + { + LOGI("Failed to get method for %s %s %s", current_class_name, method, sig); + *failed = 1; + } + + return mid; +} + +static jmethodID get_static_method(int *failed, JNIEnv *env, const char *method, const char *sig) { jmethodID mid; - if (*failed || cla == NULL) + if (*failed || current_class == NULL) return NULL; - mid = (*env)->GetMethodID(env, cla, method, sig); - if (mid == (jmethodID)0) + mid = (*env)->GetStaticMethodID(env, current_class, method, sig); + if (mid == 0) { - LOGI("Failed to get method for %s %s %s", last_class_obtained ? last_class_obtained : "<noclass>", method, sig); + LOGI("Failed to get static method for %s %s %s", current_class_name, method, sig); *failed = 1; } @@ -208,125 +280,167 @@ get_method(int *failed, JNIEnv *env, jclass cla, const char *method, const char static int find_fids(JNIEnv *env) { - int failed = 0; - - annot_class = get_class(&failed, env, PACKAGEPATH"Annotation"); - annot_fid = get_field(&failed, env, annot_class, "nativeAnnot", "J"); - annot_const_mid = get_method(&failed, env, annot_class, "<init>", "(J)V"); - cdevice_class = get_class(&failed, env, PACKAGEPATH"CDevice"); - cdevice_nativeresource_fid = get_field(&failed, env, cdevice_class, "nativeResource", "Ljava.lang.Object;"); - cdevice_nativeinfo_fid = get_field(&failed, env, cdevice_class, "nativeInfo", "J"); - colorspace_class = get_class(&failed, env, PACKAGEPATH"ColorSpace"); - colorspace_fid = get_field(&failed, env, colorspace_class, "nativeColorSpace", "J"); - colorspace_const_mid = get_method(&failed, env, colorspace_class, "<init>", "(J)V"); - cookie_class = get_class(&failed, env, PACKAGEPATH"Cookie"); - cookie_fid = get_field(&failed, env, cookie_class, "nativeCookie", "J"); - device_class = get_class(&failed, env, PACKAGEPATH"Device"); - device_fid = get_field(&failed, env, device_class, "nativeDevice", "J"); - device_begin_page_mid = get_method(&failed, env, device_class, "beginPage", "(L"PACKAGEPATH"Rect;L"PACKAGEPATH"Matrix;)V"); - device_end_page_mid = get_method(&failed, env, device_class, "endPage", "()V"); - device_fill_path_mid = get_method(&failed, env, device_class, "fillPath", "(L"PACKAGEPATH"Path;IL"PACKAGEPATH"Matrix;L"PACKAGEPATH"ColorSpace;[FF)V"); - device_stroke_path_mid = get_method(&failed, env, device_class, "strokePath", "(JL"PACKAGEPATH"Path;L"PACKAGEPATH"StrokeState;L"PACKAGEPATH"Matrix;L"PACKAGEPATH"ColorSpace;[FF)V"); - device_clip_path_mid = get_method(&failed, env, device_class, "clipPath", "(L"PACKAGEPATH"Path;L"PACKAGEPATH"Rect;IL"PACKAGEPATH"Matrix;)V"); - device_clip_stroke_path_mid = get_method(&failed, env, device_class, "clipStrokePath", "(L"PACKAGEPATH"Path;L"PACKAGEPATH"Rect;L"PACKAGEPATH"StrokeState;L"PACKAGEPATH"Matrix;)V"); - device_fill_text_mid = get_method(&failed, env, device_class, "fillText", "(L"PACKAGEPATH"Text;L"PACKAGEPATH"Matrix;L"PACKAGEPATH"ColorSpace;[FF)V"); - device_stroke_text_mid = get_method(&failed, env, device_class, "strokeText", "(L"PACKAGEPATH"Text;L"PACKAGEPATH"StrokeState;L"PACKAGEPATH"Matrix;L"PACKAGEPATH"ColorSpace;[FF)V"); - device_clip_text_mid = get_method(&failed, env, device_class, "clipText", "(L"PACKAGEPATH"Text;L"PACKAGEPATH"Matrix;)V"); - device_clip_stroke_text_mid = get_method(&failed, env, device_class, "clipStrokeText", "(L"PACKAGEPATH"Text;L"PACKAGEPATH"StrokeState;L"PACKAGEPATH"Matrix;)V"); - device_ignore_text_mid = get_method(&failed, env, device_class, "ignoreText", "(L"PACKAGEPATH"Text;L"PACKAGEPATH"Matrix;)V"); - device_fill_shade_mid = get_method(&failed, env, device_class, "fillShade", "(L"PACKAGEPATH"Shade;L"PACKAGEPATH"Matrix;F)V"); - device_fill_image_mid = get_method(&failed, env, device_class, "fillImage", "(L"PACKAGEPATH"Image;L"PACKAGEPATH"Matrix;F)V"); - device_fill_image_mask_mid = get_method(&failed, env, device_class, "fillImageMask", "(L"PACKAGEPATH"Image;L"PACKAGEPATH"Matrix;L"PACKAGEPATH"ColorSpace;[FF)V"); - device_clip_image_mask_mid = get_method(&failed, env, device_class, "clipImageMask", "(L"PACKAGEPATH"Image;L"PACKAGEPATH"Rect;L"PACKAGEPATH"Matrix;)V"); - device_pop_clip_mid = get_method(&failed, env, device_class, "popClip", "()V"); - device_begin_mask_mid = get_method(&failed, env, device_class, "beginMask", "(L"PACKAGEPATH"Rect;IL"PACKAGEPATH"ColorSpace;[F)V"); - device_end_mask_mid = get_method(&failed, env, device_class, "endMask", "()V"); - device_begin_group_mid = get_method(&failed, env, device_class, "beginGroup", "(L"PACKAGEPATH"Rect;IIIF)V"); - device_end_group_mid = get_method(&failed, env, device_class, "endGroup", "()V"); - device_begin_tile_mid = get_method(&failed, env, device_class, "beginTile", "(L"PACKAGEPATH"Rect;L"PACKAGEPATH"Rect;FFL"PACKAGEPATH"Matrix;I)I"); - device_end_tile_mid = get_method(&failed, env, device_class, "endTile", "()V"); - exception_class = get_class(&failed, env, "java/lang/Exception"); - displaylist_class = get_class(&failed, env, PACKAGEPATH"DisplayList"); - displaylist_fid = get_field(&failed, env, displaylist_class, "nativeDisplayList", "J"); - document_class = get_class(&failed, env, PACKAGEPATH"Document"); - document_fid = get_field(&failed, env, document_class, "nativeDocument", "J"); - font_class = get_class(&failed, env, PACKAGEPATH"Font"); - font_fid = get_field(&failed, env, font_class, "nativeFont", "J"); - //font_isconst_fid = get_field(&failed, env, font_class, "isConst", "Z"); - image_class = get_class(&failed, env, PACKAGEPATH"Image"); - image_fid = get_field(&failed, env, image_class, "nativeImage", "J"); - image_const_mid = get_method(&failed, env, image_class, "<init>", "(J)V"); - link_class = get_class(&failed, env, PACKAGEPATH"Link"); - link_fid = get_field(&failed, env, link_class, "nativeLink", "J"); - matrix_class = get_class(&failed, env, PACKAGEPATH"Matrix"); - matrix_a_fid = get_field(&failed, env, matrix_class, "a", "F"); - matrix_b_fid = get_field(&failed, env, matrix_class, "b", "F"); - matrix_c_fid = get_field(&failed, env, matrix_class, "c", "F"); - matrix_d_fid = get_field(&failed, env, matrix_class, "d", "F"); - matrix_e_fid = get_field(&failed, env, matrix_class, "e", "F"); - matrix_f_fid = get_field(&failed, env, matrix_class, "f", "F"); - matrix_const_mid = get_method(&failed, env, matrix_class, "<init>", "(FFFFFF)V"); - outline_class = get_class(&failed, env, PACKAGEPATH"Outline"); - outline_fid = get_field(&failed, env, outline_class, "nativeOutline", "J"); - outline_const_mid = get_method(&failed, env, outline_class, "<init>", "(J)V"); - page_class = get_class(&failed, env, PACKAGEPATH"Page"); - page_fid = get_field(&failed, env, page_class, "nativePage", "J"); - page_const_mid = get_method(&failed, env, page_class, "<init>", "(J)V"); - page_annots_fid = get_field(&failed, env, page_class, "nativeAnnots", "[L"PACKAGEPATH"Annotation;"); - path_class = get_class(&failed, env, PACKAGEPATH"Path"); - path_fid = get_field(&failed, env, path_class, "nativePath", "J"); - path_const_mid = get_method(&failed, env, path_class, "<init>", "(J)V"); - point_class = get_class(&failed, env, PACKAGEPATH"Point"); - point_const_mid = get_method(&failed, env, point_class, "<init>", "(FF)V"); - pathproc_class = get_class(&failed, env, PACKAGEPATH"PathProcessor"); - pathproc_moveto_mid = get_method(&failed, env, pathproc_class, "moveTo", "(FF)V"); - pathproc_lineto_mid = get_method(&failed, env, pathproc_class, "lineTo", "(FF)V"); - pathproc_curveto_mid = get_method(&failed, env, pathproc_class, "curveTo", "(FFFFFF)V"); - pathproc_close_mid = get_method(&failed, env, pathproc_class, "close", "()V"); - rect_class = get_class(&failed, env, PACKAGEPATH"Rect"); - rect_x0_fid = get_field(&failed, env, rect_class, "x0", "F"); - rect_x1_fid = get_field(&failed, env, rect_class, "x1", "F"); - rect_y0_fid = get_field(&failed, env, rect_class, "y0", "F"); - rect_y1_fid = get_field(&failed, env, rect_class, "y1", "F"); - rect_const_mid = get_method(&failed, env, rect_class, "<init>", "(FFFF)V"); - shade_class = get_class(&failed, env, PACKAGEPATH"Shade"); - shade_fid = get_field(&failed, env, shade_class, "nativeShade", "J"); - shade_const_mid = get_method(&failed, env, shade_class, "<init>", "(J)V"); - stroke_class = get_class(&failed, env, PACKAGEPATH"StrokeState"); - stroke_fid = get_field(&failed, env, stroke_class, "nativeStroke", "J"); - stroke_const_mid = get_method(&failed, env, stroke_class, "<init>", "(J)V"); - text_class = get_class(&failed, env, PACKAGEPATH"Text"); - text_fid = get_field(&failed, env, text_class, "nativeText", "J"); - text_const_mid = get_method(&failed, env, text_class, "<init>", "(J)V"); - trylaterexception_class = get_class(&failed, env, PACKAGEPATH"TryLaterException"); - - return failed; + int err = 0; + + cls_Annot = get_class(&err, env, PKG"Annotation"); + fid_Annot_pointer = get_field(&err, env, "pointer", "J"); + mid_Annot_init = get_method(&err, env, "<init>", "(J)V"); + + cls_ColorSpace = get_class(&err, env, PKG"ColorSpace"); + fid_ColorSpace_pointer = get_field(&err, env, "pointer", "J"); + mid_ColorSpace_init = get_method(&err, env, "<init>", "(J)V"); + mid_ColorSpace_fromPointer = get_static_method(&err, env, "fromPointer", "(J)L"PKG"ColorSpace;"); + + cls_Cookie = get_class(&err, env, PKG"Cookie"); + fid_Cookie_pointer = get_field(&err, env, "pointer", "J"); + + cls_Device = get_class(&err, env, PKG"Device"); + fid_Device_pointer = get_field(&err, env, "pointer", "J"); + mid_Device_beginPage = get_method(&err, env, "beginPage", "(L"PKG"Rect;L"PKG"Matrix;)V"); + mid_Device_endPage = get_method(&err, env, "endPage", "()V"); + mid_Device_fillPath = get_method(&err, env, "fillPath", "(L"PKG"Path;ZL"PKG"Matrix;L"PKG"ColorSpace;[FF)V"); + mid_Device_strokePath = get_method(&err, env, "strokePath", "(L"PKG"Path;L"PKG"StrokeState;L"PKG"Matrix;L"PKG"ColorSpace;[FF)V"); + mid_Device_clipPath = get_method(&err, env, "clipPath", "(L"PKG"Path;L"PKG"Rect;ZL"PKG"Matrix;)V"); + mid_Device_clipStrokePath = get_method(&err, env, "clipStrokePath", "(L"PKG"Path;L"PKG"Rect;L"PKG"StrokeState;L"PKG"Matrix;)V"); + mid_Device_fillText = get_method(&err, env, "fillText", "(L"PKG"Text;L"PKG"Matrix;L"PKG"ColorSpace;[FF)V"); + mid_Device_strokeText = get_method(&err, env, "strokeText", "(L"PKG"Text;L"PKG"StrokeState;L"PKG"Matrix;L"PKG"ColorSpace;[FF)V"); + mid_Device_clipText = get_method(&err, env, "clipText", "(L"PKG"Text;L"PKG"Matrix;)V"); + mid_Device_clipStrokeText = get_method(&err, env, "clipStrokeText", "(L"PKG"Text;L"PKG"StrokeState;L"PKG"Matrix;)V"); + mid_Device_ignoreText = get_method(&err, env, "ignoreText", "(L"PKG"Text;L"PKG"Matrix;)V"); + mid_Device_fillShade = get_method(&err, env, "fillShade", "(L"PKG"Shade;L"PKG"Matrix;F)V"); + mid_Device_fillImage = get_method(&err, env, "fillImage", "(L"PKG"Image;L"PKG"Matrix;F)V"); + mid_Device_fillImageMask = get_method(&err, env, "fillImageMask", "(L"PKG"Image;L"PKG"Matrix;L"PKG"ColorSpace;[FF)V"); + mid_Device_clipImageMask = get_method(&err, env, "clipImageMask", "(L"PKG"Image;L"PKG"Rect;L"PKG"Matrix;)V"); + mid_Device_popClip = get_method(&err, env, "popClip", "()V"); + mid_Device_beginMask = get_method(&err, env, "beginMask", "(L"PKG"Rect;ZL"PKG"ColorSpace;[F)V"); + mid_Device_endMask = get_method(&err, env, "endMask", "()V"); + mid_Device_beginGroup = get_method(&err, env, "beginGroup", "(L"PKG"Rect;ZZIF)V"); + mid_Device_endGroup = get_method(&err, env, "endGroup", "()V"); + mid_Device_beginTile = get_method(&err, env, "beginTile", "(L"PKG"Rect;L"PKG"Rect;FFL"PKG"Matrix;I)I"); + mid_Device_endTile = get_method(&err, env, "endTile", "()V"); + + cls_NativeDevice = get_class(&err, env, PKG"NativeDevice"); + fid_NativeDevice_nativeResource = get_field(&err, env, "nativeResource", "Ljava/lang/Object;"); + fid_NativeDevice_nativeInfo = get_field(&err, env, "nativeInfo", "J"); + + cls_DisplayList = get_class(&err, env, PKG"DisplayList"); + fid_DisplayList_pointer = get_field(&err, env, "pointer", "J"); + + cls_Document = get_class(&err, env, PKG"Document"); + fid_Document_pointer = get_field(&err, env, "pointer", "J"); + + cls_Font = get_class(&err, env, PKG"Font"); + fid_Font_pointer = get_field(&err, env, "pointer", "J"); + mid_Font_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Image = get_class(&err, env, PKG"Image"); + fid_Image_pointer = get_field(&err, env, "pointer", "J"); + mid_Image_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Link = get_class(&err, env, PKG"Link"); + fid_Link_pointer = get_field(&err, env, "pointer", "J"); + + cls_Matrix = get_class(&err, env, PKG"Matrix"); + fid_Matrix_a = get_field(&err, env, "a", "F"); + fid_Matrix_b = get_field(&err, env, "b", "F"); + fid_Matrix_c = get_field(&err, env, "c", "F"); + fid_Matrix_d = get_field(&err, env, "d", "F"); + fid_Matrix_e = get_field(&err, env, "e", "F"); + fid_Matrix_f = get_field(&err, env, "f", "F"); + mid_Matrix_init = get_method(&err, env, "<init>", "(FFFFFF)V"); + + cls_Outline = get_class(&err, env, PKG"Outline"); + fid_Outline_pointer = get_field(&err, env, "pointer", "J"); + mid_Outline_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Page = get_class(&err, env, PKG"Page"); + fid_Page_pointer = get_field(&err, env, "pointer", "J"); + fid_Page_nativeAnnots = get_field(&err, env, "nativeAnnots", "[L"PKG"Annotation;"); + mid_Page_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Path = get_class(&err, env, PKG"Path"); + fid_Path_pointer = get_field(&err, env, "pointer", "J"); + mid_Path_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Pixmap = get_class(&err, env, PKG"Pixmap"); + fid_Pixmap_pointer = get_field(&err, env, "pointer", "J"); + mid_Pixmap_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Point = get_class(&err, env, PKG"Point"); + mid_Point_init = get_method(&err, env, "<init>", "(FF)V"); + + cls_PathWalker = get_class(&err, env, PKG"PathWalker"); + mid_PathWalker_moveTo = get_method(&err, env, "moveTo", "(FF)V"); + mid_PathWalker_lineTo = get_method(&err, env, "lineTo", "(FF)V"); + mid_PathWalker_curveTo = get_method(&err, env, "curveTo", "(FFFFFF)V"); + mid_PathWalker_closePath = get_method(&err, env, "closePath", "()V"); + + cls_Rect = get_class(&err, env, PKG"Rect"); + fid_Rect_x0 = get_field(&err, env, "x0", "F"); + fid_Rect_x1 = get_field(&err, env, "x1", "F"); + fid_Rect_y0 = get_field(&err, env, "y0", "F"); + fid_Rect_y1 = get_field(&err, env, "y1", "F"); + mid_Rect_init = get_method(&err, env, "<init>", "(FFFF)V"); + + cls_Shade = get_class(&err, env, PKG"Shade"); + fid_Shade_pointer = get_field(&err, env, "pointer", "J"); + mid_Shade_init = get_method(&err, env, "<init>", "(J)V"); + + cls_StrokeState = get_class(&err, env, PKG"StrokeState"); + fid_StrokeState_pointer = get_field(&err, env, "pointer", "J"); + mid_StrokeState_init = get_method(&err, env, "<init>", "(J)V"); + + cls_Text = get_class(&err, env, PKG"Text"); + fid_Text_pointer = get_field(&err, env, "pointer", "J"); + mid_Text_init = get_method(&err, env, "<init>", "(J)V"); + + cls_TextWalker = get_class(&err, env, PKG"TextWalker"); + mid_TextWalker_showGlyph = get_method(&err, env, "showGlyph", "(L"PKG"Font;ZL"PKG"Matrix;II)V"); + + cls_TryLaterException = get_class(&err, env, PKG"TryLaterException"); + + /* Standard Java classes */ + + cls_Object = get_class(&err, env, "java/lang/Object"); + mid_Object_toString = get_method(&err, env, "toString", "()Ljava/lang/String;"); + + cls_Exception = get_class(&err, env, "java/lang/Exception"); + + cls_OutOfMemoryError = get_class(&err, env, "java/lang/OutOfMemoryError"); + + return err; } static void lose_fids(JNIEnv *env) { - (*env)->DeleteGlobalRef(env, annot_class); - (*env)->DeleteGlobalRef(env, cdevice_class); - (*env)->DeleteGlobalRef(env, colorspace_class); - (*env)->DeleteGlobalRef(env, cookie_class); - (*env)->DeleteGlobalRef(env, device_class); - (*env)->DeleteGlobalRef(env, displaylist_class); - (*env)->DeleteGlobalRef(env, document_class); - (*env)->DeleteGlobalRef(env, exception_class); - (*env)->DeleteGlobalRef(env, font_class); - (*env)->DeleteGlobalRef(env, image_class); - (*env)->DeleteGlobalRef(env, link_class); - (*env)->DeleteGlobalRef(env, matrix_class); - (*env)->DeleteGlobalRef(env, outline_class); - (*env)->DeleteGlobalRef(env, page_class); - (*env)->DeleteGlobalRef(env, path_class); - (*env)->DeleteGlobalRef(env, pathproc_class); - (*env)->DeleteGlobalRef(env, rect_class); - (*env)->DeleteGlobalRef(env, shade_class); - (*env)->DeleteGlobalRef(env, stroke_class); - (*env)->DeleteGlobalRef(env, text_class); - (*env)->DeleteGlobalRef(env, trylaterexception_class); -} + (*env)->DeleteGlobalRef(env, cls_Annot); + (*env)->DeleteGlobalRef(env, cls_ColorSpace); + (*env)->DeleteGlobalRef(env, cls_Cookie); + (*env)->DeleteGlobalRef(env, cls_Device); + (*env)->DeleteGlobalRef(env, cls_DisplayList); + (*env)->DeleteGlobalRef(env, cls_Document); + (*env)->DeleteGlobalRef(env, cls_Exception); + (*env)->DeleteGlobalRef(env, cls_Font); + (*env)->DeleteGlobalRef(env, cls_Image); + (*env)->DeleteGlobalRef(env, cls_Link); + (*env)->DeleteGlobalRef(env, cls_Matrix); + (*env)->DeleteGlobalRef(env, cls_NativeDevice); + (*env)->DeleteGlobalRef(env, cls_Object); + (*env)->DeleteGlobalRef(env, cls_OutOfMemoryError); + (*env)->DeleteGlobalRef(env, cls_Outline); + (*env)->DeleteGlobalRef(env, cls_Page); + (*env)->DeleteGlobalRef(env, cls_Path); + (*env)->DeleteGlobalRef(env, cls_PathWalker); + (*env)->DeleteGlobalRef(env, cls_Pixmap); + (*env)->DeleteGlobalRef(env, cls_Point); + (*env)->DeleteGlobalRef(env, cls_Rect); + (*env)->DeleteGlobalRef(env, cls_Shade); + (*env)->DeleteGlobalRef(env, cls_StrokeState); + (*env)->DeleteGlobalRef(env, cls_Text); + (*env)->DeleteGlobalRef(env, cls_TryLaterException); +} + +/* Put the fz_context in thread-local storage */ static pthread_mutex_t mutexes[FZ_LOCK_MAX]; @@ -347,12 +461,7 @@ static const fz_locks_context locks = unlock }; -static void fin_context(void *ctx) -{ - fz_drop_context((fz_context *)ctx); -} - -static int fin_base_context(JNIEnv *env) +static void fin_base_context(JNIEnv *env) { int i; @@ -367,6 +476,8 @@ static int init_base_context(JNIEnv *env) { int i; + pthread_key_create(&context_key, NULL); + for (i = 0; i < FZ_LOCK_MAX; i++) (void)pthread_mutex_init(&mutexes[i], NULL); @@ -389,7 +500,7 @@ static fz_context *get_context(JNIEnv *env) ctx = fz_clone_context(base_context); if (ctx == NULL) { - throwOutOfMemoryError(env, "Failed to clone fz_context"); + jni_throw_oom(env, "Failed to clone fz_context"); return NULL; } pthread_setspecific(context_key, ctx); @@ -403,6 +514,24 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) if ((*vm)->GetEnv(vm, (void **)&env, MY_JNI_VERSION) != JNI_OK) return -1; + return MY_JNI_VERSION; +} + +void JNI_OnUnload(JavaVM *vm, void *reserved) +{ + JNIEnv *env; + + if ((*vm)->GetEnv(vm, (void **)&env, MY_JNI_VERSION) != JNI_OK) + return; /* If this fails, we're really in trouble! */ + + fz_drop_context(base_context); + base_context = NULL; + lose_fids(env); +} + +JNIEXPORT jint JNICALL +FUN(Context_initNative)(JNIEnv *env, jclass cls) +{ /* Must init the context before find_finds, because the act of * finding the fids can cause classes to load. This causes * statics to be setup, which can in turn call JNI code, which @@ -416,260 +545,473 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) return -1; } - return MY_JNI_VERSION; + return 0; } -void JNI_OnUnload(JavaVM *vm, void *reserved) +/* Conversion functions: C to Java. These all throw fitz exceptions. */ + +static inline jobject to_Matrix(fz_context *ctx, JNIEnv *env, const fz_matrix *mat) { - JNIEnv *env; + jobject jobj; - if ((*vm)->GetEnv(vm, (void **)&env, MY_JNI_VERSION) != JNI_OK) - return; /* If this fails, we're really in trouble! */ + if (ctx == NULL) + return NULL; - fz_drop_context(base_context); - base_context = NULL; - lose_fids(env); + jobj = (*env)->NewObject(env, cls_Matrix, mid_Matrix_init, mat->a, mat->b, mat->c, mat->d, mat->e, mat->f); + if (jobj == NULL) + fz_throw_java(ctx, env); + + return jobj; } -// Do our best to avoid casting warnings. -#define CAST(type, var) (type)pointer_cast(var) +static inline jobject to_Rect(fz_context *ctx, JNIEnv *env, const fz_rect *rect) +{ + jobject jobj; -static inline void *pointer_cast(jlong l) + if (ctx == NULL) + return NULL; + + jobj = (*env)->NewObject(env, cls_Rect, mid_Rect_init, rect->x0, rect->y0, rect->x1, rect->y1); + if (jobj == NULL) + fz_throw_java(ctx, env); + + return jobj; +} + +static inline jobject to_Point(fz_context *ctx, JNIEnv *env, fz_point point) { - return (void *)(intptr_t)l; + jobject jpoint; + + if (ctx == NULL) + return NULL; + + jpoint = (*env)->NewObject(env, cls_Point, mid_Point_init, point.x, point.y); + if (jpoint == NULL) + fz_throw_java(ctx, env); + + return jpoint; } -static inline jlong jlong_cast(const void *p) +static inline jfloatArray to_jfloatArray(fz_context *ctx, JNIEnv *env, const float *color, jint n) { - return (jlong)(intptr_t)p; + jfloatArray arr; + + if (ctx == NULL) + return NULL; + + arr = (*env)->NewFloatArray(env, n); + if (arr == NULL) + fz_throw_java(ctx, env); + + (*env)->SetFloatArrayRegion(env, arr, 0, n, color); + + return arr; } -/* Conversion functions: C to Java */ -static inline jobject Annotation_from_fz_annot(fz_context *ctx, JNIEnv *env, fz_annot *annot) +static inline jobject to_Annotation(fz_context *ctx, JNIEnv *env, fz_annot *annot) { jobject jannot; - if (ctx == NULL) + if (ctx == NULL || annot == NULL) return NULL; - (*env)->NewObject(env, annot_class, annot_const_mid, annot); + jannot = (*env)->NewObject(env, cls_Annot, mid_Annot_init, annot); if (jannot == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "Annotation creation failed"); + fz_throw_java(ctx, env); return jannot; } -static inline jobject ColorSpace_from_fz_colorspace(fz_context *ctx, JNIEnv *env, fz_colorspace *cs) +static inline jobject to_ColorSpace(fz_context *ctx, JNIEnv *env, fz_colorspace *cs) { jobject jobj; - if (ctx == NULL) + if (ctx == NULL || cs == NULL) return NULL; - jobj = (*env)->NewObject(env, colorspace_class, colorspace_const_mid, jlong_cast(cs)); + jobj = (*env)->CallStaticObjectMethod(env, cls_ColorSpace, mid_ColorSpace_fromPointer, jlong_cast(cs)); if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of ColorSpace failed"); + fz_throw_java(ctx, env); fz_keep_colorspace(ctx, cs); return jobj; } -static inline jobject Image_from_fz_image(fz_context *ctx, JNIEnv *env, fz_image *img) +/* don't throw fitz exceptions */ +static inline jobject to_Font_safe(fz_context *ctx, JNIEnv *env, fz_font *font) +{ + jobject jfont; + + if (ctx == NULL || font == NULL) + return NULL; + + jfont = (*env)->NewObject(env, cls_Font, mid_Font_init, jlong_cast(font)); + if (jfont != NULL) + fz_keep_font(ctx, font); + + return jfont; +} + +static inline jobject to_Image(fz_context *ctx, JNIEnv *env, fz_image *img) { jobject jobj; - if (ctx == NULL) + if (ctx == NULL || img == NULL) return NULL; - jobj = (*env)->NewObject(env, image_class, image_const_mid, jlong_cast(img)); + jobj = (*env)->NewObject(env, cls_Image, mid_Image_init, jlong_cast(img)); if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Image failed"); + fz_throw_java(ctx, env); fz_keep_image(ctx, img); return jobj; } -static inline jobject Matrix_from_fz_matrix(fz_context *ctx, JNIEnv *env, const fz_matrix *mat) +#if 0 +static inline jobject to_Outline(fz_context *ctx, JNIEnv *env, fz_outline *outline) { - jobject jobj; + jobject joutline; - if (ctx == NULL) + if (ctx == NULL || outline == NULL) return NULL; - jobj = (*env)->NewObject(env, matrix_class, matrix_const_mid, mat->a, mat->b, mat->c, mat->d, mat->e, mat->f); - if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Matrix failed"); + joutline = (*env)->NewObject(env, cls_Outline, mid_Outline_init, jlong_cast(outline)); + if (joutline == NULL) + fz_throw_java(ctx, env); - return jobj; + fz_keep_outline(ctx, outline); + + return joutline; } +#endif -static inline jobject Outline_from_fz_outline(fz_context *ctx, JNIEnv *env, fz_outline *outline) +/* take ownership and don't throw fitz exceptions */ +static inline jobject to_Outline_safe(fz_context *ctx, JNIEnv *env, fz_outline *outline) { jobject joutline; - if (ctx == NULL) + if (ctx == NULL || outline == NULL) return NULL; - joutline = (*env)->NewObject(env, outline_class, outline_const_mid, jlong_cast(outline)); + joutline = (*env)->NewObject(env, cls_Outline, mid_Outline_init, jlong_cast(outline)); if (joutline == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "getOutline failed (3)"); + { + fz_drop_outline(ctx, outline); + return NULL; + } return joutline; } -static inline jobject Page_from_fz_page(fz_context *ctx, JNIEnv *env, fz_page *page) +#if 0 +static inline jobject to_Page(fz_context *ctx, JNIEnv *env, fz_page *page) { jobject jobj; - if (ctx == NULL) + if (ctx == NULL || page == NULL) return NULL; - jobj = (*env)->NewObject(env, page_class, page_const_mid, jlong_cast(page)); + jobj = (*env)->NewObject(env, cls_Page, mid_Page_init, jlong_cast(page)); if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Page failed"); + fz_throw_java(ctx, env); return jobj; } +#endif -static inline jobject Path_from_fz_path(fz_context *ctx, JNIEnv *env, fz_path *path) +/* take ownership and don't throw fitz exceptions */ +static inline jobject to_Page_safe(fz_context *ctx, JNIEnv *env, fz_page *page) { jobject jobj; - fz_path *new_path; - if (ctx == NULL) + if (ctx == NULL || page == NULL) return NULL; - new_path = fz_clone_path(ctx, path); - - jobj = (*env)->NewObject(env, path_class, path_const_mid, jlong_cast(new_path)); + jobj = (*env)->NewObject(env, cls_Page, mid_Page_init, jlong_cast(page)); if (jobj == NULL) { - fz_drop_path(ctx, new_path); - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Path failed"); + fz_drop_page(ctx, page); + return NULL; } return jobj; } -static inline jobject Point_from_fz_point(fz_context *ctx, JNIEnv *env, fz_point point) +static inline jobject to_Path(fz_context *ctx, JNIEnv *env, const fz_path *path) { - jobject jpoint; + jobject jobj; - if (ctx == NULL) + if (ctx == NULL || path == NULL) return NULL; - jpoint = (*env)->NewObject(env, point_class, point_const_mid, point.x, point.y); - if (jpoint == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "currentPoint failed (3)"); + jobj = (*env)->NewObject(env, cls_Path, mid_Path_init, jlong_cast(path)); + if (jobj == NULL) + fz_throw_java(ctx, env); - return jpoint; + fz_keep_path(ctx, path); + + return jobj; } -static inline jobject Rect_from_fz_rect(fz_context *ctx, JNIEnv *env, const fz_rect *rect) +#if 0 +static inline jobject to_Pixmap(fz_context *ctx, JNIEnv *env, fz_pixmap *pixmap) { jobject jobj; - if (ctx == NULL) + if (ctx == NULL || pixmap == NULL) return NULL; - jobj = (*env)->NewObject(env, rect_class, rect_const_mid, rect->x0, rect->y0, rect->x1, rect->y1); + jobj = (*env)->NewObject(env, cls_Pixmap, mid_Pixmap_init, jlong_cast(pixmap)); if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Rect failed"); + fz_throw_java(ctx, env); + + fz_keep_pixmap(ctx, pixmap); return jobj; } +#endif -static inline jobject Shade_from_fz_shade(fz_context *ctx, JNIEnv *env, fz_shade *shade) +/* take ownership and don't throw fitz exceptions */ +static inline jobject to_Pixmap_safe(fz_context *ctx, JNIEnv *env, fz_pixmap *pixmap) { jobject jobj; - if (ctx == NULL) + if (ctx == NULL || pixmap == NULL) return NULL; - jobj = (*env)->NewObject(env, shade_class, shade_const_mid, jlong_cast(shade)); + jobj = (*env)->NewObject(env, cls_Pixmap, mid_Pixmap_init, jlong_cast(pixmap)); if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Shade failed"); + { + fz_drop_pixmap(ctx, pixmap); + return NULL; + } + + return jobj; +} + +static inline jobject to_Shade(fz_context *ctx, JNIEnv *env, fz_shade *shade) +{ + jobject jobj; + + if (ctx == NULL || shade == NULL) + return NULL; + + jobj = (*env)->NewObject(env, cls_Shade, mid_Shade_init, jlong_cast(shade)); + if (jobj == NULL) + fz_throw_java(ctx, env); fz_keep_shade(ctx, shade); return jobj; } -static inline jobject StrokeState_from_fz_stroke_state(fz_context *ctx, JNIEnv *env, fz_stroke_state *state) +static inline jobject to_StrokeState(fz_context *ctx, JNIEnv *env, const fz_stroke_state *state) { jobject jobj; if (ctx == NULL) return NULL; - jobj = (*env)->NewObject(env, stroke_class, stroke_const_mid, jlong_cast(state)); + jobj = (*env)->NewObject(env, cls_StrokeState, mid_StrokeState_init, jlong_cast(state)); if (jobj == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of StrokeState failed"); + fz_throw_java(ctx, env); fz_keep_stroke_state(ctx, state); return jobj; } -static inline jobject Text_from_fz_text(fz_context *ctx, JNIEnv *env, fz_text *text) +static inline jobject to_Text(fz_context *ctx, JNIEnv *env, const fz_text *text) { jobject jobj; - fz_text *new_text; if (ctx == NULL) return NULL; - new_text = fz_clone_text(ctx, text); - - jobj = (*env)->NewObject(env, text_class, text_const_mid, jlong_cast(new_text)); + jobj = (*env)->NewObject(env, cls_Text, mid_Text_init, jlong_cast(text)); if (jobj == NULL) - { - fz_drop_text(ctx, new_text); - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Text failed"); - } + fz_throw_java(ctx, env); + + fz_keep_text(ctx, text); return jobj; } -static inline jfloatArray jfloatArray_from_fz_color(fz_context *ctx, JNIEnv *env, float *color, int n) +/* Conversion functions: Java to C. These all throw java exceptions. */ + +static inline fz_matrix from_Matrix(JNIEnv *env, jobject jmat) { - jfloatArray arr; + fz_matrix mat; - if (ctx == NULL) + mat.a = (*env)->GetFloatField(env, jmat, fid_Matrix_a); + mat.b = (*env)->GetFloatField(env, jmat, fid_Matrix_b); + mat.c = (*env)->GetFloatField(env, jmat, fid_Matrix_c); + mat.d = (*env)->GetFloatField(env, jmat, fid_Matrix_d); + mat.e = (*env)->GetFloatField(env, jmat, fid_Matrix_e); + mat.f = (*env)->GetFloatField(env, jmat, fid_Matrix_f); + + return mat; +} + +static inline fz_rect from_Rect(JNIEnv *env, jobject jrect) +{ + fz_rect rect; + + rect.x0 = (*env)->GetFloatField(env, jrect, fid_Rect_x0); + rect.x1 = (*env)->GetFloatField(env, jrect, fid_Rect_x1); + rect.y0 = (*env)->GetFloatField(env, jrect, fid_Rect_y0); + rect.y1 = (*env)->GetFloatField(env, jrect, fid_Rect_y1); + + return rect; +} + +static inline void from_jfloatArray(JNIEnv *env, float *color, jint n, jfloatArray jcolor) +{ + jsize len = (*env)->GetArrayLength(env, jcolor); + if (len > n) + len = n; + (*env)->GetFloatArrayRegion(env, jcolor, 0, len, color); + if (len < n) + memset(color+len, 0, (n-len)*sizeof(float)); +} + +static inline fz_annot *from_Annotation(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) return NULL; + return CAST(fz_annot *, (*env)->GetLongField(env, jobj, fid_Annot_pointer)); +} - arr = (*env)->NewFloatArray(env, n); - if (arr == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of floatArray failed"); +static inline fz_cookie *from_Cookie(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_cookie *, (*env)->GetLongField(env, jobj, fid_Cookie_pointer)); +} - (*env)->SetFloatArrayRegion(env, arr, 0, n, color); +static inline fz_colorspace *from_ColorSpace(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_colorspace *, (*env)->GetLongField(env, jobj, fid_ColorSpace_pointer)); +} - return arr; +static fz_device *from_Device(JNIEnv *env, jobject jobj, fz_context *ctx) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_device *, (*env)->GetLongField(env, jobj, fid_Device_pointer)); } -/* Devices can either be implemented in C, or in Java. - * - * We therefore have to think about 4 possible call combinations. - * - * 1) C -> C: The standard mupdf case. No special worries here. - * 2) C -> Java: This can only happen when we call run on a page/annotation/ - * displaylist. We need to ensure that the java Device has an - * appropriate fz_java_device generated for it. The 'run' calls - * take care to lock/unlock for us. - * 3) Java -> C: The C device will have a java shim (a subclass of CDevice). - * All calls will go through the device methods in CDevice, - * which converts the java objects to C ones, and lock/unlock - * any underlying objects as required. - * 4) Java -> Java: No special worries. - */ +static inline fz_display_list *from_DisplayList(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_display_list *, (*env)->GetLongField(env, jobj, fid_DisplayList_pointer)); +} + +static inline fz_document *from_Document(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_document *, (*env)->GetLongField(env, jobj, fid_Document_pointer)); +} + +static inline fz_font *from_Font(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_font *, (*env)->GetLongField(env, jobj, fid_Font_pointer)); +} + +static inline fz_image *from_Image(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_image *, (*env)->GetLongField(env, jobj, fid_Image_pointer)); +} + +static inline fz_link *from_Link(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_link *, (*env)->GetLongField(env, jobj, fid_Link_pointer)); +} + +static inline fz_outline *from_Outline(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_outline *, (*env)->GetLongField(env, jobj, fid_Outline_pointer)); +} + +static inline fz_page *from_Page(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_page *, (*env)->GetLongField(env, jobj, fid_Page_pointer)); +} + +static inline fz_path *from_Path(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_path *, (*env)->GetLongField(env, jobj, fid_Path_pointer)); +} + +static inline fz_pixmap *from_Pixmap(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_pixmap *, (*env)->GetLongField(env, jobj, fid_Pixmap_pointer)); +} + +static inline fz_shade *from_Shade(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_shade *, (*env)->GetLongField(env, jobj, fid_Shade_pointer)); +} -/* Our java device wrapping functions */ +static inline fz_stroke_state *from_StrokeState(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_stroke_state *, (*env)->GetLongField(env, jobj, fid_StrokeState_pointer)); +} + +static inline fz_text *from_Text(JNIEnv *env, jobject jobj) +{ + if (jobj == NULL) + return NULL; + return CAST(fz_text *, (*env)->GetLongField(env, jobj, fid_Text_pointer)); +} + +/* + Devices can either be implemented in C, or in Java. + We therefore have to think about 4 possible call combinations. + + 1) C -> C: + The standard mupdf case. No special worries here. + 2) C -> Java: + This can only happen when we call run on a page/annotation/ + displaylist. We need to ensure that the java Device has an + appropriate fz_java_device generated for it, which is done by the + Device constructor. The 'run' calls take care to lock/unlock for us. + 3) Java -> C: + The C device will have a java shim (a subclass of NativeDevice). + All calls will go through the device methods in NativeDevice, + which converts the java objects to C ones, and lock/unlock + any underlying objects as required. + 4) Java -> Java: + No special worries. + */ typedef struct { - fz_device base; + fz_device super; JNIEnv *env; jobject self; } @@ -680,10 +1022,12 @@ fz_java_device_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *rect, { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jrect = Rect_from_fz_rect(ctx, env, rect); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jrect = to_Rect(ctx, env, rect); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_begin_page_mid, jrect, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_beginPage, jrect, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -692,125 +1036,140 @@ fz_java_device_end_page(fz_context *ctx, fz_device *dev) fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - (*env)->CallVoidMethod(env, jdev->self, device_end_page_mid); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_endPage); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *cs, float *color, float alpha) +fz_java_device_fill_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *cs, const float *color, float alpha) { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jpath = Path_from_fz_path(ctx, env, path); - jobject jcs = ColorSpace_from_fz_colorspace(ctx, env, cs); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); - jfloatArray jcolor = jfloatArray_from_fz_color(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); + jobject jpath = to_Path(ctx, env, path); + jobject jcs = to_ColorSpace(ctx, env, cs); + jobject jctm = to_Matrix(ctx, env, ctm); + jfloatArray jcolor = to_jfloatArray(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); - (*env)->CallVoidMethod(env, jdev->self, device_fill_path_mid, jpath, even_odd, jctm, jcs, jcolor, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_fillPath, jpath, (jboolean)even_odd, jctm, jcs, jcolor, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *state, const fz_matrix *ctm, fz_colorspace *cs, float *color, float alpha) +fz_java_device_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_stroke_state *state, const fz_matrix *ctm, fz_colorspace *cs, const float *color, float alpha) { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jpath = Path_from_fz_path(ctx, env, path); - jobject jstate = StrokeState_from_fz_stroke_state(ctx, env, state); - jobject jcs = ColorSpace_from_fz_colorspace(ctx, env, cs); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); - jfloatArray jcolor = jfloatArray_from_fz_color(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); + jobject jpath = to_Path(ctx, env, path); + jobject jstate = to_StrokeState(ctx, env, state); + jobject jcs = to_ColorSpace(ctx, env, cs); + jobject jctm = to_Matrix(ctx, env, ctm); + jfloatArray jcolor = to_jfloatArray(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); - (*env)->CallVoidMethod(env, jdev->self, device_stroke_path_mid, jpath, jstate, jctm, jcs, jcolor, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_strokePath, jpath, jstate, jctm, jcs, jcolor, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +fz_java_device_clip_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jpath = Path_from_fz_path(ctx, env, path); - jobject jrect = Rect_from_fz_rect(ctx, env, rect); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jpath = to_Path(ctx, env, path); + jobject jrect = to_Rect(ctx, env, rect); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_clip_path_mid, jpath, jrect, even_odd, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_clipPath, jpath, jrect, (jboolean)even_odd, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *state, const fz_matrix *ctm) +fz_java_device_clip_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_rect *rect, const fz_stroke_state *state, const fz_matrix *ctm) { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jpath = Path_from_fz_path(ctx, env, path); - jobject jrect = Rect_from_fz_rect(ctx, env, rect); - jobject jstate = StrokeState_from_fz_stroke_state(ctx, env, state); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jpath = to_Path(ctx, env, path); + jobject jrect = to_Rect(ctx, env, rect); + jobject jstate = to_StrokeState(ctx, env, state); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_clip_stroke_path_mid, jpath, jrect, jstate, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_clipStrokePath, jpath, jrect, jstate, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *cs, float *color, float alpha) +fz_java_device_fill_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm, fz_colorspace *cs, const float *color, float alpha) { - LOGI("fz_java_device_fill_text"); fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jtext = Text_from_fz_text(ctx, env, text); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); - jobject jcs = ColorSpace_from_fz_colorspace(ctx, env, cs); - jfloatArray jcolor = jfloatArray_from_fz_color(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); + jobject jtext = to_Text(ctx, env, text); + jobject jctm = to_Matrix(ctx, env, ctm); + jobject jcs = to_ColorSpace(ctx, env, cs); + jfloatArray jcolor = to_jfloatArray(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); - (*env)->CallVoidMethod(env, jdev->self, device_fill_text_mid, jtext, jctm, jcs, jcolor, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_fillText, jtext, jctm, jcs, jcolor, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *state, const fz_matrix *ctm, fz_colorspace *cs, float *color, float alpha) +fz_java_device_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_stroke_state *state, const fz_matrix *ctm, fz_colorspace *cs, const float *color, float alpha) { - LOGI("fz_java_device_stroke_text"); fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jtext = Text_from_fz_text(ctx, env, text); - jobject jstate = StrokeState_from_fz_stroke_state(ctx, env, state); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); - jobject jcs = ColorSpace_from_fz_colorspace(ctx, env, cs); - jfloatArray jcolor = jfloatArray_from_fz_color(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); + jobject jtext = to_Text(ctx, env, text); + jobject jstate = to_StrokeState(ctx, env, state); + jobject jctm = to_Matrix(ctx, env, ctm); + jobject jcs = to_ColorSpace(ctx, env, cs); + jfloatArray jcolor = to_jfloatArray(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); - (*env)->CallVoidMethod(env, jdev->self, device_stroke_text_mid, jtext, jstate, jctm, jcs, jcolor, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_strokeText, jtext, jstate, jctm, jcs, jcolor, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_java_device_clip_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm) { - LOGI("fz_java_device_clip_text"); fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jtext = Text_from_fz_text(ctx, env, text); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jtext = to_Text(ctx, env, text); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_clip_text_mid, jtext, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_clipText, jtext, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *state, const fz_matrix *ctm) +fz_java_device_clip_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_stroke_state *state, const fz_matrix *ctm) { - LOGI("fz_java_device_clip_stroke_text"); fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jtext = Text_from_fz_text(ctx, env, text); - jobject jstate = StrokeState_from_fz_stroke_state(ctx, env, state); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jtext = to_Text(ctx, env, text); + jobject jstate = to_StrokeState(ctx, env, state); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_clip_stroke_text_mid, jtext, jstate, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_clipStrokeText, jtext, jstate, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_java_device_ignore_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm) { - LOGI("fz_java_device_ignore_text"); fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jtext = Text_from_fz_text(ctx, env, text); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jtext = to_Text(ctx, env, text); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_ignore_text_mid, jtext, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_ignoreText, jtext, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -818,10 +1177,12 @@ fz_java_device_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shd, const { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jshd = Shade_from_fz_shade(ctx, env, shd); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jshd = to_Shade(ctx, env, shd); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_fill_shade_mid, jshd, jctm, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_fillShade, jshd, jctm, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -829,23 +1190,27 @@ fz_java_device_fill_image(fz_context *ctx, fz_device *dev, fz_image *img, const { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jimg = Image_from_fz_image(ctx, env, img); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jimg = to_Image(ctx, env, img); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_fill_image_mid, jimg, jctm, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_fillImage, jimg, jctm, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *img, const fz_matrix *ctm, fz_colorspace *cs, float *color, float alpha) +fz_java_device_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *img, const fz_matrix *ctm, fz_colorspace *cs, const float *color, float alpha) { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jimg = Image_from_fz_image(ctx, env, img); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); - jobject jcs = ColorSpace_from_fz_colorspace(ctx, env, cs); - jfloatArray jcolor = jfloatArray_from_fz_color(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); + jobject jimg = to_Image(ctx, env, img); + jobject jctm = to_Matrix(ctx, env, ctm); + jobject jcs = to_ColorSpace(ctx, env, cs); + jfloatArray jcolor = to_jfloatArray(ctx, env, color, cs ? cs->n : FZ_MAX_COLORS); - (*env)->CallVoidMethod(env, jdev->self, device_fill_image_mask_mid, jimg, jctm, jcs, jcolor, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_fillImageMask, jimg, jctm, jcs, jcolor, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -853,11 +1218,13 @@ fz_java_device_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *img, c { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jimg = Image_from_fz_image(ctx, env, img); - jobject jrect = Rect_from_fz_rect(ctx, env, rect); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jimg = to_Image(ctx, env, img); + jobject jrect = to_Rect(ctx, env, rect); + jobject jctm = to_Matrix(ctx, env, ctm); - (*env)->CallVoidMethod(env, jdev->self, device_clip_image_mask_mid, jimg, jrect, jctm); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_clipImageMask, jimg, jrect, jctm); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -866,19 +1233,23 @@ fz_java_device_pop_clip(fz_context *ctx, fz_device *dev) fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - (*env)->CallVoidMethod(env, jdev->self, device_pop_clip_mid); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_popClip); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -fz_java_device_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *cs, float *bc) +fz_java_device_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *cs, const float *bc) { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jrect = Rect_from_fz_rect(ctx, env, rect); - jobject jcs = ColorSpace_from_fz_colorspace(ctx, env, cs); - jfloatArray jbc = jfloatArray_from_fz_color(ctx, env, bc, cs ? cs->n : FZ_MAX_COLORS); + jobject jrect = to_Rect(ctx, env, rect); + jobject jcs = to_ColorSpace(ctx, env, cs); + jfloatArray jbc = to_jfloatArray(ctx, env, bc, cs ? cs->n : FZ_MAX_COLORS); - (*env)->CallVoidMethod(env, jdev->self, device_begin_mask_mid, jrect, luminosity, jcs, jbc); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_beginMask, jrect, (jint)luminosity, jcs, jbc); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -887,7 +1258,9 @@ fz_java_device_end_mask(fz_context *ctx, fz_device *dev) fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - (*env)->CallVoidMethod(env, jdev->self, device_end_mask_mid); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_endMask); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -895,9 +1268,11 @@ fz_java_device_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *rect, { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jrect = Rect_from_fz_rect(ctx, env, rect); + jobject jrect = to_Rect(ctx, env, rect); - (*env)->CallVoidMethod(env, jdev->self, device_begin_group_mid, jrect, isolated, knockout, blendmode, alpha); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_beginGroup, jrect, (jboolean)isolated, (jboolean)knockout, (jint)blendmode, alpha); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void @@ -906,7 +1281,9 @@ fz_java_device_end_group(fz_context *ctx, fz_device *dev) fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - (*env)->CallVoidMethod(env, jdev->self, device_end_group_mid); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_endGroup); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static int @@ -914,12 +1291,14 @@ fz_java_device_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, { fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - jobject jarea = Rect_from_fz_rect(ctx, env, area); - jobject jview = Rect_from_fz_rect(ctx, env, view); - jobject jctm = Matrix_from_fz_matrix(ctx, env, ctm); + jobject jarea = to_Rect(ctx, env, area); + jobject jview = to_Rect(ctx, env, view); + jobject jctm = to_Matrix(ctx, env, ctm); int res; - res = (*env)->CallIntMethod(env, jdev->self, device_begin_tile_mid, jarea, jview, xstep, ystep, jctm, id); + res = (*env)->CallIntMethod(env, jdev->self, mid_Device_beginTile, jarea, jview, xstep, ystep, jctm, (jint)id); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); return res; } @@ -930,293 +1309,112 @@ fz_java_device_end_tile(fz_context *ctx, fz_device *dev) fz_java_device *jdev = (fz_java_device *)dev; JNIEnv *env = jdev->env; - (*env)->CallVoidMethod(env, jdev->self, device_end_tile_mid); + (*env)->CallVoidMethod(env, jdev->self, mid_Device_endTile); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void fz_java_device_drop_imp(fz_context *ctx, fz_device *dev) { fz_java_device *jdev = (fz_java_device *)dev; + JNIEnv *env = jdev->env; - /* Nothing to do, currently */ - jdev = jdev; + (*env)->DeleteGlobalRef(env, jdev->self); } -static fz_device *fz_new_java_device(JNIEnv *env, jobject self, fz_context *ctx) +static fz_device *fz_new_java_device(fz_context *ctx, JNIEnv *env, jobject self) { - fz_device *dev = NULL; - fz_java_device *jdev = NULL; - - fz_var(dev); - fz_var(jdev); + fz_java_device *dev = NULL; fz_try(ctx) { - jdev = fz_new_device(ctx, sizeof(fz_java_device)); - dev = &jdev->base; - jdev->env = env; - jdev->self = self; - dev->drop_imp = fz_java_device_drop_imp; - - dev->fill_path = fz_java_device_fill_path; - dev->stroke_path = fz_java_device_stroke_path; - dev->clip_path = fz_java_device_clip_path; - dev->clip_stroke_path = fz_java_device_clip_stroke_path; - - dev->fill_text = fz_java_device_fill_text; - dev->stroke_text = fz_java_device_stroke_text; - dev->clip_text = fz_java_device_clip_text; - dev->clip_stroke_text = fz_java_device_clip_stroke_text; - - dev->fill_shade = fz_java_device_fill_shade; - dev->fill_image = fz_java_device_fill_image; - dev->fill_image_mask = fz_java_device_fill_image_mask; - dev->clip_image_mask = fz_java_device_clip_image_mask; - - dev->pop_clip = fz_java_device_pop_clip; - - dev->begin_mask = fz_java_device_begin_mask; - dev->end_mask = fz_java_device_end_mask; - dev->begin_group = fz_java_device_begin_group; - dev->end_group = fz_java_device_end_group; - - dev->begin_tile = fz_java_device_begin_tile; - dev->end_tile = fz_java_device_end_tile; - } - fz_catch(ctx) - { - jclass exClass; + dev = fz_new_device(ctx, sizeof(fz_java_device)); + dev->env = env; - fz_free(ctx, jdev); - throwOutOfMemoryError(env, "Failed to create fz_java_device"); - dev = NULL; - } - return dev; -} + dev->self = (*env)->NewGlobalRef(env, self); -/* Conversion functions: Java to C */ -static inline fz_colorspace *fz_colorspace_from_ColorSpace(JNIEnv *env, jobject jobj) -{ - return CAST(fz_colorspace *, (*env)->GetLongField(env, jobj, colorspace_fid)); -} + dev->super.drop_imp = fz_java_device_drop_imp; + dev->super.begin_page = fz_java_device_begin_page; + dev->super.end_page = fz_java_device_end_page; -static fz_device *fz_device_from_Device(JNIEnv *env, jobject self, fz_context *ctx) -{ - fz_device *dev = CAST(fz_device *, (*env)->GetLongField(env, self, device_fid)); + dev->super.fill_path = fz_java_device_fill_path; + dev->super.stroke_path = fz_java_device_stroke_path; + dev->super.clip_path = fz_java_device_clip_path; + dev->super.clip_stroke_path = fz_java_device_clip_stroke_path; - if (dev == NULL) - { - /* This must be a Java device. Create a native shim. */ - dev = fz_new_java_device(env, self, ctx); - (*env)->SetLongField(env, self, device_fid, jlong_cast(dev)); - } - return dev; -} + dev->super.fill_text = fz_java_device_fill_text; + dev->super.stroke_text = fz_java_device_stroke_text; + dev->super.clip_text = fz_java_device_clip_text; + dev->super.clip_stroke_text = fz_java_device_clip_stroke_text; + dev->super.ignore_text = fz_java_device_ignore_text; -static inline fz_image *fz_image_from_Image(JNIEnv *env, jobject jobj) -{ - return CAST(fz_image *, (*env)->GetLongField(env, jobj, image_fid)); -} - -static inline fz_matrix fz_matrix_from_Matrix(JNIEnv *env, jobject jmat) -{ - fz_matrix mat; - - mat.a = (*env)->GetFloatField(env, jmat, matrix_a_fid); - mat.b = (*env)->GetFloatField(env, jmat, matrix_b_fid); - mat.c = (*env)->GetFloatField(env, jmat, matrix_c_fid); - mat.d = (*env)->GetFloatField(env, jmat, matrix_d_fid); - mat.e = (*env)->GetFloatField(env, jmat, matrix_e_fid); - mat.f = (*env)->GetFloatField(env, jmat, matrix_f_fid); - - return mat; -} - -static inline fz_path *fz_path_from_Path(JNIEnv *env, jobject jobj) -{ - return CAST(fz_path *, (*env)->GetLongField(env, jobj, path_fid)); -} - -static inline fz_rect fz_rect_from_Rect(JNIEnv *env, jobject jrect) -{ - fz_rect rect; - - rect.x0 = (*env)->GetFloatField(env, jrect, rect_x0_fid); - rect.x1 = (*env)->GetFloatField(env, jrect, rect_x1_fid); - rect.y0 = (*env)->GetFloatField(env, jrect, rect_y0_fid); - rect.y1 = (*env)->GetFloatField(env, jrect, rect_y1_fid); - - return rect; -} - -static inline fz_shade *fz_shade_from_Shade(JNIEnv *env, jobject jobj) -{ - return CAST(fz_shade *, (*env)->GetLongField(env, jobj, shade_fid)); -} - -static inline fz_stroke_state *fz_stroke_state_from_StrokeState(JNIEnv *env, jobject jobj) -{ - return CAST(fz_stroke_state *, (*env)->GetLongField(env, jobj, stroke_fid)); -} - -static inline fz_text *fz_text_from_Text(JNIEnv *env, jobject jobj) -{ - return CAST(fz_text *, (*env)->GetLongField(env, jobj, text_fid)); -} - -static inline fz_font *fz_font_from_Font(JNIEnv *env, jobject jobj) -{ - return CAST(fz_font *, (*env)->GetLongField(env, jobj, font_fid)); -} - -static inline void fz_color_from_jfloatArray(JNIEnv *env, float *color, int n, jfloatArray jcolor) -{ - jsize len = (*env)->GetArrayLength(env, jcolor); - if (len > n) - len = n; - (*env)->GetFloatArrayRegion(env, jcolor, 0, len, color); - if (len < n) - memset(color+len, 0, (n-len)*sizeof(float)); -} - -static inline fz_cookie *fz_cookie_from_Cookie(JNIEnv *env, jobject jobj) -{ - return CAST(fz_cookie *, (*env)->GetLongField(env, jobj, cookie_fid)); -} - -static inline fz_display_list *fz_display_list_from_DisplayList(JNIEnv *env, jobject jobj) -{ - return CAST(fz_display_list *, (*env)->GetLongField(env, jobj, displaylist_fid)); -} - -static inline fz_page *fz_page_from_Page(JNIEnv *env, jobject jobj) -{ - return CAST(fz_page *, (*env)->GetLongField(env, jobj, page_fid)); -} + dev->super.fill_shade = fz_java_device_fill_shade; + dev->super.fill_image = fz_java_device_fill_image; + dev->super.fill_image_mask = fz_java_device_fill_image_mask; + dev->super.clip_image_mask = fz_java_device_clip_image_mask; -static inline fz_document *fz_document_from_Document(JNIEnv *env, jobject jobj) -{ - jlong l; - - l = (*env)->GetLongField(env, jobj, document_fid); - return CAST(fz_document *, l); -} - -static inline fz_annot *fz_annot_from_Annotation(JNIEnv *env, jobject jobj) -{ - return CAST(fz_annot *, (*env)->GetLongField(env, jobj, annot_fid)); -} + dev->super.pop_clip = fz_java_device_pop_clip; -static inline fz_outline *fz_outline_from_Outline(JNIEnv *env, jobject jobj) -{ - return CAST(fz_outline *, (*env)->GetLongField(env, jobj, outline_fid)); -} + dev->super.begin_mask = fz_java_device_begin_mask; + dev->super.end_mask = fz_java_device_end_mask; + dev->super.begin_group = fz_java_device_begin_group; + dev->super.end_group = fz_java_device_end_group; -static inline fz_link *fz_link_from_Link(JNIEnv *env, jobject jobj) -{ - return CAST(fz_link *, (*env)->GetLongField(env, jobj, link_fid)); -} - -/* Helper function for exception handling */ - -static void jni_throw(JNIEnv *env, int type, const char *mess) -{ - const char *className; - int len; - jclass cla; - - switch(type) + dev->super.begin_tile = fz_java_device_begin_tile; + dev->super.end_tile = fz_java_device_end_tile; + } + fz_catch(ctx) { - case FZ_ERROR_TRYLATER: - cla = trylaterexception_class; - break; - default: - case FZ_ERROR_GENERIC: - cla = exception_class; - break; + jni_rethrow(env, ctx); } - (void)(*env)->ThrowNew(env, cla, mess); -} - -static void jni_rethrow(JNIEnv *env, fz_context *ctx) -{ - jni_throw(env, fz_caught(ctx), fz_caught_message(ctx)); -} - -/* ColorSpace Interface */ - -JNIEXPORT void JNICALL -JNI_FN(ColorSpace_finalize)(JNIEnv * env, jobject self) -{ - fz_context *ctx = get_context(env); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, self); - - if (ctx == NULL || cs == NULL) - return; - - fz_drop_colorspace(ctx, cs); -} - -JNIEXPORT void JNICALL -JNI_FN(ColorSpace_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(ColorSpace_finalize)(env, self); - - (*env)->SetLongField(env, self, colorspace_fid, 0); -} - -JNIEXPORT int JNICALL -JNI_FN(ColorSpace_getNumComponents)(JNIEnv * env, jobject self) -{ - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, self); - - if (cs == NULL) - return 0; - - return cs->n; + return (fz_device*)dev; } JNIEXPORT jlong JNICALL -JNI_FN(ColorSpace_newDeviceRGB)(JNIEnv * env, jobject self, jlong size) +FUN(Device_newNative)(JNIEnv *env, jclass self) { fz_context *ctx = get_context(env); - return jlong_cast(fz_device_rgb(ctx)); -} + fz_device *dev = NULL; -JNIEXPORT jlong JNICALL -JNI_FN(ColorSpace_newDeviceGray)(JNIEnv * env, jobject self, jlong size) -{ - fz_context *ctx = get_context(env); + fz_try(ctx) + dev = fz_new_java_device(ctx, env, self); + fz_catch(ctx) + jni_rethrow(env, ctx); - return jlong_cast(fz_device_gray(ctx)); + return jlong_cast(dev); } -JNIEXPORT jlong JNICALL -JNI_FN(ColorSpace_newDeviceCMYK)(JNIEnv * env, jobject self, jlong size) +JNIEXPORT void JNICALL +FUN(Device_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); + fz_device *dev = from_Device(env, self, ctx); - return jlong_cast(fz_device_cmyk(ctx)); + if (ctx == NULL || dev == NULL) + return; + + fz_drop_device(ctx, dev); } /* Device Interface */ -typedef struct CDeviceNativeInfo CDeviceNativeInfo; +typedef struct NativeDeviceInfo NativeDeviceInfo; -typedef void (CDeviceLockFn)(JNIEnv *env, CDeviceNativeInfo *info); -typedef void (CDeviceUnlockFn)(JNIEnv *env, CDeviceNativeInfo *info); +typedef void (NativeDeviceLockFn)(JNIEnv *env, NativeDeviceInfo *info); +typedef void (NativeDeviceUnlockFn)(JNIEnv *env, NativeDeviceInfo *info); -struct CDeviceNativeInfo +struct NativeDeviceInfo { - /* Some devices (like the AndroidDrawDevice, or AwtDrawDevice) need + /* Some devices (like the AndroidDrawDevice, or DrawDevice) need * to lock/unlock the java object around device calls. We have functions * here to do that. Other devices (like the DisplayList device) need * no such locking, so these are NULL. */ - CDeviceLockFn *lock; /* Function to lock */ - CDeviceUnlockFn *unlock; /* Function to unlock */ + NativeDeviceLockFn *lock; /* Function to lock */ + NativeDeviceUnlockFn *unlock; /* Function to unlock */ jobject object; /* The java object that needs to be locked. */ /* Conceptually, we support drawing onto a 'plane' of pixels. @@ -1233,699 +1431,582 @@ struct CDeviceNativeInfo int width; }; -static CDeviceNativeInfo *lockCDevice(JNIEnv *env, jobject self) +static NativeDeviceInfo *lockNativeDevice(JNIEnv *env, jobject self) { - CDeviceNativeInfo *info; + NativeDeviceInfo *info = NULL; + + if (!(*env)->IsInstanceOf(env, self, cls_NativeDevice)) + return NULL; - info = CAST(CDeviceNativeInfo *, (*env)->GetLongField(env, self, cdevice_nativeinfo_fid)); + info = CAST(NativeDeviceInfo *, (*env)->GetLongField(env, self, fid_NativeDevice_nativeInfo)); if (info == NULL) { - /* Some devices (like the Displaylist device) need no locking, - * so have no info. */ + /* Some devices (like the Displaylist device) need no locking, so have no info. */ return NULL; } - info->object = (*env)->GetObjectField(env, self, cdevice_nativeresource_fid); + info->object = (*env)->GetObjectField(env, self, fid_NativeDevice_nativeResource); info->lock(env, info); return info; } -static void unlockCDevice(JNIEnv *env, CDeviceNativeInfo *info) +static void unlockNativeDevice(JNIEnv *env, NativeDeviceInfo *info) { if (info != NULL) info->unlock(env, info); } JNIEXPORT void JNICALL -JNI_FN(Device_finalize)(JNIEnv * env, jobject self) +FUN(NativeDevice_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); + fz_device *dev = from_Device(env, self, ctx); + NativeDeviceInfo *ninfo; if (ctx == NULL || dev == NULL) return; - fz_drop_device(ctx, dev); -} - -JNIEXPORT void JNICALL -JNI_FN(Device_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Device_finalize)(env, self); + FUN(Device_finalize)(env, self); /* Call super.finalize() */ - (*env)->SetLongField(env, self, device_fid, 0); + ninfo = CAST(NativeDeviceInfo *, (*env)->GetLongField(env, self, fid_NativeDevice_nativeInfo)); + if (ninfo != NULL) + { + fz_drop_pixmap(ctx, ninfo->pixmap); + fz_free(ctx, ninfo); + } } - JNIEXPORT void JNICALL -JNI_FN(CDevice_beginPage)(JNIEnv *env, jobject self, jobject jrect, jobject jctm) +FUN(NativeDevice_beginPage)(JNIEnv *env, jobject self, jobject jrect, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_rect rect = fz_rect_from_Rect(env, jrect); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_rect rect = from_Rect(env, jrect); + fz_matrix ctm = from_Matrix(env, jctm); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_begin_page(ctx, dev, &rect, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_endPage)(JNIEnv *env, jobject self) +FUN(NativeDevice_endPage)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_end_page(ctx, dev); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_fillPath)(JNIEnv *env, jobject self, jobject jpath, int even_odd, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) +FUN(NativeDevice_fillPath)(JNIEnv *env, jobject self, jobject jpath, jboolean even_odd, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_path *path = fz_path_from_Path(env, jpath); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, jcs); + fz_device *dev = from_Device(env, self, ctx); + fz_path *path = from_Path(env, jpath); + fz_matrix ctm = from_Matrix(env, jctm); + fz_colorspace *cs = from_ColorSpace(env, jcs); float color[FZ_MAX_COLORS]; - CDeviceNativeInfo *info; + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); + from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); + info = lockNativeDevice(env, self); fz_try(ctx) - { - fz_color_from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); - fz_fill_path(ctx, dev, path, even_odd, &ctm, cs, color, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_strokePath)(JNIEnv *env, jobject self, jobject jpath, jobject jstroke, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) +FUN(NativeDevice_strokePath)(JNIEnv *env, jobject self, jobject jpath, jobject jstroke, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_path *path = fz_path_from_Path(env, jpath); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, jcs); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, jstroke); + fz_device *dev = from_Device(env, self, ctx); + fz_path *path = from_Path(env, jpath); + fz_matrix ctm = from_Matrix(env, jctm); + fz_colorspace *cs = from_ColorSpace(env, jcs); + fz_stroke_state *stroke = from_StrokeState(env, jstroke); float color[FZ_MAX_COLORS]; - CDeviceNativeInfo *info; + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); + from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); + info = lockNativeDevice(env, self); fz_try(ctx) - { - fz_color_from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); - fz_stroke_path(ctx, dev, path, stroke, &ctm, cs, color, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_clipPath)(JNIEnv *env, jobject self, jobject jpath, jobject jrect, int even_odd, jobject jctm) +FUN(NativeDevice_clipPath)(JNIEnv *env, jobject self, jobject jpath, jobject jrect, jboolean even_odd, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_path *path = fz_path_from_Path(env, jpath); - fz_rect rect = fz_rect_from_Rect(env, jrect); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_path *path = from_Path(env, jpath); + fz_rect rect = from_Rect(env, jrect); + fz_matrix ctm = from_Matrix(env, jctm); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_clip_path(ctx, dev, path, &rect, even_odd, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_clipStrokePath)(JNIEnv *env, jobject self, jobject jpath, jobject jrect, jobject jstroke, jobject jctm) +FUN(NativeDevice_clipStrokePath)(JNIEnv *env, jobject self, jobject jpath, jobject jrect, jobject jstroke, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_path *path = fz_path_from_Path(env, jpath); - fz_rect rect = fz_rect_from_Rect(env, jrect); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, jstroke); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_path *path = from_Path(env, jpath); + fz_rect rect = from_Rect(env, jrect); + fz_matrix ctm = from_Matrix(env, jctm); + fz_stroke_state *stroke = from_StrokeState(env, jstroke); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_clip_stroke_path(ctx, dev, path, &rect, stroke, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_fillText)(JNIEnv *env, jobject self, jobject jtext, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) +FUN(NativeDevice_fillText)(JNIEnv *env, jobject self, jobject jtext, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_text *text = fz_text_from_Text(env, jtext); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, jcs); + fz_device *dev = from_Device(env, self, ctx); + fz_text *text = from_Text(env, jtext); + fz_matrix ctm = from_Matrix(env, jctm); + fz_colorspace *cs = from_ColorSpace(env, jcs); float color[FZ_MAX_COLORS]; - CDeviceNativeInfo *info; + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); + from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); + info = lockNativeDevice(env, self); fz_try(ctx) - { - fz_color_from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); - fz_fill_text(ctx, dev, text, &ctm, cs, color, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_strokeText)(JNIEnv *env, jobject self, jobject jtext, jobject jstroke, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) +FUN(NativeDevice_strokeText)(JNIEnv *env, jobject self, jobject jtext, jobject jstroke, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_text *text = fz_text_from_Text(env, jtext); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, jcs); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, jstroke); + fz_device *dev = from_Device(env, self, ctx); + fz_text *text = from_Text(env, jtext); + fz_matrix ctm = from_Matrix(env, jctm); + fz_colorspace *cs = from_ColorSpace(env, jcs); + fz_stroke_state *stroke = from_StrokeState(env, jstroke); float color[FZ_MAX_COLORS]; - CDeviceNativeInfo *info; + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); + from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); + info = lockNativeDevice(env, self); fz_try(ctx) - { - fz_color_from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); - fz_stroke_text(ctx, dev, text, stroke, &ctm, cs, color, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_clipText)(JNIEnv *env, jobject self, jobject jtext, jobject jctm) +FUN(NativeDevice_clipText)(JNIEnv *env, jobject self, jobject jtext, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_text *text = fz_text_from_Text(env, jtext); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_text *text = from_Text(env, jtext); + fz_matrix ctm = from_Matrix(env, jctm); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_clip_text(ctx, dev, text, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_clipStrokeText)(JNIEnv *env, jobject self, jobject jtext, jobject jstroke, jobject jctm) +FUN(NativeDevice_clipStrokeText)(JNIEnv *env, jobject self, jobject jtext, jobject jstroke, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_text *text = fz_text_from_Text(env, jtext); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, jstroke); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_matrix ctm = from_Matrix(env, jctm); + fz_text *text = from_Text(env, jtext); + fz_stroke_state *stroke = from_StrokeState(env, jstroke); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_clip_stroke_text(ctx, dev, text, stroke, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_ignoreText)(JNIEnv *env, jobject self, jobject jtext, jobject jctm) +FUN(NativeDevice_ignoreText)(JNIEnv *env, jobject self, jobject jtext, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_text *text = fz_text_from_Text(env, jtext); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_text *text = from_Text(env, jtext); + fz_matrix ctm = from_Matrix(env, jctm); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_ignore_text(ctx, dev, text, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_fillShade)(JNIEnv *env, jobject self, jobject jshade, jobject jctm, float alpha) +FUN(NativeDevice_fillShade)(JNIEnv *env, jobject self, jobject jshade, jobject jctm, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_shade *shade = fz_shade_from_Shade(env, jshade); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_matrix ctm = from_Matrix(env, jctm); + fz_shade *shade = from_Shade(env, jshade); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_fill_shade(ctx, dev, shade, &ctm, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_fillImage)(JNIEnv *env, jobject self, jobject jimg, jobject jctm, float alpha) +FUN(NativeDevice_fillImage)(JNIEnv *env, jobject self, jobject jimg, jobject jctm, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_image *image = fz_image_from_Image(env, jimg); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_image *image = from_Image(env, jimg); + fz_matrix ctm = from_Matrix(env, jctm); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_fill_image(ctx, dev, image, &ctm, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_fillImageMask)(JNIEnv *env, jobject self, jobject jimg, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) +FUN(NativeDevice_fillImageMask)(JNIEnv *env, jobject self, jobject jimg, jobject jctm, jobject jcs, jfloatArray jcolor, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_image *image = fz_image_from_Image(env, jimg); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, jcs); + fz_device *dev = from_Device(env, self, ctx); + fz_image *image = from_Image(env, jimg); + fz_matrix ctm = from_Matrix(env, jctm); + fz_colorspace *cs = from_ColorSpace(env, jcs); float color[FZ_MAX_COLORS]; - CDeviceNativeInfo *info; + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); + from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); + info = lockNativeDevice(env, self); fz_try(ctx) - { - fz_color_from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); - fz_fill_image_mask(ctx, dev, image, &ctm, cs, color, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_clipImageMask)(JNIEnv *env, jobject self, jobject jimg, jobject jrect, jobject jctm) +FUN(NativeDevice_clipImageMask)(JNIEnv *env, jobject self, jobject jimg, jobject jrect, jobject jctm) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_image *image = fz_image_from_Image(env, jimg); - fz_rect rect = fz_rect_from_Rect(env, jrect); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_image *image = from_Image(env, jimg); + fz_rect rect = from_Rect(env, jrect); + fz_matrix ctm = from_Matrix(env, jctm); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_clip_image_mask(ctx, dev, image, &rect, &ctm); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_popClip)(JNIEnv *env, jobject self) +FUN(NativeDevice_popClip)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_pop_clip(ctx, dev); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_beginMask)(JNIEnv *env, jobject self, jobject jrect, int luminosity, jobject jcs, jfloatArray jcolor) +FUN(NativeDevice_beginMask)(JNIEnv *env, jobject self, jobject jrect, jboolean luminosity, jobject jcs, jfloatArray jcolor) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_rect rect = fz_rect_from_Rect(env, jrect); - fz_colorspace *cs = fz_colorspace_from_ColorSpace(env, jcs); + fz_device *dev = from_Device(env, self, ctx); + fz_rect rect = from_Rect(env, jrect); + fz_colorspace *cs = from_ColorSpace(env, jcs); float color[FZ_MAX_COLORS]; - CDeviceNativeInfo *info; + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); + from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); + info = lockNativeDevice(env, self); fz_try(ctx) - { - fz_color_from_jfloatArray(env, color, cs ? cs->n : FZ_MAX_COLORS, jcolor); - fz_begin_mask(ctx, dev, &rect, luminosity, cs, color); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_endMask)(JNIEnv *env, jobject self) +FUN(NativeDevice_endMask)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_end_mask(ctx, dev); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_beginGroup)(JNIEnv *env, jobject self, jobject jrect, int isolated, int knockout, int blendmode, float alpha) +FUN(NativeDevice_beginGroup)(JNIEnv *env, jobject self, jobject jrect, jboolean isolated, jboolean knockout, jint blendmode, float alpha) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_rect rect = fz_rect_from_Rect(env, jrect); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_rect rect = from_Rect(env, jrect); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_begin_group(ctx, dev, &rect, isolated, knockout, blendmode, alpha); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(CDevice_endGroup)(JNIEnv *env, jobject self) +FUN(NativeDevice_endGroup)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_end_group(ctx, dev); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } -JNIEXPORT int JNICALL -JNI_FN(CDevice_beginTile)(JNIEnv *env, jobject self, jobject jarea, jobject jview, float xstep, float ystep, jobject jctm, int id) +JNIEXPORT jint JNICALL +FUN(NativeDevice_beginTile)(JNIEnv *env, jobject self, jobject jarea, jobject jview, float xstep, float ystep, jobject jctm, jint id) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_rect area = fz_rect_from_Rect(env, jarea); - fz_rect view = fz_rect_from_Rect(env, jview); - int i; - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + fz_matrix ctm = from_Matrix(env, jctm); + fz_rect area = from_Rect(env, jarea); + fz_rect view = from_Rect(env, jview); + NativeDeviceInfo *info; + int i = 0; if (ctx == NULL || dev == NULL) - return; - - info = lockCDevice(env, self); + return 0; + info = lockNativeDevice(env, self); fz_try(ctx) - { i = fz_begin_tile_id(ctx, dev, &area, &view, xstep, ystep, &ctm, id); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } return i; } JNIEXPORT void JNICALL -JNI_FN(CDevice_endTile)(JNIEnv *env, jobject self) +FUN(NativeDevice_endTile)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_device *dev = fz_device_from_Device(env, self, ctx); - CDeviceNativeInfo *info; + fz_device *dev = from_Device(env, self, ctx); + NativeDeviceInfo *info; if (ctx == NULL || dev == NULL) return; - info = lockCDevice(env, self); - + info = lockNativeDevice(env, self); fz_try(ctx) - { fz_end_tile(ctx, dev); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } -/* Draw Device interface */ +JNIEXPORT jlong JNICALL +FUN(DrawDevice_newNative)(JNIEnv *env, jclass self, jobject pixmap_) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, pixmap_); + fz_device *device = NULL; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + device = fz_new_draw_device(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return jlong_cast(device); +} + +JNIEXPORT jlong JNICALL +FUN(DisplayListDevice_newNative)(JNIEnv *env, jclass self, jobject jlist) +{ + fz_context *ctx = get_context(env); + fz_display_list *list = from_DisplayList(env, jlist); + fz_device *device = NULL; + + if (ctx == NULL || list == NULL) + return 0; + + fz_try(ctx) + device = fz_new_list_device(ctx, list); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return jlong_cast(device); +} + +#ifdef HAVE_ANDROID + static jlong -newCDevice(JNIEnv *env, jobject self, fz_context *ctx, jobject obj, jint width, jint height, CDeviceLockFn *lock, CDeviceUnlockFn *unlock, int pageX0, int pageY0, int pageX1, int pageY1, int patchX0, int patchY0, int patchX1, int patchY1) +newNativeAndroidDrawDevice(JNIEnv *env, jobject self, fz_context *ctx, jobject obj, jint width, jint height, NativeDeviceLockFn *lock, NativeDeviceUnlockFn *unlock, jint pageX0, jint pageY0, jint pageX1, jint pageY1, jint patchX0, jint patchY0, jint patchX1, jint patchY1) { fz_device *device = NULL; fz_pixmap *pixmap = NULL; - int ret; unsigned char dummy; - CDeviceNativeInfo *ninfo = NULL; + NativeDeviceInfo *ninfo = NULL; fz_irect clip, pixbbox; if (ctx == NULL) @@ -1936,7 +2017,7 @@ newCDevice(JNIEnv *env, jobject self, fz_context *ctx, jobject obj, jint width, fz_try(ctx) { - //LOGI("DrawDeviceNative: bitmap=%d,%d page=%d,%d->%d,%d patch=%d,%d->%d,%d", width, height, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); + LOGI("DrawDeviceNative: bitmap=%d,%d page=%d,%d->%d,%d patch=%d,%d->%d,%d", width, height, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); /* Sanitise patch w.r.t page. */ if (patchX0 < pageX0) patchX0 = pageX0; @@ -1975,11 +2056,11 @@ newCDevice(JNIEnv *env, jobject self, fz_context *ctx, jobject obj, jint width, ninfo->pageY0 = pageY0; ninfo->width = width; ninfo->object = obj; - (*env)->SetLongField(env, self, cdevice_nativeinfo_fid, jlong_cast(ninfo)); - (*env)->SetObjectField(env, self, cdevice_nativeresource_fid, obj); - lockCDevice(env,self); + (*env)->SetLongField(env, self, fid_NativeDevice_nativeInfo, jlong_cast(ninfo)); + (*env)->SetObjectField(env, self, fid_NativeDevice_nativeResource, obj); + lockNativeDevice(env,self); fz_clear_pixmap_rect_with_value(ctx, pixmap, 0xff, &clip); - unlockCDevice(env,ninfo); + unlockNativeDevice(env,ninfo); device = fz_new_draw_device_with_bbox(ctx, pixmap, &clip); } fz_catch(ctx) @@ -1991,7 +2072,7 @@ newCDevice(JNIEnv *env, jobject self, fz_context *ctx, jobject obj, jint width, return jlong_cast(device); } -static void androidDrawDevice_lock(JNIEnv *env, CDeviceNativeInfo *info) +static void androidDrawDevice_lock(JNIEnv *env, NativeDeviceInfo *info) { uint8_t *pixels; @@ -2010,7 +2091,7 @@ static void androidDrawDevice_lock(JNIEnv *env, CDeviceNativeInfo *info) info->pixmap->samples = pixels; } -static void androidDrawDevice_unlock(JNIEnv *env, CDeviceNativeInfo *info) +static void androidDrawDevice_unlock(JNIEnv *env, NativeDeviceInfo *info) { assert(info != NULL); assert(info->object != NULL); @@ -2022,7 +2103,7 @@ static void androidDrawDevice_unlock(JNIEnv *env, CDeviceNativeInfo *info) } JNIEXPORT jlong JNICALL -JNI_FN(AndroidDrawDevice_newNative)(JNIEnv *env, jobject self, jobject jbitmap, int pageX0, int pageY0, int pageX1, int pageY1, int patchX0, int patchY0, int patchX1, int patchY1) +FUN(AndroidDrawDevice_newNative)(JNIEnv *env, jclass self, jobject jbitmap, jint pageX0, jint pageY0, jint pageX1, jint pageY1, jint patchX0, jint patchY0, jint patchX1, jint patchY1) { fz_context *ctx = get_context(env); AndroidBitmapInfo info; @@ -2040,7 +2121,7 @@ JNI_FN(AndroidDrawDevice_newNative)(JNIEnv *env, jobject self, jobject jbitmap, if (info.stride != info.width*4) fz_throw(ctx, FZ_ERROR_GENERIC, "new DrawDevice failed as bitmap width != stride"); - device = newCDevice(env, self, ctx, jbitmap, info.width, info.height, androidDrawDevice_lock, androidDrawDevice_unlock, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); + device = newNativeAndroidDrawDevice(env, self, ctx, jbitmap, info.width, info.height, androidDrawDevice_lock, androidDrawDevice_unlock, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); } fz_catch(ctx) { @@ -2049,90 +2130,402 @@ JNI_FN(AndroidDrawDevice_newNative)(JNIEnv *env, jobject self, jobject jbitmap, return device; } -static void awtDrawDevice_lock(JNIEnv *env, CDeviceNativeInfo *info) +#endif + +#ifdef HAVE_ANDROID +JNIEXPORT jlong JNICALL +FUN(Image_newImageFromBitmap)(JNIEnv *env, jobject self, jobject jbitmap, jlong jmask) { - int8_t *pixels; + fz_context *ctx = get_context(env); + fz_image *mask = CAST(fz_image *, jmask); + fz_image *image = NULL; + fz_pixmap *pixmap = NULL; + AndroidBitmapInfo info; + void *pixels; + int ret; - assert(info != NULL); - assert(info->object != NULL); - assert(info->pixmap != NULL); + if (ctx == NULL) + return 0; - //pixels = (unsigned char *)((*env)->GetIntArrayElements(env, info->object, 0)); + fz_var(pixmap); - /* Now offset pixels to allow for the page offsets */ - pixels += sizeof(int32_t) * (info->pageX0 + info->width * info->pageY0); + fz_try(ctx) + { + if (mask && mask->mask) + fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed as mask cannot be masked"); - info->pixmap->samples = pixels; + if ((ret = AndroidBitmap_getInfo(env, jbitmap, &info)) < 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed to get bitmap info"); + + if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) + fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed as bitmap format is not RGBA_8888"); + + if (info.stride != info.width) + fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed as bitmap width != stride"); + + pixmap = fz_new_pixmap(ctx, fz_device_rgb(ctx), info.width, info.height); + if (AndroidBitmap_lockPixels(env, jbitmap, &pixels) < 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "Bitmap lock failed in new Image"); + memcpy(pixmap->samples, pixels, info.width * info.height * 4); + (void)AndroidBitmap_unlockPixels(env, jbitmap); + + image = fz_new_image_from_pixmap(ctx, fz_keep_pixmap(ctx, pixmap), fz_keep_image(ctx, mask)); + } + fz_always(ctx) + { + fz_drop_pixmap(ctx, pixmap); + } + fz_catch(ctx) + { + jni_rethrow(env, ctx); + } + return jlong_cast(image); } +#endif -static void awtDrawDevice_unlock(JNIEnv *env, CDeviceNativeInfo *info) +/* ColorSpace Interface */ + +JNIEXPORT void JNICALL +FUN(ColorSpace_finalize)(JNIEnv *env, jobject self) { - int8_t *pixels = info->pixmap->samples; + fz_context *ctx = get_context(env); + fz_colorspace *cs = from_ColorSpace(env, self); - assert(info != NULL); - assert(info->object != NULL); - assert(info->pixmap != NULL); + if (ctx == NULL || cs == NULL) + return; - /* Now offset pixels to allow for the page offsets */ - //pixels -= sizeof(int32_t) * (info->pageX0 + info->width * info->pageY0); + fz_drop_colorspace(ctx, cs); +} + +JNIEXPORT jint JNICALL +FUN(ColorSpace_getNumberOfComponents)(JNIEnv *env, jobject self) +{ + fz_colorspace *cs = from_ColorSpace(env, self); - (*env)->ReleaseIntArrayElements(env, info->object, (int *)(void *)pixels, 0); + if (cs == NULL) + return 0; + + return cs->n; } JNIEXPORT jlong JNICALL -JNI_FN(AwtDrawDevice_newNative)(JNIEnv *env, jobject self, jobject rgba, jint w, jint h, int pageX0, int pageY0, int pageX1, int pageY1, int patchX0, int patchY0, int patchX1, int patchY1) +FUN(ColorSpace_nativeDeviceGray)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); + return jlong_cast(fz_device_gray(ctx)); +} - return newCDevice(env, self, ctx, rgba, w, h, awtDrawDevice_lock, awtDrawDevice_unlock, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1); +JNIEXPORT jlong JNICALL +FUN(ColorSpace_nativeDeviceRGB)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + return jlong_cast(fz_device_rgb(ctx)); } +JNIEXPORT jlong JNICALL +FUN(ColorSpace_nativeDeviceBGR)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + return jlong_cast(fz_device_bgr(ctx)); +} + +JNIEXPORT jlong JNICALL +FUN(ColorSpace_nativeDeviceCMYK)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + return jlong_cast(fz_device_cmyk(ctx)); +} + +/* Font interface */ + JNIEXPORT void JNICALL -JNI_FN(CDevice_finalize)(JNIEnv *env, jobject self) +FUN(Font_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - CDeviceNativeInfo *ninfo; + fz_font *font = from_Font(env, self); - ninfo = CAST(CDeviceNativeInfo *, (*env)->GetLongField(env, self, cdevice_nativeinfo_fid)); - if (ninfo != NULL) + if (ctx == NULL || font == NULL) + return; + + fz_drop_font(ctx, font); +} + +JNIEXPORT jstring JNICALL +FUN(Font_getName)(JNIEnv *env, jobject self) +{ + fz_font *font = from_Font(env, self); + + if (font == NULL) + return NULL; + + return (*env)->NewStringUTF(env, font->name); +} + +/* Pixmap Interface */ + +JNIEXPORT void JNICALL +FUN(Pixmap_finalize)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + if (ctx == NULL || pixmap == NULL) + return; + + fz_drop_pixmap(ctx, pixmap); +} + +JNIEXPORT jlong JNICALL +FUN(Pixmap_newNative)(JNIEnv *env, jobject self, jobject colorspace_, jint x, jint y, jint w, jint h) +{ + fz_context *ctx = get_context(env); + fz_colorspace *colorspace = from_ColorSpace(env, colorspace_); + + fz_pixmap *pixmap = NULL; + + if (ctx == NULL) + return 0; + + fz_try(ctx) { - fz_drop_pixmap(ctx, ninfo->pixmap); - fz_free(ctx, ninfo); + pixmap = fz_new_pixmap(ctx, colorspace, w, h); + pixmap->x = x; + pixmap->y = y; } - (*env)->SetLongField(env, self, cdevice_nativeinfo_fid, 0); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return jlong_cast(pixmap); } JNIEXPORT void JNICALL -JNI_FN(CDevice_destroy)(JNIEnv *env, jobject self) +FUN(Pixmap_clear)(JNIEnv *env, jobject self) { - JNI_FN(CDevice_finalize)(env, self); - JNI_FN(Device_finalize)(env, self); /* Super class destroy */ -} + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); -/* Path Interface */ + if (ctx == NULL || pixmap == NULL) + return; + + fz_try(ctx) + fz_clear_pixmap(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); +} JNIEXPORT void JNICALL -JNI_FN(Path_finalize)(JNIEnv * env, jobject self) +FUN(Pixmap_clearWithValue)(JNIEnv *env, jobject self, jint value) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_pixmap *pixmap = from_Pixmap(env, self); - if (ctx == NULL || path == NULL) + if (ctx == NULL || pixmap == NULL) return; - fz_drop_path(ctx, path); + fz_try(ctx) + fz_clear_pixmap_with_value(ctx, pixmap, value); + fz_catch(ctx) + jni_rethrow(env, ctx); } +JNIEXPORT jint JNICALL +FUN(Pixmap_getX)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + int x = 0; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + x = fz_pixmap_x(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return x; +} + +JNIEXPORT jint JNICALL +FUN(Pixmap_getY)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + int y = 0; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + y = fz_pixmap_y(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return y; +} + +JNIEXPORT jint JNICALL +FUN(Pixmap_getWidth)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + int w = 0; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + w = fz_pixmap_width(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return w; +} + +JNIEXPORT jint JNICALL +FUN(Pixmap_getHeight)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + int h = 0; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + h = fz_pixmap_height(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return h; +} + +JNIEXPORT jint JNICALL +FUN(Pixmap_getNumberOfComponents)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + int n = 0; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + n = fz_pixmap_components(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return n; +} + +JNIEXPORT jint JNICALL +FUN(Pixmap_getStride)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + int stride = 0; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + stride = fz_pixmap_stride(ctx, pixmap); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return stride; +} + +JNIEXPORT jobject JNICALL +FUN(Pixmap_getColorSpace)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + + jobject jcolorspace = NULL; + + if (ctx == NULL || pixmap == NULL) + return 0; + + fz_try(ctx) + { + fz_colorspace *colorspace = fz_pixmap_colorspace(ctx, pixmap); + jcolorspace = to_ColorSpace(ctx, env, colorspace); + } + fz_catch(ctx) + jni_rethrow(env, ctx); + + return jcolorspace; +} + +JNIEXPORT jbyteArray JNICALL +FUN(Pixmap_getSamples)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + int size = pixmap->w * pixmap->h * pixmap->n; + jbyteArray ary; + + if (ctx == NULL || pixmap == NULL) + return NULL; + + ary = (*env)->NewByteArray(env, size); + if (!ary) + return NULL; + + (*env)->SetByteArrayRegion(env, ary, 0, size, (const jbyte *)pixmap->samples); + + return ary; +} + +JNIEXPORT jintArray JNICALL +FUN(Pixmap_getPixels)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_pixmap *pixmap = from_Pixmap(env, self); + int size = pixmap->w * pixmap->h; + jintArray ary; + + if (ctx == NULL || pixmap == NULL) + return NULL; + + if (pixmap->n != 4) + { + jni_throw(env, FZ_ERROR_GENERIC, "invalid colorspace for getPixels"); + return NULL; + } + + ary = (*env)->NewIntArray(env, size); + if (!ary) + return NULL; + + (*env)->SetIntArrayRegion(env, ary, 0, size, (const jint *)pixmap->samples); + + return ary; +} + +/* Path Interface */ + JNIEXPORT void JNICALL -JNI_FN(Path_destroy)(JNIEnv * env, jobject self) +FUN(Path_finalize)(JNIEnv *env, jobject self) { - JNI_FN(Path_finalize)(env, self); + fz_context *ctx = get_context(env); + fz_path *path = from_Path(env, self); - (*env)->SetLongField(env, self, path_fid, 0); + if (ctx == NULL || path == NULL) + return; + + fz_drop_path(ctx, path); } JNIEXPORT jlong JNICALL -JNI_FN(Path_newNative)(JNIEnv * env, jobject self) +FUN(Path_newNative)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); fz_path *path = NULL; @@ -2141,292 +2534,259 @@ JNI_FN(Path_newNative)(JNIEnv * env, jobject self) return 0; fz_try(ctx) - { path = fz_new_path(ctx); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } + return jlong_cast(path); } JNIEXPORT jobject JNICALL -JNI_FN(Path_currentPoint)(JNIEnv * env, jobject self) +FUN(Path_currentPoint)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); - fz_point point; - jmethodID cons; - jobject jpoint; + fz_path *path = from_Path(env, self); + jobject jpoint = NULL; if (ctx == NULL || path == NULL) return NULL; fz_try(ctx) - { - point = fz_currentpoint(ctx, path); - jpoint = Point_from_fz_point(ctx, env, point); - } + jpoint = to_Point(ctx, env, fz_currentpoint(ctx, path)); fz_catch(ctx) - { jni_rethrow(env, ctx); - } + return jpoint; } JNIEXPORT void JNICALL -JNI_FN(Path_moveTo)(JNIEnv * env, jobject self, float x, float y) +FUN(Path_moveTo)(JNIEnv *env, jobject self, float x, float y) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_path *path = from_Path(env, self); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_moveto(ctx, path, x, y); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Path_lineTo)(JNIEnv * env, jobject self, float x, float y) +FUN(Path_lineTo)(JNIEnv *env, jobject self, float x, float y) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_path *path = from_Path(env, self); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_lineto(ctx, path, x, y); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Path_curveTo)(JNIEnv * env, jobject self, float cx1, float cy1, float cx2, float cy2, float ex, float ey) +FUN(Path_curveTo)(JNIEnv *env, jobject self, float cx1, float cy1, float cx2, float cy2, float ex, float ey) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_path *path = from_Path(env, self); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_curveto(ctx, path, cx1, cy1, cx2, cy2, ex, ey); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Path_curveToV)(JNIEnv * env, jobject self, float cx, float cy, float ex, float ey) +FUN(Path_curveToV)(JNIEnv *env, jobject self, float cx, float cy, float ex, float ey) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_path *path = from_Path(env, self); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_curvetov(ctx, path, cx, cy, ex, ey); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Path_curveToY)(JNIEnv * env, jobject self, float cx, float cy, float ex, float ey) +FUN(Path_curveToY)(JNIEnv *env, jobject self, float cx, float cy, float ex, float ey) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_path *path = from_Path(env, self); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_curvetoy(ctx, path, cx, cy, ex, ey); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Path_close)(JNIEnv * env, jobject self) +FUN(Path_closePath)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); + fz_path *path = from_Path(env, self); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_closepath(ctx, path); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Path_transform)(JNIEnv * env, jobject self, jobject jctm) +FUN(Path_transform)(JNIEnv *env, jobject self, jobject jctm) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); + fz_path *path = from_Path(env, self); + fz_matrix ctm = from_Matrix(env, jctm); if (ctx == NULL || path == NULL) return; fz_try(ctx) - { fz_transform_path(ctx, path, &ctm); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT jlong JNICALL -JNI_FN(Path_clone)(JNIEnv * env, jobject self) +FUN(Path_cloneNative)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); - fz_path *path2 = NULL; + fz_path *old_path = from_Path(env, self); + fz_path *new_path = NULL; - if (ctx == NULL || path == NULL) + if (ctx == NULL || old_path == NULL) return 0; fz_try(ctx) - { - path2 = fz_clone_path(ctx, path); - } + new_path = fz_clone_path(ctx, old_path); fz_catch(ctx) - { jni_rethrow(env, ctx); - } - return jlong_cast(path2); + + return jlong_cast(new_path); } JNIEXPORT jobject JNICALL -JNI_FN(Path_bound)(JNIEnv * env, jobject self, jobject jstroke, jobject jctm) +FUN(Path_getBounds)(JNIEnv *env, jobject self, jobject jstroke, jobject jctm) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); - jobject jrect; - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, jstroke); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); + fz_path *path = from_Path(env, self); + fz_stroke_state *stroke = from_StrokeState(env, jstroke); + fz_matrix ctm = from_Matrix(env, jctm); + jobject jrect = NULL; fz_rect rect; if (ctx == NULL || path == NULL) return NULL; fz_try(ctx) - { - fz_bound_path(ctx, path, stroke, &ctm, &rect); - - jrect = Rect_from_fz_rect(ctx, env, &rect); - } + jrect = to_Rect(ctx, env, fz_bound_path(ctx, path, stroke, &ctm, &rect)); fz_catch(ctx) - { jni_rethrow(env, ctx); - } + return jrect; } typedef struct { JNIEnv *env; - jobject jproc; -} pproc_data; + jobject obj; +} path_walker_state; static void -pathProcMoveTo(fz_context *ctx, void *arg, float x, float y) +pathWalkMoveTo(fz_context *ctx, void *arg, float x, float y) { - pproc_data *pproc = (pproc_data *)arg; - - (*pproc->env)->CallVoidMethod(pproc->env, pproc->jproc, pathproc_moveto_mid, x, y); + path_walker_state *state = (path_walker_state *)arg; + JNIEnv *env = state->env; + (*env)->CallVoidMethod(env, state->obj, mid_PathWalker_moveTo, x, y); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -pathProcLineTo(fz_context *ctx, void *arg, float x, float y) +pathWalkLineTo(fz_context *ctx, void *arg, float x, float y) { - pproc_data *pproc = (pproc_data *)arg; - - (*pproc->env)->CallVoidMethod(pproc->env, pproc->jproc, pathproc_lineto_mid, x, y); + path_walker_state *state = (path_walker_state *)arg; + JNIEnv *env = state->env; + (*env)->CallVoidMethod(env, state->obj, mid_PathWalker_lineTo, x, y); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -pathProcCurveTo(fz_context *ctx, void *arg, float x1, float y1, float x2, float y2, float x3, float y3) +pathWalkCurveTo(fz_context *ctx, void *arg, float x1, float y1, float x2, float y2, float x3, float y3) { - pproc_data *pproc = (pproc_data *)arg; - - (*pproc->env)->CallVoidMethod(pproc->env, pproc->jproc, pathproc_curveto_mid, x1, y1, x2, y2, x3, y3); + path_walker_state *state = (path_walker_state *)arg; + JNIEnv *env = state->env; + (*env)->CallVoidMethod(env, state->obj, mid_PathWalker_curveTo, x1, y1, x2, y2, x3, y3); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } static void -pathProcClose(fz_context *ctx, void *arg) +pathWalkClosePath(fz_context *ctx, void *arg) { - pproc_data *pproc = (pproc_data *) arg; - - (*pproc->env)->CallVoidMethod(pproc->env, pproc->jproc, pathproc_close_mid); + path_walker_state *state = (path_walker_state *) arg; + JNIEnv *env = state->env; + (*env)->CallVoidMethod(env, state->obj, mid_PathWalker_closePath); + if ((*env)->ExceptionCheck(env)) + fz_throw_java(ctx, env); } -static const fz_path_processor path_proc = +static const fz_path_walker java_path_walker = { - pathProcMoveTo, - pathProcLineTo, - pathProcCurveTo, - pathProcClose + pathWalkMoveTo, + pathWalkLineTo, + pathWalkCurveTo, + pathWalkClosePath, + NULL, + NULL, + NULL, + NULL }; -void JNICALL -JNI_FN(Path_process)(JNIEnv * env, jobject self, jobject jproc) +JNIEXPORT void JNICALL +FUN(Path_walk)(JNIEnv *env, jobject self, jobject obj) { fz_context *ctx = get_context(env); - fz_path *path = fz_path_from_Path(env, self); - int i = 0, k = 0; - int n; - pproc_data data; + fz_path *path = from_Path(env, self); + path_walker_state state; - if (path == NULL || jproc == NULL) + if (path == NULL || obj == NULL) return; - data.env = env; - data.jproc = jproc; + state.env = env; + state.obj = obj; - fz_process_path(ctx, &path_proc, &data, path); + fz_try(ctx) + fz_walk_path(ctx, path, &java_path_walker, &state); + fz_catch(ctx) + jni_rethrow(env, ctx); } - /* StrokeState interface */ JNIEXPORT void JNICALL -JNI_FN(StrokeState_finalize)(JNIEnv * env, jobject self) +FUN(StrokeState_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); + fz_stroke_state *stroke = from_StrokeState(env, self); if (ctx == NULL || stroke == NULL) return; @@ -2434,17 +2794,8 @@ JNI_FN(StrokeState_finalize)(JNIEnv * env, jobject self) fz_drop_stroke_state(ctx, stroke); } -JNIEXPORT void JNICALL -JNI_FN(StrokeState_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(StrokeState_finalize)(env, self); - - (*env)->SetLongField(env, self, stroke_fid, 0); -} - - JNIEXPORT jlong JNICALL -JNI_FN(Path_newStrokeState)(JNIEnv * env, jobject self, int startCap, int dashCap, int endCap, int lineJoin, float lineWidth, float miterLimit, float dashPhase, jfloatArray dash) +FUN(Path_newStrokeState)(JNIEnv *env, jobject self, jint startCap, jint dashCap, jint endCap, jint lineJoin, float lineWidth, float miterLimit, float dashPhase, jfloatArray dash) { fz_context *ctx = get_context(env); fz_stroke_state *stroke = NULL; @@ -2453,8 +2804,6 @@ JNI_FN(Path_newStrokeState)(JNIEnv * env, jobject self, int startCap, int dashCa if (ctx == NULL) return 0; - fz_var(stroke); - fz_try(ctx) { stroke = fz_new_stroke_state_with_dash_len(ctx, len); @@ -2469,74 +2818,65 @@ JNI_FN(Path_newStrokeState)(JNIEnv * env, jobject self, int startCap, int dashCa (*env)->GetFloatArrayRegion(env, dash, 0, len, &stroke->dash_list[0]); } fz_catch(ctx) - { - fz_drop_stroke_state(ctx, stroke); jni_rethrow(env, ctx); - } + return jlong_cast(stroke); } -JNIEXPORT int JNICALL -JNI_FN(StrokeState_getStartCap)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(StrokeState_getStartCap)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->start_cap : 0; } -JNIEXPORT int JNICALL -JNI_FN(StrokeState_getDashCap)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(StrokeState_getDashCap)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->dash_cap : 0; } -JNIEXPORT int JNICALL -JNI_FN(StrokeState_getEndCap)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(StrokeState_getEndCap)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->end_cap : 0; } -JNIEXPORT int JNICALL -JNI_FN(StrokeState_getLineJoin)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(StrokeState_getLineJoin)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->linejoin : 0; } JNIEXPORT float JNICALL -JNI_FN(StrokeState_getLineWidth)(JNIEnv * env, jobject self) +FUN(StrokeState_getLineWidth)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->linewidth : 0; } JNIEXPORT float JNICALL -JNI_FN(StrokeState_getMiterLimit)(JNIEnv * env, jobject self) +FUN(StrokeState_getMiterLimit)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->miterlimit : 0; } JNIEXPORT float JNICALL -JNI_FN(StrokeState_getDashPhase)(JNIEnv * env, jobject self) +FUN(StrokeState_getDashPhase)(JNIEnv *env, jobject self) { - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); - + fz_stroke_state *stroke = from_StrokeState(env, self); return stroke ? stroke->dash_phase : 0; } JNIEXPORT jfloatArray JNICALL -JNI_FN(StrokeState_getDashes)(JNIEnv * env, jobject self) +FUN(StrokeState_getDashes)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, self); + fz_stroke_state *stroke = from_StrokeState(env, self); jfloatArray arr; if (stroke->dash_len == 0) @@ -2554,10 +2894,10 @@ JNI_FN(StrokeState_getDashes)(JNIEnv * env, jobject self) /* Text interface */ JNIEXPORT void JNICALL -JNI_FN(Text_finalize)(JNIEnv * env, jobject self) +FUN(Text_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_text *text = fz_text_from_Text(env, self); + fz_text *text = from_Text(env, self); if (ctx == NULL || text == NULL) return; @@ -2565,64 +2905,48 @@ JNI_FN(Text_finalize)(JNIEnv * env, jobject self) fz_drop_text(ctx, text); } -JNIEXPORT void JNICALL -JNI_FN(Text_destroy)(JNIEnv * env, jobject self) +JNIEXPORT jlong JNICALL +FUN(Text_clone)(JNIEnv *env, jobject self) { - JNI_FN(Text_finalize)(env, self); + fz_context *ctx = get_context(env); + fz_text *old_text = from_Text(env, self); + fz_text *new_text = NULL; + + if (ctx == NULL || old_text == NULL) + return 0; + + fz_try(ctx) + new_text = fz_clone_text(ctx, old_text); + fz_catch(ctx) + jni_rethrow(env, ctx); - (*env)->SetLongField(env, self, text_fid, 0); + return jlong_cast(new_text); } JNIEXPORT jlong JNICALL -JNI_FN(Text_clone)(JNIEnv * env, jobject self) +FUN(Text_newNative)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_text *text = fz_text_from_Text(env, self); - fz_text *text2 = NULL; + fz_text *text = NULL; - if (ctx == NULL || text == NULL) + if (ctx == NULL) return 0; fz_try(ctx) - { - text2 = fz_clone_text(ctx, text); - } + text = fz_new_text(ctx); fz_catch(ctx) - { jni_rethrow(env, ctx); - } - return jlong_cast(text2); -} - -//JNIEXPORT jlong JNICALL -//JNI_FN(Text_newText)(JNIEnv * env, jobject self, jobject jfont, jobject jctm, int wmode) -//{ -// fz_context *ctx = get_context(env); -// fz_text *text = NULL; -// fz_font *font = fz_font_from_Font(env, jfont); -// fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); -// -// if (ctx == NULL) -// return 0; -// -// fz_try(ctx) -// { -// text = fz_new_text(ctx, font, &ctm, wmode); -// } -// fz_catch(ctx) -// { -// jni_rethrow(env, ctx); -// } -// return jlong_cast(text); -//} + + return jlong_cast(text); +} JNIEXPORT jobject JNICALL -JNI_FN(Text_bound)(JNIEnv * env, jobject self, jobject jstroke, jobject jctm) +FUN(Text_getBounds)(JNIEnv *env, jobject self, jobject jstroke, jobject jctm) { fz_context *ctx = get_context(env); - fz_text *text = fz_text_from_Text(env, self); - fz_stroke_state *stroke = fz_stroke_state_from_StrokeState(env, jstroke); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); + fz_text *text = from_Text(env, self); + fz_stroke_state *stroke = from_StrokeState(env, jstroke); + fz_matrix ctm = from_Matrix(env, jctm); jobject jrect; fz_rect rect; @@ -2630,200 +2954,175 @@ JNI_FN(Text_bound)(JNIEnv * env, jobject self, jobject jstroke, jobject jctm) return NULL; fz_try(ctx) - { - fz_bound_text(ctx, text, stroke, &ctm, &rect); - - jrect = Rect_from_fz_rect(ctx, env, &rect); - } + jrect = to_Rect(ctx, env, fz_bound_text(ctx, text, stroke, &ctm, &rect)); fz_catch(ctx) - { jni_rethrow(env, ctx); - } + return jrect; } -//JNIEXPORT void JNICALL -//JNI_FN(Text_add)(JNIEnv * env, jobject self, int gid, int ucs, float x, float y) -//{ -// fz_context *ctx = get_context(env); -// fz_text *text = fz_text_from_Text(env, self); -// -// if (ctx == NULL || text == NULL) -// return; -// -// fz_try(ctx) -// { -// fz_add_text(ctx, text, gid, ucs, x, y); -// } -// fz_catch(ctx) -// { -// jni_rethrow(env, ctx); -// } -//} - -/* Image interface */ - JNIEXPORT void JNICALL -JNI_FN(Image_finalize)(JNIEnv * env, jobject self) +FUN(Text_showGlyph)(JNIEnv *env, jobject self, jobject font_, jboolean wmode, jobject matrix_, jint glyph, jint unicode) { fz_context *ctx = get_context(env); - fz_image *image = fz_image_from_Image(env, self); + fz_text *text = from_Text(env, self); + fz_font *font = from_Font(env, font_); + fz_matrix trm = from_Matrix(env, matrix_); - if (ctx == NULL || image == NULL) + if (ctx == NULL || text == NULL) return; - fz_drop_image(ctx, image); + fz_try(ctx) + fz_show_glyph(ctx, text, font, wmode, &trm, glyph, unicode); + fz_catch(ctx) + jni_rethrow(env, ctx); } JNIEXPORT void JNICALL -JNI_FN(Image_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Image_finalize)(env, self); - - (*env)->SetLongField(env, self, image_fid, 0); -} - -JNIEXPORT jlong JNICALL -JNI_FN(Image_newImageFromBitmap)(JNIEnv * env, jobject self, jobject jbitmap, jlong jmask) +FUN(Text_walk)(JNIEnv *env, jobject self, jobject walker) { fz_context *ctx = get_context(env); - fz_image *mask = CAST(fz_image *, jmask); - fz_image *image = NULL; - fz_pixmap *pixmap = NULL; - AndroidBitmapInfo info; - void *pixels; - int ret; + fz_text *text = from_Text(env, self); + fz_text_span *span; + fz_font *font = NULL; + jobject jfont = NULL; + jobject jtrm = NULL; + int i; - if (ctx == NULL) - return 0; + if (!text->head) + return; - fz_var(pixmap); + /* TODO: We reuse the same Matrix object for each call, but should we? */ + jtrm = (*env)->NewObject(env, cls_Matrix, mid_Matrix_init, 1, 0, 0, 1, 0, 0); + if (!jtrm) + return; - fz_try(ctx) + for (span = text->head; span; span = span->next) { - if (mask && mask->mask) - fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed as mask cannot be masked"); - - if ((ret = AndroidBitmap_getInfo(env, jbitmap, &info)) < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed to get bitmap info"); + if (font != span->font) + { + font = span->font; + jfont = to_Font_safe(ctx, env, font); + if (!jfont) + return; + } - if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) - fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed as bitmap format is not RGBA_8888"); + (*env)->SetFloatField(env, jtrm, fid_Matrix_a, span->trm.a); + (*env)->SetFloatField(env, jtrm, fid_Matrix_b, span->trm.b); + (*env)->SetFloatField(env, jtrm, fid_Matrix_c, span->trm.c); + (*env)->SetFloatField(env, jtrm, fid_Matrix_d, span->trm.d); - if (info.stride != info.width) - fz_throw(ctx, FZ_ERROR_GENERIC, "new Image failed as bitmap width != stride"); + for (i = 0; i < span->len; ++i) + { + (*env)->SetFloatField(env, jtrm, fid_Matrix_e, span->items[i].x); + (*env)->SetFloatField(env, jtrm, fid_Matrix_f, span->items[i].y); - pixmap = fz_new_pixmap(ctx, fz_device_rgb(ctx), info.width, info.height); - if (AndroidBitmap_lockPixels(env, jbitmap, &pixels) < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bitmap lock failed in new Image"); - memcpy(pixmap->samples, pixels, info.width * info.height * 4); - (void)AndroidBitmap_unlockPixels(env, jbitmap); + (*env)->CallVoidMethod(env, walker, mid_TextWalker_showGlyph, + jfont, (jboolean)span->wmode, jtrm, + (jint)span->items[i].gid, + (jint)span->items[i].ucs); - image = fz_new_image_from_pixmap(ctx, fz_keep_pixmap(ctx, pixmap), fz_keep_image(ctx, mask)); - } - fz_always(ctx) - { - fz_drop_pixmap(ctx, pixmap); - } - fz_catch(ctx) - { - jni_rethrow(env, ctx); + if ((*env)->ExceptionCheck(env)) + return; + } } - return jlong_cast(image); } -JNIEXPORT int JNICALL -JNI_FN(Image_getWidth)(JNIEnv * env, jobject self) +/* Image interface */ + +JNIEXPORT void JNICALL +FUN(Image_finalize)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); + fz_context *ctx = get_context(env); + fz_image *image = from_Image(env, self); - return image ? image->w : 0; + if (ctx == NULL || image == NULL) + return; + + fz_drop_image(ctx, image); } -JNIEXPORT int JNICALL -JNI_FN(Image_getHeight)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(Image_getWidth)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); + fz_image *image = from_Image(env, self); + return image ? image->w : 0; +} +JNIEXPORT jint JNICALL +FUN(Image_getHeight)(JNIEnv *env, jobject self) +{ + fz_image *image = from_Image(env, self); return image ? image->h : 0; } -JNIEXPORT int JNICALL -JNI_FN(Image_getNumComponents)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(Image_getNumberOfComponents)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); - + fz_image *image = from_Image(env, self); return image ? image->n : 0; } -JNIEXPORT int JNICALL -JNI_FN(Image_getBitsPerComponent)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(Image_getBitsPerComponent)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); - + fz_image *image = from_Image(env, self); return image ? image->bpc : 0; } -JNIEXPORT int JNICALL -JNI_FN(Image_getXResolution)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(Image_getXResolution)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); - + fz_image *image = from_Image(env, self); return image ? image->xres : 0; } -JNIEXPORT int JNICALL -JNI_FN(Image_getYResolution)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(Image_getYResolution)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); - + fz_image *image = from_Image(env, self); return image ? image->yres : 0; } -JNIEXPORT int JNICALL -JNI_FN(Image_getImageMask)(JNIEnv * env, jobject self) +JNIEXPORT jboolean JNICALL +FUN(Image_getImageMask)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); - + fz_image *image = from_Image(env, self); return image ? image->imagemask : 0; } -JNIEXPORT int JNICALL -JNI_FN(Image_getInterpolate)(JNIEnv * env, jobject self) +JNIEXPORT jboolean JNICALL +FUN(Image_getInterpolate)(JNIEnv *env, jobject self) { - fz_image *image = fz_image_from_Image(env, self); - + fz_image *image = from_Image(env, self); return image ? image->interpolate : 0; } JNIEXPORT jobject JNICALL -JNI_FN(Image_getMask)(JNIEnv *env, jobject self) +FUN(Image_getMask)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_image *img = fz_image_from_Image(env, self); - jobject jobj; + fz_image *img = from_Image(env, self); + jobject jmask = NULL; if (img == NULL || img->mask == NULL) return NULL; - jobj = Image_from_fz_image(ctx, env, img->mask); - if (jobj != NULL) - fz_keep_image(ctx, img->mask); - - return jobj; + fz_try(ctx) + jmask = to_Image(ctx, env, img->mask); + fz_catch(ctx) + jni_rethrow(env, ctx); -died: - fz_throw(ctx, FZ_ERROR_GENERIC, "JNI creation of Image(Mask) failed"); - return NULL; + return jmask; } /* Outline interface */ JNIEXPORT void JNICALL -JNI_FN(Outline_finalize)(JNIEnv * env, jobject self) +FUN(Outline_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_outline *outline = fz_outline_from_Outline(env, self); + fz_outline *outline = from_Outline(env, self); if (ctx == NULL || outline == NULL) return; @@ -2831,97 +3130,69 @@ JNI_FN(Outline_finalize)(JNIEnv * env, jobject self) fz_drop_outline(ctx, outline); } -JNIEXPORT void JNICALL -JNI_FN(Outline_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Outline_finalize)(env, self); - - (*env)->SetLongField(env, self, outline_fid, 0); -} - /* Annotation Interface */ JNIEXPORT void JNICALL -JNI_FN(Annotation_finalize)(JNIEnv * env, jobject self) +FUN(Annotation_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_annot *annot = fz_annot_from_Annotation(env, self); + fz_annot *annot = from_Annotation(env, self); - if (ctx == NULL || link == NULL) + if (ctx == NULL || annot == NULL) return; fz_drop_annot(ctx, annot); } JNIEXPORT void JNICALL -JNI_FN(Annotation_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Annotation_finalize)(env, self); - - (*env)->SetLongField(env, self, annot_fid, 0); -} - -JNIEXPORT void JNICALL -JNI_FN(Annotation_run)(JNIEnv * env, jobject self, jobject jdev, jobject jctm, jobject jcookie) +FUN(Annotation_run)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jcookie) { fz_context *ctx = get_context(env); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_cookie *cookie= fz_cookie_from_Cookie(env, jcookie); - fz_device *dev = fz_device_from_Device(env, jdev, ctx); - jobject jdoc; - fz_annot *annot = fz_annot_from_Annotation(env, self); - CDeviceNativeInfo *info; + fz_matrix ctm = from_Matrix(env, jctm); + fz_cookie *cookie= from_Cookie(env, jcookie); + fz_device *dev = from_Device(env, jdev, ctx); + fz_annot *annot = from_Annotation(env, self); + NativeDeviceInfo *info; if (ctx == NULL || self == NULL || jdev == NULL) return; - fz_var(dev); - - info = lockCDevice(env, jdev); - + info = lockNativeDevice(env, jdev); fz_try(ctx) - { fz_run_annot(ctx, annot, dev, &ctm, cookie); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT jlong JNICALL -JNI_FN(Annotation_advance)(JNIEnv * env, jobject self) +FUN(Annotation_advance)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); fz_annot *annot; - if (ctx == NULL) - return; + if (ctx == NULL || self == NULL) + return 0; fz_try(ctx) { - annot = fz_annot_from_Annotation(env, self); - + annot = from_Annotation(env, self); annot = fz_next_annot(ctx, annot); } fz_catch(ctx) - { jni_rethrow(env, ctx); - } + return jlong_cast(annot); } /* Link interface */ JNIEXPORT void JNICALL -JNI_FN(Link_finalize)(JNIEnv * env, jobject self) +FUN(Link_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_link *link = fz_link_from_Link(env, self); + fz_link *link = from_Link(env, self); if (ctx == NULL || link == NULL) return; @@ -2929,21 +3200,13 @@ JNI_FN(Link_finalize)(JNIEnv * env, jobject self) fz_drop_link(ctx, link); } -JNIEXPORT void JNICALL -JNI_FN(Link_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Link_finalize)(env, self); - - (*env)->SetLongField(env, self, link_fid, 0); -} - /* Document interface */ JNIEXPORT void JNICALL -JNI_FN(Document_finalize)(JNIEnv * env, jobject self) +FUN(Document_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_document *doc = fz_document_from_Document(env, self); + fz_document *doc = from_Document(env, self); if (ctx == NULL || doc == NULL) return; @@ -2951,16 +3214,8 @@ JNI_FN(Document_finalize)(JNIEnv * env, jobject self) fz_drop_document(ctx, doc); } -JNIEXPORT void JNICALL -JNI_FN(Document_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Document_finalize)(env, self); - - (*env)->SetLongField(env, self, document_fid, 0); -} - JNIEXPORT jlong JNICALL -JNI_FN(Document_newNative)(JNIEnv * env, jobject self, jstring jfilename) +FUN(Document_newNativeWithPath)(JNIEnv *env, jobject self, jstring jfilename) { fz_context *ctx = get_context(env); fz_document *document = NULL; @@ -2969,160 +3224,138 @@ JNI_FN(Document_newNative)(JNIEnv * env, jobject self, jstring jfilename) if (ctx == NULL || jfilename == NULL) return 0; - fz_var(filename); + filename = (*env)->GetStringUTFChars(env, jfilename, NULL); + if (filename == NULL) + return 0; fz_try(ctx) - { - filename = (*env)->GetStringUTFChars(env, jfilename, NULL); - if (filename == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to convert filename"); document = fz_open_document(ctx, filename); - } fz_always(ctx) - { (*env)->ReleaseStringUTFChars(env, jfilename, filename); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - } return jlong_cast(document); } -JNIEXPORT int JNICALL -JNI_FN(Document_needsPassword)(JNIEnv * env, jobject self) +JNIEXPORT jboolean JNICALL +FUN(Document_needsPassword)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); - int ret; + fz_document *document = from_Document(env, self); + int okay = 0; if (ctx == NULL || document == NULL) return 0; fz_try(ctx) - { - ret = fz_needs_password(ctx, document); - } + okay = fz_needs_password(ctx, document); fz_catch(ctx) - { jni_rethrow(env, ctx); - ret = 0; - } - return ret; + + return okay; } -JNIEXPORT int JNICALL -JNI_FN(Document_authenticatePassword)(JNIEnv * env, jobject self, jstring jpassword) +JNIEXPORT jboolean JNICALL +FUN(Document_authenticatePassword)(JNIEnv *env, jobject self, jstring jpassword) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); - int ret; + fz_document *document = from_Document(env, self); const char *password = NULL; + int okay = 0; if (ctx == NULL || document == NULL) return 0; - fz_var(password); - - fz_try(ctx) + if (jpassword == NULL) + password = ""; + else { - if (jpassword == NULL) - password = ""; - else - { - password = (*env)->GetStringUTFChars(env, jpassword, NULL); - if (password == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to convert password"); - } - - ret = fz_authenticate_password(ctx, document, password); + password = (*env)->GetStringUTFChars(env, jpassword, NULL); + if (!password) + return 0; } + + fz_try(ctx) + okay = fz_authenticate_password(ctx, document, password); fz_always(ctx) - { if (jpassword != NULL) (*env)->ReleaseStringUTFChars(env, jpassword, password); - } fz_catch(ctx) - { jni_rethrow(env, ctx); - ret = 0; - } - return ret; + + return okay; } -JNIEXPORT int JNICALL -JNI_FN(Document_countPages)(JNIEnv * env, jobject self) +JNIEXPORT jint JNICALL +FUN(Document_countPages)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); - int ret; + fz_document *document = from_Document(env, self); + int count = 0; if (ctx == NULL || document == NULL) return 0; fz_try(ctx) - { - ret = fz_count_pages(ctx, document); - } + count = fz_count_pages(ctx, document); fz_catch(ctx) - { jni_rethrow(env, ctx); - ret = 0; - } - return ret; + + return count; } JNIEXPORT jobject JNICALL -JNI_FN(Document_getPage)(JNIEnv * env, jobject self, int n) +FUN(Document_loadPage)(JNIEnv *env, jobject self, jint number) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); + fz_document *document = from_Document(env, self); fz_page *page = NULL; - jobject jpage; if (ctx == NULL || document == NULL) return NULL; - fz_var(page); - fz_try(ctx) - { - page = fz_load_page(ctx, document, n); - if (page == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "getPage failed"); - - jpage = Page_from_fz_page(ctx, env, page); - } + page = fz_load_page(ctx, document, number); fz_catch(ctx) - { - fz_drop_page(ctx, page); jni_rethrow(env, ctx); - jpage = NULL; - } - return jpage; + + return to_Page_safe(ctx, env, page); } JNIEXPORT jobject JNICALL -JNI_FN(Document_getFileFormat)(JNIEnv * env, jobject self) +FUN(Document_getMetaData)(JNIEnv *env, jobject self, jstring jkey) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); - char info[64]; + fz_document *document = from_Document(env, self); + const char *ckey; + char info[256]; if (ctx == NULL || document == NULL) return NULL; - fz_lookup_metadata(ctx, document, FZ_META_FORMAT, info, sizeof(info)); + ckey = (*env)->GetStringUTFChars(env, jkey, NULL); + if (!ckey) + return NULL; + + fz_try(ctx) + fz_lookup_metadata(ctx, document, ckey, info, sizeof info); + fz_always(ctx) + (*env)->ReleaseStringUTFChars(env, jkey, ckey); + fz_catch(ctx) + { + jni_rethrow(env, ctx); + return NULL; + } return (*env)->NewStringUTF(env, info); } JNIEXPORT jboolean JNICALL -JNI_FN(Document_isUnencryptedPDF)(JNIEnv * env, jobject self) +FUN(Document_isUnencryptedPDF)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); + fz_document *document = from_Document(env, self); pdf_document *idoc = pdf_specifics(ctx, document); int cryptVer; @@ -3134,12 +3367,11 @@ JNI_FN(Document_isUnencryptedPDF)(JNIEnv * env, jobject self) } JNIEXPORT jobject JNICALL -JNI_FN(Document_getOutline)(JNIEnv * env, jobject self) +FUN(Document_loadOutline)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_document *document = fz_document_from_Document(env, self); + fz_document *document = from_Document(env, self); fz_outline *outline = NULL; - jobject joutline; if (ctx == NULL || document == NULL) return NULL; @@ -3147,29 +3379,20 @@ JNI_FN(Document_getOutline)(JNIEnv * env, jobject self) fz_var(outline); fz_try(ctx) - { outline = fz_load_outline(ctx, document); - if (outline == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "getOutline failed"); - - joutline = Outline_from_fz_outline(ctx, env, outline); - } fz_catch(ctx) - { - fz_drop_outline(ctx, outline); jni_rethrow(env, ctx); - joutline = NULL; - } - return joutline; + + return to_Outline_safe(ctx, env, outline); } /* Page interface */ JNIEXPORT void JNICALL -JNI_FN(Page_finalize)(JNIEnv * env, jobject self) +FUN(Page_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_page *page = fz_page_from_Page(env, self); + fz_page *page = from_Page(env, self); if (ctx == NULL || page == NULL) return; @@ -3177,20 +3400,29 @@ JNI_FN(Page_finalize)(JNIEnv * env, jobject self) fz_drop_page(ctx, page); } -JNIEXPORT void JNICALL -JNI_FN(Page_destroy)(JNIEnv * env, jobject self) +JNIEXPORT jobject JNICALL +FUN(Page_toPixmap)(JNIEnv *env, jobject self, jobject ctm_, jobject colorspace_) { - JNI_FN(Page_finalize)(env, self); + fz_context *ctx = get_context(env); + fz_page *page = from_Page(env, self); + fz_colorspace *colorspace = from_ColorSpace(env, colorspace_); + fz_matrix ctm = from_Matrix(env, ctm_); + + fz_pixmap *pixmap = NULL; - (*env)->SetLongField(env, self, page_fid, 0); - (*env)->SetLongField(env, self, page_annots_fid, 0); + fz_try(ctx) + pixmap = fz_new_pixmap_from_page(ctx, page, &ctm, colorspace); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return to_Pixmap_safe(ctx, env, pixmap); } JNIEXPORT jobject JNICALL -JNI_FN(Page_bound)(JNIEnv * env, jobject self) +FUN(Page_getBounds)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_page *page = fz_page_from_Page(env, self); + fz_page *page = from_Page(env, self); jobject jrect; fz_rect rect; @@ -3198,87 +3430,65 @@ JNI_FN(Page_bound)(JNIEnv * env, jobject self) return NULL; fz_try(ctx) - { - fz_bound_page(ctx, page, &rect); - - jrect = Rect_from_fz_rect(ctx, env, &rect); - } + jrect = to_Rect(ctx, env, fz_bound_page(ctx, page, &rect)); fz_catch(ctx) - { jni_rethrow(env, ctx); - } + return jrect; } JNIEXPORT void JNICALL -JNI_FN(Page_run)(JNIEnv * env, jobject self, jobject jdev, jobject jctm, jobject jcookie) +FUN(Page_run)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jcookie) { fz_context *ctx = get_context(env); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_cookie *cookie = fz_cookie_from_Cookie(env, jcookie); - fz_device *dev = fz_device_from_Device(env, jdev, ctx); - fz_page *page = fz_page_from_Page(env, self); - CDeviceNativeInfo *info; + fz_matrix ctm = from_Matrix(env, jctm); + fz_cookie *cookie = from_Cookie(env, jcookie); + fz_device *dev = from_Device(env, jdev, ctx); + fz_page *page = from_Page(env, self); + NativeDeviceInfo *info; if (ctx == NULL || self == NULL || jdev == NULL) return; - info = lockCDevice(env, jdev); - + info = lockNativeDevice(env, jdev); fz_try(ctx) - { fz_run_page(ctx, page, dev, &ctm, cookie); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(Page_runPageContents)(JNIEnv * env, jobject self, jobject jdev, jobject jctm, jobject jcookie) +FUN(Page_runPageContents)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jcookie) { fz_context *ctx = get_context(env); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_cookie *cookie = fz_cookie_from_Cookie(env, jcookie); - fz_device *dev = fz_device_from_Device(env, jdev, ctx); - fz_page *page = fz_page_from_Page(env, self); - CDeviceNativeInfo *info; + fz_matrix ctm = from_Matrix(env, jctm); + fz_cookie *cookie = from_Cookie(env, jcookie); + fz_device *dev = from_Device(env, jdev, ctx); + fz_page *page = from_Page(env, self); + NativeDeviceInfo *info; - if (ctx == NULL) + if (ctx == NULL || page == NULL || dev == NULL) return; - info = lockCDevice(env, jdev); - + info = lockNativeDevice(env, jdev); fz_try(ctx) - { fz_run_page_contents(ctx, page, dev, &ctm, cookie); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT jobject JNICALL -JNI_FN(Page_getAnnotations)(JNIEnv * env, jobject self) +FUN(Page_getAnnotations)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_page *page = fz_page_from_Page(env, self); - jobject jrect; - fz_rect rect; + fz_page *page = from_Page(env, self); fz_annot *annot = NULL; fz_annot *first = NULL; jobject jannots = NULL; - int ret; int annot_count; int i; @@ -3290,7 +3500,7 @@ JNI_FN(Page_getAnnotations)(JNIEnv * env, jobject self) fz_try(ctx) { - jannots = (*env)->GetObjectField(env, self, page_annots_fid); + jannots = (*env)->GetObjectField(env, self, fid_Page_nativeAnnots); first = fz_first_annot(ctx, page); @@ -3305,21 +3515,21 @@ JNI_FN(Page_getAnnotations)(JNIEnv * env, jobject self) * object stored in the page. */ if (jannots != NULL) { - (*env)->SetObjectField(env, self, page_annots_fid, NULL); + (*env)->SetObjectField(env, self, fid_Page_nativeAnnots, NULL); } break; /* No annotations! */ } - jannots = (*env)->NewObjectArray(env, annot_count, annot_class, NULL); + jannots = (*env)->NewObjectArray(env, annot_count, cls_Annot, NULL); if (jannots == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "getAnnotations failed (1)"); - (*env)->SetObjectField(env, self, page_annots_fid, jannots); + (*env)->SetObjectField(env, self, fid_Page_nativeAnnots, jannots); /* Now run through actually creating the annotation objects */ annot = first; for (i = 0; annot != NULL && i < annot_count; i++) { - jobject jannot = Annotation_from_fz_annot(ctx, env, annot); + jobject jannot = to_Annotation(ctx, env, annot); (*env)->SetObjectArrayElement(env, jannots, i, jannot); annot = fz_next_annot(ctx, annot); } @@ -3333,16 +3543,13 @@ JNI_FN(Page_getAnnotations)(JNIEnv * env, jobject self) return jannots; } -/* private native final Link[] getLinks(jlong ctx); */ - - /* Cookie interface */ JNIEXPORT void JNICALL -JNI_FN(Cookie_finalize)(JNIEnv * env, jobject self) +FUN(Cookie_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_cookie *cookie = fz_cookie_from_Cookie(env, self); + fz_cookie *cookie = from_Cookie(env, self); if (ctx == NULL || cookie == NULL) return; @@ -3350,27 +3557,28 @@ JNI_FN(Cookie_finalize)(JNIEnv * env, jobject self) fz_free(ctx, cookie); } -JNIEXPORT void JNICALL -JNI_FN(Cookie_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(Cookie_finalize)(env, self); - - (*env)->SetLongField(env, self, cookie_fid, 0); -} - JNIEXPORT jlong JNICALL -JNI_FN(Cookie_newNative)(JNIEnv * env, jobject self) +FUN(Cookie_newNative)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); + fz_cookie *cookie = NULL; - return jlong_cast(fz_malloc_struct(ctx, fz_cookie)); + if (ctx == NULL) + return 0; + + fz_try(ctx) + cookie = fz_malloc_struct(ctx, fz_cookie); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return jlong_cast(cookie); } JNIEXPORT void JNICALL -JNI_FN(Cookie_abort)(JNIEnv * env, jobject self) +FUN(Cookie_abort)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_cookie *cookie = fz_cookie_from_Cookie(env, self); + fz_cookie *cookie = from_Cookie(env, self); if (ctx == NULL || cookie == NULL) return; @@ -3379,95 +3587,64 @@ JNI_FN(Cookie_abort)(JNIEnv * env, jobject self) } /* DisplayList interface */ + JNIEXPORT jlong JNICALL -JNI_FN(DisplayList_newNative)(JNIEnv * env, jobject self) +FUN(DisplayList_newNative)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - return jlong_cast(fz_new_display_list(ctx)); + fz_display_list *list = NULL; + + if (ctx == NULL) + return 0; + + fz_try(ctx) + list = fz_new_display_list(ctx); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return jlong_cast(list); } JNIEXPORT void JNICALL -JNI_FN(DisplayList_run)(JNIEnv * env, jobject self, jobject jdev, jobject jctm, jobject jrect, jobject jcookie) +FUN(DisplayList_run)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jrect, jobject jcookie) { fz_context *ctx = get_context(env); - fz_display_list *list = fz_display_list_from_DisplayList(env, self); - fz_matrix ctm = fz_matrix_from_Matrix(env, jctm); - fz_cookie *cookie = fz_cookie_from_Cookie(env, jcookie); - fz_device *dev = fz_device_from_Device(env, jdev, ctx); - CDeviceNativeInfo *info; + fz_display_list *list = from_DisplayList(env, self); + fz_matrix ctm = from_Matrix(env, jctm); + fz_cookie *cookie = from_Cookie(env, jcookie); + fz_device *dev = from_Device(env, jdev, ctx); + NativeDeviceInfo *info; fz_rect local_rect; - fz_rect *rect; + fz_rect *rect = NULL; if (ctx == NULL || self == NULL || jdev == NULL || list == NULL) return; /* Use a scissor rectangle if one is supplied */ - if (jrect == NULL) - { - rect = NULL; - } - else + if (jrect) { rect = &local_rect; - local_rect = fz_rect_from_Rect(env, jrect); + local_rect = from_Rect(env, jrect); } - info = lockCDevice(env, jdev); - + info = lockNativeDevice(env, jdev); fz_try(ctx) - { fz_run_display_list(ctx, list, dev, &ctm, rect, cookie); - } fz_always(ctx) - { - unlockCDevice(env, info); - } + unlockNativeDevice(env, info); fz_catch(ctx) - { jni_rethrow(env, ctx); - } } JNIEXPORT void JNICALL -JNI_FN(DisplayList_finalize)(JNIEnv * env, jobject self) +FUN(DisplayList_finalize)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); - fz_display_list *list = fz_display_list_from_DisplayList(env, self); + fz_display_list *list = from_DisplayList(env, self); if (ctx == NULL || list == NULL) return; fz_drop_display_list(ctx, list); } - -JNIEXPORT void JNICALL -JNI_FN(DisplayList_destroy)(JNIEnv * env, jobject self) -{ - JNI_FN(DisplayList_finalize)(env, self); - - (*env)->SetLongField(env, self, displaylist_fid, 0); -} - -JNIEXPORT jlong JNICALL -JNI_FN(DisplayListDevice_newNative)(JNIEnv *env, jobject self, jobject jlist) -{ - fz_context *ctx = get_context(env); - fz_display_list *list = fz_display_list_from_DisplayList(env, jlist); - fz_device *device = NULL; - int ret; - unsigned char dummy; - - if (ctx == NULL || list == NULL) - return 0; - - fz_try(ctx) - { - device = fz_new_list_device(ctx, list); - } - fz_catch(ctx) - { - jni_rethrow(env, ctx); - } - return jlong_cast(device); -} diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h new file mode 100644 index 00000000..61ba01b7 --- /dev/null +++ b/platform/java/mupdf_native.h @@ -0,0 +1,1559 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class com_artifex_mupdf_fitz_Annotation */ + +#ifndef _Included_com_artifex_mupdf_fitz_Annotation +#define _Included_com_artifex_mupdf_fitz_Annotation +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Annotation + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Annotation_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Annotation + * Method: run + * Signature: (Lcom/artifex/mupdf/fitz/Device;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/Cookie;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Annotation_run + (JNIEnv *, jobject, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Annotation + * Method: advance + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Annotation_advance + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_ColorSpace */ + +#ifndef _Included_com_artifex_mupdf_fitz_ColorSpace +#define _Included_com_artifex_mupdf_fitz_ColorSpace +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_ColorSpace + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_ColorSpace_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_ColorSpace + * Method: nativeDeviceGray + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_ColorSpace_nativeDeviceGray + (JNIEnv *, jclass); + +/* + * Class: com_artifex_mupdf_fitz_ColorSpace + * Method: nativeDeviceRGB + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_ColorSpace_nativeDeviceRGB + (JNIEnv *, jclass); + +/* + * Class: com_artifex_mupdf_fitz_ColorSpace + * Method: nativeDeviceBGR + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_ColorSpace_nativeDeviceBGR + (JNIEnv *, jclass); + +/* + * Class: com_artifex_mupdf_fitz_ColorSpace + * Method: nativeDeviceCMYK + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_ColorSpace_nativeDeviceCMYK + (JNIEnv *, jclass); + +/* + * Class: com_artifex_mupdf_fitz_ColorSpace + * Method: getNumberOfComponents + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_ColorSpace_getNumberOfComponents + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Context */ + +#ifndef _Included_com_artifex_mupdf_fitz_Context +#define _Included_com_artifex_mupdf_fitz_Context +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Context + * Method: initNative + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Context_initNative + (JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Cookie */ + +#ifndef _Included_com_artifex_mupdf_fitz_Cookie +#define _Included_com_artifex_mupdf_fitz_Cookie +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Cookie + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Cookie_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Cookie + * Method: newNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Cookie_newNative + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Cookie + * Method: abort + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Cookie_abort + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Device */ + +#ifndef _Included_com_artifex_mupdf_fitz_Device +#define _Included_com_artifex_mupdf_fitz_Device +#ifdef __cplusplus +extern "C" { +#endif +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_MASK +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_MASK 1L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_COLOR +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_COLOR 2L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_UNCACHEABLE +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_UNCACHEABLE 4L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_FILLCOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_FILLCOLOR_UNDEFINED 8L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_STROKECOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_STROKECOLOR_UNDEFINED 16L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_STARTCAP_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_STARTCAP_UNDEFINED 32L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_DASHCAP_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_DASHCAP_UNDEFINED 64L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_ENDCAP_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_ENDCAP_UNDEFINED 128L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_LINEJOIN_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_LINEJOIN_UNDEFINED 256L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_MITERLIMIT_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_MITERLIMIT_UNDEFINED 512L +#undef com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_LINEWIDTH_UNDEFINED +#define com_artifex_mupdf_fitz_Device_FZ_DEVFLAG_LINEWIDTH_UNDEFINED 1024L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_NORMAL +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_NORMAL 0L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_MULTIPLY +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_MULTIPLY 1L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_SCREEN +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_SCREEN 2L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_OVERLAY +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_OVERLAY 3L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_DARKEN +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_DARKEN 4L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_LIGHTEN +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_LIGHTEN 5L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_COLOR_DODGE +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_COLOR_DODGE 6L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_COLOR_BURN +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_COLOR_BURN 7L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_HARD_LIGHT +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_HARD_LIGHT 8L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_SOFT_LIGHT +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_SOFT_LIGHT 9L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_DIFFERENCE +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_DIFFERENCE 10L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_EXCLUSION +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_EXCLUSION 11L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_HUE +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_HUE 12L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_SATURATION +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_SATURATION 13L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_COLOR +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_COLOR 14L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_LUMINOSITY +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_LUMINOSITY 15L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_MODEMASK +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_MODEMASK 15L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_ISOLATED +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_ISOLATED 16L +#undef com_artifex_mupdf_fitz_Device_FZ_BLEND_KNOCKOUT +#define com_artifex_mupdf_fitz_Device_FZ_BLEND_KNOCKOUT 32L +#undef com_artifex_mupdf_fitz_Device_FZ_IGNORE_IMAGE +#define com_artifex_mupdf_fitz_Device_FZ_IGNORE_IMAGE 1L +#undef com_artifex_mupdf_fitz_Device_FZ_IGNORE_SHADE +#define com_artifex_mupdf_fitz_Device_FZ_IGNORE_SHADE 2L +/* + * Class: com_artifex_mupdf_fitz_Device + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Device_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Device + * Method: newNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Device_newNative + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Device + * Method: getHints + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Device_getHints + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Device + * Method: enableDeviceHints + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Device_enableDeviceHints + (JNIEnv *, jobject, jint); + +/* + * Class: com_artifex_mupdf_fitz_Device + * Method: disableDeviceHints + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Device_disableDeviceHints + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_DisplayList */ + +#ifndef _Included_com_artifex_mupdf_fitz_DisplayList +#define _Included_com_artifex_mupdf_fitz_DisplayList +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_DisplayList + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_DisplayList_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_DisplayList + * Method: newNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_DisplayList_newNative + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_DisplayList + * Method: run + * Signature: (Lcom/artifex/mupdf/fitz/Device;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/Rect;Lcom/artifex/mupdf/fitz/Cookie;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_DisplayList_run + (JNIEnv *, jobject, jobject, jobject, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_DisplayListDevice */ + +#ifndef _Included_com_artifex_mupdf_fitz_DisplayListDevice +#define _Included_com_artifex_mupdf_fitz_DisplayListDevice +#ifdef __cplusplus +extern "C" { +#endif +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_MASK +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_MASK 1L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_COLOR +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_COLOR 2L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_UNCACHEABLE +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_UNCACHEABLE 4L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_FILLCOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_FILLCOLOR_UNDEFINED 8L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_STROKECOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_STROKECOLOR_UNDEFINED 16L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_STARTCAP_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_STARTCAP_UNDEFINED 32L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_DASHCAP_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_DASHCAP_UNDEFINED 64L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_ENDCAP_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_ENDCAP_UNDEFINED 128L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_LINEJOIN_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_LINEJOIN_UNDEFINED 256L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_MITERLIMIT_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_MITERLIMIT_UNDEFINED 512L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_LINEWIDTH_UNDEFINED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_DEVFLAG_LINEWIDTH_UNDEFINED 1024L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_NORMAL +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_NORMAL 0L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_MULTIPLY +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_MULTIPLY 1L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_SCREEN +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_SCREEN 2L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_OVERLAY +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_OVERLAY 3L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_DARKEN +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_DARKEN 4L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_LIGHTEN +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_LIGHTEN 5L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_COLOR_DODGE +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_COLOR_DODGE 6L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_COLOR_BURN +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_COLOR_BURN 7L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_HARD_LIGHT +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_HARD_LIGHT 8L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_SOFT_LIGHT +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_SOFT_LIGHT 9L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_DIFFERENCE +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_DIFFERENCE 10L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_EXCLUSION +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_EXCLUSION 11L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_HUE +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_HUE 12L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_SATURATION +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_SATURATION 13L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_COLOR +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_COLOR 14L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_LUMINOSITY +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_LUMINOSITY 15L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_MODEMASK +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_MODEMASK 15L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_ISOLATED +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_ISOLATED 16L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_KNOCKOUT +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_BLEND_KNOCKOUT 32L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_IGNORE_IMAGE +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_IGNORE_IMAGE 1L +#undef com_artifex_mupdf_fitz_DisplayListDevice_FZ_IGNORE_SHADE +#define com_artifex_mupdf_fitz_DisplayListDevice_FZ_IGNORE_SHADE 2L +/* + * Class: com_artifex_mupdf_fitz_DisplayListDevice + * Method: newNative + * Signature: (Lcom/artifex/mupdf/fitz/DisplayList;)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_DisplayListDevice_newNative + (JNIEnv *, jclass, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Document */ + +#ifndef _Included_com_artifex_mupdf_fitz_Document +#define _Included_com_artifex_mupdf_fitz_Document +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Document_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: newNativeWithPath + * Signature: (Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Document_newNativeWithPath + (JNIEnv *, jobject, jstring); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: newNativeWithBuffer + * Signature: ([BLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Document_newNativeWithBuffer + (JNIEnv *, jobject, jbyteArray, jstring); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: needsPassword + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Document_needsPassword + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: authenticatePassword + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Document_authenticatePassword + (JNIEnv *, jobject, jstring); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: countPages + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Document_countPages + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: loadPage + * Signature: (I)Lcom/artifex/mupdf/fitz/Page; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Document_loadPage + (JNIEnv *, jobject, jint); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: loadOutline + * Signature: ()Lcom/artifex/mupdf/fitz/Outline; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Document_loadOutline + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: getMetaData + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_artifex_mupdf_fitz_Document_getMetaData + (JNIEnv *, jobject, jstring); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: isUnencryptedPDF + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Document_isUnencryptedPDF + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_DrawDevice */ + +#ifndef _Included_com_artifex_mupdf_fitz_DrawDevice +#define _Included_com_artifex_mupdf_fitz_DrawDevice +#ifdef __cplusplus +extern "C" { +#endif +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_MASK +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_MASK 1L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_COLOR +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_COLOR 2L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_UNCACHEABLE +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_UNCACHEABLE 4L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_FILLCOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_FILLCOLOR_UNDEFINED 8L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_STROKECOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_STROKECOLOR_UNDEFINED 16L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_STARTCAP_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_STARTCAP_UNDEFINED 32L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_DASHCAP_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_DASHCAP_UNDEFINED 64L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_ENDCAP_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_ENDCAP_UNDEFINED 128L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_LINEJOIN_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_LINEJOIN_UNDEFINED 256L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_MITERLIMIT_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_MITERLIMIT_UNDEFINED 512L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_LINEWIDTH_UNDEFINED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_DEVFLAG_LINEWIDTH_UNDEFINED 1024L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_NORMAL +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_NORMAL 0L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_MULTIPLY +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_MULTIPLY 1L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_SCREEN +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_SCREEN 2L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_OVERLAY +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_OVERLAY 3L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_DARKEN +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_DARKEN 4L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_LIGHTEN +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_LIGHTEN 5L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_COLOR_DODGE +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_COLOR_DODGE 6L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_COLOR_BURN +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_COLOR_BURN 7L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_HARD_LIGHT +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_HARD_LIGHT 8L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_SOFT_LIGHT +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_SOFT_LIGHT 9L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_DIFFERENCE +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_DIFFERENCE 10L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_EXCLUSION +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_EXCLUSION 11L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_HUE +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_HUE 12L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_SATURATION +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_SATURATION 13L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_COLOR +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_COLOR 14L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_LUMINOSITY +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_LUMINOSITY 15L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_MODEMASK +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_MODEMASK 15L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_ISOLATED +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_ISOLATED 16L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_KNOCKOUT +#define com_artifex_mupdf_fitz_DrawDevice_FZ_BLEND_KNOCKOUT 32L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_IGNORE_IMAGE +#define com_artifex_mupdf_fitz_DrawDevice_FZ_IGNORE_IMAGE 1L +#undef com_artifex_mupdf_fitz_DrawDevice_FZ_IGNORE_SHADE +#define com_artifex_mupdf_fitz_DrawDevice_FZ_IGNORE_SHADE 2L +/* + * Class: com_artifex_mupdf_fitz_DrawDevice + * Method: newNative + * Signature: (Lcom/artifex/mupdf/fitz/Pixmap;)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_DrawDevice_newNative + (JNIEnv *, jclass, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Font */ + +#ifndef _Included_com_artifex_mupdf_fitz_Font +#define _Included_com_artifex_mupdf_fitz_Font +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Font + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Font_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Font + * Method: getName + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_artifex_mupdf_fitz_Font_getName + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Image */ + +#ifndef _Included_com_artifex_mupdf_fitz_Image +#define _Included_com_artifex_mupdf_fitz_Image +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Image_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getWidth + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Image_getWidth + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getHeight + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Image_getHeight + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getNumberOfComponents + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Image_getNumberOfComponents + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getBitsPerComponent + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Image_getBitsPerComponent + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getXResolution + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Image_getXResolution + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getYResolution + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Image_getYResolution + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getImageMask + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Image_getImageMask + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getInterpolate + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Image_getInterpolate + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Image + * Method: getMask + * Signature: ()Lcom/artifex/mupdf/fitz/Image; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Image_getMask + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Link */ + +#ifndef _Included_com_artifex_mupdf_fitz_Link +#define _Included_com_artifex_mupdf_fitz_Link +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Link + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Link_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Link + * Method: getNext + * Signature: ()Lcom/artifex/mupdf/fitz/Link; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Link_getNext + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Matrix */ + +#ifndef _Included_com_artifex_mupdf_fitz_Matrix +#define _Included_com_artifex_mupdf_fitz_Matrix +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_NativeDevice */ + +#ifndef _Included_com_artifex_mupdf_fitz_NativeDevice +#define _Included_com_artifex_mupdf_fitz_NativeDevice +#ifdef __cplusplus +extern "C" { +#endif +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_MASK +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_MASK 1L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_COLOR +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_COLOR 2L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_UNCACHEABLE +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_UNCACHEABLE 4L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_FILLCOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_FILLCOLOR_UNDEFINED 8L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_STROKECOLOR_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_STROKECOLOR_UNDEFINED 16L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_STARTCAP_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_STARTCAP_UNDEFINED 32L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_DASHCAP_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_DASHCAP_UNDEFINED 64L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_ENDCAP_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_ENDCAP_UNDEFINED 128L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_LINEJOIN_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_LINEJOIN_UNDEFINED 256L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_MITERLIMIT_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_MITERLIMIT_UNDEFINED 512L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_LINEWIDTH_UNDEFINED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_DEVFLAG_LINEWIDTH_UNDEFINED 1024L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_NORMAL +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_NORMAL 0L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_MULTIPLY +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_MULTIPLY 1L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_SCREEN +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_SCREEN 2L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_OVERLAY +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_OVERLAY 3L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_DARKEN +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_DARKEN 4L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_LIGHTEN +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_LIGHTEN 5L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_COLOR_DODGE +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_COLOR_DODGE 6L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_COLOR_BURN +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_COLOR_BURN 7L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_HARD_LIGHT +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_HARD_LIGHT 8L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_SOFT_LIGHT +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_SOFT_LIGHT 9L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_DIFFERENCE +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_DIFFERENCE 10L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_EXCLUSION +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_EXCLUSION 11L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_HUE +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_HUE 12L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_SATURATION +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_SATURATION 13L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_COLOR +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_COLOR 14L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_LUMINOSITY +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_LUMINOSITY 15L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_MODEMASK +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_MODEMASK 15L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_ISOLATED +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_ISOLATED 16L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_KNOCKOUT +#define com_artifex_mupdf_fitz_NativeDevice_FZ_BLEND_KNOCKOUT 32L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_IGNORE_IMAGE +#define com_artifex_mupdf_fitz_NativeDevice_FZ_IGNORE_IMAGE 1L +#undef com_artifex_mupdf_fitz_NativeDevice_FZ_IGNORE_SHADE +#define com_artifex_mupdf_fitz_NativeDevice_FZ_IGNORE_SHADE 2L +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: beginPage + * Signature: (Lcom/artifex/mupdf/fitz/Rect;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_beginPage + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: endPage + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_endPage + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: fillPath + * Signature: (Lcom/artifex/mupdf/fitz/Path;ZLcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/ColorSpace;[FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_fillPath + (JNIEnv *, jobject, jobject, jboolean, jobject, jobject, jfloatArray, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: strokePath + * Signature: (Lcom/artifex/mupdf/fitz/Path;Lcom/artifex/mupdf/fitz/StrokeState;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/ColorSpace;[FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_strokePath + (JNIEnv *, jobject, jobject, jobject, jobject, jobject, jfloatArray, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: clipPath + * Signature: (Lcom/artifex/mupdf/fitz/Path;Lcom/artifex/mupdf/fitz/Rect;ZLcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_clipPath + (JNIEnv *, jobject, jobject, jobject, jboolean, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: clipStrokePath + * Signature: (Lcom/artifex/mupdf/fitz/Path;Lcom/artifex/mupdf/fitz/Rect;Lcom/artifex/mupdf/fitz/StrokeState;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_clipStrokePath + (JNIEnv *, jobject, jobject, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: fillText + * Signature: (Lcom/artifex/mupdf/fitz/Text;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/ColorSpace;[FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_fillText + (JNIEnv *, jobject, jobject, jobject, jobject, jfloatArray, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: strokeText + * Signature: (Lcom/artifex/mupdf/fitz/Text;Lcom/artifex/mupdf/fitz/StrokeState;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/ColorSpace;[FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_strokeText + (JNIEnv *, jobject, jobject, jobject, jobject, jobject, jfloatArray, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: clipText + * Signature: (Lcom/artifex/mupdf/fitz/Text;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_clipText + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: clipStrokeText + * Signature: (Lcom/artifex/mupdf/fitz/Text;Lcom/artifex/mupdf/fitz/StrokeState;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_clipStrokeText + (JNIEnv *, jobject, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: ignoreText + * Signature: (Lcom/artifex/mupdf/fitz/Text;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_ignoreText + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: fillShade + * Signature: (Lcom/artifex/mupdf/fitz/Shade;Lcom/artifex/mupdf/fitz/Matrix;F)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_fillShade + (JNIEnv *, jobject, jobject, jobject, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: fillImage + * Signature: (Lcom/artifex/mupdf/fitz/Image;Lcom/artifex/mupdf/fitz/Matrix;F)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_fillImage + (JNIEnv *, jobject, jobject, jobject, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: fillImageMask + * Signature: (Lcom/artifex/mupdf/fitz/Image;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/ColorSpace;[FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_fillImageMask + (JNIEnv *, jobject, jobject, jobject, jobject, jfloatArray, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: clipImageMask + * Signature: (Lcom/artifex/mupdf/fitz/Image;Lcom/artifex/mupdf/fitz/Rect;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_clipImageMask + (JNIEnv *, jobject, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: popClip + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_popClip + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: beginMask + * Signature: (Lcom/artifex/mupdf/fitz/Rect;ZLcom/artifex/mupdf/fitz/ColorSpace;[F)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_beginMask + (JNIEnv *, jobject, jobject, jboolean, jobject, jfloatArray); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: endMask + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_endMask + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: beginGroup + * Signature: (Lcom/artifex/mupdf/fitz/Rect;ZZIF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_beginGroup + (JNIEnv *, jobject, jobject, jboolean, jboolean, jint, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: endGroup + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_endGroup + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: beginTile + * Signature: (Lcom/artifex/mupdf/fitz/Rect;Lcom/artifex/mupdf/fitz/Rect;FFLcom/artifex/mupdf/fitz/Matrix;I)I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_beginTile + (JNIEnv *, jobject, jobject, jobject, jfloat, jfloat, jobject, jint); + +/* + * Class: com_artifex_mupdf_fitz_NativeDevice + * Method: endTile + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_NativeDevice_endTile + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Outline */ + +#ifndef _Included_com_artifex_mupdf_fitz_Outline +#define _Included_com_artifex_mupdf_fitz_Outline +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Outline + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Outline_finalize + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Page */ + +#ifndef _Included_com_artifex_mupdf_fitz_Page +#define _Included_com_artifex_mupdf_fitz_Page +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Page_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: getBounds + * Signature: ()Lcom/artifex/mupdf/fitz/Rect; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Page_getBounds + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: toPixmap + * Signature: (Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/ColorSpace;)Lcom/artifex/mupdf/fitz/Pixmap; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Page_toPixmap + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: run + * Signature: (Lcom/artifex/mupdf/fitz/Device;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/Cookie;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Page_run + (JNIEnv *, jobject, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: runPageContents + * Signature: (Lcom/artifex/mupdf/fitz/Device;Lcom/artifex/mupdf/fitz/Matrix;Lcom/artifex/mupdf/fitz/Cookie;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Page_runPageContents + (JNIEnv *, jobject, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: getAnnotations + * Signature: ()[Lcom/artifex/mupdf/fitz/Annotation; + */ +JNIEXPORT jobjectArray JNICALL Java_com_artifex_mupdf_fitz_Page_getAnnotations + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Page + * Method: getLinks + * Signature: ()[Lcom/artifex/mupdf/fitz/Link; + */ +JNIEXPORT jobjectArray JNICALL Java_com_artifex_mupdf_fitz_Page_getLinks + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Path */ + +#ifndef _Included_com_artifex_mupdf_fitz_Path +#define _Included_com_artifex_mupdf_fitz_Path +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: newNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Path_newNative + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: cloneNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Path_cloneNative + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: currentPoint + * Signature: ()Lcom/artifex/mupdf/fitz/Point; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Path_currentPoint + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: moveTo + * Signature: (FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_moveTo + (JNIEnv *, jobject, jfloat, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: lineTo + * Signature: (FF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_lineTo + (JNIEnv *, jobject, jfloat, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: curveTo + * Signature: (FFFFFF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_curveTo + (JNIEnv *, jobject, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: curveToV + * Signature: (FFFF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_curveToV + (JNIEnv *, jobject, jfloat, jfloat, jfloat, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: curveToY + * Signature: (FFFF)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_curveToY + (JNIEnv *, jobject, jfloat, jfloat, jfloat, jfloat); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: closePath + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_closePath + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: transform + * Signature: (Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_transform + (JNIEnv *, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: getBounds + * Signature: (Lcom/artifex/mupdf/fitz/StrokeState;Lcom/artifex/mupdf/fitz/Matrix;)Lcom/artifex/mupdf/fitz/Rect; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Path_getBounds + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Path + * Method: walk + * Signature: (Lcom/artifex/mupdf/fitz/PathWalker;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Path_walk + (JNIEnv *, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_PathWalker */ + +#ifndef _Included_com_artifex_mupdf_fitz_PathWalker +#define _Included_com_artifex_mupdf_fitz_PathWalker +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Pixmap */ + +#ifndef _Included_com_artifex_mupdf_fitz_Pixmap +#define _Included_com_artifex_mupdf_fitz_Pixmap +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Pixmap_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: newNative + * Signature: (Lcom/artifex/mupdf/fitz/ColorSpace;IIII)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Pixmap_newNative + (JNIEnv *, jobject, jobject, jint, jint, jint, jint); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: clear + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Pixmap_clear + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: clearWithValue + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Pixmap_clearWithValue + (JNIEnv *, jobject, jint); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: saveAsPNG + * Signature: (Ljava/lang/String;Z)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Pixmap_saveAsPNG + (JNIEnv *, jobject, jstring, jboolean); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getX + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getX + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getY + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getY + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getWidth + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getWidth + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getHeight + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getHeight + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getStride + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getStride + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getNumberOfComponents + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getNumberOfComponents + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getColorSpace + * Signature: ()Lcom/artifex/mupdf/fitz/ColorSpace; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getColorSpace + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getSamples + * Signature: ()[B + */ +JNIEXPORT jbyteArray JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getSamples + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Pixmap + * Method: getPixels + * Signature: ()[I + */ +JNIEXPORT jintArray JNICALL Java_com_artifex_mupdf_fitz_Pixmap_getPixels + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Point */ + +#ifndef _Included_com_artifex_mupdf_fitz_Point +#define _Included_com_artifex_mupdf_fitz_Point +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Rect */ + +#ifndef _Included_com_artifex_mupdf_fitz_Rect +#define _Included_com_artifex_mupdf_fitz_Rect +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_RectI */ + +#ifndef _Included_com_artifex_mupdf_fitz_RectI +#define _Included_com_artifex_mupdf_fitz_RectI +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Shade */ + +#ifndef _Included_com_artifex_mupdf_fitz_Shade +#define _Included_com_artifex_mupdf_fitz_Shade +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Shade + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Shade_finalize + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_StrokeState */ + +#ifndef _Included_com_artifex_mupdf_fitz_StrokeState +#define _Included_com_artifex_mupdf_fitz_StrokeState +#ifdef __cplusplus +extern "C" { +#endif +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_BUTT +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_BUTT 0L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_ROUND +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_ROUND 1L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_SQUARE +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_SQUARE 2L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_TRIANGLE +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINECAP_TRIANGLE 3L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_MITER +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_MITER 0L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_ROUND +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_ROUND 1L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_BEVEL +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_BEVEL 2L +#undef com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_MITER_XPS +#define com_artifex_mupdf_fitz_StrokeState_FZ_LINEJOIN_MITER_XPS 3L +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_StrokeState_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: newNative + * Signature: (IIIIFFF[F)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_StrokeState_newNative + (JNIEnv *, jobject, jint, jint, jint, jint, jfloat, jfloat, jfloat, jfloatArray); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: adjustRectForStroke + * Signature: (Lcom/artifex/mupdf/fitz/Rect;Lcom/artifex/mupdf/fitz/Matrix;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_StrokeState_adjustRectForStroke + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getStartCap + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getStartCap + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getDashCap + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getDashCap + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getEndCap + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getEndCap + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getLineJoin + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getLineJoin + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getLineWidth + * Signature: ()F + */ +JNIEXPORT jfloat JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getLineWidth + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getMiterLimit + * Signature: ()F + */ +JNIEXPORT jfloat JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getMiterLimit + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getDashPhase + * Signature: ()F + */ +JNIEXPORT jfloat JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getDashPhase + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_StrokeState + * Method: getDashes + * Signature: ()[F + */ +JNIEXPORT jfloatArray JNICALL Java_com_artifex_mupdf_fitz_StrokeState_getDashes + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_Text */ + +#ifndef _Included_com_artifex_mupdf_fitz_Text +#define _Included_com_artifex_mupdf_fitz_Text +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Text + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Text_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Text + * Method: newNative + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Text_newNative + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Text + * Method: cloneNative + * Signature: (Lcom/artifex/mupdf/fitz/Text;)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Text_cloneNative + (JNIEnv *, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Text + * Method: showGlyph + * Signature: (Lcom/artifex/mupdf/fitz/Font;ZLcom/artifex/mupdf/fitz/Matrix;II)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Text_showGlyph + (JNIEnv *, jobject, jobject, jboolean, jobject, jint, jint); + +/* + * Class: com_artifex_mupdf_fitz_Text + * Method: getBounds + * Signature: (Lcom/artifex/mupdf/fitz/StrokeState;Lcom/artifex/mupdf/fitz/Matrix;)Lcom/artifex/mupdf/fitz/Rect; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Text_getBounds + (JNIEnv *, jobject, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Text + * Method: walk + * Signature: (Lcom/artifex/mupdf/fitz/TextWalker;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Text_walk + (JNIEnv *, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_TextWalker */ + +#ifndef _Included_com_artifex_mupdf_fitz_TextWalker +#define _Included_com_artifex_mupdf_fitz_TextWalker +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class com_artifex_mupdf_fitz_TryLaterException */ + +#ifndef _Included_com_artifex_mupdf_fitz_TryLaterException +#define _Included_com_artifex_mupdf_fitz_TryLaterException +#ifdef __cplusplus +extern "C" { +#endif +#undef com_artifex_mupdf_fitz_TryLaterException_serialVersionUID +#define com_artifex_mupdf_fitz_TryLaterException_serialVersionUID -3042686055658047285LL +#undef com_artifex_mupdf_fitz_TryLaterException_serialVersionUID +#define com_artifex_mupdf_fitz_TryLaterException_serialVersionUID -3387516993124229948LL +#ifdef __cplusplus +} +#endif +#endif |