You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2006/05/18 14:44:16 UTC

svn commit: r407541 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/area/ src/java/org/apache/fop/layoutmgr/ src/java/org/apache/fop/render/xml/ src/java/org/apache/fop/util/ src/sandbox/META-INF/services/ src/sandbox/org/apache/fop/render/pcl/ te...

Author: jeremias
Date: Thu May 18 05:44:15 2006
New Revision: 407541

URL: http://svn.apache.org/viewvc?rev=407541&view=rev
Log:
Extended PageViewport to carry foreign attributes.
Foreign attributes from simple-page-master are transferred to the PageViewport.
Added foreign attributes handling in AreaTreeParser.
Fixed proper generation of foreign attributes in XMLRenderer.
EvalCheck extended so it can use namespace prefix mappings in its context.
Test case for foreign attributes.

Paper source/tray support for PCL (pcl:paper-source="<tray-code>" on s-p-m)

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeObject.java   (with props)
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Area.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Page.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/PageViewport.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/QName.java
    xmlgraphics/fop/trunk/src/sandbox/META-INF/services/org.apache.fop.fo.ElementMapping
    xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java
    xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Area.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Area.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Area.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Area.java Thu May 18 05:44:15 2006
@@ -19,15 +19,11 @@
 package org.apache.fop.area;
 
 import java.io.Serializable;
-
-import java.util.Collections;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.traits.BorderProps;
-import org.apache.fop.util.QName;
 
 // If the area appears more than once in the output
 // or if the area has external data it is cached
@@ -40,7 +36,7 @@
 /**
  * Base object for all areas.
  */
-public class Area implements Serializable {
+public class Area extends AreaTreeObject implements Serializable {
     // stacking directions
     /**
      * Stacking left to right
@@ -132,9 +128,6 @@
      */
     protected Map props = null;
 
-    /** Foreign attributes */
-    protected Map foreignAttributes = null;
-    
     /**
      * logging instance
      */
@@ -459,57 +452,6 @@
             throw new IllegalArgumentException("Trait "
                     + oTraitCode.getClass().getName()
                     + " could not be converted to an integer");
-        }
-    }
-    
-    /**
-     * Sets a foreign attribute.
-     * @param name the qualified name of the attribute
-     * @param value the attribute value
-     */
-    public void setForeignAttribute(QName name, String value) {
-        if (this.foreignAttributes == null) {
-            this.foreignAttributes = new java.util.HashMap();
-        }
-        this.foreignAttributes.put(name, value);
-    }
-    
-    /**
-     * Set foreign attributes from a Map.
-     * @param atts a Map with attributes (keys: QName, values: String)
-     */
-    public void setForeignAttributes(Map atts) {
-        if (atts.size() == 0) {
-            return;
-        }
-        Iterator iter = atts.keySet().iterator();
-        while (iter.hasNext()) {
-            QName qName = (QName)iter.next();
-            String value = (String)atts.get(qName);
-            //The casting is only to ensure type safety (too bad we can't use generics, yet) 
-            setForeignAttribute(qName, value);
-        }
-    }
-    
-    /**
-     * Returns the value of a foreign attribute on the area.
-     * @param name the qualified name of the attribute
-     * @return the attribute value or null if it isn't set
-     */
-    public String getForeignAttributeValue(QName name) {
-        if (this.foreignAttributes != null) {
-            return (String)this.foreignAttributes.get(name);
-        } else {
-            return null;
-        }
-    }
-    
-    /** @return the foreign attributes associated with this area */
-    public Map getForeignAttributes() {
-        if (this.foreignAttributes != null) {
-            return Collections.unmodifiableMap(this.foreignAttributes);
-        } else {
-            return Collections.EMPTY_MAP;
         }
     }
     

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeObject.java?rev=407541&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeObject.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeObject.java Thu May 18 05:44:15 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.area;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.fop.util.QName;
+
+/**
+ * Abstract base class for all area tree objects.
+ */
+public abstract class AreaTreeObject {
+
+    /** Foreign attributes */
+    protected Map foreignAttributes = null;
+    
+    /**
+     * Sets a foreign attribute.
+     * @param name the qualified name of the attribute
+     * @param value the attribute value
+     */
+    public void setForeignAttribute(QName name, String value) {
+        if (this.foreignAttributes == null) {
+            this.foreignAttributes = new java.util.HashMap();
+        }
+        this.foreignAttributes.put(name, value);
+    }
+    
+    /**
+     * Set foreign attributes from a Map.
+     * @param atts a Map with attributes (keys: QName, values: String)
+     */
+    public void setForeignAttributes(Map atts) {
+        if (atts.size() == 0) {
+            return;
+        }
+        Iterator iter = atts.keySet().iterator();
+        while (iter.hasNext()) {
+            QName qName = (QName)iter.next();
+            String value = (String)atts.get(qName);
+            //The casting is only to ensure type safety (too bad we can't use generics, yet) 
+            setForeignAttribute(qName, value);
+        }
+    }
+    
+    /**
+     * Returns the value of a foreign attribute on the area.
+     * @param name the qualified name of the attribute
+     * @return the attribute value or null if it isn't set
+     */
+    public String getForeignAttributeValue(QName name) {
+        if (this.foreignAttributes != null) {
+            return (String)this.foreignAttributes.get(name);
+        } else {
+            return null;
+        }
+    }
+    
+    /** @return the foreign attributes associated with this area */
+    public Map getForeignAttributes() {
+        if (this.foreignAttributes != null) {
+            return Collections.unmodifiableMap(this.foreignAttributes);
+        } else {
+            return Collections.EMPTY_MAP;
+        }
+    }
+    
+    
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java Thu May 18 05:44:15 2006
@@ -63,6 +63,7 @@
 import org.apache.fop.util.ContentHandlerFactory;
 import org.apache.fop.util.ContentHandlerFactoryRegistry;
 import org.apache.fop.util.DefaultErrorListener;
+import org.apache.fop.util.QName;
 import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
 import org.xml.sax.Attributes;
@@ -336,6 +337,7 @@
 
             public void startElement(Attributes attributes) {
                 LineArea line = new LineArea();
+                transferForeignObjects(attributes, line);
                 areaStack.push(line);
             }
 
@@ -367,6 +369,7 @@
                 currentPageViewport = new PageViewport(viewArea, 
                         pageNumber, pageNumberString,
                         pageMaster, blank);
+                transferForeignObjects(attributes, currentPageViewport);
                 currentPageViewport.setKey(key);
             }
 
