gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] alph/org/nongnu/alph/impl PageImageScroll.java


From: Tuomas J. Lukka
Subject: [Gzz-commits] alph/org/nongnu/alph/impl PageImageScroll.java
Date: Tue, 22 Apr 2003 07:43:41 -0400

CVSROOT:        /cvsroot/alph
Module name:    alph
Changes by:     Tuomas J. Lukka <address@hidden>        03/04/22 07:43:41

Modified files:
        org/nongnu/alph/impl: PageImageScroll.java 

Log message:
        Remove legacy image cache code from pageimagescroll. Feels GOOD.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/PageImageScroll.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: alph/org/nongnu/alph/impl/PageImageScroll.java
diff -u alph/org/nongnu/alph/impl/PageImageScroll.java:1.8 
alph/org/nongnu/alph/impl/PageImageScroll.java:1.9
--- alph/org/nongnu/alph/impl/PageImageScroll.java:1.8  Tue Apr 22 07:37:29 2003
+++ alph/org/nongnu/alph/impl/PageImageScroll.java      Tue Apr 22 07:43:41 2003
@@ -28,7 +28,10 @@
 
 package org.nongnu.alph.impl;
 import org.nongnu.alph.*;
+import org.nongnu.alph.util.*;
 import org.nongnu.storm.*;
+import org.python.util.*;
+import org.python.core.*;
 import java.awt.*;
 import java.awt.image.*;
 import java.io.*;
@@ -39,21 +42,13 @@
  */
 
 public class PageImageScroll extends AbstractScrollBlock implements 
PageScrollBlock{
-String rcsid = "$Id: PageImageScroll.java,v 1.8 2003/04/22 11:37:29 benja Exp 
$";
+String rcsid = "$Id: PageImageScroll.java,v 1.9 2003/04/22 11:43:41 tjl Exp $";
     public static boolean dbg = true;
     final static void p(String s) { if(dbg) System.out.println(s); }
     final static void pa(String s) { System.out.println(s); }
 
-    int WIDTH=612; // Letter size fixed, for now, in points, 1/72ths of 
inches..
-    int HEIGHT=792;
 
-    /** Resolution of the images to use.
-     */
-    int RESOLUTION=170; // sigh
-
-    String DIR="../tmpimg/"; // XXX Non-platform-independent!
-
-    int pages;
+    PageInfo pageInfo;
 
 
     public boolean equals(Object o) {
@@ -63,49 +58,53 @@
     }
     //    Mediaserver.Block block;
 
-    public PageImageScroll(Alph alph, Object blockId, String contentType) {
-       super(alph, blockId, contentType);
-
-       checkLen();
-    }
+    static PythonInterpreter interp;
 
-    /** Return the image file name for the given, 0-based page.
-     */
-    public String imageFilename(int page) {
-       String id = getID();
-       int ind;
-       while((ind = id.indexOf("/")) >= 0) {
-           id = id.substring(0,ind) + "__" + id.substring(ind+1);
+    private void generatePageInfo() {
+       if(interp == null) {
+           interp = new PythonInterpreter();
+           interp.exec("import alph\nps=alph.util.dscutil.reliablePS2DSC\n"+
+                       "pdf=alph.util.dscutil.reliablePDF2DSC\n"+
+                       "pinf=alph.util.dscutil.dsc2pageinfo\n");
+       }
+       PyObject conv1;
+       if(contentType.equals("application/postscript")) {
+           conv1 = interp.get("ps");
+       } else {
+           conv1 = interp.get("pdf");
+       }
+       File dsc;
+       try {
+           dsc = File.createTempFile("dsc","dsc");
+       } catch(Exception e) {
+           throw new Error(""+e);
        }
-       return new String(DIR+id+"-"+RESOLUTION+"-"+(page+1));
+       PyObject res = conv1.__call__(new PyObject[] {
+           new PyString(alph.getBlockFile(this).getFilename()),
+           new PyString(dsc.getPath()),
+       });
+       pageInfo= (PageInfo)res.__tojava__(PageInfo.class);
     }
-    /** The resolution of the images.
-     */
-    public float imageFileResolution(int page) {
-       return RESOLUTION;
+
+
+    public PageImageScroll(Alph alph, Object blockId, String contentType) {
+       super(alph, blockId, contentType);
+       if(!( contentType.equals("application/postscript") ||
+             contentType.equals("application/pdf")))
+           throw new Error("Can't do pageimagescroll except for ps/pdf. ("
+                               +contentType+")");
+       generatePageInfo();
     }
+
     /** The resolution of the coordinates on the original paper.
      */
     public float coordinateResolution() {
        return 72;
     }
 
-    private void checkLen() {
-       int i=0;
-       while(new File(imageFilename(i)).exists())
-           i++;
-       pages = i;
-       pa("Checked document of "+i+" pages");
-    }
-    /** DO NOT USE EXCEPT WHEN CREATING FAKE PAGESPANS
-     * FOR TESTS.
-     */
-    public void forcelengthKLUDGE(int len) {
-       pages = len;
-    }
 
     public Span getCurrent() {
-       return new StdPageSpan(this, 0, pages);
+       return new StdPageSpan(this, 0, pageInfo.getNPages());
     }
     public Span getSpan(int p0, int p1) {
        return new StdPageSpan(this, p0, p1);
@@ -126,8 +125,11 @@
        public int getPageIndex() { return page; }
     }
 
-    public PageImageSpan getPage(int p) {
-       return new PageImageSpanImpl(this, p, 0, 0, WIDTH, HEIGHT);
+    public ImageSpan getPage(int p) {
+       return new PageImageSpanImpl(this, p, 0, 0, 
+               (int)pageInfo.getWidth(p),
+               (int)pageInfo.getHeight(p)
+               );
     }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]