[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] alph/org/nongnu/alph impl/PageImageScroll.java ...
From: |
Tuomas J. Lukka |
Subject: |
[ff-cvs] alph/org/nongnu/alph impl/PageImageScroll.java ... |
Date: |
Tue, 26 Aug 2003 14:10:41 -0400 |
CVSROOT: /cvsroot/alph
Module name: alph
Branch:
Changes by: Tuomas J. Lukka <address@hidden> 03/08/26 14:10:41
Modified files:
org/nongnu/alph/impl: PageImageScroll.java
org/nongnu/alph/util: PageInfo.java
Log message:
Cache .dsc to speed up fenpdf startup
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/PageImageScroll.java.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/util/PageInfo.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: alph/org/nongnu/alph/impl/PageImageScroll.java
diff -u alph/org/nongnu/alph/impl/PageImageScroll.java:1.16
alph/org/nongnu/alph/impl/PageImageScroll.java:1.17
--- alph/org/nongnu/alph/impl/PageImageScroll.java:1.16 Thu Aug 14 01:47:13 2003
+++ alph/org/nongnu/alph/impl/PageImageScroll.java Tue Aug 26 14:10:41 2003
@@ -39,13 +39,28 @@
/** An scrollblock containing paged media (PS/PDF).
+ * <p>
+ * For performance on startup, dsc info is cached into the directory
+ * specified by the alph.cache.dsc property
*/
public class PageImageScroll extends AbstractScrollBlock implements
PageScrollBlock{
-String rcsid = "$Id: PageImageScroll.java,v 1.16 2003/08/14 05:47:13 tjl Exp
$";
+String rcsid = "$Id: PageImageScroll.java,v 1.17 2003/08/26 18:10:41 tjl Exp
$";
public static boolean dbg = false;
final static void pa(String s) { System.out.println(s); }
+ static File dscCacheDir;
+
+ static {
+ String dir = System.getProperty("alph.cache.dsc", "./tmpimg");
+ dscCacheDir = new File(dir);
+ if(!dscCacheDir.exists()) {
+ pa("DSC CACHE DIR NOT FOUND -- NOT CACHING");
+ dscCacheDir = null;
+ } else {
+ pa("USING DSC CACHE "+dscCacheDir);
+ }
+ }
PageInfo pageInfo;
@@ -59,7 +74,10 @@
static PythonInterpreter interp;
+ /** Generate the page info for this scrollblock.
+ */
private void generatePageInfo() {
+ pa("Generating page info: "+getID());
if(interp == null) {
interp = new PythonInterpreter();
interp.exec("import alph\nps=alph.util.dscutil.reliablePS2DSC\n"+
@@ -96,6 +114,56 @@
pageInfo= (PageInfo)res.__tojava__(PageInfo.class);
}
+ private File getDscCacheFile() {
+ if(dscCacheDir == null)
+ return null;
+ // Munge the string to not use bad chars
+ String s = getID();
+ s = s.replace('/','-');
+ s = s.replace(':','_');
+ return new File(dscCacheDir, "dsccache-"+s);
+ }
+
+ /** Get the page info for this scrollblock from the cache or generate it.
+ */
+ private void getPageInfo() {
+ File cache = getDscCacheFile();
+ if(cache == null) {
+ generatePageInfo();
+ return;
+ }
+ if(cache.exists()) {
+ // try to read
+ ObjectInputStream i = null ;
+ try {
+ i = new ObjectInputStream(
+ new FileInputStream(cache));
+ this.pageInfo = (PageInfo)i.readObject();
+ i.close();
+ } catch(Exception e) {
+ pa("Exception reading cache: "+e);
+ e.printStackTrace();
+ try {
+ if(i != null)
+ i.close();
+ } catch(IOException g) {
+ }
+ }
+ }
+ if(this.pageInfo == null) {
+ // Couldn't read,
+ generatePageInfo();
+ try {
+ ObjectOutputStream o = new ObjectOutputStream(
+ new FileOutputStream(cache));
+ o.writeObject(this.pageInfo);
+ o.close();
+ } catch(IOException e) {
+ pa("Exception writing cache: "+e);
+ e.printStackTrace();
+ }
+ }
+ }
public PageImageScroll(Alph alph, Object blockId, String contentType) {
super(alph, blockId, contentType);
@@ -103,7 +171,7 @@
contentType.equals("application/pdf")))
throw new Error("Can't do pageimagescroll except for ps/pdf. ("
+contentType+")");
- generatePageInfo();
+ getPageInfo();
}
/** The resolution of the coordinates on the original paper.
Index: alph/org/nongnu/alph/util/PageInfo.java
diff -u alph/org/nongnu/alph/util/PageInfo.java:1.2
alph/org/nongnu/alph/util/PageInfo.java:1.3
--- alph/org/nongnu/alph/util/PageInfo.java:1.2 Wed Jun 11 13:50:18 2003
+++ alph/org/nongnu/alph/util/PageInfo.java Tue Aug 26 14:10:41 2003
@@ -26,6 +26,9 @@
package org.nongnu.alph.util;
+/** A class that represents the sizes of the pages
+ * from a postscript/pdf document.
+ */
public class PageInfo implements java.io.Serializable {
float[] w;
float[] h;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ff-cvs] alph/org/nongnu/alph impl/PageImageScroll.java ...,
Tuomas J. Lukka <=