@@ -394,6 +397,7 @@
                 }
                 Rectangle2D viewArea = parseRect(attributes.getValue("rect"));
                 rv = new RegionViewport(viewArea);
+                transferForeignObjects(attributes, rv);
                 rv.setClip(getAttributeAsBoolean(attributes, "clipped", false));
                 setAreaAttributes(attributes, rv);
                 setTraits(attributes, rv, SUBSET_COMMON);
@@ -464,6 +468,7 @@
                 RegionViewport rv = getCurrentRegionViewport();
                 body = new BodyRegion(Constants.FO_REGION_BODY, 
                         regionName, rv, columnCount, columnGap);
+                transferForeignObjects(attributes, body);
                 body.setCTM(getAttributeAsCTM(attributes, "ctm"));
                 setAreaAttributes(attributes, body);
                 rv.setRegionReference(body);
@@ -487,6 +492,7 @@
                     firstFlow = false;
                 }
                 NormalFlow flow = body.getMainReference().getCurrentSpan().getCurrentFlow();
+                transferForeignObjects(attributes, flow);
                 setAreaAttributes(attributes, flow);
                 areaStack.push(flow);
             }
@@ -500,7 +506,9 @@
 
             public void startElement(Attributes attributes) {
                 //mainReference is created by the BodyRegion
-                setAreaAttributes(attributes, getCurrentBodyRegion().getMainReference());
+                MainReference mr = getCurrentBodyRegion().getMainReference();
+                transferForeignObjects(attributes, mr);
+                setAreaAttributes(attributes, mr);
             }
         }
 
@@ -512,6 +520,7 @@
                 BodyRegion body = getCurrentBodyRegion();
                 Span span = new Span(columnCount, 
                         body.getColumnGap(), ipd);
+                transferForeignObjects(attributes, span);
                 setAreaAttributes(attributes, span);
                 body.getMainReference().getSpans().add(span);
                 firstFlow = true;
