[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] fenfire/org/fenfire fenpdf/fenpdftestutil.py fe...
From: |
Tuomas J. Lukka |
Subject: |
[ff-cvs] fenfire/org/fenfire fenpdf/fenpdftestutil.py fe... |
Date: |
Sat, 08 Nov 2003 14:45:10 -0500 |
CVSROOT: /cvsroot/fenfire
Module name: fenfire
Branch:
Changes by: Tuomas J. Lukka <address@hidden> 03/11/08 14:45:10
Modified files:
org/fenfire/fenpdf: fenpdftestutil.py init.test
org/fenfire/fenpdf/actions: eventgrabs.py
org/fenfire/fenpdf/appearance: papers.py
org/fenfire/fenpdf/events: MouseEventGrabber.java
org/fenfire/functional: DirectFunctional.java Functional.java
FunctionalTest.java
SuperFunctional1.java functionaltest.py
superfunctional1.test
org/fenfire/spanimages: SpanImageFactory.java
org/fenfire/spanimages/gl: DefaultSpanImageFactory.java
PaperMaker.java PlainPaperMaker.java
ScrollBlockImager.java papermakers.py
org/fenfire/util: PaperMillFunction.java
org/fenfire/view: PaperView2D.java TextNodeView.test
irregularviewport.test papercanvas2d.test
paperview2d.test
Log message:
sync
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/fenpdf/fenpdftestutil.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/fenpdf/init.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/fenpdf/actions/eventgrabs.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/fenpdf/appearance/papers.py.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/fenpdf/events/MouseEventGrabber.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/functional/DirectFunctional.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/functional/Functional.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/functional/FunctionalTest.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/functional/SuperFunctional1.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/functional/functionaltest.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/functional/superfunctional1.test.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/SpanImageFactory.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/PaperMaker.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/papermakers.py.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/util/PaperMillFunction.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/PaperView2D.java.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/TextNodeView.test.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/irregularviewport.test.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/papercanvas2d.test.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/paperview2d.test.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: fenfire/org/fenfire/fenpdf/actions/eventgrabs.py
diff -u fenfire/org/fenfire/fenpdf/actions/eventgrabs.py:1.3
fenfire/org/fenfire/fenpdf/actions/eventgrabs.py:1.4
--- fenfire/org/fenfire/fenpdf/actions/eventgrabs.py:1.3 Wed Nov 5
05:25:51 2003
+++ fenfire/org/fenfire/fenpdf/actions/eventgrabs.py Sat Nov 8 14:45:09 2003
@@ -1,4 +1,23 @@
-# (c) Matti J. Katila
+#
+# Copyright (c) 2003, Matti J. Katila
+# This file is part of Fenfire.
+#
+# Fenfire is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Fenfire is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General
+# Public License along with Fenfire; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
import java, jarray
import org.nongnu.libvob as vob
Index: fenfire/org/fenfire/fenpdf/appearance/papers.py
diff -u fenfire/org/fenfire/fenpdf/appearance/papers.py:1.14
fenfire/org/fenfire/fenpdf/appearance/papers.py:1.15
--- fenfire/org/fenfire/fenpdf/appearance/papers.py:1.14 Wed Nov 5
05:25:51 2003
+++ fenfire/org/fenfire/fenpdf/appearance/papers.py Sat Nov 8 14:45:09 2003
@@ -28,12 +28,6 @@
def p(*s):
print 'ff.fenpdf.appearance.papers::', s
-class ConstantPaperMill(vob.gl.PaperMill):
- def __init__(self, paper):
- self.paper = paper
- def getPaper(self, seed):
- return self.paper
-
class Papers:
"""Encapsulate the selection of background drawing methods.
"""
@@ -108,6 +102,21 @@
For functioninstances, use the given functional
object.
"""
+
+ # The function to create papers.
+ if self.useBg:
+ self.paperFunc = functional.createFunctionInstance(
+ "PaperMill",
+ ff.util.PaperMillFunction,
+ [ vob.paper.papermill.ThePaperMill(),
+ java.lang.Boolean(1)
+ ])
+ else:
+ self.paperFunc = functional.createFunctionInstance(
+ "ConstantPaper",
+ ff.functional.ConstantFunction,
+ [ vob.gl.SpecialPapers.solidPaper(java.awt.Color.white)])
+
# self.spanImageFactory.poolManager.DICELENGTH = 10
makerEntry = None
if self.useBg:
@@ -120,12 +129,26 @@
self.whitePaperMakerIndex]
p("Set paper maker: ", makerEntry)
- if makerEntry != None:
- if makerEntry[0] != None:
- paperMaker = makerEntry[0]()
- if dbg: print "Maker:", paperMaker
+ assert makerEntry != None
+
+ if makerEntry[0] != None:
+ args = makerEntry[0]()
+ #
+ # Kludgeish: currently Functional can't
+ # create both Java and Jython function instances
+ # with the same method; we hope we can later
+ # improve that.
+ #
+ if args[0].__class__ == java.lang.Class:
+ paperMaker = functional.createFunctionInstance(
+ "PaperMaker", *args)
else:
- raise 'FIX ME! Got None makeEntry.'
+ paperMaker = functional.createFunctionInstance_Jython(
+ "PaperMaker", *args)
+ if dbg: print "Maker:", paperMaker
+ else:
+ raise 'FIX ME! Got None makeEntry.'
+
self.spanImageFactory = \
functional.createFunctionInstance(
"SpanImageFactory",
@@ -133,22 +156,14 @@
[self.scrollBlockImager,
paperMaker])
- # # Then, make it cache stuff
- # self.spanImageFactory = \
- # ff.spanimages.gl.CachingSpanImageFactory(
- # self.spanImageFactory)
-
def getSpanImageFactory(self):
return self.spanImageFactory
def decorateWithPaperView(self, view2d):
- paperView = ff.view.PaperView2D(view2d)
+ paperView = ff.view.PaperView2D(
+ self.paperFunc.getCallableFunction(), view2d)
paperView.paperScaling = .1
p("decorateWithPaperView", self.useBg)
- if not self.useBg:
- paperView.paperMill = \
- ConstantPaperMill(vob.gl.SpecialPapers.solidPaper(
- java.awt.Color.white))
return paperView
Index: fenfire/org/fenfire/fenpdf/events/MouseEventGrabber.java
diff -u fenfire/org/fenfire/fenpdf/events/MouseEventGrabber.java:1.1
fenfire/org/fenfire/fenpdf/events/MouseEventGrabber.java:1.2
--- fenfire/org/fenfire/fenpdf/events/MouseEventGrabber.java:1.1 Fri Oct
31 02:22:03 2003
+++ fenfire/org/fenfire/fenpdf/events/MouseEventGrabber.java Sat Nov 8
14:45:09 2003
@@ -1,4 +1,28 @@
-// (c): Matti J. Katila
+/*
+MouseEventGrabber.java
+ *
+ * Copyright (c) 2003, Matti J. Katila
+ * This file is part of Fenfire.
+ *
+ * Fenfire is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Fenfire is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with Fenfire; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+/*
+ * Written by Matti J. Katila
+ */
package org.fenfire.fenpdf.events;
import org.nongnu.libvob.*;
Index: fenfire/org/fenfire/fenpdf/fenpdftestutil.py
diff -u fenfire/org/fenfire/fenpdf/fenpdftestutil.py:1.1
fenfire/org/fenfire/fenpdf/fenpdftestutil.py:1.2
--- fenfire/org/fenfire/fenpdf/fenpdftestutil.py:1.1 Wed Nov 5 05:25:50 2003
+++ fenfire/org/fenfire/fenpdf/fenpdftestutil.py Sat Nov 8 14:45:08 2003
@@ -1,4 +1,23 @@
-# (c) Tuomas J. Lukka
+#
+# Copyright (c) 2003, Tuomas J. Lukka
+# This file is part of Fenfire.
+#
+# Fenfire is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Fenfire is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General
+# Public License along with Fenfire; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
"""Testing utilities for fenpdf.
To be run from inside the test framework only.
Index: fenfire/org/fenfire/fenpdf/init.test
diff -u fenfire/org/fenfire/fenpdf/init.test:1.1
fenfire/org/fenfire/fenpdf/init.test:1.2
--- fenfire/org/fenfire/fenpdf/init.test:1.1 Wed Nov 5 05:25:50 2003
+++ fenfire/org/fenfire/fenpdf/init.test Sat Nov 8 14:45:08 2003
@@ -1,4 +1,23 @@
-# (c) Tuomas J. Lukka
+#
+# Copyright (c) 2003, Tuomas J. Lukka
+# This file is part of Fenfire.
+#
+# Fenfire is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Fenfire is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General
+# Public License along with Fenfire; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
"""Test that FenPDF can be created.
"""
Index: fenfire/org/fenfire/functional/DirectFunctional.java
diff -u fenfire/org/fenfire/functional/DirectFunctional.java:1.3
fenfire/org/fenfire/functional/DirectFunctional.java:1.4
--- fenfire/org/fenfire/functional/DirectFunctional.java:1.3 Sat Oct 18
02:06:30 2003
+++ fenfire/org/fenfire/functional/DirectFunctional.java Sat Nov 8
14:45:09 2003
@@ -28,11 +28,15 @@
import org.fenfire.util.*;
import org.fenfire.swamp.*;
import java.lang.reflect.*;
+import org.python.core.*;
/** An implementation of Functional that
* just uses direct calls.
*/
public class DirectFunctional extends Functional {
+ public static boolean dbg = false;
+ private static void p(String s) { System.out.println(s); }
+
protected final ConstGraph constGraph;
public DirectFunctional(ConstGraph constGraph) {
@@ -80,6 +84,28 @@
return o;
}
+ /** Map a parameter (that may be a wrapped FunctionInstance) to a real
+ * object for the parameter list of the Function class.
+ */
+ protected PyObject mapParameterToFunction_Jython(PyObject o) {
+ if(o instanceof PyJavaInstance) {
+ Object dfni = o.__tojava__(DirectFunctionInstance.class);
+ if(dfni != Py.NoConversion)
+ return Py.java2py(((DirectFunctionInstance)dfni).f);
+
+ Object dnfni = o.__tojava__(DirectNodeFunctionInstance.class);
+ if(dnfni != Py.NoConversion)
+ return Py.java2py(((DirectNodeFunctionInstance)dnfni).func);
+
+ if((o.__tojava__(Function.class) != Py.NoConversion) ||
+ (o.__tojava__(NodeFunction.class) != Py.NoConversion))
+ throw new Error(
+ "Can't use functions as parameters to Functional. "+o);
+
+ }
+ return o;
+ }
+
protected void instError(Exception e, Constructor constructor, Object[]
params) {
e.printStackTrace();
Class[] types = constructor.getParameterTypes();
@@ -124,6 +150,49 @@
return new DirectNodeFunctionInstance(f);
}
+ }
+
+ public FunctionInstance createFunctionInstance_Jython(
+ Object id,
+ org.python.core.PyClass functionClass,
+ org.python.core.PyObject[] parameters0
+ ) {
+ PyObject[] parameters = new PyObject[parameters0.length];
+ System.arraycopy(parameters0, 0, parameters, 0, parameters0.length);
+
+ for(int i=0; i<parameters.length; i++)
+ parameters[i] = mapParameterToFunction_Jython(parameters[i]);
+
+ PyObject instance = functionClass.__call__(parameters,
+ new String[] {});
+
+ if(dbg) p("Instance: "+instance+" "+
+ instance.__tojava__(Function.class)+" "+
+ instance.__tojava__(NodeFunction.class));
+
+ Object f = instance.__tojava__(Function.class);
+ if(f != Py.NoConversion)
+ return new DirectFunctionInstance((Function)f);
+ Object nf = instance.__tojava__(NodeFunction.class);
+ if(nf != Py.NoConversion)
+ return new DirectNodeFunctionInstance((NodeFunction)nf);
+
+
+
+ /*
+ org.python.core.PyTuple bases = functionClass.__bases__;
+ for(int i=0; i<bases.list.length; i++) {
+ Class c = (Class)bases.list[i].__tojava__(java.lang.Class.class);
+ p("BASE: "+bases.list[i]+" "+bases.list[i].getClass()+" "+
+ c+" "+c.getClass());
+
+ if(Function.class.isAssignableFrom(c)) {
+ } else if(NodeFunction.class.isAssignableFrom(c)) {
+ }
+ }
+ */
+ throw new Error("No suitable base class! "+instance+" "+
+ instance.getClass());
}
}
Index: fenfire/org/fenfire/functional/Functional.java
diff -u fenfire/org/fenfire/functional/Functional.java:1.5
fenfire/org/fenfire/functional/Functional.java:1.6
--- fenfire/org/fenfire/functional/Functional.java:1.5 Fri Oct 31 07:30:34 2003
+++ fenfire/org/fenfire/functional/Functional.java Sat Nov 8 14:45:09 2003
@@ -30,6 +30,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
+import org.python.core.*;
/** An object that manages a DAG of Function instances, enabling
* transparent and super-lazy caching.
@@ -39,7 +40,7 @@
*/
public abstract class Functional {
public static boolean dbg = false;
- private void p(String s) { System.out.println(s); }
+ static private void p(String s) { System.out.println(s); }
/** The id of the hint for which background thread group
* a function should use, if it's not run directly.
@@ -139,6 +140,45 @@
Object[] parameters
);
+ /** Create a new node in the DAG.
+ * @param id An identifier for the node. Used for determining caching &c.
+ * Should be stable between invocations.
+ * @param functionClass The class of which the Function (or NodeFunction)
+ * object should
+ * be created.
+ * @param parameters The parameters for the constructor of the class.
+ * These may contain Node objects, which will be converted
+ * to functions or nodefunctions as appropriate.
+ */
+ public abstract FunctionInstance createFunctionInstance_Jython(
+ Object id,
+ org.python.core.PyClass functionClass,
+ org.python.core.PyObject[] parameters
+ );
+
+ /*
+ * XXX I couldn't make the following work.
+ public FunctionInstance createFunctionInstance_Any(
+ Object id,
+ Object functionClass,
+ Object[] parameters) {
+ p("Any: Fcl = "+functionClass);
+ if(functionClass instanceof PyObject) {
+ p("Any: ispy");
+ PyObject[] params = new PyObject[parameters.length];
+ for(int i=0; i<params.length; i++)
+ params[i] = Py.java2py(parameters[i]);
+ return createFunctionInstance_Jython(id,
+ (PyClass)functionClass, params);
+ } else if(functionClass instanceof Class) {
+ p("Any: isj");
+ return createFunctionInstance(id,
+ (Class)functionClass, parameters);
+ }
+ throw new Error("CreateFunctionINstance...");
+ }
+ */
+
/** Helper function: Select a suitable constructor.
* Useful for createFunctionInstance.
* Goes through the constructors of functionClass and
@@ -193,6 +233,16 @@
}
}
+ if(ptypes[j].isAssignableFrom(java.lang.Boolean.TYPE)) {
+ if(parameters[j] instanceof java.lang.Boolean)
+ continue PARAMETERS;
+ }
+
+ if(ptypes[j].isAssignableFrom(java.lang.Integer.TYPE)) {
+ if(parameters[j] instanceof java.lang.Integer)
+ continue PARAMETERS;
+ }
+
if(! ptypes[j].isAssignableFrom(givenParamType)) {
if (dbg) p("DISMATCH: "+givenParamType+", "+ptypes[j]);
continue CONSTRUCTORS;
@@ -201,6 +251,41 @@
}
return constructors[i];
}
+
+ // Since we didn't find a constructor
+ // and will die, we may as well print
+ // out some useful debug info for the caller
+
+ for(int i=0; i<parameters.length; i++) {
+ p("Parameter "+i+" "+parameters[i]+" "+parameters[i].getClass());
+ }
+ for(int i=0; i<constructors.length; i++) {
+ p("Constructor "+i);
+ Class[] ptypes = constructors[i].getParameterTypes();
+ for(int j=0; j<ptypes.length; j++)
+ p(" "+ptypes[j]);
+ }
+
+ Class c = functionClass;
+ while(c != null) {
+ p("SUP: "+c);
+ c = c.getSuperclass();
+ }
+ Class[] in = functionClass.getInterfaces();
+ for(int i=0; i<in.length; i++)
+ p("IN: "+in[i]);
+
+ p("Class of class");
+ c = functionClass.getClass();
+ while(c != null) {
+ p("SUP: "+c);
+ c = c.getSuperclass();
+ }
+ in = functionClass.getClass().getInterfaces();
+ for(int i=0; i<in.length; i++)
+ p("IN: "+in[i]);
+
+
throw new Error("No constructor found: "+functionClass);
}
}
Index: fenfire/org/fenfire/functional/FunctionalTest.java
diff -u fenfire/org/fenfire/functional/FunctionalTest.java:1.5
fenfire/org/fenfire/functional/FunctionalTest.java:1.6
--- fenfire/org/fenfire/functional/FunctionalTest.java:1.5 Fri Oct 31
11:59:41 2003
+++ fenfire/org/fenfire/functional/FunctionalTest.java Sat Nov 8 14:45:09 2003
@@ -172,16 +172,32 @@
/** A class used to test mapping of integer
* and double parameters into float.
*/
- static public class floatParamClass implements Function {
- public floatParamClass(float f) { }
+ static public class ConstructorParam_float implements Function {
+ public ConstructorParam_float(float f) { }
public Object f(Object o) { return o; }
}
/** A class used to test mapping of float
* parameters into double.
*/
- static public class doubleParamClass implements Function {
- public doubleParamClass(double d) { }
+ static public class ConstructorParam_double implements Function {
+ public ConstructorParam_double(double d) { }
+ public Object f(Object o) { return o; }
+ }
+
+ /** A class used to test mapping of boolean
+ * parameters.
+ */
+ static public class ConstructorParam_boolean implements Function {
+ public ConstructorParam_boolean(boolean d) { }
+ public Object f(Object o) { return o; }
+ }
+
+ /** A class used to test mapping of int
+ * parameters.
+ */
+ static public class ConstructorParam_int implements Function {
+ public ConstructorParam_int(int d) { }
public Object f(Object o) { return o; }
}
}
Index: fenfire/org/fenfire/functional/SuperFunctional1.java
diff -u fenfire/org/fenfire/functional/SuperFunctional1.java:1.5
fenfire/org/fenfire/functional/SuperFunctional1.java:1.6
--- fenfire/org/fenfire/functional/SuperFunctional1.java:1.5 Fri Oct 31
11:59:41 2003
+++ fenfire/org/fenfire/functional/SuperFunctional1.java Sat Nov 8
14:45:09 2003
@@ -32,6 +32,8 @@
import org.nongnu.libvob.util.Background;
import java.lang.reflect.*;
import java.util.*;
+import org.python.core.*;
+
/** A first step in evolving Functional impls: single thread, superlazy.
* This class is VERY single-threaded: all calls must come from
@@ -105,6 +107,25 @@
FunctionInstance directInstance = super.createFunctionInstance(id,
functionClass,
parameters0);
+ return wrapFunctionInstance(id, directInstance);
+ }
+
+ public FunctionInstance createFunctionInstance_Jython(
+ Object id,
+ PyClass functionClass,
+ PyObject[] parameters0
+ ) {
+ if(dbg) p("CreateFunctionInstance: "+id+" "+functionClass);
+ FunctionInstance directInstance =
+ super.createFunctionInstance_Jython(id, functionClass,
+ parameters0);
+ return wrapFunctionInstance(id, directInstance);
+ }
+
+ private FunctionInstance wrapFunctionInstance(
+ Object id,
+ FunctionInstance directInstance) {
+
CacheInfo cacheInfo = (CacheInfo)cacheInfos.get(id);
if(cacheInfo == null) {
if(dbg) p("No caching - return direct instance");
@@ -131,6 +152,14 @@
if(o instanceof CachedFunctionInstance)
return ((CachedFunctionInstance)o).wrapper;
return super.mapParameterToFunction(o);
+ }
+ protected PyObject mapParameterToFunction_Jython(PyObject o) {
+ if(o instanceof PyJavaInstance) {
+ Object cfi = o.__tojava__(CachedFunctionInstance.class);
+ if(cfi != Py.NoConversion)
+ return Py.java2py(((CachedFunctionInstance)cfi).wrapper);
+ }
+ return super.mapParameterToFunction_Jython(o);
}
// Who needs to know about accesses to a cache?
Index: fenfire/org/fenfire/functional/functionaltest.py
diff -u fenfire/org/fenfire/functional/functionaltest.py:1.4
fenfire/org/fenfire/functional/functionaltest.py:1.5
--- fenfire/org/fenfire/functional/functionaltest.py:1.4 Fri Oct 31
11:59:41 2003
+++ fenfire/org/fenfire/functional/functionaltest.py Sat Nov 8 14:45:09 2003
@@ -23,10 +23,66 @@
from org import fenfire as ff
from org.fenfire.functional import FunctionalTest
+import java
def _simpleWaitEval(x):
x()
+# Test classes exactly corresponding to FunctionalTest.java
+# Use the same counters!
+# (no placeholders)
+class G0(ff.functional.PureFunction):
+ def __init__(self, str):
+ self.str = str
+ def f(self, o):
+ FunctionalTest.G0.counter += 1
+ return o + self.str
+
+class G1(ff.functional.PureFunction):
+ def __init__(self, str, func):
+ assert isinstance(func, ff.functional.Function), func
+ self.str = str
+ self.func = func
+ def f(self, o):
+ FunctionalTest.G1.counter += 1
+ fres = self.func.f(o)
+ if fres == None: fres = "null"
+ return fres + self.str
+
+class G0_Node(ff.functional.PureNodeFunction):
+ def __init__(self, str):
+ self.str = str
+ def f(self, constGraph, o):
+ FunctionalTest.G0_Node.counter += 1
+ return o + self.str
+
+class G1_Node(ff.functional.PureNodeFunction):
+ def __init__(self, str, func):
+ assert isinstance(func, ff.functional.NodeFunction), func
+ self.str = str
+ self.func = func
+ def f(self, constGraph, o):
+ FunctionalTest.G1_Node.counter += 1
+ fres = self.func.f(constGraph, o)
+ if fres == None: fres = "null"
+ return fres + self.str
+
+class TripleSet_Node(ff.functional.PureNodeFunction):
+ def __init__(self, o2):
+ self.o2 = o2
+ def f(self, constGraph, o):
+ res = java.util.HashSet()
+ iter = constGraph.findN_11X_Iter(o, self.o2)
+ while iter.hasNext():
+ res.add(iter.next())
+ return res
+
+class Identity_Node(ff.functional.PureNodeFunction):
+ def __init__(self, func):
+ assert isinstance(func, ff.functional.NodeFunction), func
+ self.func = func
+ def f(self, constGraph, o):
+ return self.func.f(constGraph, o)
def setUpFunctionalTest(theFunctional, waitEval = _simpleWaitEval):
global functional
@@ -43,7 +99,17 @@
"B",
FunctionalTest.G1,
["YYY", node0])
- return node1
+
+ node0_j = functional.createFunctionInstance_Jython(
+ "A",
+ G0,
+ ["XXX"])
+ node1_j = functional.createFunctionInstance_Jython(
+ "B",
+ G1,
+ ["YYY", node0_j])
+
+ return (node1, node1_j)
def createFunc1_error_ph(functional):
node0 = functional.createFunctionInstance(
@@ -54,7 +120,7 @@
"B",
FunctionalTest.G1,
["YYY", node0])
- return node1
+ return (node1, )
def createFunc1_Node(functional):
node0 = functional.createFunctionInstance(
@@ -65,24 +131,36 @@
"D",
FunctionalTest.G1_Node,
["YYY", node0])
- return node1
+
+ node0_j = functional.createFunctionInstance_Jython(
+ "C",
+ G0_Node,
+ ["XXX"])
+ node1_j = functional.createFunctionInstance_Jython(
+ "D",
+ G1_Node,
+ ["YYY", node0_j])
+ return (node1, node1_j)
# XXX Need to reorg for superlazy
def test_Functional_simple():
- node1 = createFunc1(functional)
- f = node1.getCallableFunction()
-
- def t():
- assert f.f("AAA") == "AAAXXXYYY", f.f("AAA")
- waitEvalFunc(t)
+ for node1 in createFunc1(functional):
+ f = node1.getCallableFunction()
+ print "Callable: ",f, f.f
+
+ def t():
+ assert f.f("AAA") == "AAAXXXYYY", f.f("AAA")
+ waitEvalFunc(t)
def test_Functional_simpleNode():
- node1 = createFunc1_Node(functional)
- f = node1.getCallableFunction()
+ for node1 in createFunc1_Node(functional):
+ f = node1.getCallableFunction()
+ print "SimpleNode: callable:",node1, f, f.f
+
+ def t():
+ assert f.f("AAA") == "AAAXXXYYY", f.f("AAA")
+ waitEvalFunc(t)
- def t():
- assert f.f("AAA") == "AAAXXXYYY", f.f("AAA")
- waitEvalFunc(t)
# map java.lang.integer and java.lang.double into float
@@ -93,7 +171,7 @@
"""
foobar = functional.createFunctionInstance(
"integer2float",
- FunctionalTest.floatParamClass,
+ FunctionalTest.ConstructorParam_float,
[1])
def test_Functional_param_double2float():
@@ -103,7 +181,7 @@
"""
foobar = functional.createFunctionInstance(
"double2float",
- FunctionalTest.floatParamClass,
+ FunctionalTest.ConstructorParam_float,
[1.])
# map java.lang.Float into double
@@ -112,8 +190,29 @@
A method used to test mapping of float
parameters into double.
"""
- import java
foobar = functional.createFunctionInstance(
"float2double",
- FunctionalTest.doubleParamClass,
+ FunctionalTest.ConstructorParam_double,
[java.lang.Float(1.)])
+
+
+
+def test_Functional_param_boolean():
+ """Test that boolean params work right.
+ """
+ foobar = functional.createFunctionInstance(
+ "Boolean2boolean",
+ FunctionalTest.ConstructorParam_boolean,
+ [java.lang.Boolean(1)])
+
+
+
+def test_Functional_param_int():
+ """Test that int params work right.
+ """
+ foobar = functional.createFunctionInstance(
+ "int2int",
+ FunctionalTest.ConstructorParam_int,
+ [java.lang.Integer(1)])
+
+
Index: fenfire/org/fenfire/functional/superfunctional1.test
diff -u fenfire/org/fenfire/functional/superfunctional1.test:1.4
fenfire/org/fenfire/functional/superfunctional1.test:1.5
--- fenfire/org/fenfire/functional/superfunctional1.test:1.4 Fri Oct 31
11:59:41 2003
+++ fenfire/org/fenfire/functional/superfunctional1.test Sat Nov 8
14:45:09 2003
@@ -48,20 +48,20 @@
functional.cache("A", 100, 0)
- node1 = createFunc1(functional)
- f = node1.getCallableFunction()
- FunctionalTest.G0.counter = 0
- FunctionalTest.G1.counter = 0
-
- assert f.f("A") == "AXXXYYY"
- assert f.f("B") == "BXXXYYY"
- assert f.f("A") == "AXXXYYY"
- assert f.f("C") == "CXXXYYY"
- assert f.f("B") == "BXXXYYY"
-
- assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 5, FunctionalTest.G1.counter
-
+ for node1 in createFunc1(functional):
+ f = node1.getCallableFunction()
+ FunctionalTest.G0.counter = 0
+ FunctionalTest.G1.counter = 0
+
+ assert f.f("A") == "AXXXYYY"
+ assert f.f("B") == "BXXXYYY"
+ assert f.f("A") == "AXXXYYY"
+ assert f.f("C") == "CXXXYYY"
+ assert f.f("B") == "BXXXYYY"
+
+ assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 5, FunctionalTest.G1.counter
+
def testSuperlazy1():
background = vob.util.ExplicitBackground()
@@ -69,30 +69,30 @@
functional.cache("A", 100, 1)
- node1 = createFunc1(functional)
- f = node1.getCallableFunction()
- FunctionalTest.G0.counter = 0
- FunctionalTest.G1.counter = 0
-
- failUnlessEqual( f.f("A") , "nullYYY")
- failUnlessEqual( f.f("B") , "nullYYY")
- failUnlessEqual( f.f("A") , "nullYYY")
- failUnlessEqual( f.f("C") , "nullYYY")
- failUnlessEqual( f.f("B") , "nullYYY")
-
- assert FunctionalTest.G0.counter == 0, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 5, FunctionalTest.G1.counter
-
- for i in range(0, 5): background.performOneTask()
-
- failUnlessEqual( f.f("A") , "AXXXYYY")
- failUnlessEqual( f.f("B") , "BXXXYYY")
- failUnlessEqual( f.f("A") , "AXXXYYY")
- failUnlessEqual( f.f("C") , "CXXXYYY")
- failUnlessEqual( f.f("B") , "BXXXYYY")
+ for node1 in createFunc1(functional):
+ f = node1.getCallableFunction()
+ FunctionalTest.G0.counter = 0
+ FunctionalTest.G1.counter = 0
+
+ failUnlessEqual( f.f("A") , "nullYYY")
+ failUnlessEqual( f.f("B") , "nullYYY")
+ failUnlessEqual( f.f("A") , "nullYYY")
+ failUnlessEqual( f.f("C") , "nullYYY")
+ failUnlessEqual( f.f("B") , "nullYYY")
+
+ assert FunctionalTest.G0.counter == 0, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 5, FunctionalTest.G1.counter
+
+ for i in range(0, 5): background.performOneTask()
+
+ failUnlessEqual( f.f("A") , "AXXXYYY")
+ failUnlessEqual( f.f("B") , "BXXXYYY")
+ failUnlessEqual( f.f("A") , "AXXXYYY")
+ failUnlessEqual( f.f("C") , "CXXXYYY")
+ failUnlessEqual( f.f("B") , "BXXXYYY")
- assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 10, FunctionalTest.G1.counter
+ assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 10, FunctionalTest.G1.counter
def testSuperlazy1_placeholder_error():
@@ -101,32 +101,32 @@
functional.cache("A", 100, 1)
- node1 = createFunc1_error_ph(functional)
- f = node1.getCallableFunction()
- FunctionalTest.G0.counter = 0
- FunctionalTest.G1.counter = 0
-
- failUnlessEqual( f.f("A") , "FOOYYY")
- failUnlessEqual( f.f("B") , "FOOYYY")
- failUnlessEqual( f.f("A") , "FOOYYY")
- failUnlessEqual( f.f("E") , "FOOYYY")
- failUnlessEqual( f.f("B") , "FOOYYY")
-
- assert FunctionalTest.G0.counter == 0, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 5, FunctionalTest.G1.counter
-
- for i in range(0, 5): background.performOneTask()
-
- failUnlessEqual( f.f("A") , "AXXXYYY")
- failUnlessEqual( f.f("B") , "BXXXYYY")
- failUnlessEqual( f.f("A") , "AXXXYYY")
- failUnlessEqual( f.f("E") , "ERRORYYY")
- failUnlessEqual( f.f("B") , "BXXXYYY")
- failUnlessEqual( f.f("E") , "ERRORYYY")
- failUnlessEqual( f.f("E") , "ERRORYYY")
+ for node1 in createFunc1_error_ph(functional):
+ f = node1.getCallableFunction()
+ FunctionalTest.G0.counter = 0
+ FunctionalTest.G1.counter = 0
+
+ failUnlessEqual( f.f("A") , "FOOYYY")
+ failUnlessEqual( f.f("B") , "FOOYYY")
+ failUnlessEqual( f.f("A") , "FOOYYY")
+ failUnlessEqual( f.f("E") , "FOOYYY")
+ failUnlessEqual( f.f("B") , "FOOYYY")
+
+ assert FunctionalTest.G0.counter == 0, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 5, FunctionalTest.G1.counter
+
+ for i in range(0, 5): background.performOneTask()
+
+ failUnlessEqual( f.f("A") , "AXXXYYY")
+ failUnlessEqual( f.f("B") , "BXXXYYY")
+ failUnlessEqual( f.f("A") , "AXXXYYY")
+ failUnlessEqual( f.f("E") , "ERRORYYY")
+ failUnlessEqual( f.f("B") , "BXXXYYY")
+ failUnlessEqual( f.f("E") , "ERRORYYY")
+ failUnlessEqual( f.f("E") , "ERRORYYY")
- assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 12, FunctionalTest.G1.counter
+ assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 12, FunctionalTest.G1.counter
def testSuperlazy1_lowercache():
@@ -136,30 +136,30 @@
functional.cache("A", 100, 1)
functional.cache("B", 100, 0)
- node1 = createFunc1(functional)
- f = node1.getCallableFunction()
- FunctionalTest.G0.counter = 0
- FunctionalTest.G1.counter = 0
-
- failUnlessEqual( f.f("A") , "nullYYY")
- failUnlessEqual( f.f("B") , "nullYYY")
- failUnlessEqual( f.f("A") , "nullYYY")
- failUnlessEqual( f.f("C") , "nullYYY")
- failUnlessEqual( f.f("B") , "nullYYY")
-
- assert FunctionalTest.G0.counter == 0, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 3, FunctionalTest.G1.counter
-
- for i in range(0, 5): background.performOneTask()
-
- failUnlessEqual( f.f("A") , "AXXXYYY")
- failUnlessEqual( f.f("B") , "BXXXYYY")
- failUnlessEqual( f.f("A") , "AXXXYYY")
- failUnlessEqual( f.f("C") , "CXXXYYY")
- failUnlessEqual( f.f("B") , "BXXXYYY")
+ for node1 in createFunc1(functional):
+ f = node1.getCallableFunction()
+ FunctionalTest.G0.counter = 0
+ FunctionalTest.G1.counter = 0
+
+ failUnlessEqual( f.f("A") , "nullYYY")
+ failUnlessEqual( f.f("B") , "nullYYY")
+ failUnlessEqual( f.f("A") , "nullYYY")
+ failUnlessEqual( f.f("C") , "nullYYY")
+ failUnlessEqual( f.f("B") , "nullYYY")
+
+ assert FunctionalTest.G0.counter == 0, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 3, FunctionalTest.G1.counter
+
+ for i in range(0, 5): background.performOneTask()
+
+ failUnlessEqual( f.f("A") , "AXXXYYY")
+ failUnlessEqual( f.f("B") , "BXXXYYY")
+ failUnlessEqual( f.f("A") , "AXXXYYY")
+ failUnlessEqual( f.f("C") , "CXXXYYY")
+ failUnlessEqual( f.f("B") , "BXXXYYY")
- assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
- assert FunctionalTest.G1.counter == 6, FunctionalTest.G1.counter
+ assert FunctionalTest.G0.counter == 3, FunctionalTest.G0.counter
+ assert FunctionalTest.G1.counter == 6, FunctionalTest.G1.counter
def testSuperlazy2_graphtwid():
background = vob.util.ExplicitBackground()
@@ -236,4 +236,4 @@
-
+# vim: set syntax=python :
Index: fenfire/org/fenfire/spanimages/SpanImageFactory.java
diff -u fenfire/org/fenfire/spanimages/SpanImageFactory.java:1.7
fenfire/org/fenfire/spanimages/SpanImageFactory.java:1.8
--- fenfire/org/fenfire/spanimages/SpanImageFactory.java:1.7 Wed Nov 5
05:25:52 2003
+++ fenfire/org/fenfire/spanimages/SpanImageFactory.java Sat Nov 8
14:45:09 2003
@@ -27,7 +27,7 @@
package org.fenfire.spanimages;
import org.fenfire.spanimages.gl.*;
import org.nongnu.alph.*;
-import org.fenfire.functional.Function;
+import org.fenfire.functional.PureFunction;
/** The central interface for creating vobs that contain
* images of ImageSpans.
@@ -39,7 +39,7 @@
* if the imagespan contains raster data, or 75 pixels per inch, if
* the imagespan contains vector data.
*/
-public abstract class SpanImageFactory implements Function {
+public abstract class SpanImageFactory implements PureFunction {
private static SpanImageFactory instance;
/** (For tests, mostly) Get a reasonable instance
Index: fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java
diff -u fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java:1.13
fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java:1.14
--- fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java:1.13 Wed Nov
5 05:25:52 2003
+++ fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java Sat Nov
8 14:45:09 2003
@@ -26,6 +26,9 @@
package org.fenfire.spanimages.gl;
import org.fenfire.spanimages.*;
+import org.fenfire.util.Pair;
+import org.fenfire.functional.PureFunction;
+import org.fenfire.functional.Function;
import org.nongnu.alph.*;
import org.nongnu.libvob.*;
import org.nongnu.libvob.gl.*;
@@ -42,11 +45,11 @@
private static void p(String s) {
System.out.println("DefaultSpanImageFactory: "+s); }
- public PaperMaker paperMaker ;
+ public Function paperMaker ;
public ScrollBlockImager scrollBlockImager;
public DefaultSpanImageFactory(ScrollBlockImager imager,
- PaperMaker paperMaker) {
+ Function paperMaker) {
this.scrollBlockImager = imager;
this.paperMaker = paperMaker;
}
@@ -114,7 +117,7 @@
if(dbg) p("Texgen quants: "+xscale+" "+yscale+" "+xoffs+" "+yoffs);
if(dbg) p("sizes: "+ps.width+" "+ps.height+" "+d.width+" "+d.height);
- Paper paper = paperMaker.makePaper(singleImage, texgen);
+ Paper paper = (Paper)paperMaker.f(new Pair(singleImage, texgen));
return PoolManager.getInstance().makeVob(
singleImage,
Index: fenfire/org/fenfire/spanimages/gl/PaperMaker.java
diff -u fenfire/org/fenfire/spanimages/gl/PaperMaker.java:1.2
fenfire/org/fenfire/spanimages/gl/PaperMaker.java:1.3
--- fenfire/org/fenfire/spanimages/gl/PaperMaker.java:1.2 Mon Jun 23
08:30:42 2003
+++ fenfire/org/fenfire/spanimages/gl/PaperMaker.java Sat Nov 8 14:45:09 2003
@@ -28,7 +28,34 @@
import java.io.File;
import org.nongnu.libvob.gl.*;
import org.nongnu.libvob.memory.*;
+import org.fenfire.functional.PureFunction;
+import org.fenfire.util.Pair;
-public interface PaperMaker {
- Paper makePaper(SingleImage img, float[] texgen);
+/** A function that, given a singleimage and a texgen,
+ * return a org.nongnu.libvob.gl.Paper.
+ * Because this is a dyadic function, the makePaper() call
+ * is also provided separately. The calls
+ *
+ * c = paperMaker.makePaper(a, b);
+ *
+ * and
+ * c = (Paper) paperMaker.f(new Pair(a,b));
+ *
+ * are equivalent.
+ * <p>
+ * The different implementations of this class can choose
+ * to use different ways to filter the texture, different
+ * backgrounds (using libpaper) etc.
+ */
+public abstract class PaperMaker implements PureFunction {
+
+ /** Make a Paper object which contains the texture
+ * in the given SingleImage, with the given texgen.
+ */
+ public abstract Paper makePaper(SingleImage img, float[] texgen);
+
+ public Object f(Object o) {
+ Pair p = (Pair)o;
+ return makePaper((SingleImage)p.first, (float[])p.second);
+ }
}
Index: fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java
diff -u fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java:1.11
fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java:1.12
--- fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java:1.11 Fri Oct 17
05:25:34 2003
+++ fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java Sat Nov 8
14:45:09 2003
@@ -25,7 +25,6 @@
*/
package org.fenfire.spanimages.gl;
-import java.io.File;
import org.nongnu.libvob.*;
import org.nongnu.libvob.gl.*;
import org.nongnu.libvob.memory.*;
@@ -35,7 +34,7 @@
* This PaperMaker loads the texture into n of the first texunits
* and executes the given callgl code.
*/
-public class PlainPaperMaker implements PaperMaker {
+public class PlainPaperMaker extends PaperMaker {
int n;
@@ -63,6 +62,7 @@
* @param teardown The teardown code
* @param depends The objects that mustn't be reclaimed by the GC
* before the papers.
+ * For instance, OpenGL programs or display lists.
*/
public PlainPaperMaker(int n, String setup, String teardown,
Object depends) {
@@ -78,6 +78,7 @@
* @param teardown The teardown code
* @param depends The objects that mustn't be reclaimed by the GC
* before the papers.
+ * For instance, OpenGL programs or display lists.
* @param papermill The papermill to use to make the optimized background
paper
*/
public PlainPaperMaker(int n, String setup, String teardown,
Index: fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java
diff -u fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java:1.5
fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java:1.6
--- fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java:1.5 Wed Nov
5 05:25:52 2003
+++ fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java Sat Nov 8
14:45:09 2003
@@ -28,11 +28,14 @@
import java.io.File;
import org.nongnu.alph.*;
-/** Base class for the classes holding scrollblock images.
- * Contains some necessary trappings.
+/** Base class for the classes that create scrollblock images.
* The getSingleImage method should only be called with
* entire image spans, i.e. objects obtained
* from imageSpan.getSuperImageSpan(), to allow proper caching.
+ * <p>
+ * This class contains some necessary trappings for handling the temporary
+ * images: the temporary directory and a method to munge strings
+ * to fit the filesystem.
*/
public abstract class ScrollBlockImager {
/** The directory to store the cached images in (in mipzip format).
Index: fenfire/org/fenfire/spanimages/gl/papermakers.py
diff -u fenfire/org/fenfire/spanimages/gl/papermakers.py:1.16
fenfire/org/fenfire/spanimages/gl/papermakers.py:1.17
--- fenfire/org/fenfire/spanimages/gl/papermakers.py:1.16 Wed Nov 5
05:25:52 2003
+++ fenfire/org/fenfire/spanimages/gl/papermakers.py Sat Nov 8 14:45:09 2003
@@ -31,6 +31,10 @@
# A list of paper makers, as tuples:
# (function, description)
#
+# The function returns the suitable parameters for
+# Functional.createFunctionInstance, i.e.
+# type and list of parameters.
+#
# Separated by whether the fancy bg is shown or not.
#
# The function is set to None for those that are
@@ -62,12 +66,12 @@
def white(w = None, paperMill = None, paperOffset = 0,
filter = ""):
- return PlainPaperMaker(1, """
+ return (PlainPaperMaker, [1, """
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE
Enable TEXTURE_2D
Disable BLEND
""" + filter, """
- """, None)
+ """, None])
whitePaperMakers.append( (white, "White background") )
@@ -127,7 +131,7 @@
if paperMill == None:
paperMill = PaperMill.getInstance()
- return PlainPaperMaker(2, """
+ return (PlainPaperMaker, [2, """
BindProgram FRAGMENT_PROGRAM_NV %s
ActiveTexture TEXTURE2
TexEnv TEXTURE_FILTER_CONTROL TEXTURE_LOD_BIAS 3.8
@@ -140,7 +144,7 @@
ActiveTexture TEXTURE2
TexEnv TEXTURE_FILTER_CONTROL TEXTURE_LOD_BIAS 0
ActiveTexture TEXTURE0
- """, [nvBlurProgram], paperMill)
+ """, [nvBlurProgram], paperMill])
if nvBlurProgram:
b = nvFancyBlur
@@ -193,14 +197,14 @@
if paperMill == None:
paperMill = PaperMill.getInstance()
- return PlainPaperMaker(1, """
+ return (PlainPaperMaker, [1, """
BindProgram FRAGMENT_PROGRAM_ARB %s
Enable FRAGMENT_PROGRAM_ARB
Disable REGISTER_COMBINERS_NV
Disable BLEND
""" % blurProgram.getProgId(),
"""
- """, [blurProgram], paperMill)
+ """, [blurProgram], paperMill])
if blurProgram:
b = fancyBlur
@@ -277,7 +281,7 @@
return fancyBlend(paperMill)
if paperMill == None:
paperMill = PaperMill.getInstance()
- return HaloPaperMaker_2tex(paperMill)
+ return (HaloPaperMaker_2tex, [paperMill])
if GL.hasExtension("GL_NV_register_combiners"):
b = fancyHalo
@@ -289,7 +293,7 @@
def fancyBlend(paperMill = None, paperOffset = 0,
filter = ""):
paperMill = getPaperMill(paperMill, paperOffset)
- return PlainPaperMaker(1,
+ return (PlainPaperMaker, [1,
"""
ActiveTexture TEXTURE0
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE
@@ -300,7 +304,7 @@
%s
Disable BLEND
ActiveTexture TEXTURE0
- """ % filter, "", None, paperMill)
+ """ % filter, "", None, paperMill])
fancyPaperMakers.append( (fancyBlend, "No enhancement, Just rendering text on
top of Bg (Not recommended)") )
Index: fenfire/org/fenfire/util/PaperMillFunction.java
diff -u fenfire/org/fenfire/util/PaperMillFunction.java:1.3
fenfire/org/fenfire/util/PaperMillFunction.java:1.4
--- fenfire/org/fenfire/util/PaperMillFunction.java:1.3 Fri Oct 31 07:30:35 2003
+++ fenfire/org/fenfire/util/PaperMillFunction.java Sat Nov 8 14:45:09 2003
@@ -28,15 +28,24 @@
import org.nongnu.libvob.gl.PaperMill;
import org.nongnu.libvob.gl.SpecialPapers;
import org.fenfire.functional.Function;
+import org.fenfire.functional.PureFunction;
import org.fenfire.functional.Functional;
/** Adapt a PaperMill into the Function API.
* Input: any object. Output an org.nongnu.libvob.gl.Paper object
* based on the hashcode of the object.
*/
-public class PaperMillFunction implements Function {
- private boolean useOptimized;
- private PaperMill paperMill;
+public class PaperMillFunction implements PureFunction {
+ /** Whether we should request optimized papers from the papermill.
+ */
+ private final boolean useOptimized;
+ /** The offset to add to the hashcode.
+ */
+ private final int offset;
+
+ /** The papermill to use.
+ */
+ private final PaperMill paperMill;
static public Functional.Hints functionalHints =
(new Functional.HintsMaker())
@@ -44,9 +53,27 @@
.setHint(Functional.HINT_PLACEHOLDER, null)
.make();
+ /** Create a new PaperMillFunction.
+ * @param paperMill The papermill to use
+ * @param useOptimized Whether to return optimized or non-optimized
+ * papers from the papermill
+ */
public PaperMillFunction(PaperMill paperMill, boolean useOptimized) {
+ this(paperMill, useOptimized, 0);
+ }
+
+ /** Create a new PaperMillFunction.
+ * @param paperMill The papermill to use
+ * @param useOptimized Whether to return optimized or non-optimized
+ * papers from the papermill
+ * @param offset The offset to add to the hashCode before calling
+ * getPaper or getOptimizedPaper.
+ */
+ public PaperMillFunction(PaperMill paperMill, boolean useOptimized,
+ int offset) {
this.paperMill = paperMill;
this.useOptimized = useOptimized;
+ this.offset = offset;
}
public Object f(Object input) {
Index: fenfire/org/fenfire/view/PaperView2D.java
diff -u fenfire/org/fenfire/view/PaperView2D.java:1.22
fenfire/org/fenfire/view/PaperView2D.java:1.23
--- fenfire/org/fenfire/view/PaperView2D.java:1.22 Wed Nov 5 05:25:53 2003
+++ fenfire/org/fenfire/view/PaperView2D.java Sat Nov 8 14:45:09 2003
@@ -27,6 +27,7 @@
package org.fenfire.view;
import org.nongnu.libvob.*;
import org.nongnu.libvob.gl.*;
+import org.fenfire.functional.Function;
/** A paper background for View2D.
* For the render call, make sure the plane object
@@ -39,12 +40,13 @@
public static boolean dbg = false;
private static void pa(String s) { System.out.println("PaperView2D::"+s); }
- public PaperMill paperMill;
public float dicefactor = 1;
public int flags = 0;
public float paperScaling = .5f;
+ private Function paperMill;
+
// implement
public void chgFast(VobScene vs,
Object plane,
@@ -60,10 +62,21 @@
}
protected View2D child;
- public PaperView2D() {
- this(null);
+ /** Create a new PaperView2D.
+ * @param paperMill A function; input: the plane object, output:
+ * a org.nongnu.libvob.gl.Paper object.
+ */
+ public PaperView2D(Function paperMill) {
+ this(paperMill, null);
}
- public PaperView2D(View2D child) {
+ /** Create a new PaperView2D.
+ * @param paperMill A function; input: the plane object, output:
+ * a org.nongnu.libvob.gl.Paper object.
+ * @param child The view to render inside this.
+ * XXX View2DList should take care of this already.
+ */
+ public PaperView2D(Function paperMill, View2D child) {
+ this.paperMill = paperMill;
this.child = child;
}
@@ -82,12 +95,8 @@
)
{
if (dbg) pa("begin render");
- if(paperMill == null)
- paperMill = PaperMill.getInstance();
- int seed = plane.hashCode();
-
- Paper p = paperMill.getOptimizedPaper(seed) ;
+ Paper p = (Paper)paperMill.f(plane) ;
org.nongnu.libvob.Vob v = GLRen.createEasyPaperQuad(p, dicefactor,
flags);
int magnified = box2paper;
Index: fenfire/org/fenfire/view/TextNodeView.test
diff -u fenfire/org/fenfire/view/TextNodeView.test:1.11
fenfire/org/fenfire/view/TextNodeView.test:1.12
--- fenfire/org/fenfire/view/TextNodeView.test:1.11 Sat Oct 18 02:06:31 2003
+++ fenfire/org/fenfire/view/TextNodeView.test Sat Nov 8 14:45:10 2003
@@ -45,7 +45,9 @@
textnodeview = ff.view.TextNodeView(contentFunction, textstyle)
view = ff.view.CanvasView2D(fen, textnodeview)
view.cull = 1
- paperview = ff.view.PaperView2D(view)
+ paperview = ff.view.PaperView2D(
+ ff.util.PaperMillFunction(vob.gl.PaperMill.getInstance(), 1),
+ view)
note = ff.swamp.Nodes.N()
paper = ff.util.RDFUtil.N(fen.graph, ff.vocab.CANVAS2D.Canvas)
Index: fenfire/org/fenfire/view/irregularviewport.test
diff -u fenfire/org/fenfire/view/irregularviewport.test:1.4
fenfire/org/fenfire/view/irregularviewport.test:1.5
--- fenfire/org/fenfire/view/irregularviewport.test:1.4 Tue Aug 5 05:54:18 2003
+++ fenfire/org/fenfire/view/irregularviewport.test Sat Nov 8 14:45:10 2003
@@ -22,7 +22,7 @@
import java
import vob
-from org import fenfire
+from org import fenfire as ff
from org.nongnu import alph
from org.nongnu import storm
from org.fenfire.test import gfx
@@ -33,8 +33,10 @@
vs = gfx.getvs()
vs.map.put(vob.vobs.SolidBackdropVob(java.awt.Color.black))
- childv2d = fenfire.view.PaperView2D()
- v2d = fenfire.view.IrregularViewportView2D(childv2d)
+ childv2d = ff.view.PaperView2D(
+ ff.util.PaperMillFunction(vob.gl.PaperMill.getInstance(), 1)
+ )
+ v2d = ff.view.IrregularViewportView2D(childv2d)
v2d.debugFlags = v2d.DEBUG_CONTENT
v2d.ripple = 300
Index: fenfire/org/fenfire/view/papercanvas2d.test
diff -u fenfire/org/fenfire/view/papercanvas2d.test:1.17
fenfire/org/fenfire/view/papercanvas2d.test:1.18
--- fenfire/org/fenfire/view/papercanvas2d.test:1.17 Wed Nov 5 05:25:53 2003
+++ fenfire/org/fenfire/view/papercanvas2d.test Sat Nov 8 14:45:10 2003
@@ -34,12 +34,6 @@
from org.fenfire.test.gfx import *
-class DummyMill(vob.gl.PaperMill):
- def __init__(self, pap):
- self.pap = pap
- def getPaper(self, seed):
- return self.pap
-
def testRenderClick():
"""Test that rendering a canvas works right and
that we get a click.
@@ -71,10 +65,11 @@
canvasView2D = ff.view.CanvasView2D(fen, textnodeview)
- paperView2D = ff.view.PaperView2D(canvasView2D)
- paperView2D.paperMill = DummyMill(
- vob.gl.SpecialPapers.solidPaper(Color.yellow)
- )
+ paperView2D = ff.view.PaperView2D(
+ ff.functional.ConstantFunction(
+ vob.gl.SpecialPapers.solidPaper(Color.yellow)
+ ),
+ canvasView2D)
paperView2D.paperScaling = 1
irregu2D = ff.view.IrregularViewportView2D(paperView2D)
Index: fenfire/org/fenfire/view/paperview2d.test
diff -u fenfire/org/fenfire/view/paperview2d.test:1.5
fenfire/org/fenfire/view/paperview2d.test:1.6
--- fenfire/org/fenfire/view/paperview2d.test:1.5 Tue Aug 5 05:54:18 2003
+++ fenfire/org/fenfire/view/paperview2d.test Sat Nov 8 14:45:10 2003
@@ -22,7 +22,7 @@
import java
import vob
-from org import fenfire
+from org import fenfire as ff
from org.nongnu import alph
from org.nongnu import storm
from org.fenfire.test import gfx
@@ -33,7 +33,8 @@
vs = gfx.getvs()
vs.map.put(vob.vobs.SolidBackdropVob(java.awt.Color.black))
- v2d = fenfire.view.PaperView2D()
+ v2d = ff.view.PaperView2D(
+ ff.util.PaperMillFunction(vob.gl.PaperMill.getInstance(), 1))
b2s = vs.orthoCS(0, "A", 0, 100, 100, 100, 100)
v2d.render(vs, "A", 0, b2s, 0)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ff-cvs] fenfire/org/fenfire fenpdf/fenpdftestutil.py fe...,
Tuomas J. Lukka <=