package com.artifex.mupdf.fitz;

// This class handles the loading of the MuPDF shared library, together
// with the ThreadLocal magic to get the required context.
//
// The only publicly accessible method here is Context.setStoreSize, which
// sets the store size to use. This must be called before any other MuPDF
// function.
public class Context
{
	private static boolean inited = false;
	private static native int initNative();
	public static native int gprfSupportedNative();

	public static void init() {
		if (!inited) {
			inited = true;
			System.loadLibrary(getLibraryName());
			if (initNative() < 0)
				throw new RuntimeException("cannot initialize mupdf library");
		}
	}

	private static String getLibraryName(void) {
		/* Mac OS always uses 64bit DLLs for any JDK 1.7 or above */
		if (System.getProperty("os.name").toLowerCase().contains("mac os")) {
			return "mupdf_java64";
		}
		String val = System.getProperty("sun.arch.data.model");
		if (val != null && val.equals("32")) {
			return "mupdf_java32"
		}
		return "mupdf_java64";
	}

	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);
}

@@ -719,20 +719,16 @@
 aryName(
-void
 ) %7B%0A%09%09/*
@@ -888,16 +888,84 @@
 4%22;%0A%09%09%7D%0A
+%09%09/* Sun and OpenJDK JVMs support this way of finding bittedness */%0A
 %09%09String
@@ -1014,16 +1014,72 @@
 odel%22);%0A
+%09%09/* Android does NOT support this, and returns NULL */%0A
 %09%09if (va
@@ -1103,18 +1103,18 @@
 equals(%22
-32
+64
 %22)) %7B%0A%09%09
@@ -1136,15 +1136,462 @@
 java
-32%22%0A%09%09%7D
+64%22;%0A%09%09%7D%0A%0A%09%09/* We might be running Android here. We could find out by%0A%09%09 * doing the following test:%0A%09%09 *  val = System.getProperty(%22java.vm.name%22);%0A%09%09 *  if (val != null && val.toLowerCase().contains(%22dalvik%22)) %7B%0A%09%09 *    ...Do something Androidy to test for 32/64 here...%0A%09%09 *  %7D%0A%09%09 * (Currently, both Dalvik and ART return 'Dalvik').%0A%09%09 * We know of no portable way to detect 32 or 64bittedness%0A%09%09 * on android though, so for now will assume 32.%0A%09%09 */%0A
 %0A%09%09r
@@ -1603,26 +1603,26 @@
  %22mupdf_java
-64
+32
 %22;%0A%09%7D%0A%0A%09stat

Fix Java 32/64bit detection.