@@ -521,7 +530,9 @@
         private class FootnoteMaker extends AbstractMaker {
 
             public void startElement(Attributes attributes) {
-                areaStack.push(getCurrentBodyRegion().getFootnote());
+                Footnote fn = getCurrentBodyRegion().getFootnote();
+                transferForeignObjects(attributes, fn);
+                areaStack.push(fn);
             }
             
             public void endElement() {
@@ -532,7 +543,9 @@
         private class BeforeFloatMaker extends AbstractMaker {
 
             public void startElement(Attributes attributes) {
-                areaStack.push(getCurrentBodyRegion().getBeforeFloat());
+                BeforeFloat bf = getCurrentBodyRegion().getBeforeFloat(); 
+                transferForeignObjects(attributes, bf);
+                areaStack.push(bf);
             }
             
             public void endElement() {
@@ -576,6 +589,7 @@
                 if (attributes.getValue("top-offset") != null) {
                     block.setYOffset(getAttributeAsInteger(attributes, "top-offset", 0));
                 }
+                transferForeignObjects(attributes, block);
                 setAreaAttributes(attributes, block);
                 setTraits(attributes, block, SUBSET_COMMON);
                 setTraits(attributes, block, SUBSET_BOX);
@@ -613,6 +627,7 @@
 
             public void startElement(Attributes attributes) {
                 InlineParent ip = new InlineParent();
+                transferForeignObjects(attributes, ip);
                 ip.setOffset(getAttributeAsInteger(attributes, "offset", 0));
                 setAreaAttributes(attributes, ip);
                 setTraits(attributes, ip, SUBSET_COMMON);
@@ -633,6 +648,7 @@
 
             public void startElement(Attributes attributes) {
                 InlineBlockParent ibp = new InlineBlockParent();
+                transferForeignObjects(attributes, ibp);
                 ibp.setOffset(getAttributeAsInteger(attributes, "offset", 0));
                 setAreaAttributes(attributes, ibp);
                 setTraits(attributes, ibp, SUBSET_COMMON);
@@ -735,6 +751,7 @@
             public void endElement() {
                 String txt = content.toString();
                 Character ch = new Character(txt.charAt(0));
+                transferForeignObjects(lastAttributes, ch);
                 setAreaAttributes(lastAttributes, ch);
                 setTraits(lastAttributes, ch, SUBSET_COMMON);
                 setTraits(lastAttributes, ch, SUBSET_BOX);
@@ -751,6 +768,7 @@
 
             public void startElement(Attributes attributes) {
                 Leader leader = new Leader();
+                transferForeignObjects(attributes, leader);
                 setAreaAttributes(attributes, leader);
                 setTraits(attributes, leader, SUBSET_COMMON);
                 setTraits(attributes, leader, SUBSET_BOX);
@@ -775,6 +793,7 @@
 
             public void startElement(Attributes attributes) {
                 Viewport viewport = new Viewport(null);
+                transferForeignObjects(attributes, viewport);
                 setAreaAttributes(attributes, viewport);
                 setTraits(attributes, viewport, SUBSET_COMMON);
                 setTraits(attributes, viewport, SUBSET_BOX);
@@ -797,6 +816,7 @@
             public void startElement(Attributes attributes) {
                 String url = attributes.getValue("url");
                 Image image = new Image(url);
+                transferForeignObjects(attributes, image);
                 setAreaAttributes(attributes, image);
                 setTraits(attributes, image, SUBSET_COMMON);
                 getCurrentViewport().setContent(image);
@@ -814,6 +834,7 @@
                             + " identified to handle namespace: " + ns);
                 }
                 ForeignObject foreign = new ForeignObject(ns);
+                transferForeignObjects(attributes, foreign);
                 setAreaAttributes(attributes, foreign);
                 setTraits(attributes, foreign, SUBSET_COMMON);
                 getCurrentViewport().setContent(foreign);
@@ -825,17 +846,6 @@
             }            
         }
 
-        /*
-        private class ?Maker extends AbstractMaker {
-
-            public void startElement(Attributes attributes) {
-            }
-            
-            public void endElement() {
-            }            
-        }
-        */
-        
         // ====================================================================
         
 
@@ -844,6 +854,7 @@
             RegionViewport rv = getCurrentRegionViewport();
             RegionReference reg = new RegionReference(side, 
                     regionName, rv);
+            transferForeignObjects(attributes, reg);
             reg.setCTM(getAttributeAsCTM(attributes, "ctm"));
             setAreaAttributes(attributes, reg);
             rv.setRegionReference(reg);
@@ -1024,6 +1035,19 @@
             return new Rectangle2D.Double(values[0], values[1], values[2], values[3]);
         }
 
+        private void transferForeignObjects(Attributes atts, AreaTreeObject ato) {
+            for (int i = 0, c = atts.getLength(); i < c; i++) {
+                String ns = atts.getURI(i);
+                if (ns.length() > 0) {
+                    if ("http://www.w3.org/2000/xmlns/".equals(ns)) {
+                        continue;
+                    }
+                    QName qname = new QName(ns, atts.getQName(i));
+                    ato.setForeignAttribute(qname, atts.getValue(i));
+                }
+            }
+        }
+        
         /** @see org.xml.sax.ContentHandler#characters(char[], int, int) */
         public void characters(char[] ch, int start, int length) throws SAXException {
             if (delegate != null) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Page.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Page.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Page.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/Page.java Thu May 18 05:44:15 2006
@@ -45,7 +45,7 @@
  * The page is cloneable so the page master can make copies of
  * the top level page and regions.
  */
-public class Page implements Serializable, Cloneable {
+public class Page extends AreaTreeObject implements Serializable, Cloneable {
     // contains before, start, body, end and after regions
     private RegionViewport regionBefore = null;
     private RegionViewport regionStart = null;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/PageViewport.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/PageViewport.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/PageViewport.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/PageViewport.java Thu May 18 05:44:15 2006
@@ -43,7 +43,7 @@
  * This is the level that creates the page.
  * The page (reference area) is then rendered inside the page object
  */
-public class PageViewport implements Resolvable, Cloneable {
+public class PageViewport extends AreaTreeObject implements Resolvable, Cloneable {
 
     private Page page;
     private Rectangle2D viewArea;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java Thu May 18 05:44:15 2006
@@ -1060,6 +1060,7 @@
                 Page page = new Page(spm, index, pageNumberString, isBlank);
                 //Set unique key obtained from the AreaTreeHandler
                 page.getPageViewport().setKey(areaTreeHandler.generatePageViewportKey());
+                page.getPageViewport().setForeignAttributes(spm.getForeignAttributes());
                 cachedPages.add(page);
                 return page;
             } catch (FOPException e) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java Thu May 18 05:44:15 2006
@@ -47,6 +47,7 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.Area;
+import org.apache.fop.area.AreaTreeObject;
 import org.apache.fop.area.BeforeFloat;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.BlockViewport;
@@ -393,11 +394,25 @@
             }
         }
         
-        //Transfer foreign attributes
-        Iterator iter = area.getForeignAttributes().entrySet().iterator();
+        transferForeignObjects(area);
+    }
+
+    private void transferForeignObjects(AreaTreeObject ato) {
+        Map prefixes = new java.util.HashMap();
+        Iterator iter = ato.getForeignAttributes().entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry entry = (Map.Entry)iter.next();
+            QName qname = (QName)entry.getKey();
+            prefixes.put(qname.getPrefix(), qname.getNamespaceURI());
+            addAttribute(qname, (String)entry.getValue());
+        }
+        //Namespace declarations
+        iter = prefixes.entrySet().iterator();
         while (iter.hasNext()) {
             Map.Entry entry = (Map.Entry)iter.next();
-            addAttribute((QName)entry.getKey(), (String)entry.getValue());
+            String qn = "xmlns:" + (String)entry.getKey();
+            atts.addAttribute("", (String)entry.getKey(), qn, 
+                    CDATA, (String)entry.getValue());
         }
     }
 
@@ -492,6 +507,7 @@
         if (page.isBlank()) {
             addAttribute("blank", "true");
         }
+        transferForeignObjects(page);
         startElement("pageViewport", atts);
         startElement("page");
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/QName.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/QName.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/QName.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/QName.java Thu May 18 05:44:15 2006
@@ -54,6 +54,30 @@
         this.hashCode = toHashString().hashCode();
     }
     
+    /**
+     * Main constructor.
+     * @param namespaceURI the namespace URI
+     * @param qName the qualified name
+     */
+    public QName(String namespaceURI, String qName) {
+        if (qName == null) {
+            throw new NullPointerException("Parameter localName must not be null");
+        }
+        if (qName.length() == 0) {
+            throw new IllegalArgumentException("Parameter localName must not be empty");
+        }
+        this.namespaceURI = namespaceURI;
+        int p = qName.indexOf(':');
+        if (p > 0) {
+            this.prefix = qName.substring(0, p);
+            this.localName = qName.substring(p + 1);
+        } else {
+            this.prefix = null;
+            this.localName = qName;
+        }
+        this.hashCode = toHashString().hashCode();
+    }
+    
     /** @return the namespace URI */
     public String getNamespaceURI() {
         return this.namespaceURI;

Modified: xmlgraphics/fop/trunk/src/sandbox/META-INF/services/org.apache.fop.fo.ElementMapping
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/META-INF/services/org.apache.fop.fo.ElementMapping?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/sandbox/META-INF/services/org.apache.fop.fo.ElementMapping (original)
+++ xmlgraphics/fop/trunk/src/sandbox/META-INF/services/org.apache.fop.fo.ElementMapping Thu May 18 05:44:15 2006
@@ -1 +1,2 @@
-org.apache.fop.render.afp.extensions.AFPElementMapping
\ No newline at end of file
+org.apache.fop.render.afp.extensions.AFPElementMapping
+org.apache.fop.render.pcl.extensions.PCLElementMapping
\ No newline at end of file

Modified: xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java (original)
+++ xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java Thu May 18 05:44:15 2006
@@ -201,6 +201,18 @@
     }
 
     /**
+     * Selects the paper source. The parameter is usually printer-specific. Usually, "1" is the 
+     * default tray, "2" is the manual paper feed, "3" is the manual envelope feed, "4" is the
+     * "lower" tray and "7" is "auto-select". Consult the technical reference for your printer
+     * for all available values.
+     * @param selector the integer representing the paper source/tray
+     * @throws IOException In case of an I/O error
+     */
+    public void selectPaperSource(int selector) throws IOException {
+        writeCommand("&l" + selector + "H");
+    }
+
+    /**
      * Clears the horizontal margins.
      * @throws IOException In case of an I/O error
      */

Modified: xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java Thu May 18 05:44:15 2006
@@ -84,6 +84,7 @@
 import org.apache.fop.render.java2d.FontMetricsMapper;
 import org.apache.fop.render.java2d.FontSetup;
 import org.apache.fop.render.java2d.Java2DRenderer;
+import org.apache.fop.render.pcl.extensions.PCLElementMapping;
 import org.apache.fop.traits.BorderProps;
 import org.apache.fop.util.QName;
 import org.apache.fop.util.UnitConv;
@@ -333,11 +334,22 @@
      */
     public void renderPage(PageViewport page) throws IOException, FOPException {
         saveGraphicsState();
+        
+        //Paper source
+        String paperSource = page.getForeignAttributeValue(
+                new QName(PCLElementMapping.NAMESPACE, null, "paper-source"));
+        if (paperSource != null) {
+            gen.selectPaperSource(Integer.parseInt(paperSource));
+        }
+        
+        //Page size
         final long pagewidth = Math.round(page.getViewArea().getWidth());
         final long pageheight = Math.round(page.getViewArea().getHeight());
         selectPageFormat(pagewidth, pageheight);
         
         super.renderPage(page);
+        
+        //Eject page
         gen.formFeed();
         restoreGraphicsState();
     }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java?rev=407541&r1=407540&r2=407541&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java Thu May 18 05:44:15 2006
@@ -20,6 +20,8 @@
 
 import javax.xml.transform.TransformerException;
 
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xml.utils.PrefixResolverDefault;
 import org.apache.xpath.XPathAPI;
 import org.apache.xpath.objects.XObject;
 import org.w3c.dom.Node;
@@ -31,6 +33,7 @@
 
     private String expected;
     private String xpath;
+    private PrefixResolver prefixResolver;
     
     /**
      * Creates a new instance
@@ -49,13 +52,14 @@
     public EvalCheck(Node node) {
         this.expected = node.getAttributes().getNamedItem("expected").getNodeValue();
         this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
+        this.prefixResolver = new PrefixResolverDefault(node);
     }
     
     /** @see org.apache.fop.layoutengine.LayoutEngineCheck */
     public void check(LayoutResult result) {
         XObject res;
         try {
-            res = XPathAPI.eval(result.getAreaTree(), xpath);
+            res = XPathAPI.eval(result.getAreaTree(), xpath, prefixResolver);
         } catch (TransformerException e) {
             throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
         }
@@ -71,6 +75,14 @@
     /** @see java.lang.Object#toString() */
     public String toString() {
         return "XPath: " + xpath;
+    }
+
+    private class MyPrefixResolver extends PrefixResolverDefault {
+        
+        public MyPrefixResolver(Node xpathExpressionContext) {
+            super(xpathExpressionContext);
+        }
+        
     }
     
 }

Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml?rev=407541&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml (added)
+++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml Thu May 18 05:44:15 2006
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 2006 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+  <info>
+    <p>
+      This test tests foreign attributes on various elements.
+    </p>
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+      <fo:layout-master-set>
+        <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in" fox:foo="bar">
+          <fo:region-body/>
+        </fo:simple-page-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="normal">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="eg">
+            <fo:external-graphic src="../../resources/images/bgimg300dpi.jpg" fox:alt="description"/>
+          </fo:block>
+          <fo:block id="bl">
+            <fo:basic-link external-destination="url(http://xmlgraphics.apache.org/fop/)" fox:blah="fop">FOP</fo:basic-link>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+    <eval expected="bar" xpath="//pageViewport[1]/@fox:foo"/>
+    <eval expected="description" xpath="//block[@prod-id='eg']//image/@fox:alt"/>
+    <!--eval expected="fop" xpath="//block[@prod-id='bl']/inlineparent/@fox:blah"/> NYI -->
+  </checks>
+</testcase>

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/foreign-attributes.xml
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org