diff options
Diffstat (limited to 'src/java/org/apache/fop/fo')
125 files changed, 19307 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/fo/AbstractCharIterator.java b/src/java/org/apache/fop/fo/AbstractCharIterator.java new file mode 100644 index 000000000..82b8d59b6 --- /dev/null +++ b/src/java/org/apache/fop/fo/AbstractCharIterator.java @@ -0,0 +1,102 @@ +/* + * $Id: AbstractCharIterator.java,v 1.4 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.NoSuchElementException; + +/** + * Abstract base class for character iterators. + */ +public abstract class AbstractCharIterator implements CharIterator, Cloneable { + + /** + * @see java.util.Iterator#hasNext() + */ + public abstract boolean hasNext(); + + /** + * @see org.apache.fop.fo.CharIterator#nextChar() + */ + public abstract char nextChar() throws NoSuchElementException ; + + /** + * @see java.util.Iterator#next() + */ + public Object next() throws NoSuchElementException { + return new Character(nextChar()); + } + + /** + * @see java.util.Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException(); + } + + + /** + * @see org.apache.fop.fo.CharIterator#replaceChar(char) + */ + public void replaceChar(char c) { + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + return null; + } + } +} + diff --git a/src/java/org/apache/fop/fo/BoxPropShorthandParser.java b/src/java/org/apache/fop/fo/BoxPropShorthandParser.java new file mode 100644 index 000000000..6fe1a2f73 --- /dev/null +++ b/src/java/org/apache/fop/fo/BoxPropShorthandParser.java @@ -0,0 +1,88 @@ +/* + * $Id: BoxPropShorthandParser.java,v 1.3 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +public class BoxPropShorthandParser extends GenericShorthandParser { + + /** + * @see org.apache.fop.fo.GenericShorthandParser#GenericShorthandParser(ListProperty) + */ + public BoxPropShorthandParser(ListProperty listprop) { + super(listprop); + } + + /** + * Stores 1 to 4 values of same type. + * Set the given property based on the number of values set. + * Example: padding, border-width, border-color, border-style, margin + * @see org.apache.fop.fo.GenericShorthandParser#convertValueForProperty(String, Maker, PropertyList) + */ + protected Property convertValueForProperty(String propName, + Property.Maker maker, + PropertyList propertyList) { + Property p = null; + if (propName.indexOf("-top") >= 0) { + p = getElement(0); + } else if (propName.indexOf("-right") >= 0) { + p = getElement(count() > 1 ? 1 : 0); + } else if (propName.indexOf("-bottom") >= 0) { + p = getElement(count() > 2 ? 2 : 0); + } else if (propName.indexOf("-left") >= 0) { + p = getElement(count() > 3 ? 3 : (count() > 1 ? 1 : 0)); + } + // if p not null, try to convert it to a value of the correct type + if (p != null) { + return maker.convertShorthandProperty(propertyList, p, null); + } + return p; + } + +} diff --git a/src/java/org/apache/fop/fo/CharIterator.java b/src/java/org/apache/fop/fo/CharIterator.java new file mode 100644 index 000000000..05c0c8c38 --- /dev/null +++ b/src/java/org/apache/fop/fo/CharIterator.java @@ -0,0 +1,62 @@ +/* + * $Id: CharIterator.java,v 1.2 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.Iterator; +import java.util.NoSuchElementException; + + +public interface CharIterator extends Iterator { + + char nextChar() throws NoSuchElementException ; + void replaceChar(char c); + Object clone(); +} diff --git a/src/java/org/apache/fop/fo/CharacterProperty.java b/src/java/org/apache/fop/fo/CharacterProperty.java new file mode 100644 index 000000000..517b91a8b --- /dev/null +++ b/src/java/org/apache/fop/fo/CharacterProperty.java @@ -0,0 +1,87 @@ +/* + * $Id: CharacterProperty.java,v 1.3 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +public class CharacterProperty extends Property { + + public static class Maker extends Property.Maker { + + public Maker(String propName) { + super(propName); + } + + public Property make(PropertyList propertyList, String value, + FObj fo) { + char c = value.charAt(0); + return new CharacterProperty(c); + } + + } // end Charakter.Maker + + private char character; + + public CharacterProperty(char character) { + this.character = character; + } + + public Object getObject() { + return new Character(character); + } + + public char getCharacter() { + return this.character; + } + + public String getString() { + return new Character(character).toString(); + } + +} diff --git a/src/java/org/apache/fop/fo/ColorProfile.java b/src/java/org/apache/fop/fo/ColorProfile.java new file mode 100644 index 000000000..da432d826 --- /dev/null +++ b/src/java/org/apache/fop/fo/ColorProfile.java @@ -0,0 +1,120 @@ +/* + * $Id: ColorProfile.java,v 1.10 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.awt.color.ICC_Profile; +import java.awt.color.ICC_ColorSpace; +import java.net.URL; +import java.io.IOException; +import java.io.InputStream; + +// FOP +import org.apache.fop.datatypes.ColorType; + +/** + * The fo:color-profile formatting object. + * This loads the color profile when needed and resolves a requested color. + */ +public class ColorProfile extends FObj { + private int intent; + private String src; + private String profileName; + private ICC_ColorSpace colorSpace = null; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + protected ColorProfile(FONode parent) { + super(parent); + } + + public void end() { + src = this.properties.get("src").getString(); + profileName = this.properties.get("color-profile-name").getString(); + intent = this.properties.get("rendering-intent").getEnum(); + this.properties = null; + } + + /** + * Get the name of this color profile. + */ + public String getProfileName() { + return profileName; + } + + /** + * Get the color specified with the color values from the color profile. + * The default values are used if the profile could not be loaded + * or the value is not found. + */ + public ColorType getColor(int[] colorVals, int defR, int defG, int defB) { + // float[] rgbvals = colorSpace.toRGB(colorVals); + // return new ColorType(rgbvals); + return null; + } + + /** + * Load the color profile. + */ + private void load() { + try { + URL url = new URL(src); + InputStream is = url.openStream(); + ICC_Profile iccProfile = ICC_Profile.getInstance(is); + colorSpace = new ICC_ColorSpace(iccProfile); + } catch (IOException ioe) { + getLogger().error("Could not read Color Profile src", ioe); + } catch (IllegalArgumentException iae) { + getLogger().error("Color Profile src not an ICC Profile", iae); + } + } +} diff --git a/src/java/org/apache/fop/fo/ColorTypeProperty.java b/src/java/org/apache/fop/fo/ColorTypeProperty.java new file mode 100644 index 000000000..de02dd2c1 --- /dev/null +++ b/src/java/org/apache/fop/fo/ColorTypeProperty.java @@ -0,0 +1,93 @@ +/* + * $Id: ColorTypeProperty.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.ColorType; + +public class ColorTypeProperty extends Property { + + public static class Maker extends Property.Maker { + + public Maker(String propName) { + super(propName); + } + + public Property convertProperty(Property p, + PropertyList propertyList, FObj fo) { + if (p instanceof ColorTypeProperty) { + return p; + } + ColorType val = p.getColorType(); + if (val != null) { + return new ColorTypeProperty(val); + } + return convertPropertyDatatype(p, propertyList, fo); + } + + } + + private ColorType colorType; + + public ColorTypeProperty(ColorType colorType) { + this.colorType = colorType; + } + + // Can't convert to any other types + public ColorType getColorType() { + return this.colorType; + } + + public Object getObject() { + return this.colorType; + } + +} + diff --git a/src/java/org/apache/fop/fo/CondLengthProperty.java b/src/java/org/apache/fop/fo/CondLengthProperty.java new file mode 100644 index 000000000..564ead0df --- /dev/null +++ b/src/java/org/apache/fop/fo/CondLengthProperty.java @@ -0,0 +1,85 @@ +/* + * $Id: CondLengthProperty.java,v 1.5 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.CondLength; + +public class CondLengthProperty extends Property { + + public static class Maker extends Property.Maker { + + public Maker(String name) { + super(name); + } + + } + + private CondLength condLength = null; + + public CondLengthProperty(CondLength condLength) { + this.condLength = condLength; + } + + public CondLength getCondLength() { + return this.condLength; + } + + /* Question, should we allow this? */ + public Length getLength() { + return this.condLength.getLength().getLength(); + } + + public Object getObject() { + return this.condLength; + } + +} diff --git a/src/java/org/apache/fop/fo/Declarations.java b/src/java/org/apache/fop/fo/Declarations.java new file mode 100644 index 000000000..6dfb9aa61 --- /dev/null +++ b/src/java/org/apache/fop/fo/Declarations.java @@ -0,0 +1,107 @@ +/* + * $Id: Declarations.java,v 1.8 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.List; +import java.util.Map; +import java.util.Iterator; + +/** + * Declarations formatting object. + * A declarations formatting object holds a set of color-profiles + * and optionally additional non-XSL namespace elements. + * The color-profiles are held in a hashmap for use with color-profile + * references. + */ +public class Declarations extends FObj { + + private Map colorProfiles = null; + private List external = null; + + protected Declarations(FONode parent) { + super(parent); + } + + /** + * At then end of this element sort out the child into + * a hashmap of color profiles and a list of external xml. + */ + public void end() { + for (Iterator iter = children.iterator(); iter.hasNext();) { + FONode node = (FONode)iter.next(); + if (node.getName().equals("fo:color-profile")) { + ColorProfile cp = (ColorProfile)node; + if (!"".equals(cp.getProfileName())) { + if (colorProfiles == null) { + colorProfiles = new java.util.HashMap(); + } + if (colorProfiles.get(cp.getProfileName()) != null) { + // duplicate names + getLogger().warn("Duplicate fo:color-profile profile name : " + + cp.getProfileName()); + } + colorProfiles.put(cp.getProfileName(), cp); + } else { + getLogger().warn("color-profile-name required for color profile"); + } + } else if (node instanceof XMLObj) { + if (external == null) { + external = new java.util.ArrayList(); + } + external.add(node); + } else { + getLogger().warn("invalid element " + node.getName() + "inside declarations"); + } + } + children = null; + } +} diff --git a/src/java/org/apache/fop/fo/ElementMapping.java b/src/java/org/apache/fop/fo/ElementMapping.java new file mode 100644 index 000000000..331ca2a85 --- /dev/null +++ b/src/java/org/apache/fop/fo/ElementMapping.java @@ -0,0 +1,67 @@ +/* + * $Id: ElementMapping.java,v 1.11 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +/** + * Interface for adding supported element and property mappings to + * the given builder. + */ +public interface ElementMapping { + final String DEFAULT = "<default>"; + + void addToBuilder(FOTreeBuilder builder); + + public static class Maker { + public FONode make(FONode parent) { + return null; + } + } +} diff --git a/src/java/org/apache/fop/fo/EnumProperty.java b/src/java/org/apache/fop/fo/EnumProperty.java new file mode 100644 index 000000000..e34bef87c --- /dev/null +++ b/src/java/org/apache/fop/fo/EnumProperty.java @@ -0,0 +1,104 @@ +/* + * $Id: EnumProperty.java,v 1.8 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.apps.FOPException; + +public class EnumProperty extends Property { + + public static class Maker extends Property.Maker { + + protected Maker(String propName) { + super(propName); + } + + /** + * Called by subclass if no match found. + */ + public Property checkEnumValues(String value) { + //log.error("Unknown enumerated value for property '" + // + getPropName() + "': " + value); + return null; + } + + protected Property findConstant(String value) { + return null; + } + + public Property convertProperty(Property p, + PropertyList propertyList, + FObj fo) throws FOPException { + if (p instanceof EnumProperty) { + return p; + } else { + return null; + } + } + } + + private int value; + + public EnumProperty(int explicitValue) { + this.value = explicitValue; + } + + public int getEnum() { + return this.value; + } + + public Object getObject() { + // FIXME: return String value: property must reference maker + // return maker.getEnumValue(this.value); + return new Integer(this.value); + } + +} + diff --git a/src/java/org/apache/fop/fo/FOElementMapping.java b/src/java/org/apache/fop/fo/FOElementMapping.java new file mode 100644 index 000000000..f9db7f51c --- /dev/null +++ b/src/java/org/apache/fop/fo/FOElementMapping.java @@ -0,0 +1,486 @@ +/* + * $Id: FOElementMapping.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.HashMap; + +/** + * Element mapping class for all XSL-FO elements. + */ +public class FOElementMapping implements ElementMapping { + + private static HashMap foObjs = null; + + private static synchronized void setupFO() { + if (foObjs == null) { + foObjs = new HashMap(); + + // Declarations and Pagination and Layout Formatting Objects + foObjs.put("root", new R()); + foObjs.put("declarations", new Dec()); + foObjs.put("color-profile", new CP()); + foObjs.put("page-sequence", new PS()); + foObjs.put("layout-master-set", new LMS()); + foObjs.put("page-sequence-master", + new PSM()); + foObjs.put("single-page-master-reference", + new SPMR()); + foObjs.put("repeatable-page-master-reference", + new RPMR()); + foObjs.put("repeatable-page-master-alternatives", + new RPMA()); + foObjs.put("conditional-page-master-reference", + new CPMR()); + foObjs.put("simple-page-master", + new SPM()); + foObjs.put("region-body", new RB()); + foObjs.put("region-before", new RBefore()); + foObjs.put("region-after", new RA()); + foObjs.put("region-start", new RS()); + foObjs.put("region-end", new RE()); + foObjs.put("flow", new Fl()); + foObjs.put("static-content", new SC()); + foObjs.put("title", new T()); + + // Block-level Formatting Objects + foObjs.put("block", new B()); + foObjs.put("block-container", new BC()); + + // Inline-level Formatting Objects + foObjs.put("bidi-override", new BO()); + foObjs.put("character", + new Ch()); + foObjs.put("initial-property-set", + new IPS()); + foObjs.put("external-graphic", new EG()); + foObjs.put("instream-foreign-object", + new IFO()); + foObjs.put("inline", new In()); + foObjs.put("inline-container", new IC()); + foObjs.put("leader", new L()); + foObjs.put("page-number", new PN()); + foObjs.put("page-number-citation", + new PNC()); + + // Formatting Objects for Tables + foObjs.put("table-and-caption", new TAC()); + foObjs.put("table", new Ta()); + foObjs.put("table-column", new TC()); + foObjs.put("table-caption", new TCaption()); + foObjs.put("table-header", new TB()); + foObjs.put("table-footer", new TB()); + foObjs.put("table-body", new TB()); + foObjs.put("table-row", new TR()); + foObjs.put("table-cell", new TCell()); + + // Formatting Objects for Lists + foObjs.put("list-block", new LB()); + foObjs.put("list-item", new LI()); + foObjs.put("list-item-body", new LIB()); + foObjs.put("list-item-label", new LIL()); + + // Dynamic Effects: Link and Multi Formatting Objects + foObjs.put("basic-link", new BL()); + foObjs.put("multi-switch", new MS()); + foObjs.put("multi-case", new MC()); + foObjs.put("multi-toggle", new MT()); + foObjs.put("multi-properties", new MP()); + foObjs.put("multi-property-set", + new MPS()); + + // Out-of-Line Formatting Objects + foObjs.put("float", + new F()); + foObjs.put("footnote", new Foot()); + foObjs.put("footnote-body", new FB()); + + // Other Formatting Objects + foObjs.put("wrapper", new W()); + foObjs.put("marker", new M()); + foObjs.put("retrieve-marker", new RM()); + } + + } + + /** + * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder) + */ + public void addToBuilder(FOTreeBuilder builder) { + setupFO(); + String uri = "http://www.w3.org/1999/XSL/Format"; + builder.addMapping(uri, foObjs); + } + + static class R extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.Root(parent); + } + } + + static class Dec extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new Declarations(parent); + } + } + + static class CP extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new ColorProfile(parent); + } + } + + static class PS extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.PageSequence(parent); + } + } + + static class LMS extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.LayoutMasterSet(parent); + } + } + + static class PSM extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.PageSequenceMaster(parent); + } + } + + static class SPMR extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.SinglePageMasterReference(parent); + } + } + + static class RPMR extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RepeatablePageMasterReference(parent); + } + } + + static class RPMA extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RepeatablePageMasterAlternatives(parent); + } + } + + static class CPMR extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.ConditionalPageMasterReference(parent); + } + } + + static class SPM extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.SimplePageMaster(parent); + } + } + + static class RB extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RegionBody(parent); + } + } + + static class RBefore extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RegionBefore(parent); + } + } + + static class RA extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RegionAfter(parent); + } + } + + static class RS extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RegionStart(parent); + } + } + + static class RE extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.pagination.RegionEnd(parent); + } + } + + static class Fl extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Flow(parent); + } + } + + static class SC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.StaticContent(parent); + } + } + + static class T extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new Title(parent); + } + } + + static class B extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Block(parent); + } + } + + static class BC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.BlockContainer(parent); + } + } + + static class BO extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.BidiOverride(parent); + } + } + + static class Ch extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Character(parent); + } + } + + static class IPS extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.InitialPropertySet(parent); + } + } + + static class EG extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.ExternalGraphic(parent); + } + } + + static class IFO extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.InstreamForeignObject(parent); + } + } + + static class In extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Inline(parent); + } + } + + static class IC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.InlineContainer(parent); + } + } + + static class L extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Leader(parent); + } + } + + static class PN extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.PageNumber(parent); + } + } + + static class PNC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.PageNumberCitation(parent); + } + } + + static class TAC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.TableAndCaption(parent); + } + } + + static class Ta extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Table(parent); + } + } + + static class TC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.TableColumn(parent); + } + } + + static class TCaption extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.TableCaption(parent); + } + } + + static class TB extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.TableBody(parent); + } + } + + static class TR extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.TableRow(parent); + } + } + + static class TCell extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.TableCell(parent); + } + } + + static class LB extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.ListBlock(parent); + } + } + + static class LI extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.ListItem(parent); + } + } + + static class LIB extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.ListItemBody(parent); + } + } + + static class LIL extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.ListItemLabel(parent); + } + } + + static class BL extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.BasicLink(parent); + } + } + + static class MS extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.MultiSwitch(parent); + } + } + + static class MC extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.MultiCase(parent); + } + } + + static class MT extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.MultiToggle(parent); + } + } + + static class MP extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.MultiProperties(parent); + } + } + + static class MPS extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.MultiPropertySet(parent); + } + } + + static class F extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Float(parent); + } + } + + static class Foot extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Footnote(parent); + } + } + + static class FB extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.FootnoteBody(parent); + } + } + + static class W extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Wrapper(parent); + } + } + + static class M extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.Marker(parent); + } + } + + static class RM extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new org.apache.fop.fo.flow.RetrieveMarker(parent); + } + } +} diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java new file mode 100644 index 000000000..240efac8e --- /dev/null +++ b/src/java/org/apache/fop/fo/FONode.java @@ -0,0 +1,203 @@ +/* + * $Id: FONode.java,v 1.34 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.ListIterator; + +// XML +import org.xml.sax.Attributes; + +// Avalon +import org.apache.avalon.framework.logger.Logger; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.util.CharUtilities; + +/** + * base class for nodes in the XML tree + * + */ +public abstract class FONode { + + /** FO User Agent for this node (for logger etc.)*/ + protected FOUserAgent userAgent; + /** Parent FO node */ + protected FONode parent; + /** Name of the node */ + protected String name; + + /** + * Main constructor. + * @param parent parent of this node + */ + protected FONode(FONode parent) { + this.parent = parent; + } + + /** + * Sets the name of the node. + * @param str the name + */ + public void setName(String str) { + name = str; + } + + /** + * Returns the logger for the node. + * @return the logger + */ + protected Logger getLogger() { + return userAgent.getLogger(); + } + + /** + * Sets the user agent for the node. + * @param ua the user agent + */ + public void setUserAgent(FOUserAgent ua) { + userAgent = ua; + } + + /** + * Returns the user agent for the node. + * @return FOUserAgent + */ + protected FOUserAgent getUserAgent() { + return userAgent; + } + + /** + * Sets the structure handler to send events to. + * @param st StructureHandler instance + */ + public void setStructHandler(StructureHandler st) { + } + + public void handleAttrs(Attributes attlist) throws FOPException { + } + + /** + * Returns the name of the object + * @return the name of this object + */ + public String getName() { + return this.name; + } + + /** + * Adds characters (does nothing here) + * @param data text + * @param start start position + * @param length length of the text + */ + protected void addCharacters(char data[], int start, int length) { + // ignore + } + + /** + * + */ + protected void start() { + // do nothing by default + } + + /** + * + */ + protected void end() { + // do nothing by default + } + + protected void addChild(FONode child) { + } + + public FONode getParent() { + return this.parent; + } + + /** + * Return an iterator over all the children of this FObj. + * @return A ListIterator. + */ + public ListIterator getChildren() { + return null; + } + + /** + * Return an iterator over the object's children starting + * at the pased node. + * @param childNode First node in the iterator + * @return A ListIterator or null if childNode isn't a child of + * this FObj. + */ + public ListIterator getChildren(FONode childNode) { + return null; + } + + public CharIterator charIterator() { + return new OneCharIterator(CharUtilities.CODE_EOT); + } + + /** + * This is a quick check to see if it is a marker. + * This is needed since there is no other quick way of checking + * for a marker and not adding to the child list. + * + * @return true if this is a marker + */ + protected boolean isMarker() { + return false; + } +} + diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java new file mode 100644 index 000000000..80d2af61b --- /dev/null +++ b/src/java/org/apache/fop/fo/FOText.java @@ -0,0 +1,180 @@ +/* + * $Id: FOText.java,v 1.43 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.NoSuchElementException; +import java.util.List; + +// FOP +import org.apache.fop.layout.TextState; +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.TextLayoutManager; +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.fo.properties.WhiteSpaceCollapse; + +/** + * A text node in the formatting object tree. + * + * Modified by Mark Lillywhite, mark-fop@inomial.com. + * Unfortunately the BufferManager implementatation holds + * onto references to the character data in this object + * longer than the lifetime of the object itself, causing + * excessive memory consumption and OOM errors. + */ +public class FOText extends FObj { + + protected char[] ca; + protected int start; + protected int length; + TextInfo textInfo; + TextState ts; + + public FOText(char[] chars, int s, int e, TextInfo ti) { + super(null); + this.start = 0; + this.ca = new char[e - s]; + System.arraycopy(chars, s, ca, 0, e - s); + this.length = e - s; + textInfo = ti; + } + + public void setStructHandler(StructureHandler st) { + super.setStructHandler(st); + structHandler.characters(ca, start, length); + } + + /** + * Check if this text node will create an area. + * This means either there is non-whitespace or it is + * preserved whitespace. + * Maybe this just needs to check length > 0, since char iterators + * handle whitespace. + * + * @return true if this will create an area in the output + */ + public boolean willCreateArea() { + if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE + && length > 0) { + return true; + } + + for (int i = start; i < start + length; i++) { + char ch = ca[i]; + if (!((ch == ' ') + || (ch == '\n') + || (ch == '\r') + || (ch == '\t'))) { // whitespace + return true; + } + } + return false; + } + + public void addLayoutManager(List list) { + // if nothing left (length=0)? + if (length == 0) { + return; + } + + if (length < ca.length) { + char[] tmp = ca; + ca = new char[length]; + System.arraycopy(tmp, 0, ca, 0, length); + } + LayoutManager lm = new TextLayoutManager(ca, textInfo); + lm.setFObj(this); + list.add(lm); + } + + public CharIterator charIterator() { + return new TextCharIterator(); + } + + private class TextCharIterator extends AbstractCharIterator { + private int curIndex = 0; + + public boolean hasNext() { + return (curIndex < length); + } + + public char nextChar() { + if (curIndex < length) { + // Just a char class? Don't actually care about the value! + return ca[curIndex++]; + } else { + throw new NoSuchElementException(); + } + } + + public void remove() { + if (curIndex > 0 && curIndex < length) { + // copy from curIndex to end to curIndex-1 + System.arraycopy(ca, curIndex, ca, curIndex - 1, + length - curIndex); + length--; + curIndex--; + } else if (curIndex == length) { + curIndex = --length; + } + } + + + public void replaceChar(char c) { + if (curIndex > 0 && curIndex <= length) { + ca[curIndex - 1] = c; + } + } + + + } +} + diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java new file mode 100644 index 000000000..4a10e4889 --- /dev/null +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -0,0 +1,275 @@ +/* + * $Id: FOTreeBuilder.java,v 1.43 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.StructureHandler; + +// Java +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +// SAX +import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.SAXException; +import org.xml.sax.Attributes; + +// Avalon +import org.apache.avalon.framework.logger.Logger; + +/** + * SAX Handler that builds the formatting object tree. + * + * Modified by Mark Lillywhite mark-fop@inomial.com. Now uses + * StreamRenderer to automagically render the document as + * soon as it receives a page-sequence end-tag. Also, + * calls methods to set up and shut down the renderer at + * the beginning and end of the FO document. Finally, + * supresses adding the PageSequence object to the Root, + * since it is parsed immediately. + */ +public class FOTreeBuilder extends DefaultHandler { + + /** + * Table mapping element names to the makers of objects + * representing formatting objects. + */ + protected Map fobjTable = new java.util.HashMap(); + + /** + * Set of mapped namespaces. + */ + protected Set namespaces = new java.util.HashSet(); + + /** + * Current formatting object being handled + */ + protected FONode currentFObj = null; + + /** + * The root of the formatting object tree + */ + protected FONode rootFObj = null; + + /** + * The class that handles formatting and rendering to a stream + * (mark-fop@inomial.com) + */ + private StructureHandler structHandler; + + private FOUserAgent userAgent; + + /** + * Default constructor + */ + public FOTreeBuilder() { + } + + private Logger getLogger() { + return userAgent.getLogger(); + } + + /** + * Sets the user agent + * @param ua the user agent + */ + public void setUserAgent(FOUserAgent ua) { + userAgent = ua; + } + + private FOUserAgent getUserAgent() { + return userAgent; + } + + /** + * Sets the structure handler to receive events. + * @param sh StructureHandler instance + */ + public void setStructHandler(StructureHandler sh) { + this.structHandler = sh; + } + + /** + * Adds a mapping from a namespace to a table of makers. + * + * @param namespaceURI namespace URI of formatting object elements + * @param table table of makers + */ + public void addMapping(String namespaceURI, HashMap table) { + this.fobjTable.put(namespaceURI, table); + this.namespaces.add(namespaceURI.intern()); + } + + /** + * SAX Handler for characters + * @see org.xml.sax.ContentHandler#characters(char[], int, int) + */ + public void characters(char data[], int start, int length) { + if (currentFObj != null) { + currentFObj.addCharacters(data, start, start + length); + } + } + + /** + * SAX Handler for the end of an element + * @see org.xml.sax.ContentHandler#endElement(String, String, String) + */ + public void endElement(String uri, String localName, String rawName) + throws SAXException { + currentFObj.end(); + currentFObj = currentFObj.getParent(); + } + + /** + * SAX Handler for the start of the document + * @see org.xml.sax.ContentHandler#startDocument() + */ + public void startDocument() throws SAXException { + rootFObj = null; // allows FOTreeBuilder to be reused + if (getLogger().isDebugEnabled()) { + getLogger().debug("Building formatting object tree"); + } + structHandler.startDocument(); + } + + /** + * SAX Handler for the end of the document + * @see org.xml.sax.ContentHandler#endDocument() + */ + public void endDocument() throws SAXException { + rootFObj = null; + currentFObj = null; + if (getLogger().isDebugEnabled()) { + getLogger().debug("Parsing of document complete"); + } + structHandler.endDocument(); + } + + /** + * SAX Handler for the start of an element + * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes) + */ + public void startElement(String uri, String localName, String rawName, + Attributes attlist) throws SAXException { + /* the formatting object started */ + FONode fobj; + + /* the maker for the formatting object started */ + ElementMapping.Maker fobjMaker = null; + + Map table = (Map)fobjTable.get(uri); + if (table != null) { + fobjMaker = (ElementMapping.Maker)table.get(localName); + // try default + if (fobjMaker == null) { + fobjMaker = (ElementMapping.Maker)table.get(ElementMapping.DEFAULT); + } + } + + if (fobjMaker == null) { + if (getLogger().isWarnEnabled()) { + getLogger().warn("Unknown formatting object " + uri + "^" + localName); + } + if (namespaces.contains(uri.intern())) { + // fall back + fobjMaker = new Unknown.Maker(); + } else { + fobjMaker = new UnknownXMLObj.Maker(uri); + } + } + + try { + fobj = fobjMaker.make(currentFObj); + fobj.setName(localName); + // set the user agent for resolving user agent values + fobj.setUserAgent(userAgent); + // set the structure handler so that appropriate + // elements can signal structure events + fobj.setStructHandler(structHandler); + + fobj.handleAttrs(attlist); + } catch (FOPException e) { + throw new SAXException(e); + } + + if (rootFObj == null) { + if (!fobj.getName().equals("fo:root")) { + throw new SAXException(new FOPException("Root element must" + + " be fo:root, not " + + fobj.getName())); + } + rootFObj = fobj; + } else { + currentFObj.addChild(fobj); + } + + currentFObj = fobj; + } + + /** + * Resets this object for another run. + */ + public void reset() { + currentFObj = null; + rootFObj = null; + structHandler = null; + } + + /** + * Indicates if data has been processed. + * @return True if data has been processed + */ + public boolean hasData() { + return (rootFObj != null); + } +} diff --git a/src/java/org/apache/fop/fo/FOUserAgent.java b/src/java/org/apache/fop/fo/FOUserAgent.java new file mode 100644 index 000000000..b35fd6426 --- /dev/null +++ b/src/java/org/apache/fop/fo/FOUserAgent.java @@ -0,0 +1,220 @@ +/* + * $Id: FOUserAgent.java,v 1.15 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.Map; +import java.io.IOException; +import java.io.InputStream; + +// XML +import org.w3c.dom.Document; + +// Avalon +import org.apache.avalon.framework.logger.LogEnabled; +import org.apache.avalon.framework.logger.Logger; + +// FOP +import org.apache.fop.render.XMLHandler; +import org.apache.fop.render.RendererContext; + +/** + * The User Agent for fo. + * This user agent is used by the processing to obtain user configurable + * options. + * <p> + * Renderer specific extensions (that do not produce normal areas on + * the output) will be done like so: + * <br> + * The extension will create an area, custom if necessary + * <br> + * this area will be added to the user agent with a key + * <br> + * the renderer will know keys for particular extensions + * <br> + * eg. bookmarks will be held in a special hierarchical area representing + * the title and bookmark structure + * <br> + * These areas may contain resolveable areas that will be processed + * with other resolveable areas + */ +public class FOUserAgent implements LogEnabled { + + private Logger log; + private Map defaults = new java.util.HashMap(); + private Map handlers = new java.util.HashMap(); + private String baseURL; + + /** + * Sets the logger. + * @param log Logger to use + * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger) + */ + public void enableLogging(Logger log) { + this.log = log; + } + + /** + * Returns the logger to use. + * @see org.apache.avalon.framework.logger.AbstractLogEnabled#getLogger() + * @todo This breaks IoC/SoC. Should be improved. + */ + public Logger getLogger() { + return this.log; + } + + /** + * Sets the base URL. + * @param baseURL base URL + */ + public void setBaseURL(String baseURL) { + this.baseURL = baseURL; + } + + /** + * Returns the base URL. + * @return the base URL + */ + public String getBaseURL() { + if ((this.baseURL == null) || (this.baseURL.trim().equals(""))) { + return "file:."; + } else { + return this.baseURL; + } + } + + /** + * Get an input stream for a reference. + * Temporary solution until API better. + * @param uri URI to access + * @return InputStream for accessing the resource. + * @throws IOException in case of an I/O problem + */ + public InputStream getStream(String uri) throws IOException { + return null; + } + + /** + * Returns the conversion factor from pixel units to millimeters. This + * depends on the desired reolution. + * @return float conversion factor + */ + public float getPixelUnitToMillimeter() { + return 0.35277777777777777778f; + } + + /** + * If to create hot links to footnotes and before floats. + * @return True if hot links dhould be created + */ + public boolean linkToFootnotes() { + return true; + } + + /** + * Set the default xml handler for the given mime type. + * @param mime MIME type + * @param handler XMLHandler to use + */ + public void setDefaultXMLHandler(String mime, XMLHandler handler) { + defaults.put(mime, handler); + } + + /** + * Add an xml handler for the given mime type and xml namespace. + * @param mime MIME type + * @param ns Namespace URI + * @param handler XMLHandler to use + */ + public void addXMLHandler(String mime, String ns, XMLHandler handler) { + Map mh = (Map) handlers.get(mime); + if (mh == null) { + mh = new java.util.HashMap(); + handlers.put(mime, mh); + } + mh.put(ns, handler); + } + + /** + * Render the xml document with the given xml namespace. + * The Render Context is by the handle to render into the current + * rendering target. + * @param ctx rendering context + * @param doc DOM Document containing the source document + * @param namespace Namespace URI of the document + */ + public void renderXML(RendererContext ctx, Document doc, + String namespace) { + String mime = ctx.getMimeType(); + Map mh = (Map) handlers.get(mime); + XMLHandler handler = null; + if (mh != null) { + handler = (XMLHandler) mh.get(namespace); + } + if (handler == null) { + handler = (XMLHandler) defaults.get(mime); + } + if (handler != null) { + try { + handler.handleXML(ctx, doc, namespace); + } catch (Throwable t) { + // could not handle document + getLogger().error("Some XML content will be ignored. " + + "Could not render XML", t); + } + } else { + // no handler found for document + getLogger().warn("Some XML content will be ignored. " + + "No handler defined for XML: " + namespace); + } + } +} + diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java new file mode 100644 index 000000000..c9a840d54 --- /dev/null +++ b/src/java/org/apache/fop/fo/FObj.java @@ -0,0 +1,376 @@ +/* + * $Id: FObj.java,v 1.40 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.Iterator; +import java.util.ListIterator; +import java.util.ArrayList; +import java.util.List; +import java.util.HashMap; +import java.util.Set; +import java.util.Map; +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.fo.properties.FOPropertyMapping; +import org.apache.fop.fo.flow.Marker; + +/** + * base class for representation of formatting objects and their processing + */ +public class FObj extends FONode { + private static final String FO_URI = "http://www.w3.org/1999/XSL/Format"; + + /** + * Static property list builder that converts xml attributes + * into fo properties. This is static since the underlying + * property mappings for fo are also static. + */ + protected static PropertyListBuilder plb = null; + + /** + * Structure handler used to notify structure events + * such as start end element. + */ + protected StructureHandler structHandler; + + /** + * Formatting properties for this fo element. + */ + public PropertyList properties; + + /** + * Property manager for handler some common properties. + */ + protected PropertyManager propMgr; + + /** + * Id of this fo element of null if no id. + */ + protected String id = null; + + /** + * The children of this node. + */ + protected ArrayList children = null; + + /** + * Markers added to this element. + */ + protected Map markers = null; + + /** + * Create a new formatting object. + * All formatting object classes extend this class. + * + * @param parent the parent node + */ + public FObj(FONode parent) { + super(parent); + } + + /** + * Set the name of this element. + * The prepends "fo:" to the name to indicate it is in the fo namespace. + * + * @param str the xml element name + */ + public void setName(String str) { + name = "fo:" + str; + } + + protected PropertyListBuilder getListBuilder() { + if (plb == null) { + plb = new PropertyListBuilder(); + plb.addList(FOPropertyMapping.getGenericMappings()); + + for (Iterator iter = + FOPropertyMapping.getElementMappings().iterator(); + iter.hasNext();) { + String elem = (String) iter.next(); + plb.addElementList(elem, + FOPropertyMapping.getElementMapping(elem)); + } + } + return plb; + } + + /** + * Handle the attributes for this element. + * The attributes must be used immediately as the sax attributes + * will be altered for the next element. + */ + public void handleAttrs(Attributes attlist) throws FOPException { + FONode par = parent; + while (par != null && !(par instanceof FObj)) { + par = par.parent; + } + PropertyList props = null; + if (par != null) { + props = ((FObj) par).properties; + } + properties = getListBuilder().makeList(FO_URI, name, attlist, props, + (FObj) par); + properties.setFObj(this); + this.propMgr = makePropertyManager(properties); + setWritingMode(); + } + + protected PropertyManager makePropertyManager( + PropertyList propertyList) { + return new PropertyManager(propertyList); + } + + /** + * Add the child to this object. + * + * @param child the child node to add + */ + protected void addChild(FONode child) { + if (containsMarkers() && child.isMarker()) { + addMarker((Marker)child); + } else { + if (children == null) { + children = new ArrayList(); + } + children.add(child); + } + } + + /** + * Set the structure handler for handling structure events. + * + * @param st the structure handler + */ + public void setStructHandler(StructureHandler st) { + structHandler = st; + } + + /** + * lets outside sources access the property list + * first used by PageNumberCitation to find the "id" property + * @param name - the name of the desired property to obtain + * @return the property + */ + public Property getProperty(String name) { + return (properties.get(name)); + } + + /** + * Setup the id for this formatting object. + * Most formatting objects can have an id that can be referenced. + * This methods checks that the id isn't already used by another + * fo and sets the id attribute of this object. + */ + protected void setupID() { + Property prop = this.properties.get("id"); + if (prop != null) { + String str = prop.getString(); + if (str != null && !str.equals("")) { + Set idrefs = structHandler.getIDReferences(); + if (!idrefs.contains(str)) { + id = str; + idrefs.add(id); + } else { + getLogger().warn("duplicate id:" + str + " ignored"); + } + } + } + } + + /** + * Get the id string for this formatting object. + * This will be unique for the fo document. + * + * @return the id string or null if not set + */ + public String getID() { + return id; + } + + /** + * Check if this formatting object generates reference areas. + * + * @return true if generates reference areas + */ + public boolean generatesReferenceAreas() { + return false; + } + + /** + * Check if this formatting object generates inline areas. + * + * @return true if generates inline areas + */ + public boolean generatesInlineAreas() { + return true; + } + + /** + * Check if this formatting object may contain markers. + * + * @return true if this can contian markers + */ + protected boolean containsMarkers() { + return false; + } + + /** + * Set writing mode for this FO. + * Find nearest ancestor, including self, which generates + * reference areas and use the value of its writing-mode property. + * If no such ancestor is found, use the value on the root FO. + */ + protected void setWritingMode() { + FObj p; + FONode parent; + for (p = this; !p.generatesReferenceAreas() + && (parent = p.getParent()) != null + && (parent instanceof FObj); p = (FObj) parent) { + } + this.properties.setWritingMode( + p.getProperty("writing-mode").getEnum()); + } + + /** + * Return a LayoutManager responsible for laying out this FObj's content. + * Must override in subclasses if their content can be laid out. + * @param list the list to add the layout manager(s) to + */ + public void addLayoutManager(List list) { + } + + /** + * Return an iterator over all the children of this FObj. + * @return A ListIterator. + */ + public ListIterator getChildren() { + if (children != null) { + return children.listIterator(); + } + return null; + } + + /** + * Return an iterator over the object's children starting + * at the pased node. + * @param childNode First node in the iterator + * @return A ListIterator or null if childNode isn't a child of + * this FObj. + */ + public ListIterator getChildren(FONode childNode) { + if (children != null) { + int i = children.indexOf(childNode); + if (i >= 0) { + return children.listIterator(i); + } + } + return null; + } + + /** + * Add the marker to this formatting object. + * If this object can contain markers it checks that the marker + * has a unique class-name for this object and that it is + * the first child. + */ + public void addMarker(Marker marker) { + String mcname = marker.getMarkerClassName(); + if (children != null) { + // check for empty children + for (Iterator iter = children.iterator(); iter.hasNext();) { + FONode node = (FONode)iter.next(); + if (node instanceof FOText) { + FOText text = (FOText)node; + if (text.willCreateArea()) { + getLogger().error("fo:marker must be an initial child: " + mcname); + return; + } else { + iter.remove(); + } + } else { + getLogger().error("fo:marker must be an initial child: " + mcname); + return; + } + } + } + if (markers == null) { + markers = new HashMap(); + } + if (!markers.containsKey(mcname)) { + markers.put(mcname, marker); + } else { + getLogger().error("fo:marker 'marker-class-name' " + + "must be unique for same parent: " + mcname); + } + } + + public boolean hasMarkers() { + return markers != null && !markers.isEmpty(); + } + + public Map getMarkers() { + return markers; + } + + /** + * lets layout managers access FO properties via PropertyManager + * @return the property manager for this FO + */ + public PropertyManager getPropertyManager() { + return this.propMgr; + } + +} + diff --git a/src/java/org/apache/fop/fo/FObjMixed.java b/src/java/org/apache/fop/fo/FObjMixed.java new file mode 100644 index 000000000..4800895b1 --- /dev/null +++ b/src/java/org/apache/fop/fo/FObjMixed.java @@ -0,0 +1,113 @@ +/* + * $Id: FObjMixed.java,v 1.33 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.layout.FontInfo; +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.layoutmgr.InlineStackingLayoutManager; +import org.apache.fop.layoutmgr.LMiter; + +import java.util.List; + +/** + * base class for representation of mixed content formatting objects + * and their processing + */ +public class FObjMixed extends FObj { + protected TextInfo textInfo = null; + protected FontInfo fontInfo = null; + + public FObjMixed(FONode parent) { + super(parent); + } + + public void setStructHandler(StructureHandler st) { + super.setStructHandler(st); + fontInfo = st.getFontInfo(); + } + + public void addLayoutManager(List lms) { + if (children != null) { + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setLMiter(new LMiter(children.listIterator())); + lms.add(lm); + } + } + + protected void addCharacters(char data[], int start, int length) { + if (textInfo == null) { + // Really only need one of these, but need to get fontInfo + // stored in propMgr for later use. + propMgr.setFontInfo(fontInfo); + textInfo = propMgr.getTextLayoutProps(fontInfo); + } + + FOText ft = new FOText(data, start, length, textInfo); + ft.setUserAgent(userAgent); + ft.setStructHandler(structHandler); + addChild(ft); + } + + public void setup() { + if (this.properties != null) { + setupID(); + } + } + + public CharIterator charIterator() { + return new RecursiveCharIterator(this); + } + +} + diff --git a/src/java/org/apache/fop/fo/GenericShorthandParser.java b/src/java/org/apache/fop/fo/GenericShorthandParser.java new file mode 100644 index 000000000..72dbb0aa3 --- /dev/null +++ b/src/java/org/apache/fop/fo/GenericShorthandParser.java @@ -0,0 +1,107 @@ +/* + * $Id: GenericShorthandParser.java,v 1.4 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.Vector; +import java.util.Enumeration; + +public class GenericShorthandParser implements ShorthandParser { + + protected Vector list; // Vector of Property objects + + public GenericShorthandParser(ListProperty listprop) { + this.list = listprop.getList(); + } + + protected Property getElement(int index) { + if (list.size() > index) { + return (Property)list.elementAt(index); + } else { + return null; + } + } + + protected int count() { + return list.size(); + } + + // Stores 1 to 3 values for border width, style, color + // Used for: border, border-top, border-right etc + public Property getValueForProperty(String propName, + Property.Maker maker, + PropertyList propertyList) { + Property prop = null; + // Check for keyword "inherit" + if (count() == 1) { + String sval = ((Property)list.elementAt(0)).getString(); + if (sval != null && sval.equals("inherit")) { + return propertyList.getFromParent(propName); + } + } + return convertValueForProperty(propName, maker, propertyList); + } + + + protected Property convertValueForProperty(String propName, + Property.Maker maker, + PropertyList propertyList) { + Property prop = null; + // Try each of the stored values in turn + Enumeration eprop = list.elements(); + while (eprop.hasMoreElements() && prop == null) { + Property p = (Property)eprop.nextElement(); + prop = maker.convertShorthandProperty(propertyList, p, null); + } + return prop; + } + +} + diff --git a/src/java/org/apache/fop/fo/InlineCharIterator.java b/src/java/org/apache/fop/fo/InlineCharIterator.java new file mode 100644 index 000000000..bcdc37d6c --- /dev/null +++ b/src/java/org/apache/fop/fo/InlineCharIterator.java @@ -0,0 +1,106 @@ +/* + * $Id: InlineCharIterator.java,v 1.4 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.util.CharUtilities; +import java.util.NoSuchElementException; + + +public class InlineCharIterator extends RecursiveCharIterator { + private boolean bStartBoundary = false; + private boolean bEndBoundary = false; + + public InlineCharIterator(FObj fobj, BorderAndPadding bap) { + super(fobj); + checkBoundaries(bap); + } + + + private void checkBoundaries(BorderAndPadding bap) { + // TODO! use start and end in BAP!! + bStartBoundary = (bap.getBorderLeftWidth(false) > 0 + || bap.getPaddingLeft(false) > 0); + bEndBoundary = (bap.getBorderRightWidth(false) > 0 + || bap.getPaddingRight(false) > 0); + } + + public boolean hasNext() { + if (bStartBoundary) { + return true; + } + return (super.hasNext() || bEndBoundary); + /* If super.hasNext() returns false, + * we return true if we are going to return a "boundary" signal + * else false. + */ + } + + public char nextChar() throws NoSuchElementException { + if (bStartBoundary) { + bStartBoundary = false; + return CharUtilities.CODE_EOT; + } + try { + return super.nextChar(); + } catch (NoSuchElementException e) { + // Underlying has nothing more to return + // Check end boundary char + if (bEndBoundary) { + bEndBoundary = false; + return CharUtilities.CODE_EOT; + } else { + throw e; + } + } + } +} + diff --git a/src/java/org/apache/fop/fo/KeepProperty.java b/src/java/org/apache/fop/fo/KeepProperty.java new file mode 100644 index 000000000..3ac7692fd --- /dev/null +++ b/src/java/org/apache/fop/fo/KeepProperty.java @@ -0,0 +1,79 @@ +/* + * $Id: KeepProperty.java,v 1.3 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.Keep; + +public class KeepProperty extends Property { + + public static class Maker extends Property.Maker { + + protected Maker(String name) { + super(name); + } + + } + + private Keep keep; + + public KeepProperty(Keep keep) { + this.keep = keep; + } + + public Keep getKeep() { + return this.keep; + } + + public Object getObject() { + return this.keep; + } + +} diff --git a/src/java/org/apache/fop/fo/LengthPairProperty.java b/src/java/org/apache/fop/fo/LengthPairProperty.java new file mode 100644 index 000000000..8b0ff539e --- /dev/null +++ b/src/java/org/apache/fop/fo/LengthPairProperty.java @@ -0,0 +1,79 @@ +/* + * $Id: LengthPairProperty.java,v 1.3 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.LengthPair; + +public class LengthPairProperty extends Property { + + public static class Maker extends LengthProperty.Maker { + + protected Maker(String name) { + super(name); + } + + } + + private LengthPair lengthPair; + + public LengthPairProperty(LengthPair lengthPair) { + this.lengthPair = lengthPair; + } + + public LengthPair getLengthPair() { + return this.lengthPair; + } + + public Object getObject() { + return this.lengthPair; + } + +} diff --git a/src/java/org/apache/fop/fo/LengthProperty.java b/src/java/org/apache/fop/fo/LengthProperty.java new file mode 100644 index 000000000..2bdeed108 --- /dev/null +++ b/src/java/org/apache/fop/fo/LengthProperty.java @@ -0,0 +1,130 @@ +/* + * $Id: LengthProperty.java,v 1.7 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.AutoLength; +import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.apps.FOPException; + +public class LengthProperty extends Property { + + public static class Maker extends Property.Maker { + + public /* protected */ Maker(String name) { + super(name); + } + + /** + * protected Property checkPropertyKeywords(String value) { + * if (isAutoLengthAllowed() && value.equals("auto")) { + * return new LengthProperty(Length.AUTO); + * } + * return null; + * } + */ + + protected boolean isAutoLengthAllowed() { + return false; + } + + public Property convertProperty(Property p, + PropertyList propertyList, + FObj fo) throws FOPException { + if (isAutoLengthAllowed()) { + String pval = p.getString(); + if (pval != null && pval.equals("auto")) { + return new LengthProperty(new AutoLength()); + } + } + if (p instanceof LengthProperty) { + return p; + } + Length val = p.getLength(); + if (val != null) { + return new LengthProperty(val); + } + return convertPropertyDatatype(p, propertyList, fo); + } + + } + + /* + * public static Property.Maker maker(String prop) { + * return new Maker(prop); + * } + */ + + /** + * This object may be also be a subclass of Length, such + * as PercentLength, TableColLength. + */ + private Length length; + + public LengthProperty(Length length) { + this.length = length; + // System.err.println("Set LengthProperty: " + length.toString()); + } + + public Numeric getNumeric() { + return length.asNumeric() ; + } + + public Length getLength() { + return this.length; + } + + public Object getObject() { + return this.length; + } + +} + diff --git a/src/java/org/apache/fop/fo/LengthRangeProperty.java b/src/java/org/apache/fop/fo/LengthRangeProperty.java new file mode 100644 index 000000000..d157b0d74 --- /dev/null +++ b/src/java/org/apache/fop/fo/LengthRangeProperty.java @@ -0,0 +1,79 @@ +/* + * $Id: LengthRangeProperty.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.LengthRange; + +public class LengthRangeProperty extends Property { + + public static class Maker extends LengthProperty.Maker { + + protected Maker(String name) { + super(name); + } + + } + + private LengthRange lengthRange; + + public LengthRangeProperty(LengthRange lengthRange) { + this.lengthRange = lengthRange; + } + + public LengthRange getLengthRange() { + return this.lengthRange; + } + + public Object getObject() { + return this.lengthRange; + } + +} diff --git a/src/java/org/apache/fop/fo/ListProperty.java b/src/java/org/apache/fop/fo/ListProperty.java new file mode 100644 index 000000000..c9b2008c8 --- /dev/null +++ b/src/java/org/apache/fop/fo/ListProperty.java @@ -0,0 +1,93 @@ +/* + * $Id: ListProperty.java,v 1.3 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.Vector; + +public class ListProperty extends Property { + + public static class Maker extends Property.Maker { + + public Maker(String name) { + super(name); + } + + public Property convertProperty(Property p, + PropertyList propertyList, FObj fo) { + if (p instanceof ListProperty) { + return p; + } else { + return new ListProperty(p); + } + } + + } + + protected Vector list; + + public ListProperty(Property prop) { + list = new Vector(); + list.addElement(prop); + } + + public void addProperty(Property prop) { + list.addElement(prop); + } + + public Vector getList() { + return list; + } + + public Object getObject() { + return list; + } + +} diff --git a/src/java/org/apache/fop/fo/NumberProperty.java b/src/java/org/apache/fop/fo/NumberProperty.java new file mode 100644 index 000000000..ea228f04f --- /dev/null +++ b/src/java/org/apache/fop/fo/NumberProperty.java @@ -0,0 +1,119 @@ +/* + * $Id: NumberProperty.java,v 1.6 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.expr.Numeric; + +public class NumberProperty extends Property { + + public static class Maker extends Property.Maker { + + public Maker(String propName) { + super(propName); + } + + public Property convertProperty(Property p, + PropertyList propertyList, FObj fo) { + if (p instanceof NumberProperty) { + return p; + } + Number val = p.getNumber(); + if (val != null) { + return new NumberProperty(val); + } + return convertPropertyDatatype(p, propertyList, fo); + } + + } + + private Number number; + + public NumberProperty(Number num) { + this.number = num; + } + + public NumberProperty(double num) { + this.number = new Double(num); + } + + public NumberProperty(int num) { + this.number = new Integer(num); + } + + public Number getNumber() { + return this.number; + } + + /** + * public Double getDouble() { + * return new Double(this.number.doubleValue()); + * } + * public Integer getInteger() { + * return new Integer(this.number.intValue()); + * } + */ + + public Object getObject() { + return this.number; + } + + public Numeric getNumeric() { + return new Numeric(this.number); + } + + public ColorType getColorType() { + // Convert numeric value to color ??? + // Convert to hexadecimal and then try to make it into a color? + return new ColorType((float)0.0, (float)0.0, (float)0.0); + } + +} diff --git a/src/java/org/apache/fop/fo/OneCharIterator.java b/src/java/org/apache/fop/fo/OneCharIterator.java new file mode 100644 index 000000000..4a618e020 --- /dev/null +++ b/src/java/org/apache/fop/fo/OneCharIterator.java @@ -0,0 +1,79 @@ +/* + * $Id: OneCharIterator.java,v 1.4 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.NoSuchElementException; + + +public class OneCharIterator extends AbstractCharIterator { + + private boolean bFirst = true; + private char charCode; + + public OneCharIterator(char c) { + this.charCode = c; + } + + public boolean hasNext() { + return bFirst; + } + + public char nextChar() throws NoSuchElementException { + if (bFirst) { + bFirst = false; + return charCode; + } else { + throw new NoSuchElementException(); + } + } + +} + diff --git a/src/java/org/apache/fop/fo/Property.java b/src/java/org/apache/fop/fo/Property.java new file mode 100644 index 000000000..0791ab967 --- /dev/null +++ b/src/java/org/apache/fop/fo/Property.java @@ -0,0 +1,490 @@ +/* + * $Id: Property.java,v 1.22 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.CondLength; +import org.apache.fop.datatypes.Keep; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.LengthPair; +import org.apache.fop.datatypes.LengthRange; +import org.apache.fop.datatypes.PercentBase; +import org.apache.fop.datatypes.Space; +import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.expr.PropertyParser; +import org.apache.fop.fo.expr.PropertyInfo; +import org.apache.fop.apps.FOPException; +import java.util.Vector; + +public class Property { + + public static class Maker { + private static final String UNKNOWN = "UNKNOWN"; + private String propName; + + /** + * Return the name of the property whose value is being set. + */ + protected String getPropName() { + return propName; + } + + /** + * Construct an instance of a Property.Maker for the given property. + * @param propName The name of the property to be made. + */ + protected Maker(String propName) { + this.propName = propName; + } + + /** + * Construct an instance of a Property.Maker. + * Note: the property name is set to "UNKNOWN". + */ + protected Maker() { + this.propName = UNKNOWN; + } + + + /** + * Default implementation of isInherited. + * @return A boolean indicating whether this property is inherited. + */ + public boolean isInherited() { + return false; + } + + /** + * Return a boolean indicating whether this property inherits the + * "specified" value rather than the "computed" value. The default is + * to inherit the "computed" value. + * @return If true, property inherits the value specified. + */ + public boolean inheritsSpecified() { + return false; + } + + + /** + * Return an object implementing the PercentBase interface. + * This is used to handle properties specified as a percentage of + * some "base length", such as the content width of their containing + * box. + * Overridden by subclasses which allow percent specifications. See + * the documentation on properties.xsl for details. + */ + public PercentBase getPercentBase(FObj fo, PropertyList pl) { + return null; + } + + /** + * Return a Maker object which is used to set the values on components + * of compound property types, such as "space". + * Overridden by property maker subclasses which handle + * compound properties. + * @param subprop The name of the component for which a Maker is to + * returned, for example "optimum", if the FO attribute is + * space.optimum='10pt'. + */ + protected Maker getSubpropMaker(String subprop) { + return null; + } + + /** + * Return a property value for the given component of a compound + * property. + * @param p A property value for a compound property type such as + * SpaceProperty. + * @param subprop The name of the component whose value is to be + * returned. + * NOTE: this is only to ease porting when calls are made to + * PropertyList.get() using a component name of a compound property, + * such as get("space.optimum"). The recommended technique is: + * get("space").getOptimum(). + * Overridden by property maker subclasses which handle + * compound properties. + */ + public Property getSubpropValue(Property p, String subprop) { + return null; + } + + /** + * Return a property value for a compound property. If the property + * value is already partially initialized, this method will modify it. + * @param baseProp The Property object representing the compound property, + * such as SpaceProperty. + * @param partName The name of the component whose value is specified. + * @param propertyList The propertyList being built. + * @param fo The FO whose properties are being set. + * @return A compound property object. + */ + public Property make(Property baseProp, String partName, + PropertyList propertyList, String value, + FObj fo) throws FOPException { + if (baseProp == null) { + baseProp = makeCompound(propertyList, fo); + } + Maker spMaker = getSubpropMaker(partName); + if (spMaker != null) { + Property p = spMaker.make(propertyList, value, fo); + if (p != null) { + return setSubprop(baseProp, partName, p); + } + } else { + //getLogger().error("compound property component " + // + partName + " unknown."); + } + return baseProp; + } + + /** + * Set a component in a compound property and return the modified + * compound property object. + * This default implementation returns the original base property + * without modifying it. + * It is overridden by property maker subclasses which handle + * compound properties. + * @param baseProp The Property object representing the compound property, + * such as SpaceProperty. + * @param partName The name of the component whose value is specified. + * @param subProp A Property object holding the specified value of the + * component to be set. + * @return The modified compound property object. + */ + protected Property setSubprop(Property baseProp, String partName, + Property subProp) { + return baseProp; + } + + /** + * Create a Property object from an attribute specification. + * @param propertyList The PropertyList object being built for this FO. + * @param value The attribute value. + * @param fo The current FO whose properties are being set. + * @return The initialized Property object. + */ + public Property make(PropertyList propertyList, String value, + FObj fo) throws FOPException { + try { + Property pret = null; + String pvalue = value; + pret = checkEnumValues(value); + if (pret == null) { + /* Check for keyword shorthand values to be substituted. */ + pvalue = checkValueKeywords(value); + // Override parsePropertyValue in each subclass of Property.Maker + Property p = PropertyParser.parse(pvalue, + new PropertyInfo(this, + propertyList, fo)); + pret = convertProperty(p, propertyList, fo); + } else if (isCompoundMaker()) { + pret = convertProperty(pret, propertyList, fo); + } + if (pret == null) { + throw new org.apache.fop.fo.expr.PropertyException("No conversion defined"); + } else if (inheritsSpecified()) { + pret.setSpecifiedValue(pvalue); + } + return pret; + } catch (org.apache.fop.fo.expr.PropertyException propEx) { + throw new FOPException("Error in " + propName + + " property value '" + value + "': " + + propEx); + } + } + + public Property convertShorthandProperty(PropertyList propertyList, + Property prop, FObj fo) { + Property pret = null; + try { + pret = convertProperty(prop, propertyList, fo); + if (pret == null) { + // If value is a name token, may be keyword or Enum + String sval = prop.getNCname(); + if (sval != null) { + // System.err.println("Convert shorthand ncname " + sval); + pret = checkEnumValues(sval); + if (pret == null) { + /* Check for keyword shorthand values to be substituted. */ + String pvalue = checkValueKeywords(sval); + if (!pvalue.equals(sval)) { + // System.err.println("Convert shorthand keyword" + pvalue); + // Substituted a value: must parse it + Property p = + PropertyParser.parse(pvalue, + new PropertyInfo(this, + propertyList, + fo)); + pret = convertProperty(p, propertyList, fo); + } + } + } + } + } catch (FOPException e) { + + //getLogger().error("convertShorthandProperty caught FOPException " + // + e); + } catch (org.apache.fop.fo.expr.PropertyException propEx) { + //getLogger().error("convertShorthandProperty caught PropertyException " + // + propEx); + } + if (pret != null) { + /* + * System.err.println("Return shorthand value " + pret.getString() + + * " for " + getPropName()); + */ + } + return pret; + } + + protected boolean isCompoundMaker() { + return false; + } + + public Property checkEnumValues(String value) { + return null; + } + + /** + * Return a String to be parsed if the passed value corresponds to + * a keyword which can be parsed and used to initialize the property. + * For example, the border-width family of properties can have the + * initializers "thin", "medium", or "thick". The foproperties.xml + * file specifies a length value equivalent for these keywords, + * such as "0.5pt" for "thin". These values are considered parseable, + * since the Length object is no longer responsible for parsing + * unit expresssions. + * @param value The string value of property attribute. + * @return A String containging a parseable equivalent or null if + * the passed value isn't a keyword initializer for this Property. + */ + protected String checkValueKeywords(String value) { + return value; + } + + /** + * Return a Property object based on the passed Property object. + * This method is called if the Property object built by the parser + * isn't the right type for this property. + * It is overridden by subclasses when the property specification in + * foproperties.xml specifies conversion rules. + * @param p The Property object return by the expression parser + * @param propertyList The PropertyList object being built for this FO. + * @param fo The current FO whose properties are being set. + * @return A Property of the correct type or null if the parsed value + * can't be converted to the correct type. + */ + public Property convertProperty(Property p, + PropertyList propertyList, + FObj fo) throws FOPException { + return null; + } + + protected Property convertPropertyDatatype(Property p, + PropertyList propertyList, + FObj fo) { + return null; + } + + /** + * Return a Property object representing the initial value. + * @param propertyList The PropertyList object being built for this FO. + */ + public Property make(PropertyList propertyList) throws FOPException { + return null; + } + + /** + * Return a Property object representing the initial value. + * @param propertyList The PropertyList object being built for this FO. + * @param parentFO The parent FO for the FO whose property is being made. + * @return a Property subclass object holding a "compound" property object + * initialized to the default values for each component. + */ + protected Property makeCompound(PropertyList propertyList, + FObj parentFO) throws FOPException { + return null; + } + + /** + * Return a Property object representing the value of this property, + * based on other property values for this FO. + * A special case is properties which inherit the specified value, + * rather than the computed value. + * @param propertyList The PropertyList for the FO. + * @return Property A computed Property value or null if no rules + * are specified (in foproperties.xml) to compute the value. + */ + public Property compute(PropertyList propertyList) + throws FOPException { + if (inheritsSpecified()) { + // recalculate based on last specified value + // Climb up propertylist and find last spec'd value + // NEED PROPNAME!!! get from Maker + Property specProp = + propertyList.getNearestSpecified(propName); + if (specProp != null) { + // Only need to do this if the value is relative!!! + String specVal = specProp.getSpecifiedValue(); + if (specVal != null) { + try { + return make(propertyList, specVal, + propertyList.getParentFObj()); + } catch (FOPException e) { + //getLogger()error("Error computing property value for " + // + propName + " from " + // + specVal); + return null; + } + } + } + } + return null; // standard + } + + public boolean isCorrespondingForced(PropertyList propertyList) { + return false; + } + + public Property getShorthand(PropertyList propertyList) { + return null; + } + + } // end of nested Maker class + + /** + * The original specified value for properties which inherit + * specified values. + */ + private String specVal; + + /** + * Set the original value specified for the property attribute. + * @param specVal The specified value. + */ + public void setSpecifiedValue(String specVal) { + this.specVal = specVal; + } + + /** + * Return the original value specified for the property attribute. + * @return The specified value as a String. + */ + public String getSpecifiedValue() { + return specVal; + } + + /** + * Accessor functions for all possible Property datatypes + */ + public Length getLength() { + return null; + } + + public ColorType getColorType() { + return null; + } + + public CondLength getCondLength() { + return null; + } + + public LengthRange getLengthRange() { + return null; + } + + public LengthPair getLengthPair() { + return null; + } + + public Space getSpace() { + return null; + } + + public Keep getKeep() { + return null; + } + + public int getEnum() { + return 0; + } + + public char getCharacter() { + return 0; + } + + public Vector getList() { + return null; + } // List of Property objects + + public Number getNumber() { + return null; + } + + // Classes used when evaluating property expressions + public Numeric getNumeric() { + return null; + } + + public String getNCname() { + return null; + } + + public Object getObject() { + return null; + } + + public String getString() { + Object o = getObject(); + return (o == null) ? null : o.toString(); + } + +} diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java new file mode 100644 index 000000000..eab6969e0 --- /dev/null +++ b/src/java/org/apache/fop/fo/PropertyList.java @@ -0,0 +1,416 @@ +/* + * $Id: PropertyList.java,v 1.20 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.HashMap; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.apps.FOPException; + +public class PropertyList extends HashMap { + + private byte[] wmtable = null; // writing-mode values + public static final int LEFT = 0; + public static final int RIGHT = 1; + public static final int TOP = 2; + public static final int BOTTOM = 3; + public static final int HEIGHT = 4; + public static final int WIDTH = 5; + + public static final int START = 0; + public static final int END = 1; + public static final int BEFORE = 2; + public static final int AFTER = 3; + public static final int BLOCKPROGDIM = 4; + public static final int INLINEPROGDIM = 5; + + private static final String[] ABS_NAMES = new String[] { + "left", "right", "top", "bottom", "height", "width" + }; + + private static final String[] REL_NAMES = new String[] { + "start", "end", "before", "after", "block-progression-dimension", + "inline-progression-dimension" + }; + + private static final HashMap WRITING_MODE_TABLES = new HashMap(4); + { + WRITING_MODE_TABLES.put(new Integer(WritingMode.LR_TB), /* lr-tb */ + new byte[] { + START, END, BEFORE, AFTER, BLOCKPROGDIM, INLINEPROGDIM + }); + WRITING_MODE_TABLES.put(new Integer(WritingMode.RL_TB), /* rl-tb */ + new byte[] { + END, START, BEFORE, AFTER, BLOCKPROGDIM, INLINEPROGDIM + }); + WRITING_MODE_TABLES.put(new Integer(WritingMode.TB_RL), /* tb-rl */ + new byte[] { + AFTER, BEFORE, START, END, INLINEPROGDIM, BLOCKPROGDIM + }); + } + + private PropertyListBuilder builder; + private PropertyList parentPropertyList = null; + private String namespace = ""; + private String element = ""; + private FObj fobj = null; + + public PropertyList(PropertyList parentPropertyList, String space, + String el) { + this.parentPropertyList = parentPropertyList; + this.namespace = space; + this.element = el; + } + + public void setFObj(FObj fobj) { + this.fobj = fobj; + } + + public FObj getFObj() { + return this.fobj; + } + + public FObj getParentFObj() { + if (parentPropertyList != null) { + return parentPropertyList.getFObj(); + } else { + return null; + } + } + + /** + * Return the value explicitly specified on this FO. + * @param propertyName The name of the property whose value is desired. + * It may be a compound name, such as space-before.optimum. + * @return The value if the property is explicitly set or set by + * a shorthand property, otherwise null. + */ + public Property getExplicitOrShorthand(String propertyName) { + /* Handle request for one part of a compound property */ + int sepchar = propertyName.indexOf('.'); + String baseName; + if (sepchar > -1) { + baseName = propertyName.substring(0, sepchar); + } else { + baseName = propertyName; + } + Property p = getExplicitBaseProp(baseName); + if (p == null) { + p = builder.getShorthand(this, namespace, element, baseName); + } + if (p != null && sepchar > -1) { + return builder.getSubpropValue(namespace, element, baseName, p, + propertyName.substring(sepchar + + 1)); + } + return p; + } + + /** + * Return the value explicitly specified on this FO. + * @param propertyName The name of the property whose value is desired. + * It may be a compound name, such as space-before.optimum. + * @return The value if the property is explicitly set, otherwise null. + */ + public Property getExplicit(String propertyName) { + /* Handle request for one part of a compound property */ + int sepchar = propertyName.indexOf('.'); + if (sepchar > -1) { + String baseName = propertyName.substring(0, sepchar); + Property p = getExplicitBaseProp(baseName); + if (p != null) { + return this.builder.getSubpropValue(namespace, element, + baseName, p, + propertyName.substring(sepchar + + 1)); + } else { + return null; + } + } + return (Property)super.get(propertyName); + } + + /** + * Return the value explicitly specified on this FO. + * @param propertyName The name of the base property whose value is desired. + * @return The value if the property is explicitly set, otherwise null. + */ + public Property getExplicitBaseProp(String propertyName) { + return (Property)super.get(propertyName); + } + + /** + * Return the value of this property inherited by this FO. + * Implements the inherited-property-value function. + * The property must be inheritable! + * @param propertyName The name of the property whose value is desired. + * @return The inherited value, otherwise null. + */ + public Property getInherited(String propertyName) { + if (builder != null) { + if (parentPropertyList != null + && builder.isInherited(namespace, element, + propertyName)) { + return parentPropertyList.get(propertyName); + } else { + // return the "initial" value + try { + return builder.makeProperty(this, namespace, element, + propertyName); + } catch (org.apache.fop.apps.FOPException e) { + //log.error("Exception in getInherited(): property=" + // + propertyName + " : " + e); + } + } + } + return null; // No builder or exception in makeProperty! + } + + /* + * If the property is a relative property with a corresponding absolute + * value specified, the absolute value is used. This is also true of + * the inheritance priority (I think...) + * If the property is an "absolute" property and it isn't specified, then + * we try to compute it from the corresponding relative property: this + * happends in computeProperty. + */ + private Property findProperty(String propertyName, boolean bTryInherit) { + Property p = null; + if (builder.isCorrespondingForced(this, namespace, element, + propertyName)) { + p = builder.computeProperty(this, namespace, element, + propertyName); + } else { + p = getExplicitBaseProp(propertyName); + if (p == null) { + p = this.builder.computeProperty(this, namespace, element, + propertyName); + } + if (p == null) { // check for shorthand specification + p = builder.getShorthand(this, namespace, element, + propertyName); + } + if (p == null + && bTryInherit) { // else inherit (if has parent and is inheritable) + if (this.parentPropertyList != null + && builder.isInherited(namespace, element, + propertyName)) { + p = parentPropertyList.findProperty(propertyName, true); + } + } + } + return p; + } + + + /** + * Return the property on the current FlowObject if it is specified, or if a + * corresponding property is specified. If neither is specified, it returns null. + */ + public Property getSpecified(String propertyName) { + return get(propertyName, false, false); + } + + + /** + * Return the property on the current FlowObject. If it isn't set explicitly, + * this will try to compute it based on other properties, or if it is + * inheritable, to return the inherited value. If all else fails, it returns + * the default value. + */ + public Property get(String propertyName) { + return get(propertyName, true, true); + } + + /** + * Return the property on the current FlowObject. Depending on the passed flags, + * this will try to compute it based on other properties, or if it is + * inheritable, to return the inherited value. If all else fails, it returns + * the default value. + */ + private Property get(String propertyName, boolean bTryInherit, + boolean bTryDefault) { + + if (builder == null) { + //log.error("OH OH, builder has not been set"); + } + /* Handle request for one part of a compound property */ + int sepchar = propertyName.indexOf('.'); + String subpropName = null; + if (sepchar > -1) { + subpropName = propertyName.substring(sepchar + 1); + propertyName = propertyName.substring(0, sepchar); + } + + Property p = findProperty(propertyName, bTryInherit); + if (p == null && bTryDefault) { // default value for this FO! + try { + p = this.builder.makeProperty(this, namespace, element, + propertyName); + } catch (FOPException e) { + // don't know what to do here + } + } + + // if value is inherit then get computed value from + // parent + if (p != null && "inherit".equals(p.getSpecifiedValue())) { + if (this.parentPropertyList != null) { + p = parentPropertyList.get(propertyName, true, false); + } + } + + if (subpropName != null && p != null) { + return this.builder.getSubpropValue(namespace, element, + propertyName, p, subpropName); + } else { + return p; + } + } + + public void setBuilder(PropertyListBuilder builder) { + this.builder = builder; + } + + public String getNameSpace() { + return namespace; + } + + public String getElement() { + return element; + } + + /** + * Return the "nearest" specified value for the given property. + * Implements the from-nearest-specified-value function. + * @param propertyName The name of the property whose value is desired. + * @return The computed value if the property is explicitly set on some + * ancestor of the current FO, else the initial value. + */ + public Property getNearestSpecified(String propertyName) { + Property p = null; + for (PropertyList plist = this; p == null && plist != null; + plist = plist.parentPropertyList) { + p = plist.getExplicit(propertyName); + } + if (p == null) { + // If no explicit setting found, return initial (default) value. + try { + p = this.builder.makeProperty(this, namespace, element, + propertyName); + } catch (FOPException e) { + //log.error("Exception in getNearestSpecified(): property=" + // + propertyName + " : " + e); + } + } + return p; + } + + /** + * Return the value of this property on the parent of this FO. + * Implements the from-parent function. + * @param propertyName The name of the property whose value is desired. + * @return The computed value on the parent or the initial value if this + * FO is the root or is in a different namespace from its parent. + */ + public Property getFromParent(String propertyName) { + if (parentPropertyList != null) { + return parentPropertyList.get(propertyName); + } else if (builder != null) { + // return the "initial" value + try { + return builder.makeProperty(this, namespace, element, + propertyName); + } catch (org.apache.fop.apps.FOPException e) { + //log.error("Exception in getFromParent(): property=" + // + propertyName + " : " + e); + } + } + return null; // No builder or exception in makeProperty! + } + + /** + * Given an absolute direction (top, bottom, left, right), + * return the corresponding writing model relative direction name + * for the flow object. Uses the stored writingMode. + */ + public String wmAbsToRel(int absdir) { + if (wmtable != null) { + return REL_NAMES[wmtable[absdir]]; + } else { + return ""; + } + } + + /** + * Given a writing mode relative direction (start, end, before, after) + * return the corresponding absolute direction name + * for the flow object. Uses the stored writingMode. + */ + public String wmRelToAbs(int reldir) { + if (wmtable != null) { + for (int i = 0; i < wmtable.length; i++) { + if (wmtable[i] == reldir) { + return ABS_NAMES[i]; + } + } + } + return ""; + } + + /** + * Set the writing mode traits for the FO with this property list. + */ + public void setWritingMode(int writingMode) { + this.wmtable = (byte[])WRITING_MODE_TABLES.get(new Integer(writingMode)); + } + +} + diff --git a/src/java/org/apache/fop/fo/PropertyListBuilder.java b/src/java/org/apache/fop/fo/PropertyListBuilder.java new file mode 100644 index 000000000..98fe85c01 --- /dev/null +++ b/src/java/org/apache/fop/fo/PropertyListBuilder.java @@ -0,0 +1,305 @@ +/* + * $Id: PropertyListBuilder.java,v 1.35 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.util.HashMap; +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; + +public class PropertyListBuilder { + + /** + * Name of font-size property attribute to set first. + */ + private static final String FONTSIZEATTR = "font-size"; + + private HashMap propertyListTable; + private HashMap elementTable; + + public PropertyListBuilder() { + this.propertyListTable = new HashMap(); + this.elementTable = new HashMap(); + } + + public void addList(HashMap list) { + propertyListTable.putAll(list); + } + + public void addElementList(String element, HashMap list) { + elementTable.put(element, list); + } + + public Property computeProperty(PropertyList propertyList, String space, + String element, String propertyName) { + + Property p = null; + Property.Maker propertyMaker = findMaker(space, element, + propertyName); + if (propertyMaker != null) { + try { + p = propertyMaker.compute(propertyList); + } catch (FOPException e) { + //log.error("exception occurred while computing" + // + " value of property '" + // + propertyName + "': " + // + e.getMessage()); + } + } else { + //log.error("property " + propertyName + // + " ignored"); + } + return p; + } + + public boolean isInherited(String space, String element, + String propertyName) { + boolean b; + + Property.Maker propertyMaker = findMaker(space, element, + propertyName); + if (propertyMaker != null) { + b = propertyMaker.isInherited(); + } else { + // log.error("Unknown property " + propertyName); + b = true; + } + return b; + } + + public PropertyList makeList(String ns, String elementName, Attributes attributes, + PropertyList parentPropertyList, + FObj parentFO) throws FOPException { + String space = "http://www.w3.org/TR/1999/XSL/Format"; + if (ns != null) { + space = ns; + } + + PropertyList par = null; + if (parentPropertyList != null + && space.equals(parentPropertyList.getNameSpace())) { + par = parentPropertyList; + } + PropertyList p = new PropertyList(par, space, + elementName); + p.setBuilder(this); + HashMap table; + table = (HashMap)elementTable.get(elementName); + + /* Store names of properties already set. */ + StringBuffer propsDone = new StringBuffer(256); + propsDone.append(' '); + + /* + * If font-size is set on this FO, must set it first, since + * other attributes specified in terms of "ems" depend on it. + * When we do "shorthand" properties, must handle the "font" + * property as well to see if font-size is set. + */ + String fontsizeval = attributes.getValue(FONTSIZEATTR); + if (fontsizeval != null) { + Property.Maker propertyMaker = findMaker(table, FONTSIZEATTR); + if (propertyMaker != null) { + try { + p.put(FONTSIZEATTR, + propertyMaker.make(p, fontsizeval, parentFO)); + } catch (FOPException e) { + /**@todo log this exception */ + } + } + // Put in the "done" list even if error or no Maker. + propsDone.append(FONTSIZEATTR + ' '); + } + + for (int i = 0; i < attributes.getLength(); i++) { + String attributeName = attributes.getQName(i); + /* Handle "compound" properties, ex. space-before.minimum */ + int sepchar = attributeName.indexOf('.'); + String propName = attributeName; + String subpropName = null; + Property propVal = null; + if (sepchar > -1) { + propName = attributeName.substring(0, sepchar); + subpropName = attributeName.substring(sepchar + 1); + } else if (propsDone.toString().indexOf(' ' + propName + ' ') + != -1) { + // Already processed this property (base property + // for a property with sub-components or font-size) + continue; + } + + Property.Maker propertyMaker = findMaker(table, propName); + + if (propertyMaker != null) { + try { + if (subpropName != null) { + Property baseProp = p.getExplicitBaseProp(propName); + if (baseProp == null) { + // See if it is specified later in this list + String baseValue = attributes.getValue(propName); + if (baseValue != null) { + baseProp = propertyMaker.make(p, baseValue, + parentFO); + propsDone.append(propName + ' '); + } + // else baseProp = propertyMaker.makeCompound(p, parentFO); + } + propVal = propertyMaker.make(baseProp, subpropName, + p, + attributes.getValue(i), + parentFO); + } else { + propVal = propertyMaker.make(p, + attributes.getValue(i), + parentFO); + } + if (propVal != null) { + p.put(propName, propVal); + } + } catch (FOPException e) { /* Do other props. */ + //log.error(e.getMessage()); + } + } else { + if (!attributeName.startsWith("xmlns")) { + //log.error("property '" + // + attributeName + "' ignored"); + } + } + } + + return p; + } + + public Property getSubpropValue(String space, String element, + String propertyName, Property p, + String subpropName) { + Property.Maker maker = findMaker(space, element, propertyName); + if (maker != null) { + return maker.getSubpropValue(p, subpropName); + } else { + return null; + } + } + + + public boolean isCorrespondingForced(PropertyList propertyList, + String space, String element, + String propertyName) { + Property.Maker propertyMaker = findMaker(space, element, + propertyName); + if (propertyMaker != null) { + return propertyMaker.isCorrespondingForced(propertyList); + } else { + //log.error("no Maker for " + propertyName); + } + return false; + } + + public Property getShorthand(PropertyList propertyList, String space, + String element, String propertyName) { + Property.Maker propertyMaker = findMaker(space, element, + propertyName); + if (propertyMaker != null) { + return propertyMaker.getShorthand(propertyList); + } else { + //log.error("no Maker for " + propertyName); + return null; + } + } + + + public Property makeProperty(PropertyList propertyList, String space, + String element, + String propertyName) throws FOPException { + + Property p = null; + + Property.Maker propertyMaker = findMaker(space, element, + propertyName); + if (propertyMaker != null) { + p = propertyMaker.make(propertyList); + } else { + //log.error("property " + propertyName + // + " ignored"); + } + return p; + } + + protected Property.Maker findMaker(String space, String elementName, + String propertyName) { + return findMaker((HashMap)elementTable.get(elementName), + propertyName); + } + + /** + * Convenience function to return the Maker for a given property + * given the HashMap containing properties specific to this element. + * If table is non-null and + * @param elemTable Element-specific properties or null if none. + * @param propertyName Name of property. + * @return A Maker for this property. + */ + private Property.Maker findMaker(HashMap elemTable, + String propertyName) { + Property.Maker propertyMaker = null; + if (elemTable != null) { + propertyMaker = (Property.Maker)elemTable.get(propertyName); + } + if (propertyMaker == null) { + propertyMaker = + (Property.Maker)propertyListTable.get(propertyName); + } + return propertyMaker; + } + +} diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java new file mode 100644 index 000000000..221994cf7 --- /dev/null +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -0,0 +1,582 @@ +/* + * $Id: PropertyManager.java,v 1.17 2003/03/05 20:38:27 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.text.MessageFormat; +import java.awt.geom.Rectangle2D; + +// FOP +import org.apache.fop.area.CTM; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.layout.FontState; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layout.AbsolutePositionProps; +import org.apache.fop.traits.BlockProps; +import org.apache.fop.traits.InlineProps; +import org.apache.fop.traits.SpaceVal; +import org.apache.fop.traits.LayoutProps; // keep, break, span, space? +import org.apache.fop.fo.properties.Constants; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.fo.properties.Span; +import org.apache.fop.fonts.FontMetrics; +import org.apache.fop.layout.HyphenationProps; + +/** + * Helper class for managing groups of properties. + */ +public class PropertyManager { + + private PropertyList properties; + private FontInfo fontInfo = null; + private FontState fontState = null; + private BorderAndPadding borderAndPadding = null; + private HyphenationProps hyphProps = null; + private TextInfo textInfo = null; + + private static final String[] SA_BEFORE = new String[]{"before"}; + private static final String[] SA_AFTER = new String[]{"after"}; + private static final String[] SA_START = new String[]{"start"}; + private static final String[] SA_END = new String[]{"end"}; + + private static final MessageFormat MSGFMT_COLOR = new MessageFormat("border-{0}-color"); + private static final MessageFormat MSGFMT_STYLE = new MessageFormat("border-{0}-style"); + private static final MessageFormat MSGFMT_WIDTH = new MessageFormat("border-{0}-width"); + private static final MessageFormat MSGFMT_PADDING = new MessageFormat("padding-{0}"); + + private static final String NONE = "none"; + + /** + * Main constructor + * @param pList property list + */ + public PropertyManager(PropertyList pList) { + this.properties = pList; + } + + /** + * Returns the property list that is used for lookup. + * @return the property list + */ + public PropertyList getProperties() { + return properties; + } + + /** + * Sets the FontInfo object telling the property manager which fonts are + * available. + * @param fontInfo available fonts + */ + public void setFontInfo(FontInfo fontInfo) { + this.fontInfo = fontInfo; + } + + + /** + * Constructs a FontState object. If it was constructed before it is + * reused. + * @param fontInfo FontInfo to work with + * @return a FontState object + */ + public FontState getFontState(FontInfo fontInfo) { + if (fontState == null) { + if (fontInfo == null) { + fontInfo = this.fontInfo; + } else if (this.fontInfo == null) { + this.fontInfo = fontInfo; + } + /**@todo this is ugly. need to improve. */ + + String fontFamily = properties.get("font-family").getString(); + String fontStyle = properties.get("font-style").getString(); + String fw = properties.get("font-weight").getString(); + int fontWeight = 400; + if (fw.equals("bolder")) { + // +100 from inherited + } else if (fw.equals("lighter")) { + // -100 from inherited + } else { + try { + fontWeight = Integer.parseInt(fw); + } catch (NumberFormatException nfe) { + } /**@todo log that exception */ + } + fontWeight = ((int) fontWeight / 100) * 100; + if (fontWeight < 100) { + fontWeight = 100; + } else if (fontWeight > 900) { + fontWeight = 900; + } + + // NOTE: this is incomplete. font-size may be specified with + // various kinds of keywords too + int fontSize = properties.get("font-size").getLength().getValue(); + //int fontVariant = properties.get("font-variant").getEnum(); + String fname = fontInfo.fontLookup(fontFamily, fontStyle, + fontWeight); + FontMetrics metrics = fontInfo.getMetricsFor(fname); + fontState = new FontState(fname, metrics, fontSize); + } + return fontState; + } + + + /** + * Constructs a BorderAndPadding object. If it was constructed before it is + * reused. + * @return a BorderAndPadding object + */ + public BorderAndPadding getBorderAndPadding() { + if (borderAndPadding == null) { + this.borderAndPadding = new BorderAndPadding(); + + initBorderInfo(BorderAndPadding.BEFORE, SA_BEFORE); + initBorderInfo(BorderAndPadding.AFTER, SA_AFTER); + initBorderInfo(BorderAndPadding.START, SA_START); + initBorderInfo(BorderAndPadding.END, SA_END); + } + return borderAndPadding; + } + + private void initBorderInfo(int whichSide, String[] saSide) { + borderAndPadding.setPadding(whichSide, + properties.get( + MSGFMT_PADDING.format(saSide)).getCondLength()); + // If style = none, force width to 0, don't get Color + int style = properties.get(MSGFMT_STYLE.format(saSide)).getEnum(); + if (style != Constants.NONE) { + borderAndPadding.setBorder(whichSide, style, + properties.get( + MSGFMT_WIDTH.format(saSide)).getCondLength(), + properties.get( + MSGFMT_COLOR.format(saSide)).getColorType()); + } + } + + /** + * Constructs a HyphenationProps objects. If it was constructed before it is + * reused. + * @return a HyphenationProps object + */ + public HyphenationProps getHyphenationProps() { + if (hyphProps == null) { + this.hyphProps = new HyphenationProps(); + hyphProps.hyphenate = + this.properties.get("hyphenate").getEnum(); + hyphProps.hyphenationChar = this.properties.get( + "hyphenation-character").getCharacter(); + hyphProps.hyphenationPushCharacterCount = this.properties.get( + "hyphenation-push-character-count").getNumber(). + intValue(); + hyphProps.hyphenationRemainCharacterCount = this.properties.get( + "hyphenation-remain-character-count").getNumber(). + intValue(); + hyphProps.language = + this.properties.get("language").getString(); + hyphProps.country = this.properties.get("country").getString(); + } + return hyphProps; + } + + /*public int checkBreakBefore(Area area) { + if (!(area instanceof ColumnArea)) { + switch (properties.get("break-before").getEnum()) { + case BreakBefore.PAGE: + return Status.FORCE_PAGE_BREAK; + case BreakBefore.ODD_PAGE: + return Status.FORCE_PAGE_BREAK_ODD; + case BreakBefore.EVEN_PAGE: + return Status.FORCE_PAGE_BREAK_EVEN; + case BreakBefore.COLUMN: + return Status.FORCE_COLUMN_BREAK; + default: + return Status.OK; + } + } else { + ColumnArea colArea = (ColumnArea)area; + switch (properties.get("break-before").getEnum()) { + case BreakBefore.PAGE: + // if first ColumnArea, and empty, return OK + if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1)) + return Status.OK; + else + return Status.FORCE_PAGE_BREAK; + case BreakBefore.ODD_PAGE: + // if first ColumnArea, empty, _and_ in odd page, + // return OK + if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1) + && (colArea.getPage().getNumber() % 2 != 0)) + return Status.OK; + else + return Status.FORCE_PAGE_BREAK_ODD; + case BreakBefore.EVEN_PAGE: + // if first ColumnArea, empty, _and_ in even page, + // return OK + if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1) + && (colArea.getPage().getNumber() % 2 == 0)) + return Status.OK; + else + return Status.FORCE_PAGE_BREAK_EVEN; + case BreakBefore.COLUMN: + // if ColumnArea is empty return OK + if (!area.hasChildren()) + return Status.OK; + else + return Status.FORCE_COLUMN_BREAK; + default: + return Status.OK; + } + } + } + + public int checkBreakAfter(Area area) { + switch (properties.get("break-after").getEnum()) { + case BreakAfter.PAGE: + return Status.FORCE_PAGE_BREAK; + case BreakAfter.ODD_PAGE: + return Status.FORCE_PAGE_BREAK_ODD; + case BreakAfter.EVEN_PAGE: + return Status.FORCE_PAGE_BREAK_EVEN; + case BreakAfter.COLUMN: + return Status.FORCE_COLUMN_BREAK; + default: + return Status.OK; + } + }*/ + + + /** + * Constructs a MarginProps objects. If it was constructed before it is + * reused. + * @return a MarginProps object + */ + public MarginProps getMarginProps() { + MarginProps props = new MarginProps(); + + // Common Margin Properties-Block + props.marginTop = + this.properties.get("margin-top").getLength().getValue(); + props.marginBottom = + this.properties.get("margin-bottom").getLength().getValue(); + props.marginLeft = + this.properties.get("margin-left").getLength().getValue(); + props.marginRight = + this.properties.get("margin-right").getLength().getValue(); + + // For now, we only get the optimum value for space-before and after + props.spaceBefore = this.properties.get("space-before"). + getSpace().getOptimum().getLength().getValue(); + props.spaceAfter = this.properties.get("space-after"). + getSpace().getOptimum().getLength().getValue(); + props.startIndent = this.properties.get("start-indent"). + getLength().getValue(); + props.endIndent = this.properties.get("end-indent"). + getLength().getValue(); + + return props; + } + + /** + * Constructs a BackgroundProps objects. If it was constructed before it is + * reused. + * @return a BackgroundProps object + */ + public BackgroundProps getBackgroundProps() { + BackgroundProps bp = new BackgroundProps(); + bp.backAttachment = properties.get("background-attachment").getEnum(); + bp.backColor = properties.get("background-color").getColorType(); + if (bp.backColor.alpha() == 1) { + bp.backColor = null; + } + + bp.backImage = properties.get("background-image").getString(); + if (bp.backImage == null || NONE.equals(bp.backImage)) { + bp.backImage = null; + } else { + bp.backRepeat = properties.get("background-repeat").getEnum(); + Property prop = properties.get("background-position-horizontal"); + if (prop != null) { + bp.backPosHorizontal = prop.getLength(); + } + prop = properties.get("background-position-vertical"); + if (prop != null) { + bp.backPosVertical = prop.getLength(); + } + } + + return bp; + } + + /** + * Constructs a MarginInlineProps objects. If it was constructed before it is + * reused. + * @return a MarginInlineProps object + */ + public MarginInlineProps getMarginInlineProps() { + MarginInlineProps props = new MarginInlineProps(); + return props; + } + + /** + * Constructs a InlineProps objects. If it was constructed before it is + * reused. + * @return a InlineProps object + */ + public InlineProps getInlineProps() { + InlineProps props = new InlineProps(); + props.spaceStart = new SpaceVal(properties.get("space-start").getSpace()); + props.spaceEnd = new SpaceVal(properties.get("space-end").getSpace()); + return props; + } + + /** + * Constructs a AccessibilityProps objects. If it was constructed before it is + * reused. + * @return a AccessibilityProps object + */ + public AccessibilityProps getAccessibilityProps() { + AccessibilityProps props = new AccessibilityProps(); + String str; + str = this.properties.get("source-document").getString(); + if (!NONE.equals(str)) { + props.sourceDoc = str; + } + str = this.properties.get("role").getString(); + if (!NONE.equals(str)) { + props.role = str; + } + return props; + } + + /** + * Constructs a AuralProps objects. If it was constructed before it is + * reused. + * @return a AuralProps object + */ + public AuralProps getAuralProps() { + AuralProps props = new AuralProps(); + return props; + } + + /** + * Constructs a RelativePositionProps objects. If it was constructed before it is + * reused. + * @return a RelativePositionProps object + */ + public RelativePositionProps getRelativePositionProps() { + RelativePositionProps props = new RelativePositionProps(); + return props; + } + + /** + * Constructs a AbsolutePositionProps objects. If it was constructed before + * it is reused. + * @return a AbsolutePositionProps object + */ + public AbsolutePositionProps getAbsolutePositionProps() { + AbsolutePositionProps props = new AbsolutePositionProps(); + props.absolutePosition = + this.properties.get("absolute-position").getEnum(); + props.top = this.properties.get("top").getLength().getValue(); + props.bottom = this.properties.get("bottom").getLength().getValue(); + props.left = this.properties.get("left").getLength().getValue(); + props.right = this.properties.get("right").getLength().getValue(); + return props; + } + + /** + * Constructs a BlockProps objects. If it was constructed before it is + * reused. + * @return a BlockProps object + */ + public BlockProps getBlockProps() { + BlockProps props = new BlockProps(); + props.firstIndent = this.properties.get("text-indent").getLength().getValue(); + props.lastIndent = 0; + /*this.properties.get("last-line-end-indent").getLength().mvalue(); */ + props.textAlign = this.properties.get("text-align").getEnum(); + props.textAlignLast = this.properties.get("text-align-last").getEnum(); + props.lineStackType = this.properties.get("line-stacking-strategy").getEnum(); + + return props; + } + + /** + * Constructs a LayoutProps objects. If it was constructed before it is + * reused. + * @return a LayoutProps object + */ + public LayoutProps getLayoutProps() { + LayoutProps props = new LayoutProps(); + props.breakBefore = this.properties.get("break-before").getEnum(); + props.breakAfter = this.properties.get("break-after").getEnum(); + props.bIsSpan = (this.properties.get("span").getEnum() == Span.ALL); + props.spaceBefore = new SpaceVal( + this.properties.get("space-before").getSpace()); + props.spaceAfter = new SpaceVal( + this.properties.get("space-after").getSpace()); + return props; + } + + /** + * Constructs a TextInfo objects. If it was constructed before it is + * reused. + * @param fontInfo available fonts + * @return a TextInfo object + */ + public TextInfo getTextLayoutProps(FontInfo fontInfo) { + if (textInfo == null) { + textInfo = new TextInfo(); + textInfo.fs = getFontState(fontInfo); + textInfo.color = properties.get("color").getColorType(); + + textInfo.verticalAlign = + properties.get("vertical-align").getEnum(); + + textInfo.wrapOption = properties.get("wrap-option").getEnum(); + textInfo.bWrap = (textInfo.wrapOption == Constants.WRAP); + + textInfo.wordSpacing = new SpaceVal( + properties.get("word-spacing").getSpace()); + + /* textInfo.letterSpacing = + new SpaceVal(properties.get("letter-spacing").getSpace());*/ + + textInfo.whiteSpaceCollapse = + properties.get("white-space-collapse").getEnum(); + + textInfo.lineHeight = this.properties.get( + "line-height").getLength().getValue(); + } + return textInfo; + } + + /** + * Construct a coordinate transformation matrix (CTM). + * @param absVPrect absolute viewpoint rectangle + * @param reldims relative dimensions + * @return CTM the coordinate transformation matrix (CTM) + */ + public CTM getCTMandRelDims(Rectangle2D absVPrect, + FODimension reldims) { + int width, height; + // We will use the absolute reference-orientation to set up the CTM. + // The value here is relative to its ancestor reference area. + int absRefOrient = getAbsRefOrient( + this.properties.get("reference-orientation").getNumber().intValue()); + if (absRefOrient % 180 == 0) { + width = (int) absVPrect.getWidth(); + height = (int) absVPrect.getHeight(); + } else { + // invert width and height since top left are rotated by 90 (cl or ccl) + height = (int) absVPrect.getWidth(); + width = (int) absVPrect.getHeight(); + } + /* Set up the CTM for the content of this reference area. + * This will transform region content coordinates in + * writing-mode relative into absolute page-relative + * which will then be translated based on the position of + * the region viewport. + * (Note: scrolling between region vp and ref area when + * doing online content!) + */ + CTM ctm = new CTM(absVPrect.getX(), absVPrect.getY()); + + // First transform for rotation + if (absRefOrient != 0) { + // Rotation implies translation to keep the drawing area in the + // first quadrant. Note: rotation is counter-clockwise + switch (absRefOrient) { + case 90: + ctm = ctm.translate(0, width); // width = absVPrect.height + break; + case 180: + ctm = ctm.translate(width, height); + break; + case 270: + ctm = ctm.translate(height, 0); // height = absVPrect.width + break; + } + ctm = ctm.rotate(absRefOrient); + } + int wm = this.properties.get("writing-mode").getEnum(); + /* Since we've already put adjusted width and height values for the + * top and left positions implied by the reference-orientation, we + * can set ipd and bpd appropriately based on the writing mode. + */ + + if (wm == WritingMode.LR_TB || wm == WritingMode.RL_TB) { + reldims.ipd = width; + reldims.bpd = height; + } else { + reldims.ipd = height; + reldims.bpd = width; + } + // Set a rectangle to be the writing-mode relative version??? + // Now transform for writing mode + return ctm.multiply(CTM.getWMctm(wm, reldims.ipd, reldims.bpd)); + } + + /** + * Calculate absolute reference-orientation relative to media orientation. + */ + private int getAbsRefOrient(int myRefOrient) { + return myRefOrient; + } +} + diff --git a/src/java/org/apache/fop/fo/RecursiveCharIterator.java b/src/java/org/apache/fop/fo/RecursiveCharIterator.java new file mode 100644 index 000000000..0f45dba76 --- /dev/null +++ b/src/java/org/apache/fop/fo/RecursiveCharIterator.java @@ -0,0 +1,134 @@ +/* + * $Id: RecursiveCharIterator.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import java.util.Iterator; +import java.util.NoSuchElementException; + + +public class RecursiveCharIterator extends AbstractCharIterator { + private Iterator childIter = null; // Child flow objects + private CharIterator curCharIter = null; // Children's characters + private FONode fobj; + private FONode curChild; + + public RecursiveCharIterator(FObj fobj) { + // Set up first child iterator + this.fobj = fobj; + this.childIter = fobj.getChildren(); + getNextCharIter(); + } + + public RecursiveCharIterator(FObj fobj, FONode child) { + // Set up first child iterator + this.fobj = fobj; + this.childIter = fobj.getChildren(child); + getNextCharIter(); + } + + public CharIterator mark() { + return (CharIterator) this.clone(); + } + + public Object clone() { + RecursiveCharIterator ci = (RecursiveCharIterator) super.clone(); + ci.childIter = fobj.getChildren(ci.curChild); + // Need to advance to the next child, else we get the same one!!! + ci.childIter.next(); + ci.curCharIter = (CharIterator) curCharIter.clone(); + return ci; + } + + + public void replaceChar(char c) { + if (curCharIter != null) { + curCharIter.replaceChar(c); + } + } + + + private void getNextCharIter() { + if (childIter != null && childIter.hasNext()) { + this.curChild = (FONode) childIter.next(); + this.curCharIter = curChild.charIterator(); + } else { + curChild = null; + curCharIter = null; + } + } + + public boolean hasNext() { + while (curCharIter != null) { + if (curCharIter.hasNext() == false) { + getNextCharIter(); + } else { + return true; + } + } + return false; + } + + public char nextChar() throws NoSuchElementException { + if (curCharIter != null) { + return curCharIter.nextChar(); + } else { + throw new NoSuchElementException(); + } + } + + + public void remove() { + if (curCharIter != null) { + curCharIter.remove(); + } + } +} + diff --git a/src/java/org/apache/fop/fo/ShorthandParser.java b/src/java/org/apache/fop/fo/ShorthandParser.java new file mode 100644 index 000000000..82c6a6d0c --- /dev/null +++ b/src/java/org/apache/fop/fo/ShorthandParser.java @@ -0,0 +1,57 @@ +/* + * $Id: ShorthandParser.java,v 1.3 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +public interface ShorthandParser { + Property getValueForProperty(String propName, + Property.Maker maker, + PropertyList propertyList); +} diff --git a/src/java/org/apache/fop/fo/SpaceProperty.java b/src/java/org/apache/fop/fo/SpaceProperty.java new file mode 100644 index 000000000..d0fac678e --- /dev/null +++ b/src/java/org/apache/fop/fo/SpaceProperty.java @@ -0,0 +1,84 @@ +/* + * $Id: SpaceProperty.java,v 1.5 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +import org.apache.fop.datatypes.Space; +import org.apache.fop.datatypes.LengthRange; + +public class SpaceProperty extends Property { + + public static class Maker extends LengthRangeProperty.Maker { + protected Maker(String name) { + super(name); + } + + } + + private Space space; + + public SpaceProperty(Space space) { + this.space = space; + } + + public Space getSpace() { + return this.space; + } + + /* Space extends LengthRange */ + public LengthRange getLengthRange() { + return this.space; + } + + public Object getObject() { + return this.space; + } + +} diff --git a/src/java/org/apache/fop/fo/StringProperty.java b/src/java/org/apache/fop/fo/StringProperty.java new file mode 100644 index 000000000..ef5fa9028 --- /dev/null +++ b/src/java/org/apache/fop/fo/StringProperty.java @@ -0,0 +1,107 @@ +/* + * $Id: StringProperty.java,v 1.4 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + + +public class StringProperty extends Property { + + public static class Maker extends Property.Maker { + + public Maker(String propName) { + super(propName); + } + + public Property make(PropertyList propertyList, String value, + FObj fo) { + // Work around the fact that most String properties are not + // specified as actual String literals (with "" or '') since + // the attribute values themselves are Strings! + // If the value starts with ' or ", make sure it also ends with + // this character + // Otherwise, just take the whole value as the String + int vlen = value.length() - 1; + if (vlen > 0) { + char q1 = value.charAt(0); + if (q1 == '"' || q1 == '\'') { + if (value.charAt(vlen) == q1) { + return new StringProperty(value.substring(1, vlen)); + } + System.err.println("Warning String-valued property starts with quote" + + " but doesn't end with quote: " + + value); + // fall through and use the entire value, including first quote + } + String str = checkValueKeywords(value); + if (str != null) { + value = str; + } + } + return new StringProperty(value); + } + + } // end String.Maker + + private String str; + + public StringProperty(String str) { + this.str = str; + // System.err.println("Set StringProperty: " + str); + } + + public Object getObject() { + return this.str; + } + + public String getString() { + return this.str; + } + +} diff --git a/src/java/org/apache/fop/fo/TextInfo.java b/src/java/org/apache/fop/fo/TextInfo.java new file mode 100644 index 000000000..cd1d307c2 --- /dev/null +++ b/src/java/org/apache/fop/fo/TextInfo.java @@ -0,0 +1,82 @@ +/* + * $Id: TextInfo.java,v 1.6 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// FOP +import org.apache.fop.layout.FontState; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.traits.SpaceVal; + +/** + * Collection of properties used in + */ +public class TextInfo { + public FontState fs; + public ColorType color; + public int wrapOption; + public boolean bWrap ; // True if wrap-option = WRAP + public int whiteSpaceCollapse; + public int verticalAlign; + public int lineHeight; + + // Props used for calculating inline-progression-dimension + public SpaceVal wordSpacing; + public SpaceVal letterSpacing; + + // Add hyphenation props too + public boolean bCanHyphenate = true; + + // Textdecoration + public boolean underlined = false; + public boolean overlined = false; + public boolean lineThrough = false; +} + diff --git a/src/java/org/apache/fop/fo/Title.java b/src/java/org/apache/fop/fo/Title.java new file mode 100644 index 000000000..1cbdf9585 --- /dev/null +++ b/src/java/org/apache/fop/fo/Title.java @@ -0,0 +1,131 @@ +/* + * $Id: Title.java,v 1.15 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// FOP +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.Length; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.FontState; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layoutmgr.ContentLayoutManager; +import org.apache.fop.layoutmgr.InlineStackingLayoutManager; +import org.apache.fop.layoutmgr.LMiter; + +/** + */ +public class Title extends FObjMixed { + + public Title(FONode parent) { + super(parent); + } + + public org.apache.fop.area.Title getTitleArea() { + org.apache.fop.area.Title title = + new org.apache.fop.area.Title(); + // use special layout manager to add the inline areas + // to the Title. + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setLMiter(new LMiter(children.listIterator())); + lm.init(); + + // get breaks then add areas to title + + ContentLayoutManager clm = new ContentLayoutManager(title); + clm.setUserAgent(getUserAgent()); + lm.setParent(clm); + + clm.fillArea(lm); + + return title; + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + FontState fontState = propMgr.getFontState(structHandler.getFontInfo()); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + Property prop; + prop = this.properties.get("baseline-shift"); + if (prop instanceof LengthProperty) { + Length bShift = prop.getLength(); + } else if (prop instanceof EnumProperty) { + int bShift = prop.getEnum(); + } + ColorType col = this.properties.get("color").getColorType(); + Length lHeight = this.properties.get("line-height").getLength(); + int lShiftAdj = this.properties.get( + "line-height-shift-adjustment").getEnum(); + int vis = this.properties.get("visibility").getEnum(); + Length zIndex = this.properties.get("z-index").getLength(); + + } +} + diff --git a/src/java/org/apache/fop/fo/ToBeImplementedElement.java b/src/java/org/apache/fop/fo/ToBeImplementedElement.java new file mode 100644 index 000000000..d8236a259 --- /dev/null +++ b/src/java/org/apache/fop/fo/ToBeImplementedElement.java @@ -0,0 +1,67 @@ +/* + * $Id: ToBeImplementedElement.java,v 1.8 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +/** + * This class is a placeholder for elements that have not been implemented. + */ +public class ToBeImplementedElement extends FObj { + + protected ToBeImplementedElement(FONode parent) { + super(parent); + } + + public void setup() { + getLogger().debug("This element \"" + this.name + + "\" is not yet implemented."); + } + +} diff --git a/src/java/org/apache/fop/fo/Unknown.java b/src/java/org/apache/fop/fo/Unknown.java new file mode 100644 index 000000000..2cff9bf37 --- /dev/null +++ b/src/java/org/apache/fop/fo/Unknown.java @@ -0,0 +1,74 @@ +/* + * $Id: Unknown.java,v 1.7 2003/03/05 21:48:01 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +/** + * This represents an unknown element. + * For example with unsupported namespaces. + * This prevents any further problems arising from the unknown + * data. + */ +public class Unknown extends FONode { + + public static class Maker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new Unknown(parent); + } + } + + public Unknown(FONode parent) { + super(parent); + } + + public void setup() { + getLogger().debug("Layout Unknown element"); + } +} diff --git a/src/java/org/apache/fop/fo/UnknownXMLObj.java b/src/java/org/apache/fop/fo/UnknownXMLObj.java new file mode 100644 index 000000000..abb26e402 --- /dev/null +++ b/src/java/org/apache/fop/fo/UnknownXMLObj.java @@ -0,0 +1,98 @@ +/* + * $Id: UnknownXMLObj.java,v 1.7 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +public class UnknownXMLObj extends XMLObj { + private String namespace; + + public static class Maker extends ElementMapping.Maker { + private String space; + + public Maker(String sp) { + space = sp; + } + + public FONode make(FONode parent) { + return new UnknownXMLObj(parent, space); + } + } + + /** + * constructs an unknown xml object (called by Maker). + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + protected UnknownXMLObj(FONode parent, String space) { + super(parent); + this.namespace = space; + } + + public String getNameSpace() { + return this.namespace; + } + + protected void addChild(FONode child) { + if (doc == null) { + createBasicDocument(); + } + super.addChild(child); + } + + protected void addCharacters(char data[], int start, int length) { + if (doc == null) { + createBasicDocument(); + } + super.addCharacters(data, start, length); + } + +} + diff --git a/src/java/org/apache/fop/fo/XMLElement.java b/src/java/org/apache/fop/fo/XMLElement.java new file mode 100644 index 000000000..3a2db0196 --- /dev/null +++ b/src/java/org/apache/fop/fo/XMLElement.java @@ -0,0 +1,88 @@ +/* + * $Id: XMLElement.java,v 1.5 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; + +/** + * class representing svg:svg pseudo flow object. + */ +public class XMLElement extends XMLObj { + + private String namespace = ""; + + /** + * constructs an XML object (called by Maker). + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + public XMLElement(FONode parent) { + super(parent); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + init(); + } + + private void init() { + createBasicDocument(); + } + + public String getNameSpace() { + return namespace; + } +} diff --git a/src/java/org/apache/fop/fo/XMLObj.java b/src/java/org/apache/fop/fo/XMLObj.java new file mode 100644 index 000000000..86edd893e --- /dev/null +++ b/src/java/org/apache/fop/fo/XMLObj.java @@ -0,0 +1,195 @@ +/* + * $Id: XMLObj.java,v 1.13 2003/03/05 21:48:02 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo; + +// Java +import java.awt.geom.Point2D; +import java.util.HashMap; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.Attributes; +import javax.xml.parsers.DocumentBuilderFactory; + +// FOP +import org.apache.fop.apps.FOPException; + +/** + * Generic XML object. + * This is used by xml objects (other than fo) than will build a DOM + * with each element. + */ +public abstract class XMLObj extends FONode { + + // temp reference for attributes + private Attributes attr = null; + + protected Element element; + protected Document doc; + + /** + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + public XMLObj(FONode parent) { + super(parent); + } + + public void setName(String str) { + name = str; + } + + public void handleAttrs(Attributes attlist) throws FOPException { + attr = attlist; + } + + public Document getDocument() { + return doc; + } + + public Point2D getDimension(Point2D view) { + return null; + } + + public abstract String getNameSpace(); + + public String getDocumentNamespace() { + return getNameSpace(); + } + + protected static HashMap ns = new HashMap(); + static { + ns.put("xlink", "http://www.w3.org/1999/xlink"); + } + + public void addElement(Document doc, Element parent) { + this.doc = doc; + element = doc.createElementNS(getNameSpace(), name); + + for (int count = 0; count < attr.getLength(); count++) { + String rf = attr.getValue(count); + String qname = attr.getQName(count); + int idx = qname.indexOf(":"); + if (idx == -1) { + element.setAttribute(qname, rf); + } else { + String pref = qname.substring(0, idx); + String tail = qname.substring(idx + 1); + if (pref.equals("xmlns")) { + ns.put(tail, rf); + } else { + element.setAttributeNS((String)ns.get(pref), tail, rf); + } + } + } + attr = null; + parent.appendChild(element); + } + + public void buildTopLevel(Document doc, Element svgRoot) { + // build up the info for the top level element + for (int count = 0; count < attr.getLength(); count++) { + String rf = attr.getValue(count); + String qname = attr.getQName(count); + int idx = qname.indexOf(":"); + if (idx == -1) { + element.setAttribute(qname, rf); + } else { + String pref = qname.substring(0, idx); + String tail = qname.substring(idx + 1); + if (pref.equals("xmlns")) { + ns.put(tail, rf); + } else { + element.setAttributeNS((String)ns.get(pref), tail, rf); + } + } + } + } + + public Document createBasicDocument() { + doc = null; + + element = null; + try { + DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); + fact.setNamespaceAware(true); + doc = fact.newDocumentBuilder().newDocument(); + Element el = doc.createElement(name); + doc.appendChild(el); + + element = doc.getDocumentElement(); + buildTopLevel(doc, element); + } catch (Exception e) { + e.printStackTrace(); + } + return doc; + } + + protected void addChild(FONode child) { + if (child instanceof XMLObj) { + ((XMLObj)child).addElement(doc, element); + } else { + // in theory someone might want to embed some defined + // xml (eg. fo) inside the foreign xml + // they could use a different namespace + getLogger().debug("Invalid element: " + child.getName() + " inside foreign xml markup"); + } + } + + protected void addCharacters(char data[], int start, int length) { + String str = new String(data, start, length - start); + org.w3c.dom.Text text = doc.createTextNode(str); + element.appendChild(text); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/AbsFunction.java b/src/java/org/apache/fop/fo/expr/AbsFunction.java new file mode 100644 index 000000000..58f173f20 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/AbsFunction.java @@ -0,0 +1,72 @@ +/* + * $Id: AbsFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + +public class AbsFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo propInfo) throws PropertyException { + Numeric num = args[0].getNumeric(); + if (num == null) { + throw new PropertyException("Non numeric operand to abs function"); + } + // What if has relative composants (percent, table-col units)? + return new NumericProperty(num.abs()); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/BodyStartFunction.java b/src/java/org/apache/fop/fo/expr/BodyStartFunction.java new file mode 100644 index 000000000..7eb3ee773 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/BodyStartFunction.java @@ -0,0 +1,82 @@ +/* + * $Id: BodyStartFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.flow.ListItem; + +public class BodyStartFunction extends FunctionBase { + + public int nbArgs() { + return 0; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Numeric distance = + pInfo.getPropertyList().get("provisional-distance-between-starts").getNumeric(); + + FONode item = pInfo.getFO(); + while (item != null && !(item instanceof ListItem)) { + item = item.getParent(); + } + if (item == null) { + throw new PropertyException("body-start() called from outside an fo:list-item"); + } + + Numeric startIndent = + ((ListItem)item).properties.get("start-indent").getNumeric(); + + return new NumericProperty(distance.add(startIndent)); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/CeilingFunction.java b/src/java/org/apache/fop/fo/expr/CeilingFunction.java new file mode 100644 index 000000000..f43544e38 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/CeilingFunction.java @@ -0,0 +1,72 @@ +/* + * $Id: CeilingFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.NumberProperty; + +class CeilingFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Number dbl = args[0].getNumber(); + if (dbl == null) { + throw new PropertyException("Non number operand to ceiling function"); + } + return new NumberProperty(Math.ceil(dbl.doubleValue())); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/FloorFunction.java b/src/java/org/apache/fop/fo/expr/FloorFunction.java new file mode 100644 index 000000000..48913dd95 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/FloorFunction.java @@ -0,0 +1,73 @@ +/* + * $Id: FloorFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.NumberProperty; + + +class FloorFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Number dbl = args[0].getNumber(); + if (dbl == null) { + throw new PropertyException("Non number operand to floor function"); + } + return new NumberProperty(Math.floor(dbl.doubleValue())); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/FopPropValFunction.java b/src/java/org/apache/fop/fo/expr/FopPropValFunction.java new file mode 100644 index 000000000..16163f6c0 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/FopPropValFunction.java @@ -0,0 +1,75 @@ +/* + * $Id: FopPropValFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + + +/** + * Return the specified or initial value of the property on this object. + */ +public class FopPropValFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + String propName = args[0].getString(); + if (propName == null) { + throw new PropertyException("Incorrect parameter to _int-property-value function"); + } + // System.err.println("Get property-value for " + propName); + return pInfo.getPropertyList().get(propName); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/FromParentFunction.java b/src/java/org/apache/fop/fo/expr/FromParentFunction.java new file mode 100644 index 000000000..f22bb948f --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/FromParentFunction.java @@ -0,0 +1,79 @@ +/* + * $Id: FromParentFunction.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + + +public class FromParentFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + String propName = args[0].getString(); + if (propName == null) { + throw new PropertyException("Incorrect parameter to from-parent function"); + } + // NOTE: special cases for shorthand property + // Should return COMPUTED VALUE + /* + * For now, this is the same as inherited-property-value(propName) + * (The only difference I can see is that this could work for + * non-inherited properties too. Perhaps the result is different for + * a property line line-height which "inherits specified"??? + */ + return pInfo.getPropertyList().getFromParent(propName); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java b/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java new file mode 100644 index 000000000..4f43aefee --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java @@ -0,0 +1,71 @@ +/* + * $Id: FromTableColumnFunction.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + + +public class FromTableColumnFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + String propName = args[0].getString(); + if (propName == null) { + throw new PropertyException("Incorrect parameter to from-table-column function"); + } + throw new PropertyException("from-table-column unimplemented!"); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/Function.java b/src/java/org/apache/fop/fo/expr/Function.java new file mode 100644 index 000000000..b83463c92 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/Function.java @@ -0,0 +1,62 @@ +/* + * $Id: Function.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.datatypes.PercentBase; + +public interface Function { + int nbArgs(); + PercentBase getPercentBase(); + Property eval(Property[] args, + PropertyInfo propInfo) throws PropertyException; +} + diff --git a/src/java/org/apache/fop/fo/expr/FunctionBase.java b/src/java/org/apache/fop/fo/expr/FunctionBase.java new file mode 100644 index 000000000..d58e096b6 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/FunctionBase.java @@ -0,0 +1,70 @@ +/* + * $Id: FunctionBase.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.datatypes.PercentBase; + +public abstract class FunctionBase implements Function { + // abstract int nbArgs() ; + + /** + * By default, functions have no percent-based arguments. + */ + public PercentBase getPercentBase() { + return null; + } + + /* + * abstract Property eval(Property[] args, PropertyInfo propInfo) + * throws PropertyException; + */ +} + diff --git a/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java b/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java new file mode 100644 index 000000000..86937a489 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java @@ -0,0 +1,71 @@ +/* + * $Id: InheritedPropFunction.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + + +public class InheritedPropFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + String propName = args[0].getString(); + if (propName == null) { + throw new PropertyException("Incorrect parameter to inherited-property-value function"); + } + return pInfo.getPropertyList().getInherited(propName); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java new file mode 100644 index 000000000..402a35306 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java @@ -0,0 +1,100 @@ +/* + * $Id: LabelEndFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.LengthBase; +import org.apache.fop.datatypes.LinearCombinationLength; +import org.apache.fop.datatypes.PercentLength; +import org.apache.fop.fo.Property; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.flow.ListItem; + +public class LabelEndFunction extends FunctionBase { + + public int nbArgs() { + return 0; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + + Length distance = + pInfo.getPropertyList().get("provisional-distance-between-starts").getLength(); + Length separation = + pInfo.getPropertyList().getNearestSpecified("provisional-label-separation").getLength(); + + FONode item = pInfo.getFO(); + while (item != null && !(item instanceof ListItem)) { + item = item.getParent(); + } + if (item == null) { + throw new PropertyException("label-end() called from outside an fo:list-item"); + } + Length startIndent = ((ListItem)item).properties.get("start-indent").getLength(); + + LinearCombinationLength labelEnd = new LinearCombinationLength(); + + // Should be CONTAINING_REFAREA but that doesn't work + LengthBase base = new LengthBase((ListItem)item, pInfo.getPropertyList(), + LengthBase.CONTAINING_BOX); + PercentLength refWidth = new PercentLength(1.0, base); + + labelEnd.addTerm(1.0, refWidth); + labelEnd.addTerm(-1.0, distance); + labelEnd.addTerm(-1.0, startIndent); + labelEnd.addTerm(1.0, separation); + + return new LengthProperty(labelEnd); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/MaxFunction.java b/src/java/org/apache/fop/fo/expr/MaxFunction.java new file mode 100644 index 000000000..b45aef603 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/MaxFunction.java @@ -0,0 +1,73 @@ +/* + * $Id: MaxFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + + +public class MaxFunction extends FunctionBase { + public int nbArgs() { + return 2; + } + + // Handle "numerics" if no proportional/percent parts! + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Numeric n1 = args[0].getNumeric(); + Numeric n2 = args[1].getNumeric(); + if (n1 == null || n2 == null) { + throw new PropertyException("Non numeric operands to max function"); + } + return new NumericProperty(n1.max(n2)); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/MinFunction.java b/src/java/org/apache/fop/fo/expr/MinFunction.java new file mode 100644 index 000000000..c287772cf --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/MinFunction.java @@ -0,0 +1,73 @@ +/* + * $Id: MinFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + + +public class MinFunction extends FunctionBase { + public int nbArgs() { + return 2; + } + + // Handle "numerics" if no proportional/percent parts! + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Numeric n1 = args[0].getNumeric(); + Numeric n2 = args[1].getNumeric(); + if (n1 == null || n2 == null) { + throw new PropertyException("Non numeric operands to min function"); + } + return new NumericProperty(n1.min(n2)); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/NCnameProperty.java b/src/java/org/apache/fop/fo/expr/NCnameProperty.java new file mode 100644 index 000000000..3e3471693 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/NCnameProperty.java @@ -0,0 +1,80 @@ +/* + * $Id: NCnameProperty.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.datatypes.ColorType; + +public class NCnameProperty extends Property { + + private final String ncName; + + public NCnameProperty(String ncName) { + this.ncName = ncName; + } + + public ColorType getColor() throws PropertyException { + // If a system color, return the corresponding value + throw new PropertyException("Not a Color"); + } + + /** + * Return the name as a String (should be specified with quotes!) + */ + public String getString() { + return this.ncName; + } + + public String getNCname() { + return this.ncName; + } + +} diff --git a/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java b/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java new file mode 100644 index 000000000..c6036d5d4 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java @@ -0,0 +1,73 @@ +/* + * $Id: NearestSpecPropFunction.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; + +public class NearestSpecPropFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + String propName = args[0].getString(); + if (propName == null) { + throw new PropertyException( + "Incorrect parameter to from-nearest-specified-value function"); + } + // NOTE: special cases for shorthand property + // Should return COMPUTED VALUE + return pInfo.getPropertyList().getNearestSpecified(propName); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/Numeric.java b/src/java/org/apache/fop/fo/expr/Numeric.java new file mode 100644 index 000000000..0315d0257 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/Numeric.java @@ -0,0 +1,420 @@ +/* + * $Id: Numeric.java,v 1.6 2003/03/05 20:38:26 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import java.util.Vector; + +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.FixedLength; +import org.apache.fop.datatypes.PercentLength; +import org.apache.fop.datatypes.MixedLength; +import org.apache.fop.datatypes.TableColLength; +import org.apache.fop.datatypes.PercentBase; + +/** + * Represents a "numeric" value as defined by the XSL FO Specification. + * This consists of one or more kinds of value specifications, from + * absolute numbers (units power of 0) to lengths (unit power of 1), + * relative lengths (ems), percentage lengths. + * A Numeric can be constructed from other Property types representing + * Numbers or Length-type values. + * Numeric provides methods to return Number and Length values based on + * its current value. + * It supports basic arithmetic operations involving Numerics. + */ +public class Numeric { + // Bit fields + public static final int ABS_LENGTH = 1; // abs units (or number) + public static final int PC_LENGTH = 2; // Percentage + public static final int TCOL_LENGTH = 4; // Table units + + private int valType; + private double absValue; + private double pcValue; + private PercentBase pcBase = null; // base value for PC_LENGTH component + private double tcolValue; + private int dim; + + + /** + * Construct a Numeric object by specifying one or more components, + * including absolute length, percent length, table units. + * @param valType A combination of bits representing the value types. + * @param absValue The value of a Number or resolved Length value if + * the ABS_LENGTH flag is set. + * @param pcValue The decimal percent value if the PC_LENGTH flag is set + * @param tcolValue The decimal table unit value if the TCOL_LENGTH flag + * is set. + * @param dim The dimension of the value. 0 for a Number, 1 for a Length + * (any type), >1, <0 if Lengths have been multiplied or divided. + * @pcBase The PercentBase object used to calculate an actual value for + * a PC_LENGTH. + */ + protected Numeric(int valType, double absValue, double pcValue, + double tcolValue, int dim, PercentBase pcBase) { + this.valType = valType; + this.absValue = absValue; + this.pcValue = pcValue; + this.tcolValue = tcolValue; + this.dim = dim; + this.pcBase = pcBase; + } + + /** + * Construct a Numeric object of dimension 0 from a double. + * @param valType A combination of bits representing the value types. + * @param absValue The value of a Number or resolved Length value. + */ + + /** + * * + * protected Numeric(int valType, double absValue) { + * this.valType = valType; + * this.absValue = absValue; + * } + */ + + /** + * Construct a Numeric object from a Number. + * @param num The number. + */ + public Numeric(Number num) { + this(ABS_LENGTH, num.doubleValue(), 0.0, 0.0, 0, null); + } + + /** + * Construct a Numeric object from a Length. + * @param l The Length. + */ + public Numeric(FixedLength l) { + this(ABS_LENGTH, (double)l.getValue(), 0.0, 0.0, 1, null); + } + + /** + * Construct a Numeric object from a PercentLength. + * @param pclen The PercentLength. + */ + public Numeric(PercentLength pclen) { + this(PC_LENGTH, 0.0, pclen.value(), 0.0, 1, pclen.getBaseLength()); + } + + /** + * Construct a Numeric object from a TableColLength. + * @param tclen The TableColLength. + */ + public Numeric(TableColLength tclen) { + this(TCOL_LENGTH, 0.0, 0.0, tclen.getTableUnits(), 1, null); + } + + + /** + * Return the current value as a Length if possible. This constructs + * a new Length or Length subclass based on the current value type + * of the Numeric. + * If the stored value has a unit dimension other than 1, null + * is returned. + */ + public Length asLength() { + if (dim == 1) { + Vector len = new Vector(3); + if ((valType & ABS_LENGTH) != 0) { + len.add(new FixedLength((int)absValue)); + } + if ((valType & PC_LENGTH) != 0) { + len.add(new PercentLength(pcValue, pcBase)); + } + if ((valType & TCOL_LENGTH) != 0) { + len.add(new TableColLength(tcolValue)); + } + if (len.size() == 1) { + return (Length)len.elementAt(0); + } else { + return new MixedLength(len); + } + } else { + // or throw exception??? + // can't make Length if dimension != 1 + return null; + } + } + + /** + * Return the current value as a Number if possible. + * Calls asDouble(). + */ + public Number asNumber() { + return asDouble(); + } + + public Double asDouble() { + if (dim == 0 && valType == ABS_LENGTH) { + return new Double(absValue); + } else { + // or throw exception??? + // can't make Number if dimension != 0 + return null; + } + } + + /** + * Return the current value as a Integer if possible. + * If the unit dimension is 0 and the value type is ABSOLUTE, an Integer + * is returned. Otherwise null is returned. Note: the current value is + * truncated if necessary to make an integer value. + */ + + /** + * public Integer asInteger() { + * if (dim == 0 && valType==ABS_LENGTH) { + * return new Integer((int)absValue); + * } + * else { + * // or throw exception??? + * // can't make Number if dimension != 0 + * return null; + * } + * } + */ + + /** + * Return a boolean value indiciating whether the currently stored + * value consists of different "types" of values (absolute, percent, + * and/or table-unit.) + */ + private boolean isMixedType() { + int ntype = 0; + for (int t = valType; t != 0; t = t >> 1) { + if ((t & 1) != 0) { + ++ntype; + } + } + return ntype > 1; + } + + /** + * Subtract the operand from the current value and return a new Numeric + * representing the result. + * @param op The value to subtract. + * @return A Numeric representing the result. + * @throws PropertyException If the dimension of the operand is different + * from the dimension of this Numeric. + */ + public Numeric subtract(Numeric op) throws PropertyException { + // Check of same dimension + // Add together absolute and table units + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == op.dim) { + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + // Subtract each type of value + return new Numeric(valType | op.valType, absValue - op.absValue, + pcValue - op.pcValue, + tcolValue - op.tcolValue, dim, npcBase); + } else { + throw new PropertyException("Can't add Numerics of different dimensions"); + } + } + + /** + * Add the operand from the current value and return a new Numeric + * representing the result. + * @param op The value to add. + * @return A Numeric representing the result. + * @throws PropertyException If the dimension of the operand is different + * from the dimension of this Numeric. + */ + public Numeric add(Numeric op) throws PropertyException { + // Check of same dimension + // Add together absolute and table units + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == op.dim) { + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + // Add each type of value + return new Numeric(valType | op.valType, absValue + op.absValue, + pcValue + op.pcValue, + tcolValue + op.tcolValue, dim, npcBase); + } else { + throw new PropertyException("Can't add Numerics of different dimensions"); + } + } + + /** + * Multiply the the current value by the operand and return a new Numeric + * representing the result. + * @param op The multiplier. + * @return A Numeric representing the result. + * @throws PropertyException If both Numerics have "mixed" type. + */ + public Numeric multiply(Numeric op) throws PropertyException { + // Multiply together absolute units and add dimensions (exponents) + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == 0) { + // This is a dimensionless quantity, ie. a "Number" + return new Numeric(op.valType, absValue * op.absValue, + absValue * op.pcValue, + absValue * op.tcolValue, op.dim, op.pcBase); + } else if (op.dim == 0) { + double opval = op.absValue; + return new Numeric(valType, opval * absValue, opval * pcValue, + opval * tcolValue, dim, pcBase); + } else if (valType == op.valType && !isMixedType()) { + // Check same relbase and pcbase ??? + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + return new Numeric(valType, absValue * op.absValue, + pcValue * op.pcValue, + tcolValue * op.tcolValue, dim + op.dim, + npcBase); + } else { + throw new PropertyException("Can't multiply mixed Numerics"); + } + } + + /** + * Divide the the current value by the operand and return a new Numeric + * representing the result. + * @param op The divisor. + * @return A Numeric representing the result. + * @throws PropertyException If both Numerics have "mixed" type. + */ + public Numeric divide(Numeric op) throws PropertyException { + // Multiply together absolute units and add dimensions (exponents) + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == 0) { + // This is a dimensionless quantity, ie. a "Number" + return new Numeric(op.valType, absValue / op.absValue, + absValue / op.pcValue, + absValue / op.tcolValue, -op.dim, op.pcBase); + } else if (op.dim == 0) { + double opval = op.absValue; + return new Numeric(valType, absValue / opval, pcValue / opval, + tcolValue / opval, dim, pcBase); + } else if (valType == op.valType && !isMixedType()) { + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + return new Numeric(valType, + (valType == ABS_LENGTH ? absValue / op.absValue : 0.0), + (valType == PC_LENGTH ? pcValue / op.pcValue : 0.0), + (valType == TCOL_LENGTH ? tcolValue / op.tcolValue : 0.0), + dim - op.dim, npcBase); + } else { + throw new PropertyException("Can't divide mixed Numerics."); + } + } + + /** + * Return the absolute value of this Numeric. + * @return A new Numeric object representing the absolute value. + */ + public Numeric abs() { + return new Numeric(valType, Math.abs(absValue), Math.abs(pcValue), + Math.abs(tcolValue), dim, pcBase); + } + + /** + * Return a Numeric which is the maximum of the current value and the + * operand. + * @throws PropertyException If the dimensions or value types of the + * object and the operand are different. + */ + public Numeric max(Numeric op) throws PropertyException { + double rslt = 0.0; + // Only compare if have same dimension and value type! + if (dim == op.dim && valType == op.valType && !isMixedType()) { + if (valType == ABS_LENGTH) { + rslt = absValue - op.absValue; + } else if (valType == PC_LENGTH) { + rslt = pcValue - op.pcValue; + } else if (valType == TCOL_LENGTH) { + rslt = tcolValue - op.tcolValue; + } + if (rslt > 0.0) { + return this; + } else { + return op; + } + } + throw new PropertyException("Arguments to max() must have same dimension and value type."); + } + + /** + * Return a Numeric which is the minimum of the current value and the + * operand. + * @throws PropertyException If the dimensions or value types of the + * object and the operand are different. + */ + public Numeric min(Numeric op) throws PropertyException { + double rslt = 0.0; + // Only compare if have same dimension and value type! + if (dim == op.dim && valType == op.valType && !isMixedType()) { + if (valType == ABS_LENGTH) { + rslt = absValue - op.absValue; + } else if (valType == PC_LENGTH) { + rslt = pcValue - op.pcValue; + } else if (valType == TCOL_LENGTH) { + rslt = tcolValue - op.tcolValue; + } + if (rslt > 0.0) { + return op; + } else { + return this; + } + } + throw new PropertyException("Arguments to min() must have same dimension and value type."); + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/NumericProperty.java b/src/java/org/apache/fop/fo/expr/NumericProperty.java new file mode 100644 index 000000000..9f28e14e8 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/NumericProperty.java @@ -0,0 +1,85 @@ +/* + * $Id: NumericProperty.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.ColorType; + +class NumericProperty extends Property { + private Numeric numeric; + + NumericProperty(Numeric value) { + this.numeric = value; + } + + public Numeric getNumeric() { + return this.numeric; + } + + public Number getNumber() { + return numeric.asNumber(); + } + + public Length getLength() { + return numeric.asLength(); + } + + public ColorType getColorType() { + // try converting to numeric number and then to color + return null; + } + + public Object getObject() { + return this.numeric; + } + +} diff --git a/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java b/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java new file mode 100644 index 000000000..c25b42a9f --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java @@ -0,0 +1,78 @@ +/* + * $Id: PPColWidthFunction.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.datatypes.TableColLength; + +public class PPColWidthFunction extends FunctionBase { + + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Number d = args[0].getNumber(); + if (d == null) { + throw new PropertyException("Non number operand to proportional-column-width function"); + } + if (!pInfo.getPropertyList().getElement().equals("table-column")) { + throw new PropertyException("proportional-column-width function " + + "may only be used on table-column FO"); + } + // Check if table-layout is "fixed"... + return new LengthProperty(new TableColLength(d.doubleValue())); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/PropertyException.java b/src/java/org/apache/fop/fo/expr/PropertyException.java new file mode 100644 index 000000000..3c9d5a795 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/PropertyException.java @@ -0,0 +1,58 @@ +/* + * $Id: PropertyException.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +public class PropertyException extends Exception { + public PropertyException(String detail) { + super(detail); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/PropertyInfo.java b/src/java/org/apache/fop/fo/expr/PropertyInfo.java new file mode 100644 index 000000000..9731faf2d --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/PropertyInfo.java @@ -0,0 +1,138 @@ +/* + * $Id: PropertyInfo.java,v 1.4 2003/03/05 20:38:26 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import java.util.Stack; + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.FObj; +import org.apache.fop.datatypes.PercentBase; + + +/** + * This class holds context information needed during property expression + * evaluation. + * It holds the Maker object for the property, the PropertyList being + * built, and the FObj parent of the FObj for which the property is being set. + */ +public class PropertyInfo { + private Property.Maker maker; + private PropertyList plist; + private FObj fo; + private Stack stkFunction; // Stack of functions being evaluated + + public PropertyInfo(Property.Maker maker, PropertyList plist, FObj fo) { + this.maker = maker; + this.plist = plist; + this.fo = fo; + } + + /** + * Return whether this property inherits specified values. + * Propagates to the Maker. + * @return true if the property inherits specified values, false if it + * inherits computed values. + */ + public boolean inheritsSpecified() { + return maker.inheritsSpecified(); + } + + /** + * Return the PercentBase object used to calculate the absolute value from + * a percent specification. + * Propagates to the Maker. + * @return The PercentBase object or null if percentLengthOK()=false. + */ + public PercentBase getPercentBase() { + PercentBase pcbase = getFunctionPercentBase(); + return (pcbase != null) ? pcbase : maker.getPercentBase(fo, plist); + } + + /** + * Return the current font-size value as base units (milli-points). + */ + public int currentFontSize() { + return plist.get("font-size").getLength().getValue(); + } + + public FObj getFO() { + return fo; + } + + public PropertyList getPropertyList() { + return plist; + } + + public void pushFunction(Function func) { + if (stkFunction == null) { + stkFunction = new Stack(); + } + stkFunction.push(func); + } + + public void popFunction() { + if (stkFunction != null) { + stkFunction.pop(); + } + } + + private PercentBase getFunctionPercentBase() { + if (stkFunction != null) { + Function f = (Function)stkFunction.peek(); + if (f != null) { + return f.getPercentBase(); + } + } + return null; + } + +} diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java new file mode 100644 index 000000000..8fea26bc6 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -0,0 +1,499 @@ +/* + * $Id: PropertyParser.java,v 1.9 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.FixedLength; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.PercentBase; +import org.apache.fop.datatypes.PercentLength; +import org.apache.fop.fo.Property; +import org.apache.fop.fo.ListProperty; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.NumberProperty; +import org.apache.fop.fo.StringProperty; +import org.apache.fop.fo.ColorTypeProperty; + +import java.util.HashMap; + +/** + * Class to parse XSL FO property expression. + * This class is heavily based on the epxression parser in James Clark's + * XT, an XSLT processor. + */ +public class PropertyParser extends PropertyTokenizer { + private PropertyInfo propInfo; // Maker and propertyList related info + + private static final String RELUNIT = "em"; + private static final Numeric NEGATIVE_ONE = new Numeric(new Double(-1.0)); + private static final HashMap FUNCTION_TABLE = new HashMap(); + + static { + // Initialize the HashMap of XSL-defined functions + FUNCTION_TABLE.put("ceiling", new CeilingFunction()); + FUNCTION_TABLE.put("floor", new FloorFunction()); + FUNCTION_TABLE.put("round", new RoundFunction()); + FUNCTION_TABLE.put("min", new MinFunction()); + FUNCTION_TABLE.put("max", new MaxFunction()); + FUNCTION_TABLE.put("abs", new AbsFunction()); + FUNCTION_TABLE.put("rgb", new RGBColorFunction()); + FUNCTION_TABLE.put("from-table-column", new FromTableColumnFunction()); + FUNCTION_TABLE.put("inherited-property-value", + new InheritedPropFunction()); + FUNCTION_TABLE.put("from-parent", new FromParentFunction()); + FUNCTION_TABLE.put("from-nearest-specified-value", + new NearestSpecPropFunction()); + FUNCTION_TABLE.put("proportional-column-width", + new PPColWidthFunction()); + FUNCTION_TABLE.put("label-end", new LabelEndFunction()); + FUNCTION_TABLE.put("body-start", new BodyStartFunction()); + // NOTE: used from code generated for corresponding properties + FUNCTION_TABLE.put("_fop-property-value", new FopPropValFunction()); + + /** + * * NOT YET IMPLEMENTED!!! + * FUNCTION_TABLE.put("icc-color", new ICCcolorFunction()); + * FUNCTION_TABLE.put("system-color", new SystemColorFunction()); + * FUNCTION_TABLE.put("system-font", new SystemFontFunction()); + * + * FUNCTION_TABLE.put("merge-property-values", new MergePropsFunction()); + */ + } + + + /** + * Public entrypoint to the Property expression parser. + * @param expr The specified value (attribute on the xml element). + * @param propInfo A PropertyInfo object representing the context in + * which the property expression is to be evaluated. + * @return A Property object holding the parsed result. + * @throws PropertyException If the "expr" cannot be parsed as a Property. + */ + public static Property parse(String expr, PropertyInfo propInfo) + throws PropertyException { + return new PropertyParser(expr, propInfo).parseProperty(); + } + + + /** + * Private constructor. Called by the static parse() method. + * @param propExpr The specified value (attribute on the xml element). + * @param propInfo A PropertyInfo object representing the context in + * which the property expression is to be evaluated. + */ + private PropertyParser(String propExpr, PropertyInfo pInfo) { + super(propExpr); + this.propInfo = pInfo; + } + + /** + * Parse the property expression described in the instance variables. + * Note: If the property expression String is empty, a StringProperty + * object holding an empty String is returned. + * @return A Property object holding the parsed result. + * @throws PropertyException If the "expr" cannot be parsed as a Property. + */ + private Property parseProperty() throws PropertyException { + next(); + if (currentToken == TOK_EOF) { + // if prop value is empty string, force to StringProperty + return new StringProperty(""); + } + ListProperty propList = null; + while (true) { + Property prop = parseAdditiveExpr(); + if (currentToken == TOK_EOF) { + if (propList != null) { + propList.addProperty(prop); + return propList; + } else { + return prop; + } + } else { + if (propList == null) { + propList = new ListProperty(prop); + } else { + propList.addProperty(prop); + } + } + // throw new PropertyException("unexpected token"); + } + // return prop; + } + + /** + * Try to parse an addition or subtraction expression and return the + * resulting Property. + */ + private Property parseAdditiveExpr() throws PropertyException { + // Evaluate and put result on the operand stack + Property prop = parseMultiplicativeExpr(); + loop: + while (true) { + switch (currentToken) { + case TOK_PLUS: + next(); + prop = evalAddition(prop.getNumeric(), + parseMultiplicativeExpr().getNumeric()); + break; + case TOK_MINUS: + next(); + prop = + evalSubtraction(prop.getNumeric(), + parseMultiplicativeExpr().getNumeric()); + break; + default: + break loop; + } + } + return prop; + } + + /** + * Try to parse a multiply, divide or modulo expression and return + * the resulting Property. + */ + private Property parseMultiplicativeExpr() throws PropertyException { + Property prop = parseUnaryExpr(); + loop: + while (true) { + switch (currentToken) { + case TOK_DIV: + next(); + prop = evalDivide(prop.getNumeric(), + parseUnaryExpr().getNumeric()); + break; + case TOK_MOD: + next(); + prop = evalModulo(prop.getNumber(), + parseUnaryExpr().getNumber()); + break; + case TOK_MULTIPLY: + next(); + prop = evalMultiply(prop.getNumeric(), + parseUnaryExpr().getNumeric()); + break; + default: + break loop; + } + } + return prop; + } + + /** + * Try to parse a unary minus expression and return the + * resulting Property. + */ + private Property parseUnaryExpr() throws PropertyException { + if (currentToken == TOK_MINUS) { + next(); + return evalNegate(parseUnaryExpr().getNumeric()); + } + return parsePrimaryExpr(); + } + + + /** + * Checks that the current token is a right parenthesis + * and throws an exception if this isn't the case. + */ + private final void expectRpar() throws PropertyException { + if (currentToken != TOK_RPAR) { + throw new PropertyException("expected )"); + } + next(); + } + + /** + * Try to parse a primary expression and return the + * resulting Property. + * A primary expression is either a parenthesized expression or an + * expression representing a primitive Property datatype, such as a + * string literal, an NCname, a number or a unit expression, or a + * function call expression. + */ + private Property parsePrimaryExpr() throws PropertyException { + Property prop; + switch (currentToken) { + case TOK_LPAR: + next(); + prop = parseAdditiveExpr(); + expectRpar(); + return prop; + + case TOK_LITERAL: + prop = new StringProperty(currentTokenValue); + break; + + case TOK_NCNAME: + // Interpret this in context of the property or do it later? + prop = new NCnameProperty(currentTokenValue); + break; + + case TOK_FLOAT: + prop = new NumberProperty(new Double(currentTokenValue)); + break; + + case TOK_INTEGER: + prop = new NumberProperty(new Integer(currentTokenValue)); + break; + + case TOK_PERCENT: + /* + * Get the length base value object from the Maker. If null, then + * this property can't have % values. Treat it as a real number. + */ + double pcval = new Double(currentTokenValue.substring(0, + currentTokenValue.length() - 1)).doubleValue() / 100.0; + // LengthBase lbase = this.propInfo.getPercentLengthBase(); + PercentBase pcBase = this.propInfo.getPercentBase(); + if (pcBase != null) { + if (pcBase.getDimension() == 0) { + prop = new NumberProperty(pcval * pcBase.getBaseValue()); + } else if (pcBase.getDimension() == 1) { + prop = new LengthProperty(new PercentLength(pcval, + pcBase)); + } else { + throw new PropertyException("Illegal percent dimension value"); + } + } else { + // WARNING? Interpret as a decimal fraction, eg. 50% = .5 + prop = new NumberProperty(pcval); + } + break; + + case TOK_NUMERIC: + // A number plus a valid unit name. + int numLen = currentTokenValue.length() - currentUnitLength; + String unitPart = currentTokenValue.substring(numLen); + Double numPart = new Double(currentTokenValue.substring(0, + numLen)); + Length length = null; + if (unitPart.equals(RELUNIT)) { + length = new FixedLength(numPart.doubleValue(), + propInfo.currentFontSize()); + } else { + length = new FixedLength(numPart.doubleValue(), unitPart); + } + if (length == null) { + throw new PropertyException("unrecognized unit name: " + + currentTokenValue); + } else { + prop = new LengthProperty(length); + } + break; + + case TOK_COLORSPEC: + prop = new ColorTypeProperty(new ColorType(currentTokenValue)); + break; + + case TOK_FUNCTION_LPAR: { + Function function = + (Function)FUNCTION_TABLE.get(currentTokenValue); + if (function == null) { + throw new PropertyException("no such function: " + + currentTokenValue); + } + next(); + // Push new function (for function context: getPercentBase()) + propInfo.pushFunction(function); + prop = function.eval(parseArgs(function.nbArgs()), propInfo); + propInfo.popFunction(); + return prop; + } + default: + throw new PropertyException("syntax error"); + } + next(); + return prop; + } + + /** + * Parse a comma separated list of function arguments. Each argument + * may itself be an expression. This method consumes the closing right + * parenthesis of the argument list. + * @param nbArgs The number of arguments expected by the function. + * @return An array of Property objects representing the arguments + * found. + * @throws PropertyException If the number of arguments found isn't equal + * to the number expected. + */ + Property[] parseArgs(int nbArgs) throws PropertyException { + Property[] args = new Property[nbArgs]; + Property prop; + int i = 0; + if (currentToken == TOK_RPAR) { + // No args: func() + next(); + } else { + while (true) { + + prop = parseAdditiveExpr(); + if (i < nbArgs) { + args[i++] = prop; + } + // ignore extra args + if (currentToken != TOK_COMMA) { + break; + } + next(); + } + expectRpar(); + } + if (nbArgs != i) { + throw new PropertyException("Wrong number of args for function"); + } + return args; + } + + + /** + * Evaluate an addition operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the sum of the two operands. + * @throws PropertyException If either operand is null. + */ + private Property evalAddition(Numeric op1, + Numeric op2) throws PropertyException { + if (op1 == null || op2 == null) { + throw new PropertyException("Non numeric operand in addition"); + } + return new NumericProperty(op1.add(op2)); + } + + /** + * Evaluate a subtraction operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the difference of the two operands. + * @throws PropertyException If either operand is null. + */ + private Property evalSubtraction(Numeric op1, + Numeric op2) throws PropertyException { + if (op1 == null || op2 == null) { + throw new PropertyException("Non numeric operand in subtraction"); + } + return new NumericProperty(op1.subtract(op2)); + } + + /** + * Evaluate a unary minus operation. If the argument is null, + * this means that it wasn't convertible to a Numeric value. + * @param op A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the negative of the operand (multiplication by *1). + * @throws PropertyException If the operand is null. + */ + private Property evalNegate(Numeric op) throws PropertyException { + if (op == null) { + throw new PropertyException("Non numeric operand to unary minus"); + } + return new NumericProperty(op.multiply(NEGATIVE_ONE)); + } + + /** + * Evaluate a multiplication operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the product of the two operands. + * @throws PropertyException If either operand is null. + */ + private Property evalMultiply(Numeric op1, + Numeric op2) throws PropertyException { + if (op1 == null || op2 == null) { + throw new PropertyException("Non numeric operand in multiplication"); + } + return new NumericProperty(op1.multiply(op2)); + } + + + /** + * Evaluate a division operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * op1 divided by op2. + * @throws PropertyException If either operand is null. + */ + private Property evalDivide(Numeric op1, + Numeric op2) throws PropertyException { + if (op1 == null || op2 == null) { + throw new PropertyException("Non numeric operand in division"); + } + return new NumericProperty(op1.divide(op2)); + } + + /** + * Evaluate a modulo operation. If either of the arguments is null, + * this means that it wasn't convertible to a Number value. + * @param op1 A Number object + * @param op2 A Number object + * @return A new NumberProperty object holding an object which represents + * op1 mod op2. + * @throws PropertyException If either operand is null. + */ + private Property evalModulo(Number op1, + Number op2) throws PropertyException { + if (op1 == null || op2 == null) { + throw new PropertyException("Non number operand to modulo"); + } + return new NumberProperty(op1.doubleValue() % op2.doubleValue()); + } + +} diff --git a/src/java/org/apache/fop/fo/expr/PropertyTokenizer.java b/src/java/org/apache/fop/fo/expr/PropertyTokenizer.java new file mode 100644 index 000000000..4a29973c3 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/PropertyTokenizer.java @@ -0,0 +1,394 @@ +/* + * $Id: PropertyTokenizer.java,v 1.6 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + + + +/** + * Class to tokenize XSL FO property expression. + * This class is heavily based on the epxression tokenizer in James Clark's + * XT, an XSLT processor. + */ +class PropertyTokenizer { + + static final int TOK_EOF = 0; + static final int TOK_NCNAME = TOK_EOF + 1; + static final int TOK_MULTIPLY = TOK_NCNAME + 1; + static final int TOK_LPAR = TOK_MULTIPLY + 1; + static final int TOK_RPAR = TOK_LPAR + 1; + static final int TOK_LITERAL = TOK_RPAR + 1; + static final int TOK_NUMBER = TOK_LITERAL + 1; + static final int TOK_FUNCTION_LPAR = TOK_NUMBER + 1; + static final int TOK_PLUS = TOK_FUNCTION_LPAR + 1; + static final int TOK_MINUS = TOK_PLUS + 1; + static final int TOK_MOD = TOK_MINUS + 1; + static final int TOK_DIV = TOK_MOD + 1; + static final int TOK_NUMERIC = TOK_DIV + 1; + static final int TOK_COMMA = TOK_NUMERIC + 1; + static final int TOK_PERCENT = TOK_COMMA + 1; + static final int TOK_COLORSPEC = TOK_PERCENT + 1; + static final int TOK_FLOAT = TOK_COLORSPEC + 1; + static final int TOK_INTEGER = TOK_FLOAT + 1; + + protected int currentToken = TOK_EOF; + protected String currentTokenValue = null; + protected int currentUnitLength = 0; + + private int currentTokenStartIndex = 0; + private /* final */ String expr; + private int exprIndex = 0; + private int exprLength; + private boolean recognizeOperator = false; + + + /** + * Construct a new PropertyTokenizer object to tokenize the passed + * String. + * @param s The Property expressio to tokenize. + */ + PropertyTokenizer(String s) { + this.expr = s; + this.exprLength = s.length(); + } + + /** + * Return the next token in the expression string. + * This sets the following package visible variables: + * currentToken An enumerated value identifying the recognized token + * currentTokenValue A String containing the token contents + * currentUnitLength If currentToken = TOK_NUMERIC, the number of + * characters in the unit name. + * @throws PropertyException If un unrecognized token is encountered. + */ + void next() throws PropertyException { + currentTokenValue = null; + currentTokenStartIndex = exprIndex; + boolean currentMaybeOperator = recognizeOperator; + boolean bSawDecimal; + recognizeOperator = true; + for (; ;) { + if (exprIndex >= exprLength) { + currentToken = TOK_EOF; + return; + } + char c = expr.charAt(exprIndex++); + switch (c) { + case ' ': + case '\t': + case '\r': + case '\n': + currentTokenStartIndex = exprIndex; + break; + case ',': + recognizeOperator = false; + currentToken = TOK_COMMA; + return; + case '+': + recognizeOperator = false; + currentToken = TOK_PLUS; + return; + case '-': + recognizeOperator = false; + currentToken = TOK_MINUS; + return; + case '(': + currentToken = TOK_LPAR; + recognizeOperator = false; + return; + case ')': + currentToken = TOK_RPAR; + return; + case '"': + case '\'': + exprIndex = expr.indexOf(c, exprIndex); + if (exprIndex < 0) { + exprIndex = currentTokenStartIndex + 1; + throw new PropertyException("missing quote"); + } + currentTokenValue = expr.substring(currentTokenStartIndex + + 1, exprIndex++); + currentToken = TOK_LITERAL; + return; + case '*': + /* + * if (currentMaybeOperator) { + * recognizeOperator = false; + */ + currentToken = TOK_MULTIPLY; + /* + * } + * else + * throw new PropertyException("illegal operator *"); + */ + return; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + scanDigits(); + if (exprIndex < exprLength && expr.charAt(exprIndex) == '.') { + exprIndex++; + bSawDecimal = true; + if (exprIndex < exprLength + && isDigit(expr.charAt(exprIndex))) { + exprIndex++; + scanDigits(); + } + } else { + bSawDecimal = false; + } + if (exprIndex < exprLength && expr.charAt(exprIndex) == '%') { + exprIndex++; + currentToken = TOK_PERCENT; + } else { + // Check for possible unit name following number + currentUnitLength = exprIndex; + scanName(); + currentUnitLength = exprIndex - currentUnitLength; + currentToken = (currentUnitLength > 0) ? TOK_NUMERIC + : (bSawDecimal ? TOK_FLOAT : TOK_INTEGER); + } + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + return; + + case '.': + if (exprIndex < exprLength + && isDigit(expr.charAt(exprIndex))) { + ++exprIndex; + scanDigits(); + if (exprIndex < exprLength + && expr.charAt(exprIndex) == '%') { + exprIndex++; + currentToken = TOK_PERCENT; + } else { + // Check for possible unit name following number + currentUnitLength = exprIndex; + scanName(); + currentUnitLength = exprIndex - currentUnitLength; + currentToken = (currentUnitLength > 0) ? TOK_NUMERIC + : TOK_FLOAT; + } + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + return; + } + throw new PropertyException("illegal character '.'"); + + case '#': // Start of color value + if (exprIndex < exprLength + && isHexDigit(expr.charAt(exprIndex))) { + ++exprIndex; + scanHexDigits(); + currentToken = TOK_COLORSPEC; + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + // Probably should have some multiple of 3 for length! + return; + } else { + throw new PropertyException("illegal character '#'"); + } + + default: + --exprIndex; + scanName(); + if (exprIndex == currentTokenStartIndex) { + throw new PropertyException("illegal character"); + } + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + // if (currentMaybeOperator) { + if (currentTokenValue.equals("mod")) { + currentToken = TOK_MOD; + return; + } else if (currentTokenValue.equals("div")) { + currentToken = TOK_DIV; + return; + } + /* + * else + * throw new PropertyException("unrecognized operator name"); + * recognizeOperator = false; + * return; + * } + */ + if (followingParen()) { + currentToken = TOK_FUNCTION_LPAR; + recognizeOperator = false; + } else { + currentToken = TOK_NCNAME; + recognizeOperator = false; + } + return; + } + } + } + + /** + * Attempt to recognize a valid NAME token in the input expression. + */ + private void scanName() { + if (exprIndex < exprLength && isNameStartChar(expr.charAt(exprIndex))) { + while (++exprIndex < exprLength + && isNameChar(expr.charAt(exprIndex))) { } + } + } + + /** + * Attempt to recognize a valid sequence of decimal DIGITS in the + * input expression. + */ + private void scanDigits() { + while (exprIndex < exprLength && isDigit(expr.charAt(exprIndex))) { + exprIndex++; + } + } + + /** + * Attempt to recognize a valid sequence of hexadecimal DIGITS in the + * input expression. + */ + private void scanHexDigits() { + while (exprIndex < exprLength && isHexDigit(expr.charAt(exprIndex))) { + exprIndex++; + } + } + + /** + * Return a boolean value indicating whether the following non-whitespace + * character is an opening parenthesis. + */ + private boolean followingParen() { + for (int i = exprIndex; i < exprLength; i++) { + switch (expr.charAt(i)) { + case '(': + exprIndex = i + 1; + return true; + case ' ': + case '\r': + case '\n': + case '\t': + break; + default: + return false; + } + } + return false; + } + + + private static final String NAME_START_CHARS = + "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + private static final String NAME_CHARS = ".-0123456789"; + private static final String DIGITS = "0123456789"; + private static final String HEX_CHARS = DIGITS + "abcdefABCDEF"; + + /** + * Return a boolean value indicating whether the argument is a + * decimal digit (0-9). + * @param c The character to check + */ + private static final boolean isDigit(char c) { + return DIGITS.indexOf(c) >= 0; + } + + /** + * Return a boolean value indicating whether the argument is a + * hexadecimal digit (0-9, A-F, a-f). + * @param c The character to check + */ + private static final boolean isHexDigit(char c) { + return HEX_CHARS.indexOf(c) >= 0; + } + + /** + * Return a boolean value indicating whether the argument is whitespace + * as defined by XSL (space, newline, CR, tab). + * @param c The character to check + */ + private static final boolean isSpace(char c) { + switch (c) { + case ' ': + case '\r': + case '\n': + case '\t': + return true; + } + return false; + } + + /** + * Return a boolean value indicating whether the argument is a valid name + * start character, ie. can start a NAME as defined by XSL. + * @param c The character to check + */ + private static final boolean isNameStartChar(char c) { + return NAME_START_CHARS.indexOf(c) >= 0 || c >= 0x80; + } + + /** + * Return a boolean value indicating whether the argument is a valid name + * character, ie. can occur in a NAME as defined by XSL. + * @param c The character to check + */ + private static final boolean isNameChar(char c) { + return NAME_START_CHARS.indexOf(c) >= 0 || NAME_CHARS.indexOf(c) >= 0 + || c >= 0x80; + } + +} + diff --git a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java new file mode 100644 index 000000000..6b0b439aa --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java @@ -0,0 +1,110 @@ +/* + * $Id: RGBColorFunction.java,v 1.3 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.ColorTypeProperty; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.PercentBase; + +class RGBColorFunction extends FunctionBase { + public int nbArgs() { + return 3; + } + + /** + * Return an object which implements the PercentBase interface. + * Percents in arguments to this function are interpreted relative + * to 255. + */ + public PercentBase getPercentBase() { + return new RGBPercentBase(); + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + // Using CSS rules, numbers are either supposed to be 0-255 + // or percentage values. If percentages value, they've already + // been converted to reals. + float[] cfvals = new float[3]; // RGB + for (int i = 0; i < 3; i++) { + Number cval = args[i].getNumber(); + if (cval == null) { + throw new PropertyException("Argument to rgb() must be a Number"); + } + float colorVal = cval.floatValue() / 255f; + if (colorVal < 0.0 || colorVal > 255.0) { + throw new PropertyException( + "Arguments to rgb() must normalize to the range 0 to 1"); + } + cfvals[i] = colorVal; + } + return new ColorTypeProperty(new ColorType(cfvals[0], cfvals[1], + cfvals[2])); + + } + + static class RGBPercentBase implements PercentBase { + public int getDimension() { + return 0; + } + + public double getBaseValue() { + return 255f; + } + + public int getBaseLength() { + return 0; + } + + } +} diff --git a/src/java/org/apache/fop/fo/expr/RoundFunction.java b/src/java/org/apache/fop/fo/expr/RoundFunction.java new file mode 100644 index 000000000..1877c87f2 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/RoundFunction.java @@ -0,0 +1,77 @@ +/* + * $Id: RoundFunction.java,v 1.4 2003/03/05 21:59:47 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.expr; + + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.NumberProperty; + +class RoundFunction extends FunctionBase { + public int nbArgs() { + return 1; + } + + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + Number dbl = args[0].getNumber(); + if (dbl == null) { + throw new PropertyException("Non number operand to round function"); + } + double n = dbl.doubleValue(); + double r = Math.floor(n + 0.5); + if (r == 0.0 && n < 0.0) { + r = -r; // round(-0.2) returns -0 not 0 + } + return new NumberProperty(r); + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/BasicLink.java b/src/java/org/apache/fop/fo/flow/BasicLink.java new file mode 100644 index 000000000..5076861cb --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/BasicLink.java @@ -0,0 +1,216 @@ +/* + * $Id: BasicLink.java,v 1.21 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; +import java.io.Serializable; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.area.inline.InlineParent; +import org.apache.fop.area.Trait; +import org.apache.fop.area.Resolveable; +import org.apache.fop.area.PageViewport; +import org.apache.fop.area.Area; +import org.apache.fop.layoutmgr.InlineStackingLayoutManager; +import org.apache.fop.layoutmgr.LMiter; +import org.apache.fop.layoutmgr.LayoutProcessor; + +/** + * The basic link. + * This sets the basic link trait on the inline parent areas + * that are created by the fo element. + */ +public class BasicLink extends Inline { + + private String link = null; + private boolean external = false; + + public BasicLink(FONode parent) { + super(parent); + } + + // add start and end properties for the link + public void addLayoutManager(List lms) { + setup(); + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager() { + protected InlineParent createArea() { + InlineParent area = super.createArea(); + setupLinkArea(parentLM, area); + return area; + } + }; + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setLMiter(new LMiter(children.listIterator())); + lms.add(lm); + } + + protected void setupLinkArea(LayoutProcessor parentLM, InlineParent area) { + if (link == null) { + return; + } + if (external) { + area.addTrait(Trait.EXTERNAL_LINK, link); + } else { + PageViewport page = parentLM.resolveRefID(link); + if (page != null) { + area.addTrait(Trait.INTERNAL_LINK, page.getKey()); + } else { + LinkResolver res = new LinkResolver(link, area); + parentLM.addUnresolvedArea(link, res); + } + } + } + + public void setup() { + String destination; + int linkType; + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("destination-place-offset"); + // this.properties.get("dominant-baseline"); + String ext = properties.get("external-destination").getString(); + setupID(); + // this.properties.get("indicate-destination"); + String internal = properties.get("internal-destination").getString(); + if (ext.length() > 0) { + link = ext; + external = true; + } else if (internal.length() > 0) { + link = internal; + } else { + getLogger().error("basic-link requires an internal or external destination"); + } + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("show-destination"); + // this.properties.get("target-processing-context"); + // this.properties.get("target-presentation-context"); + // this.properties.get("target-stylesheet"); + + } + + protected boolean containsMarkers() { + return true; + } + + /** + * Link resolving for resolving internal links. + * This is static since it is independant of the link fo. + */ + protected static class LinkResolver implements Resolveable, Serializable { + private boolean resolved = false; + private String idRef; + private Area area; + + /** + * Create a new link resolver. + * + * @param id the id to resolve + * @param a the area that will have the link attribute + */ + public LinkResolver(String id, Area a) { + idRef = id; + area = a; + } + + public boolean isResolved() { + return resolved; + } + + public String[] getIDs() { + return new String[] {idRef}; + } + + /** + * Resolve by adding an internal link. + */ + public void resolve(String id, List pages) { + resolved = true; + if (idRef.equals(id) && pages != null) { + PageViewport page = (PageViewport)pages.get(0); + area.addTrait(Trait.INTERNAL_LINK, page.getKey()); + } + } + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/BidiOverride.java b/src/java/org/apache/fop/fo/flow/BidiOverride.java new file mode 100644 index 000000000..8e53e1e0a --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/BidiOverride.java @@ -0,0 +1,154 @@ +/* + * $Id: BidiOverride.java,v 1.14 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObjMixed; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.RelativePositionProps; + +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.apache.fop.layoutmgr.LayoutProcessor; +import org.apache.fop.area.inline.InlineArea; + +import java.util.List; +import java.util.ArrayList; + +/** + * fo:bidi-override element. + */ +public class BidiOverride extends FObjMixed { + + public BidiOverride(FONode parent) { + super(parent); + } + + public void addLayoutManager(List list) { + if (false) { + super.addLayoutManager(list); + } else { + ArrayList childList = new ArrayList(); + super.addLayoutManager(childList); + for (int count = childList.size() - 1; count >= 0; count--) { + LayoutProcessor lm = (LayoutProcessor) childList.get(count); + if (lm.generatesInlineAreas()) { + LayoutProcessor blm = new BidiLayoutManager((LeafNodeLayoutManager) lm); + blm.setFObj(this); + list.add(blm); + } else { + list.add(lm); + } + } + } + } + + public void setup() { + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Font Properties + //this.fontState = propMgr.getFontState(area.getFontInfo()); + + // Common Margin Properties-Inline + RelativePositionProps mProps = propMgr.getRelativePositionProps(); + + // this.properties.get("color"); + // this.properties.get("direction"); + setupID(); + // this.properties.get("letter-spacing"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("score-spaces"); + // this.properties.get("text-shadow"); + // this.properties.get("text-transform"); + // this.properties.get("unicode-bidi"); + // this.properties.get("word-spacing"); + + } + + protected boolean containsMarkers() { + return true; + } + + /** + * If this bidi has a different writing mode direction + * ltr or rtl than its parent writing mode then this + * reverses the inline areas (at the character level). + */ + class BidiLayoutManager extends LeafNodeLayoutManager { + + private List children; + + BidiLayoutManager(LeafNodeLayoutManager cLM) { + children = new ArrayList(); +/* for (int count = cLM.size() - 1; count >= 0; count--) { + InlineArea ia = cLM.get(count); + if (ia instanceof Word) { + // reverse word + Word word = (Word) ia; + StringBuffer sb = new StringBuffer(word.getWord()); + word.setWord(sb.reverse().toString()); + } + children.add(ia); + } +*/ } + + public int size() { + return children.size(); + } + + public InlineArea get(int index) { + return (InlineArea) children.get(index); + } + } +} diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java new file mode 100644 index 000000000..35c1f1f19 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -0,0 +1,385 @@ +/* + * $Id: Block.java,v 1.68 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.CharIterator; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.RecursiveCharIterator; +import org.apache.fop.fo.TextInfo; +import org.apache.fop.fo.properties.Constants; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.HyphenationProps; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.BlockLayoutManager; +import org.apache.fop.util.CharUtilities; + +/* + Modified by Mark Lillywhite mark-fop@inomial.com. The changes + here are based on memory profiling and do not change functionality. + Essentially, the Block object had a pointer to a BlockArea object + that it created. The BlockArea was not referenced after the Block + was finished except to determine the size of the BlockArea, however + a reference to the BlockArea was maintained and this caused a lot of + GC problems, and was a major reason for FOP memory leaks. So, + the reference to BlockArea was made local, the required information + is now stored (instead of a reference to the complex BlockArea object) + and it appears that there are a lot of changes in this file, in fact + there are only a few sematic changes; mostly I just got rid of + "this." from blockArea since BlockArea is now local. + */ +public class Block extends FObjMixed { + + private int align; + private int alignLast; + private int breakAfter; + private int lineHeight; + private int startIndent; + private int endIndent; + private int spaceBefore; + private int spaceAfter; + private int textIndent; + private int keepWithNext; + private ColorType backgroundColor; + private int blockWidows; + private int blockOrphans; + + private String id; + private int span; + private int wsTreatment; //ENUMERATION + private int lfTreatment; //ENUMERATION + private boolean bWScollapse; //true if white-space-collapse=true + + // this may be helpful on other FOs too + private boolean anythingLaidOut = false; + + /** + * Index of first inline-type FO seen in a sequence. + * Used during FO tree building to do white-space handling. + */ + private FONode firstInlineChild = null; + + public Block(FONode parent) { + super(parent); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + this.span = this.properties.get("span").getEnum(); + this.wsTreatment = + this.properties.get("white-space-treatment").getEnum(); + this.bWScollapse = + (this.properties.get("white-space-collapse").getEnum() + == Constants.TRUE); + this.lfTreatment = + this.properties.get("linefeed-treatment").getEnum(); + + setupID(); + + structHandler.startBlock(this); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + //this.fontState = propMgr.getFontState(area.getFontInfo()); + + // Common Hyphenation Properties + HyphenationProps mHyphProps = propMgr.getHyphenationProps(); + + // Common Margin Properties-Block + MarginProps mProps = propMgr.getMarginProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + // this.properties.get("break-after"); + // this.properties.get("break-before"); + // this.properties.get("color"); + // this.properties.get("text-depth"); + // this.properties.get("text-altitude"); + // this.properties.get("hyphenation-keep"); + // this.properties.get("hyphenation-ladder-count"); + setupID(); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("last-line-end-indent"); + // this.properties.get("linefeed-treatment"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("line-stacking-strategy"); + // this.properties.get("orphans"); + // this.properties.get("white-space-treatment"); + // this.properties.get("span"); + // this.properties.get("text-align"); + // this.properties.get("text-align-last"); + // this.properties.get("text-indent"); + // this.properties.get("visibility"); + // this.properties.get("white-space-collapse"); + // this.properties.get("widows"); + // this.properties.get("wrap-option"); + // this.properties.get("z-index"); + + this.align = this.properties.get("text-align").getEnum(); + this.alignLast = + this.properties.get("text-align-last").getEnum(); + this.breakAfter = this.properties.get("break-after").getEnum(); + this.lineHeight = this.properties.get( + "line-height").getLength().getValue(); + this.startIndent = this.properties.get( + "start-indent").getLength().getValue(); + this.endIndent = this.properties.get( + "end-indent").getLength().getValue(); + this.spaceBefore = this.properties.get( + "space-before.optimum").getLength().getValue(); + this.spaceAfter = this.properties.get( + "space-after.optimum").getLength().getValue(); + this.textIndent = this.properties.get( + "text-indent").getLength().getValue(); + this.keepWithNext = + this.properties.get("keep-with-next").getEnum(); + + this.blockWidows = + this.properties.get("widows").getNumber().intValue(); + this.blockOrphans = + this.properties.get("orphans").getNumber().intValue(); + + } + + protected boolean containsMarkers() { + return true; + } + + public int getSpan() { + return this.span; + } + + public void addLayoutManager(List list) { + BlockLayoutManager blm = new BlockLayoutManager(); + blm.setUserAgent(getUserAgent()); + blm.setFObj(this); + TextInfo ti = propMgr.getTextLayoutProps(fontInfo); + blm.setBlockTextInfo(ti); + list.add(blm); + } + + public boolean generatesInlineAreas() { + return false; + } + + public void addChild(FONode child) { + // Handle whitespace based on values of properties + // Handle a sequence of inline-producing children in + // one pass + if (child instanceof FObj && ((FObj) child).generatesInlineAreas()) { + if (firstInlineChild == null) { + firstInlineChild = child; + } + // lastInlineChild = children.size(); + } else { + // Handle whitespace in preceeding inline areas if any + handleWhiteSpace(); + } + super.addChild(child); + } + + public void end() { + handleWhiteSpace(); + structHandler.endBlock(this); + } + + private void handleWhiteSpace() { + //getLogger().debug("fo:block: handleWhiteSpace"); + if (firstInlineChild != null) { + boolean bInWS = false; + boolean bPrevWasLF = false; + RecursiveCharIterator charIter = + new RecursiveCharIterator(this, firstInlineChild); + LFchecker lfCheck = new LFchecker(charIter); + + while (charIter.hasNext()) { + switch (CharUtilities.classOf(charIter.nextChar())) { + case CharUtilities.XMLWHITESPACE: + /* Some kind of whitespace character, except linefeed. */ + boolean bIgnore = false; + + switch (wsTreatment) { + case Constants.IGNORE: + bIgnore = true; + break; + case Constants.IGNORE_IF_BEFORE_LINEFEED: + bIgnore = lfCheck.nextIsLF(); + break; + case Constants.IGNORE_IF_SURROUNDING_LINEFEED: + bIgnore = (bPrevWasLF + || lfCheck.nextIsLF()); + break; + case Constants.IGNORE_IF_AFTER_LINEFEED: + bIgnore = bPrevWasLF; + break; + } + // Handle ignore + if (bIgnore) { + charIter.remove(); + } else if (bWScollapse) { + if (bInWS || (lfTreatment == Constants.PRESERVE + && (bPrevWasLF || lfCheck.nextIsLF()))) { + charIter.remove(); + } else { + bInWS = true; + } + } + break; + + case CharUtilities.LINEFEED: + /* A linefeed */ + lfCheck.reset(); + bPrevWasLF = true; // for following whitespace + + switch (lfTreatment) { + case Constants.IGNORE: + charIter.remove(); + break; + case Constants.TREAT_AS_SPACE: + if (bInWS) { + // only if bWScollapse=true + charIter.remove(); + } else { + if (bWScollapse) { + bInWS = true; + } + charIter.replaceChar('\u0020'); + } + break; + case Constants.TREAT_AS_ZERO_WIDTH_SPACE: + charIter.replaceChar('\u200b'); + // Fall through: this isn't XML whitespace + case Constants.PRESERVE: + bInWS = false; + break; + } + break; + + case CharUtilities.EOT: + // A "boundary" objects such as non-character inline + // or nested block object was encountered. + // If any whitespace run in progress, finish it. + // FALL THROUGH + + case CharUtilities.UCWHITESPACE: // Non XML-whitespace + case CharUtilities.NONWHITESPACE: + /* Any other character */ + bInWS = bPrevWasLF = false; + lfCheck.reset(); + break; + } + } + firstInlineChild = null; + } + } + + private static class LFchecker { + private boolean bNextIsLF = false; + private RecursiveCharIterator charIter; + + LFchecker(RecursiveCharIterator charIter) { + this.charIter = charIter; + } + + boolean nextIsLF() { + if (bNextIsLF == false) { + CharIterator lfIter = charIter.mark(); + while (lfIter.hasNext()) { + char c = lfIter.nextChar(); + if (c == '\n') { + bNextIsLF = true; + break; + } else if (CharUtilities.classOf(c) + != CharUtilities.XMLWHITESPACE) { + break; + } + } + } + return bNextIsLF; + } + + void reset() { + bNextIsLF = false; + } + } +} + diff --git a/src/java/org/apache/fop/fo/flow/BlockContainer.java b/src/java/org/apache/fop/fo/flow/BlockContainer.java new file mode 100644 index 000000000..0163c0094 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/BlockContainer.java @@ -0,0 +1,154 @@ +/* + * $Id: BlockContainer.java,v 1.22 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AbsolutePositionProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layoutmgr.BlockContainerLayoutManager; + +import org.xml.sax.Attributes; + +import java.util.List; + +public class BlockContainer extends FObj { + + private ColorType backgroundColor; + private int position; + + private int top; + private int bottom; + private int left; + private int right; + private int width; + private int height; + + private int span; + + public BlockContainer(FONode parent) { + super(parent); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + this.span = this.properties.get("span").getEnum(); + setupID(); + } + + public void addLayoutManager(List list) { + BlockContainerLayoutManager blm = new BlockContainerLayoutManager(); + blm.setUserAgent(getUserAgent()); + blm.setFObj(this); + blm.setOverflow(properties.get("overflow").getEnum()); + list.add(blm); + } + + public void setup() { + + // Common Accessibility Properties + AbsolutePositionProps mAbsProps = propMgr.getAbsolutePositionProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin-Block Properties + MarginProps mProps = propMgr.getMarginProps(); + + // this.properties.get("block-progression-dimension"); + // this.properties.get("break-after"); + // this.properties.get("break-before"); + // this.properties.get("clip"); + // this.properties.get("display-align"); + // this.properties.get("height"); + setupID(); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("overflow"); + // this.properties.get("reference-orientation"); + // this.properties.get("span"); + // this.properties.get("width"); + // this.properties.get("writing-mode"); + + this.backgroundColor = + this.properties.get("background-color").getColorType(); + + this.width = this.properties.get("width").getLength().getValue(); + this.height = this.properties.get("height").getLength().getValue(); + span = this.properties.get("span").getEnum(); + + } + + public boolean generatesReferenceAreas() { + return true; + } + + public boolean generatesInlineAreas() { + return false; + } + + protected boolean containsMarkers() { + return true; + } + + public int getSpan() { + return this.span; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/Character.java b/src/java/org/apache/fop/fo/flow/Character.java new file mode 100644 index 000000000..d18924836 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Character.java @@ -0,0 +1,170 @@ +/* + * $Id: Character.java,v 1.22 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.fo.CharIterator; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.OneCharIterator; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.HyphenationProps; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.apps.FOPException; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; + +/** + * This class represents the flow object 'fo:character'. Its use is defined by + * the spec: "The fo:character flow object represents a character that is mapped to + * a glyph for presentation. It is an atomic unit to the formatter. + * When the result tree is interpreted as a tree of formatting objects, + * a character in the result tree is treated as if it were an empty + * element of type fo:character with a character attribute + * equal to the Unicode representation of the character. + * The semantics of an "auto" value for character properties, which is + * typically their initial value, are based on the Unicode codepoint. + * Overrides may be specified in an implementation-specific manner." (6.6.3) + * + */ +public class Character extends FObj { + + public static final int OK = 0; + public static final int DOESNOT_FIT = 1; + + private char characterValue; + + public Character(FONode parent) { + super(parent); + } + + public void addLayoutManager(List list) { + InlineArea inline = getInlineArea(); + if (inline != null) { + LeafNodeLayoutManager lm = new LeafNodeLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setCurrentArea(inline); + list.add(lm); + } + } + + protected InlineArea getInlineArea() { + String str = this.properties.get("character").getString(); + if (str.length() == 1) { + org.apache.fop.area.inline.Character ch = + new org.apache.fop.area.inline.Character( + str.charAt(0)); + return ch; + } + return null; + } + + public void setup() throws FOPException { + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + //this.fontState = propMgr.getFontState(area.getFontInfo()); + + // Common Hyphenation Properties + HyphenationProps mHyphProps = propMgr.getHyphenationProps(); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("treat-as-word-space"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("character"); + // this.properties.get("color"); + // this.properties.get("dominant-baseline"); + // this.properties.get("text-depth"); + // this.properties.get("text-altitude"); + // this.properties.get("glyph-orientation-horizontal"); + // this.properties.get("glyph-orientation-vertical"); + setupID(); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("letter-spacing"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("score-spaces"); + // this.properties.get("suppress-at-line-break"); + // this.properties.get("text-decoration"); + // this.properties.get("text-shadow"); + // this.properties.get("text-transform"); + // this.properties.get("word-spacing"); + } + + public CharIterator charIterator() { + return new OneCharIterator(characterValue); + // But what it the character is ignored due to white space handling? + } + + +} diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java new file mode 100644 index 000000000..97b3235c2 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -0,0 +1,321 @@ +/* + * $Id: ExternalGraphic.java,v 1.32 2003/03/05 20:38:21 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.fo.properties.TextAlign; +import org.apache.fop.fo.properties.Overflow; +import org.apache.fop.fo.properties.DisplayAlign; +import org.apache.fop.fo.properties.Scaling; +import org.apache.fop.image.ImageFactory; +import org.apache.fop.image.FopImage; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.apache.fop.layoutmgr.TraitSetter; +import org.apache.fop.area.inline.Image; +import org.apache.fop.area.inline.Viewport; +import org.apache.fop.datatypes.Length; + +// Java +import java.util.List; +import java.awt.geom.Rectangle2D; + +/** + * External graphic formatting object. + * This FO node handles the external graphic. It creates an image + * inline area that can be added to the area tree. + */ +public class ExternalGraphic extends FObj { + private String url; + private int breakAfter; + private int breakBefore; + private int align; + private int startIndent; + private int endIndent; + private int spaceBefore; + private int spaceAfter; + private int viewWidth = -1; + private int viewHeight = -1; + private boolean clip = false; + private Rectangle2D placement = null; + + /** + * Create a new External graphic node. + * + * @param parent the parent of this node + */ + public ExternalGraphic(FONode parent) { + super(parent); + } + + /** + * Add the layout manager for this to the list. + * This adds a leafnode layout manager that deals with the + * created viewport/image area. + * + * @param list the list to add the layout manager to + */ + public void addLayoutManager(List list) { + InlineArea area = getInlineArea(); + if (area != null) { + setupID(); + LeafNodeLayoutManager lm = new LeafNodeLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setCurrentArea(area); + lm.setAlignment(properties.get("vertical-align").getEnum()); + lm.setLead(viewHeight); + list.add(lm); + } + } + + /** + * Get the inline area for this external grpahic. + * This creates the image area and puts it inside a viewport. + * + * @return the viewport containing the image area + */ + protected InlineArea getInlineArea() { + setup(); + if (url == null) { + return null; + } + Image imArea = new Image(url); + Viewport vp = new Viewport(imArea); + vp.setWidth(viewWidth); + vp.setHeight(viewHeight); + vp.setClip(clip); + vp.setContentPosition(placement); + vp.setOffset(0); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + TraitSetter.addBorders(vp, bap); + TraitSetter.addBackground(vp, bProps); + + return vp; + } + + /** + * Setup this image. + * This gets the sizes for the image and the dimensions and clipping. + */ + public void setup() { + url = this.properties.get("src").getString(); + if (url == null) { + return; + } + url = ImageFactory.getURL(url); + + // assume lr-tb for now + Length ipd = properties.get("inline-progression-dimension.optimum").getLength(); + if (!ipd.isAuto()) { + viewWidth = ipd.getValue(); + } else { + ipd = properties.get("width").getLength(); + if (!ipd.isAuto()) { + viewWidth = ipd.getValue(); + } + } + Length bpd = properties.get("block-progression-dimension.optimum").getLength(); + if (!bpd.isAuto()) { + viewHeight = bpd.getValue(); + } else { + bpd = properties.get("height").getLength(); + if (!bpd.isAuto()) { + viewHeight = bpd.getValue(); + } + } + + // if we need to load this image to get its size + FopImage fopimage = null; + + int cwidth = -1; + int cheight = -1; + Length ch = properties.get("content-height").getLength(); + if (!ch.isAuto()) { + /*if (ch.scaleToFit()) { + if (viewHeight != -1) { + cheight = viewHeight; + } + } else {*/ + cheight = ch.getValue(); + } + Length cw = properties.get("content-width").getLength(); + if (!cw.isAuto()) { + /*if (cw.scaleToFit()) { + if (viewWidth != -1) { + cwidth = viewWidth; + } + } else {*/ + cwidth = cw.getValue(); + } + + int scaling = properties.get("scaling").getEnum(); + if ((scaling == Scaling.UNIFORM) || (cwidth == -1) || cheight == -1) { + ImageFactory fact = ImageFactory.getInstance(); + fopimage = fact.getImage(url, userAgent); + if (fopimage == null) { + // error + url = null; + return; + } + // load dimensions + if (!fopimage.load(FopImage.DIMENSIONS, userAgent)) { + // error + url = null; + return; + } + if (cwidth == -1) { + cwidth = (int)(fopimage.getWidth() * 1000); + } + if (cheight == -1) { + cheight = (int)(fopimage.getHeight() * 1000); + } + if (scaling == Scaling.UNIFORM) { + // adjust the larger + double rat1 = cwidth / (fopimage.getWidth() * 1000f); + double rat2 = cheight / (fopimage.getHeight() * 1000f); + if (rat1 < rat2) { + // reduce cheight + cheight = (int)(rat1 * fopimage.getHeight() * 1000); + } else { + cwidth = (int)(rat2 * fopimage.getWidth() * 1000); + } + } + } + + if (viewWidth == -1) { + viewWidth = cwidth; + } + if (viewHeight == -1) { + viewHeight = cheight; + } + + if (cwidth > viewWidth || cheight > viewHeight) { + int overflow = properties.get("overflow").getEnum(); + if (overflow == Overflow.HIDDEN) { + clip = true; + } else if (overflow == Overflow.ERROR_IF_OVERFLOW) { + getLogger().error("Image: " + url + + " overflows the viewport, clipping to viewport"); + clip = true; + } + } + + int xoffset = 0; + int yoffset = 0; + int da = properties.get("display-align").getEnum(); + switch(da) { + case DisplayAlign.BEFORE: + break; + case DisplayAlign.AFTER: + yoffset = viewHeight - cheight; + break; + case DisplayAlign.CENTER: + yoffset = (viewHeight - cheight) / 2; + break; + case DisplayAlign.AUTO: + default: + break; + } + + int ta = properties.get("text-align").getEnum(); + switch(ta) { + case TextAlign.CENTER: + xoffset = (viewWidth - cwidth) / 2; + break; + case TextAlign.END: + xoffset = viewWidth - cwidth; + break; + case TextAlign.START: + break; + case TextAlign.JUSTIFY: + default: + break; + } + placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("content-type"); + // this.properties.get("dominant-baseline"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("scaling-method"); + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/Float.java b/src/java/org/apache/fop/fo/flow/Float.java new file mode 100644 index 000000000..6782955e8 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Float.java @@ -0,0 +1,76 @@ +/* + * $Id: Float.java,v 1.8 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; + +/** + * fo:float element. + */ +public class Float extends ToBeImplementedElement { + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public Float(FONode parent) { + super(parent); + this.name = "fo:float"; + } + + public void setup() { + + // this.properties.get("float"); + // this.properties.get("clear"); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/Flow.java b/src/java/org/apache/fop/fo/flow/Flow.java new file mode 100644 index 000000000..c648d03e4 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Flow.java @@ -0,0 +1,163 @@ +/* + * $Id: Flow.java,v 1.37 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.ArrayList; +import java.util.List; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.apps.FOPException; +import org.apache.fop.layoutmgr.FlowLayoutManager; + +public class Flow extends FObj { + + /** + * PageSequence container + */ + private PageSequence pageSequence; + + /** + * ArrayList to store snapshot + */ + private ArrayList markerSnapshot; + + /** + * flow-name attribute + */ + private String flowName; + + /** + * Content-width of current column area during layout + */ + private int contentWidth; + + + public Flow(FONode parent) { + super(parent); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + if (parent.getName().equals("fo:page-sequence")) { + this.pageSequence = (PageSequence) parent; + } else { + throw new FOPException("flow must be child of " + + "page-sequence, not " + parent.getName()); + } + // according to communication from Paul Grosso (XSL-List, + // 001228, Number 406), confusion in spec section 6.4.5 about + // multiplicity of fo:flow in XSL 1.0 is cleared up - one (1) + // fo:flow per fo:page-sequence only. + + /* if (pageSequence.isFlowSet()) { + if (this.name.equals("fo:flow")) { + throw new FOPException("Only a single fo:flow permitted" + + " per fo:page-sequence"); + } else { + throw new FOPException(this.name + + " not allowed after fo:flow"); + } + } + */ + setFlowName(getProperty("flow-name").getString()); + // Now done in addChild of page-sequence + //pageSequence.addFlow(this); + + structHandler.startFlow(this); + } + + public void end() { + structHandler.endFlow(this); + } + + protected void setFlowName(String name) throws FOPException { + if (name == null || name.equals("")) { + throw new FOPException("A 'flow-name' is required for " + + getName()); + } else { + flowName = name; + } + } + + public String getFlowName() { + return flowName; + } + + protected void setContentWidth(int contentWidth) { + this.contentWidth = contentWidth; + } + /** + * Return the content width of this flow (really of the region + * in which it is flowing). + */ + public int getContentWidth() { + return this.contentWidth; + } + + public boolean generatesReferenceAreas() { + return true; + } + + public void addLayoutManager(List list) { + FlowLayoutManager lm = new FlowLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + list.add(lm); + } + +} diff --git a/src/java/org/apache/fop/fo/flow/Footnote.java b/src/java/org/apache/fop/fo/flow/Footnote.java new file mode 100644 index 000000000..ffda294ee --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Footnote.java @@ -0,0 +1,89 @@ +/* + * $Id: Footnote.java,v 1.15 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; + +public class Footnote extends FObj { + + private Inline inlineFO = null; + private FootnoteBody body; + + public Footnote(FONode parent) { + super(parent); + } + + public void addLayoutManager(List lms) { + // add inlines layout manager + if (inlineFO == null) { + getLogger().error("inline required in footnote"); + return; + } + inlineFO.addLayoutManager(lms); + } + + public void addChild(FONode child) { + String name = child.getName(); + if ("fo:inline".equals(name)) { + inlineFO = (Inline)child; + } else if ("fo:footnote-body".equals(name)) { + body = (FootnoteBody)child; + } else { + getLogger().error("invalid child of footnote: " + name); + } + } +} + diff --git a/src/java/org/apache/fop/fo/flow/FootnoteBody.java b/src/java/org/apache/fop/fo/flow/FootnoteBody.java new file mode 100644 index 000000000..d29570bf1 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/FootnoteBody.java @@ -0,0 +1,70 @@ +/* + * $Id: FootnoteBody.java,v 1.12 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; + +public class FootnoteBody extends FObj { + + private int align; + private int alignLast; + private int lineHeight; + private int startIndent; + private int endIndent; + private int textIndent; + + public FootnoteBody(FONode parent) { + super(parent); + } + +} diff --git a/src/java/org/apache/fop/fo/flow/InitialPropertySet.java b/src/java/org/apache/fop/fo/flow/InitialPropertySet.java new file mode 100644 index 000000000..5e07fe4b6 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/InitialPropertySet.java @@ -0,0 +1,101 @@ +/* + * $Id: InitialPropertySet.java,v 1.9 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.RelativePositionProps; + +/** + * fo:initial-property-set element. + */ +public class InitialPropertySet extends ToBeImplementedElement { + + public InitialPropertySet(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + //this.fontState = propMgr.getFontState(area.getFontInfo()); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("color"); + setupID(); + // this.properties.get("letter-spacing"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("score-spaces"); + // this.properties.get("text-decoration"); + // this.properties.get("text-shadow"); + // this.properties.get("text-transform"); + // this.properties.get("word-spacing"); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/Inline.java b/src/java/org/apache/fop/fo/flow/Inline.java new file mode 100644 index 000000000..49fc1f611 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Inline.java @@ -0,0 +1,147 @@ +/* + * $Id: Inline.java,v 1.16 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.CharIterator; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.InlineCharIterator; +import org.apache.fop.fo.properties.TextDecoration; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.apps.FOPException; + +public class Inline extends FObjMixed { + + // Textdecoration + protected boolean underlined = false; + protected boolean overlined = false; + protected boolean lineThrough = false; + + + public Inline(FONode parent) { + super(parent); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + if (parent.getName().equals("fo:flow")) { + throw new FOPException("inline formatting objects cannot" + + " be directly under flow"); + } + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + //this.fontState = propMgr.getFontState(area.getFontInfo()); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("color"); + // this.properties.get("dominant-baseline"); + setupID(); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("text-devoration"); + // this.properties.get("visibility"); + // this.properties.get("z-index"); + + int textDecoration = this.properties.get("text-decoration").getEnum(); + + if (textDecoration == TextDecoration.UNDERLINE) { + this.underlined = true; + } + + if (textDecoration == TextDecoration.OVERLINE) { + this.overlined = true; + } + + if (textDecoration == TextDecoration.LINE_THROUGH) { + this.lineThrough = true; + } + } + + protected boolean containsMarkers() { + return true; + } + + public CharIterator charIterator() { + return new InlineCharIterator(this, propMgr.getBorderAndPadding()); + } + +} diff --git a/src/java/org/apache/fop/fo/flow/InlineContainer.java b/src/java/org/apache/fop/fo/flow/InlineContainer.java new file mode 100644 index 000000000..ab1dc1192 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/InlineContainer.java @@ -0,0 +1,145 @@ +/* + * $Id: InlineContainer.java,v 1.11 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; +import java.util.ArrayList; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.apps.FOPException; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.apache.fop.area.inline.InlineArea; + +/** + * fo:inline-container element. + */ +public class InlineContainer extends FObj { + + public InlineContainer(FONode parent) { + super(parent); + } + + public void addLayoutManager(List lms) { + ArrayList childList = new ArrayList(); + super.addLayoutManager(childList); + LayoutManager lm = new ICLayoutManager(childList); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lms.add(lm); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("block-progression-dimension"); + // this.properties.get("clip"); + // this.properties.get("display-align"); + // this.properties.get("dominant-baseline"); + // this.properties.get("height"); + setupID(); + // this.properties.get("inline-progression-dimension"); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("overflow"); + // this.properties.get("reference-orientation"); + // this.properties.get("width"); + // this.properties.get("writing-mode"); + } + + protected boolean containsMarkers() { + return true; + } + + /** + * This creates a single inline container area after + * laying out the child block areas. All footnotes, floats + * and id areas are maintained for later retrieval. + */ + class ICLayoutManager extends LeafNodeLayoutManager { + + private List childrenLM; + + ICLayoutManager(List childLM) { + childrenLM = childLM; + } + + public InlineArea get(int index) { + return null; + } + } +} diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java new file mode 100644 index 000000000..5f71404fd --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -0,0 +1,387 @@ +/* + * $Id: InstreamForeignObject.java,v 1.37 2003/03/05 20:38:21 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.apache.fop.area.inline.ForeignObject; +import org.apache.fop.area.inline.Viewport; +import org.apache.fop.datatypes.Length; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.XMLObj; +import org.apache.fop.fo.properties.DisplayAlign; +import org.apache.fop.fo.properties.Overflow; +import org.apache.fop.fo.properties.Scaling; +import org.apache.fop.fo.properties.TextAlign; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.w3c.dom.Document; + +/** + * The instream-foreign-object flow formatting object. + * This is an atomic inline object that contains + * xml data. + */ +public class InstreamForeignObject extends FObj { + + private Viewport areaCurrent; + + /** + * constructs an instream-foreign-object object (called by Maker). + * + * @param parent the parent formatting object + */ + public InstreamForeignObject(FONode parent) { + super(parent); + } + + /** + * Add the layout manager for this into the list. + * @see org.apache.fop.fo.FObj#addLayoutManager(List) + */ + public void addLayoutManager(List list) { + areaCurrent = getInlineArea(); + if (areaCurrent != null) { + LeafNodeLayoutManager lm = new LeafNodeLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setCurrentArea(areaCurrent); + lm.setAlignment(properties.get("vertical-align").getEnum()); + lm.setLead(areaCurrent.getHeight()); + list.add(lm); + } + } + + /** + * Get the inline area created by this element. + * + * @return the viewport inline area + */ + protected Viewport getInlineArea() { + if (children == null) { + return areaCurrent; + } + + if (this.children.size() != 1) { + // error + return null; + } + FONode fo = (FONode)children.get(0); + if (!(fo instanceof XMLObj)) { + // error + return null; + } + XMLObj child = (XMLObj)fo; + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // viewport size is determined by block-progression-dimension + // and inline-progression-dimension + + // if replaced then use height then ignore block-progression-dimension + //int h = this.properties.get("height").getLength().mvalue(); + + // use specified line-height then ignore dimension in height direction + boolean hasLH = false;//properties.get("line-height").getSpecifiedValue() != null; + + Length len; + + int bpd = -1; + int ipd = -1; + boolean bpdauto = false; + if (hasLH) { + bpd = properties.get("line-height").getLength().getValue(); + } else { + // this property does not apply when the line-height applies + // isn't the block-progression-dimension always in the same + // direction as the line height? + len = properties.get("block-progression-dimension.optimum").getLength(); + if (!len.isAuto()) { + bpd = len.getValue(); + } else { + len = properties.get("height").getLength(); + if (!len.isAuto()) { + bpd = len.getValue(); + } + } + } + + len = properties.get("inline-progression-dimension.optimum").getLength(); + if (!len.isAuto()) { + ipd = len.getValue(); + } else { + len = properties.get("width").getLength(); + if (!len.isAuto()) { + ipd = len.getValue(); + } + } + + // if auto then use the intrinsic size of the content scaled + // to the content-height and content-width + int cwidth = -1; + int cheight = -1; + len = properties.get("content-width").getLength(); + if (!len.isAuto()) { + /*if(len.scaleToFit()) { + if(ipd != -1) { + cwidth = ipd; + } + } else {*/ + cwidth = len.getValue(); + } + len = properties.get("content-height").getLength(); + if (!len.isAuto()) { + /*if(len.scaleToFit()) { + if(bpd != -1) { + cwidth = bpd; + } + } else {*/ + cheight = len.getValue(); + } + + Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f, + cheight == -1 ? -1 : cheight / 1000f); + Point2D size = child.getDimension(csize); + if (size == null) { + // error + return null; + } + if (cwidth == -1) { + cwidth = (int)size.getX() * 1000; + } + if (cheight == -1) { + cheight = (int)size.getY() * 1000; + } + int scaling = properties.get("scaling").getEnum(); + if (scaling == Scaling.UNIFORM) { + // adjust the larger + double rat1 = cwidth / (size.getX() * 1000f); + double rat2 = cheight / (size.getY() * 1000f); + if (rat1 < rat2) { + // reduce cheight + cheight = (int)(rat1 * size.getY() * 1000); + } else { + cwidth = (int)(rat2 * size.getX() * 1000); + } + } + + if (ipd == -1) { + ipd = cwidth; + } + if (bpd == -1) { + bpd = cheight; + } + + boolean clip = false; + if (cwidth > ipd || cheight > bpd) { + int overflow = properties.get("overflow").getEnum(); + if (overflow == Overflow.HIDDEN) { + clip = true; + } else if (overflow == Overflow.ERROR_IF_OVERFLOW) { + getLogger().error("Instream foreign object overflows the viewport: clipping"); + clip = true; + } + } + + int xoffset = 0; + int yoffset = 0; + int da = properties.get("display-align").getEnum(); + switch (da) { + case DisplayAlign.BEFORE: + break; + case DisplayAlign.AFTER: + yoffset = bpd - cheight; + break; + case DisplayAlign.CENTER: + yoffset = (bpd - cheight) / 2; + break; + case DisplayAlign.AUTO: + default: + break; + } + + int ta = properties.get("text-align").getEnum(); + switch (ta) { + case TextAlign.CENTER: + xoffset = (ipd - cwidth) / 2; + break; + case TextAlign.END: + xoffset = ipd - cwidth; + break; + case TextAlign.START: + break; + case TextAlign.JUSTIFY: + default: + break; + } + Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); + + Document doc = child.getDocument(); + String ns = child.getDocumentNamespace(); + + children = null; + ForeignObject foreign = new ForeignObject(doc, ns); + + areaCurrent = new Viewport(foreign); + areaCurrent.setWidth(ipd); + areaCurrent.setHeight(bpd); + areaCurrent.setContentPosition(placement); + areaCurrent.setClip(clip); + areaCurrent.setOffset(0); + + return areaCurrent; + } + + /** + * This flow object generates inline areas. + * @see org.apache.fop.fo.FObj#generatesInlineAreas() + * @return true + */ + public boolean generatesInlineAreas() { + return true; + } + + /* + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("block-progression-dimension"); + // this.properties.get("content-height"); + // this.properties.get("content-type"); + // this.properties.get("content-width"); + // this.properties.get("display-align"); + // this.properties.get("dominant-baseline"); + // this.properties.get("height"); + setupID(); + // this.properties.get("inline-progression-dimension"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("overflow"); + // this.properties.get("scaling"); + // this.properties.get("scaling-method"); + // this.properties.get("text-align"); + // this.properties.get("width"); + + /* retrieve properties * + int align = this.properties.get("text-align").getEnum(); + int valign = this.properties.get("vertical-align").getEnum(); + int overflow = this.properties.get("overflow").getEnum(); + + this.breakBefore = this.properties.get("break-before").getEnum(); + this.breakAfter = this.properties.get("break-after").getEnum(); + this.width = this.properties.get("width").getLength().mvalue(); + this.height = this.properties.get("height").getLength().mvalue(); + this.contwidth = + this.properties.get("content-width").getLength().mvalue(); + this.contheight = + this.properties.get("content-height").getLength().mvalue(); + this.wauto = this.properties.get("width").getLength().isAuto(); + this.hauto = this.properties.get("height").getLength().isAuto(); + this.cwauto = + this.properties.get("content-width").getLength().isAuto(); + this.chauto = + this.properties.get("content-height").getLength().isAuto(); + + this.startIndent = + this.properties.get("start-indent").getLength().mvalue(); + this.endIndent = + this.properties.get("end-indent").getLength().mvalue(); + this.spaceBefore = + this.properties.get("space-before.optimum").getLength().mvalue(); + this.spaceAfter = + this.properties.get("space-after.optimum").getLength().mvalue(); + + this.scaling = this.properties.get("scaling").getEnum(); + +*/ +} diff --git a/src/java/org/apache/fop/fo/flow/Leader.java b/src/java/org/apache/fop/fo/flow/Leader.java new file mode 100644 index 000000000..e4958f4bb --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Leader.java @@ -0,0 +1,308 @@ +/* + * $Id: Leader.java,v 1.35 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.area.Trait; +import org.apache.fop.area.inline.FilledArea; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.Space; +import org.apache.fop.area.inline.Word; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.PercentLength; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.properties.LeaderPattern; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.FontState; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.ContentLayoutManager; +import org.apache.fop.layoutmgr.InlineStackingLayoutManager; +import org.apache.fop.layoutmgr.LMiter; +import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.apache.fop.layoutmgr.MinOptMax; +import org.apache.fop.util.CharUtilities; + +/** + * Implements fo:leader; main property of leader leader-pattern. + * The following patterns are treated: rule, space, dots and use-content. + */ +public class Leader extends FObjMixed { + + private int ruleStyle; + private int ruleThickness; + private int leaderPattern; + private int patternWidth; + protected FontInfo fontInfo = null; + protected FontState fontState; + protected InlineArea leaderArea = null; + + public Leader(FONode parent) { + super(parent); + } + + public void addLayoutManager(List list) { + LeafNodeLayoutManager lm = new LeafNodeLayoutManager() { + public InlineArea get(LayoutContext context) { + return getInlineArea(); + } + + protected MinOptMax getAllocationIPD(int refIPD) { + return getAllocIPD(refIPD); + } + + /*protected void offsetArea(LayoutContext context) { + if(leaderPattern == LeaderPattern.DOTS) { + curArea.setOffset(context.getBaseline()); + } + }*/ + }; + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setAlignment(properties.get("leader-alignment").getEnum()); + list.add(lm); + } + + protected InlineArea getInlineArea() { + if (leaderArea == null) { + createLeaderArea(); + } + return leaderArea; + } + + protected void createLeaderArea() { + setup(); + + if (leaderPattern == LeaderPattern.RULE) { + org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader(); + + leader.setRuleStyle(ruleStyle); + leader.setRuleThickness(ruleThickness); + + leaderArea = leader; + } else if (leaderPattern == LeaderPattern.SPACE) { + leaderArea = new Space(); + } else if (leaderPattern == LeaderPattern.DOTS) { + Word w = new Word(); + char dot = '.'; // userAgent.getLeaderDotCharacter(); + + w.setWord("" + dot); + w.addTrait(Trait.FONT_NAME, fontState.getFontName()); + w.addTrait(Trait.FONT_SIZE, + new Integer(fontState.getFontSize())); + // set offset of dot within inline parent + w.setOffset(fontState.getAscender()); + int width = CharUtilities.getCharWidth(dot, fontState); + Space spacer = null; + if (patternWidth > width) { + spacer = new Space(); + spacer.setWidth(patternWidth - width); + width = patternWidth; + } + FilledArea fa = new FilledArea(); + fa.setUnitWidth(width); + fa.addChild(w); + if (spacer != null) { + fa.addChild(spacer); + } + fa.setHeight(fontState.getAscender()); + + leaderArea = fa; + } else if (leaderPattern == LeaderPattern.USECONTENT) { + if (children == null) { + getLogger().error("Leader use-content with no content"); + return; + } + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lm.setLMiter(new LMiter(children.listIterator())); + lm.init(); + + // get breaks then add areas to FilledArea + FilledArea fa = new FilledArea(); + + ContentLayoutManager clm = new ContentLayoutManager(fa); + clm.setUserAgent(getUserAgent()); + lm.setParent(clm); + + clm.fillArea(lm); + int width = clm.getStackingSize(); + Space spacer = null; + if (patternWidth > width) { + spacer = new Space(); + spacer.setWidth(patternWidth - width); + width = patternWidth; + } + fa.setUnitWidth(width); + if (spacer != null) { + fa.addChild(spacer); + } + leaderArea = fa; + } + } + + public void setStructHandler(StructureHandler st) { + super.setStructHandler(st); + fontInfo = st.getFontInfo(); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + this.fontState = propMgr.getFontState(fontInfo); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("color"); + // this.properties.get("dominant-baseline"); + // this.properties.get("text-depth"); + // this.properties.get("text-altitude"); + setupID(); + // this.properties.get("leader-alignment"); + // this.properties.get("leader-length"); + // this.properties.get("leader-pattern"); + // this.properties.get("leader-pattern-width"); + // this.properties.get("rule-style"); + // this.properties.get("rule-thickness"); + // this.properties.get("letter-spacing"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("text-shadow"); + // this.properties.get("visibility"); + // this.properties.get("word-spacing"); + // this.properties.get("z-index"); + + // color properties + ColorType c = this.properties.get("color").getColorType(); + float red = c.getRed(); + float green = c.getGreen(); + float blue = c.getBlue(); + + // fo:leader specific properties + // determines the pattern of leader; allowed values: space, rule,dots, use-content + leaderPattern = this.properties.get("leader-pattern").getEnum(); + switch(leaderPattern) { + case LeaderPattern.SPACE: + // use Space + break; + case LeaderPattern.RULE: + // the following properties only apply + // for leader-pattern = "rule" + ruleThickness = + properties.get("rule-thickness").getLength().getValue(); + ruleStyle = properties.get("rule-style").getEnum(); + break; + case LeaderPattern.DOTS: + break; + case LeaderPattern.USECONTENT: + // use inline layout manager to create inline areas + // add the inline parent multiple times until leader full + break; + } + + // if leaderPatternWidth = 0 = default = use-font-metric + patternWidth = + this.properties.get("leader-pattern-width").getLength().getValue(); + + } + + protected MinOptMax getAllocIPD(int ipd) { + // length of the leader + int opt = getLength("leader-length.optimum", ipd); + int min = getLength("leader-length.minimum", ipd); + int max = getLength("leader-length.maximum", ipd); + + return new MinOptMax(min, opt, max); + } + + protected int getLength(String prop, int dim) { + int length; + Length maxlength = properties.get(prop).getLength(); + if (maxlength instanceof PercentLength) { + length = (int)(((PercentLength)maxlength).value() + * dim); + } else { + length = maxlength.getValue(); + } + return length; + } +} + diff --git a/src/java/org/apache/fop/fo/flow/ListBlock.java b/src/java/org/apache/fop/fo/flow/ListBlock.java new file mode 100644 index 000000000..6618ead78 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/ListBlock.java @@ -0,0 +1,148 @@ +/* + * $Id: ListBlock.java,v 1.33 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.list.ListBlockLayoutManager; + +public class ListBlock extends FObj { + + private int align; + private int alignLast; + private int breakBefore; + private int breakAfter; + private int lineHeight; + private int startIndent; + private int endIndent; + private int spaceBefore; + private int spaceAfter; + private int spaceBetweenListRows = 0; + private ColorType backgroundColor; + + public ListBlock(FONode parent) { + super(parent); + } + + public void addLayoutManager(List list) { + ListBlockLayoutManager blm = new ListBlockLayoutManager(); + blm.setUserAgent(getUserAgent()); + blm.setFObj(this); + list.add(blm); + } + + public void setup() throws FOPException { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Block + MarginProps mProps = propMgr.getMarginProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("break-after"); + // this.properties.get("break-before"); + setupID(); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("provisional-distance-between-starts"); + // this.properties.get("provisional-label-separation"); + + this.align = this.properties.get("text-align").getEnum(); + this.alignLast = this.properties.get("text-align-last").getEnum(); + this.lineHeight = + this.properties.get("line-height").getLength().getValue(); + this.startIndent = + this.properties.get("start-indent").getLength().getValue(); + this.endIndent = + this.properties.get("end-indent").getLength().getValue(); + this.spaceBefore = + this.properties.get("space-before.optimum").getLength().getValue(); + this.spaceAfter = + this.properties.get("space-after.optimum").getLength().getValue(); + this.spaceBetweenListRows = 0; // not used at present + this.backgroundColor = + this.properties.get("background-color").getColorType(); + + } + + public boolean generatesInlineAreas() { + return false; + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/ListItem.java b/src/java/org/apache/fop/fo/flow/ListItem.java new file mode 100644 index 000000000..a3e9a3b17 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/ListItem.java @@ -0,0 +1,157 @@ +/* + * $Id: ListItem.java,v 1.30 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.list.ListItemLayoutManager; + +public class ListItem extends FObj { + + private ListItemLabel label = null; + private ListItemBody body = null; + + private int align; + private int alignLast; + private int breakBefore; + private int breakAfter; + private int lineHeight; + private int startIndent; + private int endIndent; + private int spaceBefore; + private int spaceAfter; + + public ListItem(FONode parent) { + super(parent); + } + + public void addLayoutManager(List list) { + if (label != null && body != null) { + ListItemLayoutManager blm = new ListItemLayoutManager(); + blm.setUserAgent(getUserAgent()); + blm.setFObj(this); + blm.setLabel(label.getItemLayoutManager()); + blm.setBody(body.getItemLayoutManager()); + list.add(blm); + } else { + getLogger().error("list-item requires list-item-label and list-item-body"); + } + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Block + MarginProps mProps = propMgr.getMarginProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("break-after"); + // this.properties.get("break-before"); + setupID(); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("relative-align"); + + this.align = this.properties.get("text-align").getEnum(); + this.alignLast = this.properties.get("text-align-last").getEnum(); + this.lineHeight = + this.properties.get("line-height").getLength().getValue(); + this.spaceBefore = + this.properties.get("space-before.optimum").getLength().getValue(); + this.spaceAfter = + this.properties.get("space-after.optimum").getLength().getValue(); + + } + + public void addChild(FONode child) { + if ("fo:list-item-label".equals(child.getName())) { + label = (ListItemLabel)child; + } else if ("fo:list-item-body".equals(child.getName())) { + body = (ListItemBody)child; + } else if ("fo:marker".equals(child.getName())) { + // marker + } else { + // error + } + } + + public boolean generatesInlineAreas() { + return false; + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/ListItemBody.java b/src/java/org/apache/fop/fo/flow/ListItemBody.java new file mode 100644 index 000000000..77a25c0ab --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/ListItemBody.java @@ -0,0 +1,94 @@ +/* + * $Id: ListItemBody.java,v 1.21 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layoutmgr.list.Item; + +public class ListItemBody extends FObj { + + public ListItemBody(FONode parent) { + super(parent); + } + + public Item getItemLayoutManager() { + Item item = new Item(); + item.setUserAgent(getUserAgent()); + item.setFObj(this); + return item; + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + setupID(); + // this.properties.get("keep-together"); + + /* + * For calculating the lineage - The fo:list-item-body formatting object + * does not generate any areas. The fo:list-item-body formatting object + * returns the sequence of areas created by concatenating the sequences + * of areas returned by each of the children of the fo:list-item-body. + */ + + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/ListItemLabel.java b/src/java/org/apache/fop/fo/flow/ListItemLabel.java new file mode 100644 index 000000000..0080331a2 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/ListItemLabel.java @@ -0,0 +1,94 @@ +/* + * $Id: ListItemLabel.java,v 1.21 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layoutmgr.list.Item; + +public class ListItemLabel extends FObj { + + public ListItemLabel(FONode parent) { + super(parent); + } + + public Item getItemLayoutManager() { + Item itemLabel = new Item(); + itemLabel.setUserAgent(getUserAgent()); + itemLabel.setFObj(this); + return itemLabel; + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + setupID(); + // this.properties.get("keep-together"); + + /* + * For calculating the lineage - The fo:list-item-label formatting object + * does not generate any areas. The fo:list-item-label formatting object + * returns the sequence of areas created by concatenating the sequences + * of areas returned by each of the children of the fo:list-item-label. + */ + + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/Marker.java b/src/java/org/apache/fop/fo/flow/Marker.java new file mode 100644 index 000000000..06405e792 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Marker.java @@ -0,0 +1,111 @@ +/* + * $Id: Marker.java,v 1.13 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObjMixed; + +/** + * Marker formatting object. + * This is the marker formatting object that handles merkers. + * This attempts to add itself to the parent formatting object. + */ +public class Marker extends FObjMixed { + + private String markerClassName; + + /** + * Create a marker fo. + * + * @param parent the parent fo node + */ + public Marker(FONode parent) { + super(parent); + } + + /** + * Handle the attributes for this marker. + * This gets the marker-class-name and attempts to add itself + * to the parent formatting object. + * + * @param attlist the attribute list + * @throws FOPException if there is an exception + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + this.markerClassName = + this.properties.get("marker-class-name").getString(); + } + + /** + * @see org.apache.fop.fo.FONode#isMarker() + */ + protected boolean isMarker() { + return true; + } + + /** + * Get the marker class name for this marker. + * + * @return the marker class name + */ + public String getMarkerClassName() { + return markerClassName; + } + + +} diff --git a/src/java/org/apache/fop/fo/flow/MultiCase.java b/src/java/org/apache/fop/fo/flow/MultiCase.java new file mode 100644 index 000000000..6730a1a1d --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/MultiCase.java @@ -0,0 +1,78 @@ +/* + * $Id: MultiCase.java,v 1.9 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; + +/** + * fo:multi-case element. + */ +public class MultiCase extends ToBeImplementedElement { + + public MultiCase(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + setupID(); + // this.properties.get("starting-state"); + // this.properties.get("case-name"); + // this.properties.get("case-title"); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/MultiProperties.java b/src/java/org/apache/fop/fo/flow/MultiProperties.java new file mode 100644 index 000000000..aac48afc6 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/MultiProperties.java @@ -0,0 +1,75 @@ +/* + * $Id: MultiProperties.java,v 1.10 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; + +/** + * fo:multi-properties element. + */ +public class MultiProperties extends ToBeImplementedElement { + + public MultiProperties(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + setupID(); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/MultiPropertySet.java b/src/java/org/apache/fop/fo/flow/MultiPropertySet.java new file mode 100644 index 000000000..3fba25228 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/MultiPropertySet.java @@ -0,0 +1,72 @@ +/* + * $Id: MultiPropertySet.java,v 1.10 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; + +/** + * fo:multi-property-set element. + */ +public class MultiPropertySet extends ToBeImplementedElement { + + public MultiPropertySet(FONode parent) { + super(parent); + } + + public void setup() { + + setupID(); + // this.properties.get("active-state"); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/MultiSwitch.java b/src/java/org/apache/fop/fo/flow/MultiSwitch.java new file mode 100644 index 000000000..e3ef64489 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/MultiSwitch.java @@ -0,0 +1,76 @@ +/* + * $Id: MultiSwitch.java,v 1.10 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; + +/** + * fo:multi-switch element. + */ +public class MultiSwitch extends ToBeImplementedElement { + + public MultiSwitch(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // this.properties.get("auto-restore"); + setupID(); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/MultiToggle.java b/src/java/org/apache/fop/fo/flow/MultiToggle.java new file mode 100644 index 000000000..b485176e4 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/MultiToggle.java @@ -0,0 +1,76 @@ +/* + * $Id: MultiToggle.java,v 1.10 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; + +/** + * fo:multi-toggle element. + */ +public class MultiToggle extends ToBeImplementedElement { + + public MultiToggle(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + setupID(); + // this.properties.get("switch-to"); + + } +} diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java new file mode 100644 index 000000000..6de17c989 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -0,0 +1,185 @@ +/* + * $Id: PageNumber.java,v 1.30 2003/03/05 20:38:21 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.FontState; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layout.TextState; +import org.apache.fop.util.CharUtilities; + +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.Word; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.area.Trait; + +public class PageNumber extends FObj { + protected FontInfo fontInfo = null; + protected FontState fontState; + + private float red; + private float green; + private float blue; + private int wrapOption; + private int whiteSpaceCollapse; + private TextState ts; + + public PageNumber(FONode parent) { + super(parent); + } + + public void setStructHandler(StructureHandler st) { + super.setStructHandler(st); + fontInfo = st.getFontInfo(); + } + + public void addLayoutManager(List lms) { + setup(); + LayoutManager lm; + lm = new LeafNodeLayoutManager() { + public InlineArea get(LayoutContext context) { + // get page string from parent, build area + Word inline = new Word(); + String str = parentLM.getCurrentPageNumber(); + int width = 0; + for (int count = 0; count < str.length(); count++) { + width += CharUtilities.getCharWidth( + str.charAt(count), fontState); + } + inline.setWord(str); + inline.setIPD(width); + inline.setHeight(fontState.getAscender() + - fontState.getDescender()); + inline.setOffset(fontState.getAscender()); + + inline.addTrait(Trait.FONT_NAME, + fontState.getFontName()); + inline.addTrait(Trait.FONT_SIZE, + new Integer(fontState.getFontSize())); + + return inline; + } + + protected void offsetArea(LayoutContext context) { + curArea.setOffset(context.getBaseline()); + } + }; + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lms.add(lm); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + this.fontState = propMgr.getFontState(fontInfo); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("dominant-baseline"); + setupID(); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("letter-spacing"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("score-spaces"); + // this.properties.get("text-decoration"); + // this.properties.get("text-shadow"); + // this.properties.get("text-transform"); + // this.properties.get("word-spacing"); + + ColorType c = this.properties.get("color").getColorType(); + this.red = c.getRed(); + this.green = c.getGreen(); + this.blue = c.getBlue(); + + this.wrapOption = this.properties.get("wrap-option").getEnum(); + this.whiteSpaceCollapse = + this.properties.get("white-space-collapse").getEnum(); + ts = new TextState(); + + } + +} diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java new file mode 100644 index 000000000..3aa394272 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -0,0 +1,246 @@ +/* + * $Id: PageNumberCitation.java,v 1.30 2003/03/05 20:38:22 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.area.PageViewport; +import org.apache.fop.area.Resolveable; +import org.apache.fop.area.Trait; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.UnresolvedPageNumber; +import org.apache.fop.area.inline.Word; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.layout.FontState; +import org.apache.fop.layout.MarginInlineProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layout.TextState; +import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.LayoutProcessor; +import org.apache.fop.layoutmgr.LeafNodeLayoutManager; +import org.apache.fop.layoutmgr.PositionIterator; +import org.apache.fop.util.CharUtilities; + +/** + * Page number citation. + * This inline fo is replaced with the text for a page number. + * The page number used is the page that contains the start of the + * block referenced with the ref-id attribute. + */ +public class PageNumberCitation extends FObj { + protected FontInfo fontInfo = null; + protected FontState fontState; + + private float red; + private float green; + private float blue; + private int wrapOption; + private int whiteSpaceCollapse; + private String pageNumber; + private String refId; + private TextState ts; + private InlineArea inline = null; + private boolean unresolved = false; + + public PageNumberCitation(FONode parent) { + super(parent); + } + + public void setStructHandler(StructureHandler st) { + super.setStructHandler(st); + fontInfo = st.getFontInfo(); + } + + public void addLayoutManager(List lms) { + setup(); + LayoutManager lm; + lm = new LeafNodeLayoutManager() { + public InlineArea get(LayoutContext context) { + return getInlineArea(parentLM); + } + + public void addAreas(PositionIterator posIter, + LayoutContext context) { + super.addAreas(posIter, context); + if (unresolved) { + parentLM.addUnresolvedArea(refId, + (Resolveable) inline); + } + } + + protected void offsetArea(LayoutContext context) { + curArea.setOffset(context.getBaseline()); + } + }; + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + lms.add(lm); + } + + // if id can be resolved then simply return a word, otherwise + // return a resolveable area + private InlineArea getInlineArea(LayoutProcessor parentLM) { + if (refId.equals("")) { + getLogger().error("page-number-citation must contain \"ref-id\""); + return null; + } + PageViewport page = parentLM.resolveRefID(refId); + if (page != null) { + String str = page.getPageNumber(); + // get page string from parent, build area + Word word = new Word(); + inline = word; + int width = getStringWidth(str); + word.setWord(str); + inline.setIPD(width); + inline.setHeight(fontState.getAscender() + - fontState.getDescender()); + inline.setOffset(fontState.getAscender()); + + inline.addTrait(Trait.FONT_NAME, fontState.getFontName()); + inline.addTrait(Trait.FONT_SIZE, + new Integer(fontState.getFontSize())); + unresolved = false; + } else { + unresolved = true; + inline = new UnresolvedPageNumber(refId); + String str = "MMM"; // reserve three spaces for page number + int width = getStringWidth(str); + inline.setIPD(width); + inline.setHeight(fontState.getAscender() + - fontState.getDescender()); + inline.setOffset(fontState.getAscender()); + + inline.addTrait(Trait.FONT_NAME, fontState.getFontName()); + inline.addTrait(Trait.FONT_SIZE, + new Integer(fontState.getFontSize())); + } + return inline; + } + + protected int getStringWidth(String str) { + int width = 0; + for (int count = 0; count < str.length(); count++) { + width += CharUtilities.getCharWidth(str.charAt(count), + fontState); + } + return width; + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Font Properties + this.fontState = propMgr.getFontState(fontInfo); + + // Common Margin Properties-Inline + MarginInlineProps mProps = propMgr.getMarginInlineProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + // this.properties.get("alignment-adjust"); + // this.properties.get("alignment-baseline"); + // this.properties.get("baseline-shift"); + // this.properties.get("dominant-baseline"); + setupID(); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("letter-spacing"); + // this.properties.get("line-height"); + // this.properties.get("line-height-shift-adjustment"); + // this.properties.get("ref-id"); + // this.properties.get("score-spaces"); + // this.properties.get("text-decoration"); + // this.properties.get("text-shadow"); + // this.properties.get("text-transform"); + // this.properties.get("word-spacing"); + + ColorType c = this.properties.get("color").getColorType(); + this.red = c.getRed(); + this.green = c.getGreen(); + this.blue = c.getBlue(); + + this.wrapOption = this.properties.get("wrap-option").getEnum(); + this.whiteSpaceCollapse = + this.properties.get("white-space-collapse").getEnum(); + + this.refId = this.properties.get("ref-id").getString(); + + if (this.refId.equals("")) { + //throw new FOPException("page-number-citation must contain \"ref-id\""); + } + + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/RetrieveMarker.java b/src/java/org/apache/fop/fo/flow/RetrieveMarker.java new file mode 100644 index 000000000..3abc308d5 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/RetrieveMarker.java @@ -0,0 +1,109 @@ +/* + * $Id: RetrieveMarker.java,v 1.13 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObjMixed; +import org.apache.fop.layoutmgr.RetrieveMarkerLayoutManager; +import org.xml.sax.Attributes; + +import java.util.List; + +/** + * The retrieve-marker formatting object. + * This will create a layout manager that will retrieve + * a marker based on the information. + */ +public class RetrieveMarker extends FObjMixed { + + private String retrieveClassName; + private int retrievePosition; + private int retrieveBoundary; + + /** + * Create a retrieve marker object. + * + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RetrieveMarker(FONode parent) { + super(parent); + } + + /** + * Handle the attributes for the retrieve-marker. + * + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + this.retrieveClassName = + this.properties.get("retrieve-class-name").getString(); + this.retrievePosition = + this.properties.get("retrieve-position").getEnum(); + this.retrieveBoundary = + this.properties.get("retrieve-boundary").getEnum(); + } + + /** + * @see org.apache.fop.fo.FObj#addLayoutManager(List) + */ + public void addLayoutManager(List lms) { + RetrieveMarkerLayoutManager rmlm; + rmlm = new RetrieveMarkerLayoutManager(retrieveClassName, + retrievePosition, + retrieveBoundary); + rmlm.setUserAgent(getUserAgent()); + rmlm.setFObj(this); + lms.add(rmlm); + } +} diff --git a/src/java/org/apache/fop/fo/flow/StaticContent.java b/src/java/org/apache/fop/fo/flow/StaticContent.java new file mode 100644 index 000000000..da7d4df82 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/StaticContent.java @@ -0,0 +1,90 @@ +/* + * $Id: StaticContent.java,v 1.26 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.apps.FOPException; +import org.apache.fop.layoutmgr.StaticContentLayoutManager; + +public class StaticContent extends Flow { + + public StaticContent(FONode parent) { + super(parent); + } + + public void setup() { + + } + + // flowname checking is more stringient for static content currently + protected void setFlowName(String name) throws FOPException { + if (name == null || name.equals("")) { + throw new FOPException("A 'flow-name' is required for " + + getName() + "."); + } else { + super.setFlowName(name); + } + + } + + private StaticContentLayoutManager lm; + + public StaticContentLayoutManager getLayoutManager() { + if (lm == null) { + lm = new StaticContentLayoutManager(); + lm.setUserAgent(getUserAgent()); + lm.setFObj(this); + } + return lm; + } + +} diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java new file mode 100644 index 000000000..8d672623f --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -0,0 +1,208 @@ +/* + * $Id: Table.java,v 1.50 2003/03/05 20:38:21 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.ArrayList; +import java.util.List; + +// FOP +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.LengthRange; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.properties.TableLayout; +import org.apache.fop.fo.properties.TableOmitFooterAtBreak; +import org.apache.fop.fo.properties.TableOmitHeaderAtBreak; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.table.TableLayoutManager; + +public class Table extends FObj { + private static final int MINCOLWIDTH = 10000; // 10pt + + protected ArrayList columns = null; + private TableBody tableHeader = null; + private TableBody tableFooter = null; + private boolean omitHeaderAtBreak = false; + private boolean omitFooterAtBreak = false; + + private int breakBefore; + private int breakAfter; + private int spaceBefore; + private int spaceAfter; + private ColorType backgroundColor; + private LengthRange ipd; + private int height; + + private boolean bAutoLayout = false; + private int contentWidth = 0; // Sum of column widths + /** Optimum inline-progression-dimension */ + private int optIPD; + /** Minimum inline-progression-dimension */ + private int minIPD; + /** Maximum inline-progression-dimension */ + private int maxIPD; + + public Table(FONode parent) { + super(parent); + } + + protected void addChild(FONode child) { + if (child.getName().equals("fo:table-column")) { + if (columns == null) { + columns = new ArrayList(); + } + columns.add(((TableColumn)child).getLayoutManager()); + } else if (child.getName().equals("fo:table-footer")) { + tableFooter = (TableBody)child; + } else if (child.getName().equals("fo:table-header")) { + tableHeader = (TableBody)child; + } else { + // add bodies + super.addChild(child); + } + } + + /** + * Return a LayoutManager responsible for laying out this FObj's content. + * Must override in subclasses if their content can be laid out. + */ + public void addLayoutManager(List list) { + TableLayoutManager tlm = new TableLayoutManager(); + tlm.setUserAgent(getUserAgent()); + tlm.setFObj(this); + tlm.setColumns(columns); + if (tableHeader != null) { + tlm.setTableHeader(tableHeader.getLayoutManager()); + } + if (tableFooter != null) { + tlm.setTableFooter(tableFooter.getLayoutManager()); + } + list.add(tlm); + } + + public void setup() { + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Block + MarginProps mProps = propMgr.getMarginProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + // this.properties.get("block-progression-dimension"); + // this.properties.get("border-after-precendence"); + // this.properties.get("border-before-precedence"); + // this.properties.get("border-collapse"); + // this.properties.get("border-end-precendence"); + // this.properties.get("border-separation"); + // this.properties.get("border-start-precendence"); + // this.properties.get("break-after"); + // this.properties.get("break-before"); + setupID(); + // this.properties.get("inline-progression-dimension"); + // this.properties.get("height"); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + // this.properties.get("table-layout"); + // this.properties.get("table-omit-footer-at-break"); + // this.properties.get("table-omit-header-at-break"); + // this.properties.get("width"); + // this.properties.get("writing-mode"); + + this.breakBefore = this.properties.get("break-before").getEnum(); + this.breakAfter = this.properties.get("break-after").getEnum(); + this.spaceBefore = this.properties.get( + "space-before.optimum").getLength().getValue(); + this.spaceAfter = this.properties.get( + "space-after.optimum").getLength().getValue(); + this.backgroundColor = + this.properties.get("background-color").getColorType(); + this.ipd = this.properties.get( + "inline-progression-dimension").getLengthRange(); + this.height = this.properties.get("height").getLength().getValue(); + this.bAutoLayout = (this.properties.get( + "table-layout").getEnum() == TableLayout.AUTO); + + this.omitHeaderAtBreak = this.properties.get( + "table-omit-header-at-break").getEnum() + == TableOmitHeaderAtBreak.TRUE; + this.omitFooterAtBreak = this.properties.get( + "table-omit-footer-at-break").getEnum() + == TableOmitFooterAtBreak.TRUE; + + } + + public boolean generatesInlineAreas() { + return false; + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/TableAndCaption.java b/src/java/org/apache/fop/fo/flow/TableAndCaption.java new file mode 100644 index 000000000..fd03bc5bd --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableAndCaption.java @@ -0,0 +1,107 @@ +/* + * $Id: TableAndCaption.java,v 1.11 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.RelativePositionProps; + +/** + * fo:table-and-caption element. + */ +public class TableAndCaption extends ToBeImplementedElement { + + public TableAndCaption(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Margin Properties-Block + MarginProps mProps = propMgr.getMarginProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("caption-side"); + setupID(); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + + } + + public boolean generatesInlineAreas() { + return false; + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java new file mode 100644 index 000000000..ce9e68cf5 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -0,0 +1,125 @@ +/* + * $Id: TableBody.java,v 1.48 2003/03/05 20:38:22 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; + +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.table.Body; + +public class TableBody extends FObj { + + private int spaceBefore; + private int spaceAfter; + private ColorType backgroundColor; + + public TableBody(FONode parent) { + super(parent); + } + + /** + * Return a LayoutManager responsible for laying out this FObj's content. + * Must override in subclasses if their content can be laid out. + */ + public void addLayoutManager(List list) { + list.add(getLayoutManager()); + } + + public Body getLayoutManager() { + Body blm = new Body(); + blm.setUserAgent(getUserAgent()); + blm.setFObj(this); + return blm; + } + + public void setup() throws FOPException { + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = + propMgr.getRelativePositionProps(); + + setupID(); + + this.spaceBefore = this.properties.get( + "space-before.optimum").getLength().getValue(); + this.spaceAfter = this.properties.get( + "space-after.optimum").getLength().getValue(); + this.backgroundColor = + this.properties.get("background-color").getColorType(); + + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/TableCaption.java b/src/java/org/apache/fop/fo/flow/TableCaption.java new file mode 100644 index 000000000..6d1dd078a --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableCaption.java @@ -0,0 +1,100 @@ +/* + * $Id: TableCaption.java,v 1.10 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.RelativePositionProps; + +/** + * fo:table-caption element. + */ +public class TableCaption extends ToBeImplementedElement { + + public TableCaption(FONode parent) { + super(parent); + } + + public void setup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("block-progression-dimension"); + // this.properties.get("height"); + setupID(); + // this.properties.get("inline-progression-dimension"); + // this.properties.get("keep-togethe"); + // this.properties.get("width"); + + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java new file mode 100644 index 000000000..b2dcc4b93 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableCell.java @@ -0,0 +1,358 @@ +/* + * $Id: TableCell.java,v 1.52 2003/03/05 20:38:22 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.properties.BorderCollapse; +import org.apache.fop.fo.properties.DisplayAlign; + +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.table.Cell; + + +public class TableCell extends FObj { + + // private int spaceBefore; + // private int spaceAfter; + private ColorType backgroundColor; + + private int numColumnsSpanned; + private int numRowsSpanned; + private int iColNumber = -1; // uninitialized + + /** + * Offset of content rectangle in inline-progression-direction, + * relative to table. + */ + protected int startOffset; + + /** + * Dimension of allocation rectangle in inline-progression-direction, + * determined by the width of the column(s) occupied by the cell + */ + protected int width; + + /** + * Offset of content rectangle, in block-progression-direction, + * relative to the row. + */ + protected int beforeOffset = 0; + + /** + * Offset of content rectangle, in inline-progression-direction, + * relative to the column start edge. + */ + protected int startAdjust = 0; + + /** + * Adjust to theoretical column width to obtain content width + * relative to the column start edge. + */ + protected int widthAdjust = 0; + + /* For collapsed border style */ + protected int borderHeight = 0; + + /** Minimum ontent height of cell. */ + protected int minCellHeight = 0; + /** Height of cell */ + protected int height = 0; + /** Ypos of cell ??? */ + protected int top; + protected int verticalAlign; + protected boolean bRelativeAlign = false; + + // boolean setup = false; + private boolean bSepBorders = true; + + /** + * Set to true if all content completely laid out. + */ + private boolean bDone = false; + + /** + * Border separation value in the block-progression dimension. + * Used in calculating cells height. + */ + private int borderSeparation = 0; + + public TableCell(FONode parent) { + super(parent); + } + + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + doSetup(); // init some basic property values + } + + /** + */ + public void addLayoutManager(List list) { + Cell clm = new Cell(); + clm.setUserAgent(getUserAgent()); + clm.setFObj(this); + list.add(clm); + } + + /** + * Set position relative to table (set by body?) + */ + public void setStartOffset(int offset) { + startOffset = offset; + } + + // Initially same as the column width containg this cell or the + // sum of the spanned columns if numColumnsSpanned > 1 + public void setWidth(int width) { + this.width = width; + } + + public int getColumnNumber() { + return iColNumber; + } + + public int getNumColumnsSpanned() { + return numColumnsSpanned; + } + + public int getNumRowsSpanned() { + return numRowsSpanned; + } + + public void doSetup() { + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("border-after-precedence"); + // this.properties.get("border-before-precendence"); + // this.properties.get("border-end-precendence"); + // this.properties.get("border-start-precendence"); + // this.properties.get("block-progression-dimension"); + // this.properties.get("column-number"); + // this.properties.get("display-align"); + // this.properties.get("relative-align"); + // this.properties.get("empty-cells"); + // this.properties.get("ends-row"); + // this.properties.get("height"); + setupID(); + // this.properties.get("number-columns-spanned"); + // this.properties.get("number-rows-spanned"); + // this.properties.get("starts-row"); + // this.properties.get("width"); + + this.iColNumber = + properties.get("column-number").getNumber().intValue(); + if (iColNumber < 0) { + iColNumber = 0; + } + this.numColumnsSpanned = + this.properties.get("number-columns-spanned").getNumber().intValue(); + if (numColumnsSpanned < 1) { + numColumnsSpanned = 1; + } + this.numRowsSpanned = + this.properties.get("number-rows-spanned").getNumber().intValue(); + if (numRowsSpanned < 1) { + numRowsSpanned = 1; + } + + this.backgroundColor = + this.properties.get("background-color").getColorType(); + + bSepBorders = (this.properties.get("border-collapse").getEnum() + == BorderCollapse.SEPARATE); + + calcBorders(propMgr.getBorderAndPadding()); + + // Vertical cell alignment + verticalAlign = this.properties.get("display-align").getEnum(); + if (verticalAlign == DisplayAlign.AUTO) { + // Depends on all cells starting in row + bRelativeAlign = true; + verticalAlign = this.properties.get("relative-align").getEnum(); + } else { + bRelativeAlign = false; // Align on a per-cell basis + } + + this.minCellHeight = + this.properties.get("height").getLength().getValue(); + } + + /** + * Calculate cell border and padding, including offset of content + * rectangle from the theoretical grid position. + */ + private void calcBorders(BorderAndPadding bp) { + if (this.bSepBorders) { + /* + * Easy case. + * Cell border is the property specified directly on cell. + * Offset content rect by half the border-separation value, + * in addition to the border and padding values. Note: + * border-separate should only be specified on the table object, + * but it inherits. + */ + int iSep = properties.get( + "border-separation.inline-progression-direction").getLength().getValue(); + this.startAdjust = iSep / 2 + bp.getBorderLeftWidth(false) + + bp.getPaddingLeft(false); + /* + * int contentOffset = iSep + bp.getBorderStartWidth(false) + + * bp.getPaddingStart(false); + */ + this.widthAdjust = startAdjust + iSep - iSep / 2 + + bp.getBorderRightWidth(false) + + bp.getPaddingRight(false); + // bp.getBorderEndWidth(false) + bp.getPaddingEnd(false); + // Offset of content rectangle in the block-progression direction + borderSeparation = properties.get( + "border-separation.block-progression-direction").getLength().getValue(); + this.beforeOffset = borderSeparation / 2 + + bp.getBorderTopWidth(false) + + bp.getPaddingTop(false); + // bp.getBorderBeforeWidth(false) + bp.getPaddingBefore(false); + + } else { + // System.err.println("Collapse borders"); + /* + * Hard case. + * Cell border is combination of other cell borders, or table + * border for edge cells. Also seems to border values specified + * on row and column FO in the table (if I read CR correclty.) + */ + + // Set up before and after borders, taking into account row + // and table border properties. + // ??? What about table-body, header,footer + + /* + * We can't calculate before and after because we aren't sure + * whether this row will be the first or last in its area, due + * to redoing break decisions (at least in the "new" architecture.) + * So in the general case, we will calculate two possible values: + * the first/last one and the "middle" one. + * Example: border-before + * 1. If the cell is in the first row in the first table body, it + * will combine with the last row of the header, or with the + * top (before) table border if there is no header. + * 2. Otherwise there are two cases: + * a. the row is first in its (non-first) Area. + * The border can combine with either: + * i. the last row of table-header and its cells, or + * ii. the table before border (no table-header or it is + * omitted on non-first Areas). + * b. the row isn't first in its Area. + * The border combines with the border of the previous + * row and the cells which end in that row. + */ + + /* + * if-first + * Calculate the effective border of the cell before-border, + * it's parent row before-border, the last header row after-border, + * the after border of the cell(s) which end in the last header + * row. + */ + /* + * if-not-first + * Calculate the effective border of the cell before-border, + * it's parent row before-border, the previous row after-border, + * the after border of the cell(s) which end in the previous + * row. + */ + + + /* ivan demakov */ + int borderStart = bp.getBorderLeftWidth(false); + int borderEnd = bp.getBorderRightWidth(false); + int borderBefore = bp.getBorderTopWidth(false); + int borderAfter = bp.getBorderBottomWidth(false); + + this.startAdjust = borderStart / 2 + bp.getPaddingLeft(false); + + this.widthAdjust = startAdjust + borderEnd / 2 + + bp.getPaddingRight(false); + this.beforeOffset = borderBefore / 2 + bp.getPaddingTop(false); + // Half border height to fix overestimate of area size! + this.borderHeight = (borderBefore + borderAfter) / 2; + } + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/TableColumn.java b/src/java/org/apache/fop/fo/flow/TableColumn.java new file mode 100644 index 000000000..956f11758 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableColumn.java @@ -0,0 +1,151 @@ +/* + * $Id: TableColumn.java,v 1.29 2003/03/05 20:38:21 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.Length; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.Property; + +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.table.Column; + +public class TableColumn extends FObj { + + private ColorType backgroundColor; + + private Length columnWidthPropVal; + private int columnWidth; + private int columnOffset; + private int numColumnsRepeated; + private int iColumnNumber; + + private boolean setup = false; + + public TableColumn(FONode parent) { + super(parent); + } + + public LayoutManager getLayoutManager() { + doSetup(); + Column clm = new Column(); + clm.setUserAgent(getUserAgent()); + clm.setFObj(this); + return clm; + } + + public Length getColumnWidthAsLength() { + return columnWidthPropVal; + } + + public int getColumnWidth() { + return columnWidth; + } + + /** + * Set the column width value in base units which overrides the + * value from the column-width Property. + */ + public void setColumnWidth(int columnWidth) { + this.columnWidth = columnWidth; + } + + public int getColumnNumber() { + return iColumnNumber; + } + + public int getNumColumnsRepeated() { + return numColumnsRepeated; + } + + public void doSetup() { + + // Common Border, Padding, and Background Properties + // only background apply, border apply if border-collapse + // is collapse. + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // this.properties.get("column-width"); + // this.properties.get("number-columns-repeated"); + // this.properties.get("number-columns-spanned"); + // this.properties.get("visibility"); + + iColumnNumber = properties.get("column-number").getNumber().intValue(); + + numColumnsRepeated = + properties.get("number-columns-repeated").getNumber().intValue(); + + this.backgroundColor = + this.properties.get("background-color").getColorType(); + + Property prop = this.properties.get("column-width"); + if (prop != null) { + columnWidthPropVal = properties.get("column-width").getLength(); + + // This won't include resolved table-units or % values yet. + columnWidth = columnWidthPropVal.getValue(); + } else { + columnWidth = 300000; + } + + // initialize id + setupID(); + + setup = true; + } + +} + diff --git a/src/java/org/apache/fop/fo/flow/TableFooter.java b/src/java/org/apache/fop/fo/flow/TableFooter.java new file mode 100644 index 000000000..17f5008dd --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableFooter.java @@ -0,0 +1,62 @@ +/* + * $Id: TableFooter.java,v 1.8 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; + +public class TableFooter extends TableBody { + + public TableFooter(FONode parent) { + super(parent); + } + +} diff --git a/src/java/org/apache/fop/fo/flow/TableHeader.java b/src/java/org/apache/fop/fo/flow/TableHeader.java new file mode 100644 index 000000000..d9b725874 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableHeader.java @@ -0,0 +1,62 @@ +/* + * $Id: TableHeader.java,v 1.6 2003/03/06 11:36:31 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; + +public class TableHeader extends TableBody { + + public TableHeader(FONode parent) { + super(parent); + } + +} diff --git a/src/java/org/apache/fop/fo/flow/TableRow.java b/src/java/org/apache/fop/fo/flow/TableRow.java new file mode 100644 index 000000000..42a058b6a --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/TableRow.java @@ -0,0 +1,157 @@ +/* + * $Id: TableRow.java,v 1.61 2003/03/05 20:38:20 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// Java +import java.util.List; + +// FOP +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.KeepValue; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.Property; +import org.apache.fop.fo.properties.Constants; + +import org.apache.fop.layout.AccessibilityProps; +import org.apache.fop.layout.AuralProps; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.RelativePositionProps; +import org.apache.fop.layoutmgr.table.Row; + +public class TableRow extends FObj { + + private boolean setup = false; + + private int breakAfter; + private ColorType backgroundColor; + + private KeepValue keepWithNext; + private KeepValue keepWithPrevious; + private KeepValue keepTogether; + + private int minHeight = 0; // force row height + + public TableRow(FONode parent) { + super(parent); + } + + /** + */ + public void addLayoutManager(List list) { + Row rlm = new Row(); + rlm.setUserAgent(getUserAgent()); + rlm.setFObj(this); + list.add(rlm); + } + + public KeepValue getKeepWithPrevious() { + return keepWithPrevious; + } + + public void doSetup() { + + // Common Accessibility Properties + AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); + + // this.properties.get("block-progression-dimension"); + + // Common Aural Properties + AuralProps mAurProps = propMgr.getAuralProps(); + + // Common Border, Padding, and Background Properties + // only background apply, border apply if border-collapse + // is collapse. + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + + // Common Relative Position Properties + RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); + + // this.properties.get("break-before"); + // this.properties.get("break-after"); + setupID(); + // this.properties.get("height"); + // this.properties.get("keep-together"); + // this.properties.get("keep-with-next"); + // this.properties.get("keep-with-previous"); + + + this.breakAfter = this.properties.get("break-after").getEnum(); + this.backgroundColor = + this.properties.get("background-color").getColorType(); + + this.keepTogether = getKeepValue("keep-together.within-column"); + this.keepWithNext = getKeepValue("keep-with-next.within-column"); + this.keepWithPrevious = + getKeepValue("keep-with-previous.within-column"); + + this.minHeight = this.properties.get("height").getLength().getValue(); + setup = true; + } + + private KeepValue getKeepValue(String sPropName) { + Property p = this.properties.get(sPropName); + Number n = p.getNumber(); + if (n != null) { + return new KeepValue(KeepValue.KEEP_WITH_VALUE, n.intValue()); + } + switch (p.getEnum()) { + case Constants.ALWAYS: + return new KeepValue(KeepValue.KEEP_WITH_ALWAYS, 0); + case Constants.AUTO: + default: + return new KeepValue(KeepValue.KEEP_WITH_AUTO, 0); + } + } +} + diff --git a/src/java/org/apache/fop/fo/flow/Wrapper.java b/src/java/org/apache/fop/fo/flow/Wrapper.java new file mode 100644 index 000000000..d3e176db6 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/Wrapper.java @@ -0,0 +1,76 @@ +/* + * $Id: Wrapper.java,v 1.9 2003/03/06 11:36:30 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.flow; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObjMixed; + +/** + * Implementation for fo:wrapper formatting object. + * The wrapper object serves as + * a property holder for it's children objects. + * + * Content: (#PCDATA|%inline;|%block;)* + * Properties: id + */ +public class Wrapper extends FObjMixed { + + public Wrapper(FONode parent) { + super(parent); + } + + protected boolean containsMarkers() { + return true; + } + +} + diff --git a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java new file mode 100644 index 000000000..acc1f72fe --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -0,0 +1,200 @@ +/* + * $Id: ConditionalPageMasterReference.java,v 1.12 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.properties.BlankOrNotBlank; +import org.apache.fop.fo.properties.OddOrEven; +import org.apache.fop.fo.properties.PagePosition; +import org.apache.fop.apps.FOPException; + +/** + * A conditional-page-master-reference formatting object. + * This is a reference to a page master with a set of conditions. + * The conditions must be satisfied for the referenced master to + * be used. + * This element is must be the child of a repeatable-page-master-alternatives + * element. + */ +public class ConditionalPageMasterReference extends FObj { + + private RepeatablePageMasterAlternatives repeatablePageMasterAlternatives; + + private String masterName; + + private int pagePosition; + private int oddOrEven; + private int blankOrNotBlank; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public ConditionalPageMasterReference(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + if (getProperty("master-reference") != null) { + setMasterName(getProperty("master-reference").getString()); + } + + validateParent(parent); + + this.pagePosition = this.properties.get("page-position").getEnum(); + this.oddOrEven = this.properties.get("odd-or-even").getEnum(); + this.blankOrNotBlank = this.properties.get("blank-or-not-blank").getEnum(); + } + + /** + * Sets the master name. + * @param masterName name for the master + */ + protected void setMasterName(String masterName) { + this.masterName = masterName; + } + + /** + * Returns the "master-name" attribute of this page master reference + * @return the master name + */ + public String getMasterName() { + return masterName; + } + + /** + * Check if the conditions for this reference are met. + * checks the page number and emptyness to determine if this + * matches. + * @param isOddPage True if page number odd + * @param isFirstPage True if page is first page + * @param isBlankPage True if page is blank + * @return True if the conditions for this reference are met + */ + protected boolean isValid(boolean isOddPage, + boolean isFirstPage, + boolean isBlankPage) { + // page-position + if (isFirstPage) { + if (pagePosition == PagePosition.REST) { + return false; + } else if (pagePosition == PagePosition.LAST) { + // how the hell do you know at this point? + getLogger().debug("LAST PagePosition NYI"); + return false; + } + } else { + if (pagePosition == PagePosition.FIRST) { + return false; + } else if (pagePosition == PagePosition.LAST) { + // how the hell do you know at this point? + getLogger().debug("LAST PagePosition NYI"); + // potentially valid, don't return + } + } + + // odd-or-even + if (isOddPage) { + if (oddOrEven == OddOrEven.EVEN) { + return false; + } + } else { + if (oddOrEven == OddOrEven.ODD) { + return false; + } + } + + // blank-or-not-blank + if (isBlankPage) { + if (blankOrNotBlank == BlankOrNotBlank.NOT_BLANK) { + return false; + } + } else { + if (blankOrNotBlank == BlankOrNotBlank.BLANK) { + return false; + } + } + return true; + } + + /** + * Check that the parent is the right type of formatting object + * repeatable-page-master-alternatives. + * @param parent parent node + * @throws FOPException If the parent is invalid + */ + protected void validateParent(FONode parent) throws FOPException { + if (parent.getName().equals("fo:repeatable-page-master-alternatives")) { + this.repeatablePageMasterAlternatives = + (RepeatablePageMasterAlternatives)parent; + + if (getMasterName() == null) { + getLogger().warn("single-page-master-reference" + + "does not have a master-name and so is being ignored"); + } else { + this.repeatablePageMasterAlternatives.addConditionalPageMasterReference(this); + } + } else { + throw new FOPException("fo:conditional-page-master-reference must be child " + + "of fo:repeatable-page-master-alternatives, not " + + parent.getName()); + } + } + +} diff --git a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java new file mode 100644 index 000000000..980bf51ea --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -0,0 +1,222 @@ +/* + * $Id: LayoutMasterSet.java,v 1.19 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.util.Iterator; +import java.util.Map; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.apps.FOPException; + +/** + * The layout-master-set formatting object. + * This class maintains the set of simple page master and + * page sequence masters. + * The masters are stored so that the page sequence can obtain + * the required page master to create a page. + * The page sequence masters can be reset as they hold state + * information for a page sequence. + */ +public class LayoutMasterSet extends FObj { + + private Map simplePageMasters; + private Map pageSequenceMasters; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public LayoutMasterSet(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + if (parent.getName().equals("fo:root")) { + Root root = (Root)parent; + root.setLayoutMasterSet(this); + } else { + throw new FOPException("fo:layout-master-set must be child of fo:root, not " + + parent.getName()); + } + + this.simplePageMasters = new java.util.HashMap(); + this.pageSequenceMasters = new java.util.HashMap(); + } + + /** + * Add a simple page master. + * The name is checked to throw an error if already added. + * @param simplePageMaster simple-page-master to add + * @throws FOPException if there's a problem with name uniqueness + */ + protected void addSimplePageMaster(SimplePageMaster simplePageMaster) + throws FOPException { + // check against duplication of master-name + if (existsName(simplePageMaster.getMasterName())) { + throw new FOPException("'master-name' (" + + simplePageMaster.getMasterName() + + ") must be unique " + + "across page-masters and page-sequence-masters"); + } + this.simplePageMasters.put(simplePageMaster.getMasterName(), + simplePageMaster); + } + + /** + * Get a simple page master by name. + * This is used by the page sequence to get a page master for + * creating pages. + * @param masterName the name of the page master + * @return the requested simple-page-master + */ + public SimplePageMaster getSimplePageMaster(String masterName) { + return (SimplePageMaster)this.simplePageMasters.get(masterName); + } + + /** + * Add a page sequence master. + * The name is checked to throw an error if already added. + * @param masterName name for the master + * @param pageSequenceMaster PageSequenceMaster instance + * @throws FOPException if there's a problem with name uniqueness + */ + protected void addPageSequenceMaster(String masterName, + PageSequenceMaster pageSequenceMaster) + throws FOPException { + // check against duplication of master-name + if (existsName(masterName)) { + throw new FOPException("'master-name' (" + masterName + + ") must be unique " + + "across page-masters and page-sequence-masters"); + } + this.pageSequenceMasters.put(masterName, pageSequenceMaster); + } + + /** + * Get a page sequence master by name. + * This is used by the page sequence to get a page master for + * creating pages. + * @param masterName name of the master + * @return the requested PageSequenceMaster instance + */ + public PageSequenceMaster getPageSequenceMaster(String masterName) { + return (PageSequenceMaster)this.pageSequenceMasters.get(masterName); + } + + private boolean existsName(String masterName) { + if (simplePageMasters.containsKey(masterName) + || pageSequenceMasters.containsKey(masterName)) { + return true; + } else { + return false; + } + } + + /** + * Section 7.33.15: check to see that if a region-name is a + * duplicate, that it maps to the same region-class. + * @throws FOPException if there's a name duplication + */ + protected void checkRegionNames() throws FOPException { + Map allRegions = new java.util.HashMap(); + for (Iterator spm = simplePageMasters.values().iterator(); + spm.hasNext();) { + SimplePageMaster simplePageMaster = + (SimplePageMaster)spm.next(); + Map spmRegions = simplePageMaster.getRegions(); + for (Iterator e = spmRegions.values().iterator(); + e.hasNext();) { + Region region = (Region)e.next(); + if (allRegions.containsKey(region.getRegionName())) { + String localClass = + (String)allRegions.get(region.getRegionName()); + if (!localClass.equals(region.getRegionClass())) { + throw new FOPException("Duplicate region-names (" + + region.getRegionName() + + ") must map " + + "to the same region-class (" + + localClass + "!=" + + region.getRegionClass() + + ")"); + } + } + allRegions.put(region.getRegionName(), + region.getRegionClass()); + } + } + } + + /** + * Checks whether or not a region name exists in this master set. + * @param regionName name of the region + * @return true when the region name specified has a region in this LayoutMasterSet + */ + protected boolean regionNameExists(String regionName) { + for (Iterator e = simplePageMasters.values().iterator(); + e.hasNext();) { + if (((SimplePageMaster)e.next()).regionNameExists(regionName)) { + return true; + } + } + return false; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/PageMasterReference.java b/src/java/org/apache/fop/fo/pagination/PageMasterReference.java new file mode 100644 index 000000000..bb61e279d --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/PageMasterReference.java @@ -0,0 +1,120 @@ +/* + * $Id: PageMasterReference.java,v 1.12 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// SAX +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.apps.FOPException; + +/** + * Base PageMasterReference class. Provides implementation for handling the + * master-reference attribute and containment within a PageSequenceMaster + */ +public abstract class PageMasterReference extends FObj + implements SubSequenceSpecifier { + + private String masterName; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public PageMasterReference(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + if (getProperty("master-reference") != null) { + this.masterName = getProperty("master-reference").getString(); + } + validateParent(parent); + } + + + /** + * Returns the "master-reference" attribute of this page master reference + * @return the name of the page master + */ + public String getMasterName() { + return masterName; + } + + /** + * Checks that the parent is the right element. The default implementation + * checks for fo:page-sequence-master. + * @param parent parent node + * @throws FOPException If the parent is invalid. + */ + protected void validateParent(FONode parent) throws FOPException { + if (parent.getName().equals("fo:page-sequence-master")) { + PageSequenceMaster pageSequenceMaster = (PageSequenceMaster)parent; + + if (getMasterName() == null) { + getLogger().warn(getName() + + " does not have a master-reference and so is being ignored"); + } else { + pageSequenceMaster.addSubsequenceSpecifier(this); + } + } else { + throw new FOPException(getName() + " must be" + + "child of fo:page-sequence-master, not " + + parent.getName()); + } + } + +} diff --git a/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java b/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java new file mode 100644 index 000000000..55706f2b1 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java @@ -0,0 +1,208 @@ +/* + * $Id: PageNumberGenerator.java,v 1.8 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Avalon +import org.apache.avalon.framework.logger.AbstractLogEnabled; + +/** + * This class uses the 'format', 'groupingSeparator', 'groupingSize', + * and 'letterValue' properties on fo:page-sequence to return a String + * corresponding to the supplied integer page number. + */ +public class PageNumberGenerator extends AbstractLogEnabled { + + private String format; + private char groupingSeparator; + private int groupingSize; + private int letterValue; + + // constants + private static final int DECIMAL = 1; // '0*1' + private static final int LOWERALPHA = 2; // 'a' + private static final int UPPERALPHA = 3; // 'A' + private static final int LOWERROMAN = 4; // 'i' + private static final int UPPERROMAN = 5; // 'I' + + // flags + private int formatType = DECIMAL; + private int minPadding = 0; // for decimal formats + + // preloaded strings of zeros + private String zeros[] = { + "", "0", "00", "000", "0000", "00000" + }; + + /** + * Main constructor. For further information on the parameters see the XSLT + * specs (Number to String Conversion Attributes). + * @param format format for the page number + * @param groupingSeparator grouping separator + * @param groupingSize grouping size + * @param letterValue letter value + */ + public PageNumberGenerator(String format, char groupingSeparator, + int groupingSize, int letterValue) { + this.format = format; + this.groupingSeparator = groupingSeparator; + this.groupingSize = groupingSize; + this.letterValue = letterValue; + + // the only accepted format strings are currently '0*1' 'a', 'A', 'i' + // and 'I' + int fmtLen = format.length(); + if (fmtLen == 1) { + if (format.equals("1")) { + formatType = DECIMAL; + minPadding = 0; + } else if (format.equals("a")) { + formatType = LOWERALPHA; + } else if (format.equals("A")) { + formatType = UPPERALPHA; + } else if (format.equals("i")) { + formatType = LOWERROMAN; + } else if (format.equals("I")) { + formatType = UPPERROMAN; + } else { + // token not handled + //getLogger().debug("'format' token not recognized; using '1'"); + formatType = DECIMAL; + minPadding = 0; + } + } else { + // only accepted token is '0+1'at this stage. Because of the + // wonderful regular expression support in Java, we will resort to a + // loop + for (int i = 0; i < fmtLen - 1; i++) { + if (format.charAt(i) != '0') { + //getLogger().debug("'format' token not recognized; using '1'"); + formatType = DECIMAL; + minPadding = 0; + } else { + minPadding = fmtLen - 1; + } + } + } + } + + /** + * Formats a page number. + * @param number page number to format + * @return the formatted page number as a String + */ + public String makeFormattedPageNumber(int number) { + String pn = null; + if (formatType == DECIMAL) { + pn = Integer.toString(number); + if (minPadding >= pn.length()) { + int nz = minPadding - pn.length() + 1; + pn = zeros[nz] + pn; + } + } else if ((formatType == LOWERROMAN) || (formatType == UPPERROMAN)) { + pn = makeRoman(number); + if (formatType == UPPERROMAN) { + pn = pn.toUpperCase(); + } + } else { + // alphabetic + pn = makeAlpha(number); + if (formatType == UPPERALPHA) { + pn = pn.toUpperCase(); + } + } + return pn; + } + + private String makeRoman(int num) { + int arabic[] = { + 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 + }; + String roman[] = { + "m", "cm", "d", "cd", "c", "xc", "l", "xl", "x", "ix", "v", "iv", + "i" + }; + + int i = 0; + StringBuffer romanNumber = new StringBuffer(); + + while (num > 0) { + while (num >= arabic[i]) { + num = num - arabic[i]; + romanNumber.append(roman[i]); + } + i = i + 1; + } + return romanNumber.toString(); + } + + private String makeAlpha(int num) { + String letters = "abcdefghijklmnopqrstuvwxyz"; + StringBuffer alphaNumber = new StringBuffer(); + + int base = 26; + int rem = 0; + + num--; + if (num < base) { + alphaNumber.append(letters.charAt(num)); + } else { + while (num >= base) { + rem = num % base; + alphaNumber.append(letters.charAt(rem)); + num = num / base; + } + alphaNumber.append(letters.charAt(num - 1)); + } + return alphaNumber.reverse().toString(); + } + +} + diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java new file mode 100644 index 000000000..a2bbd82a0 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -0,0 +1,807 @@ +/* + * $Id: PageSequence.java,v 1.61 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.Title; +import org.apache.fop.fo.flow.Flow; +import org.apache.fop.fo.flow.StaticContent; +import org.apache.fop.layout.PageMaster; +import org.apache.fop.area.AreaTree; +import org.apache.fop.area.PageViewport; +import org.apache.fop.apps.FOPException; + +import org.apache.fop.layoutmgr.PageLayoutManager; + +// Java +import java.util.HashMap; + +import org.xml.sax.Attributes; + +/** + * This provides pagination of flows onto pages. Much of the + * logic for paginating flows is contained in this class. + * The main entry point is the format method. + */ +public class PageSequence extends FObj { + // + // intial-page-number types + // + private static final int EXPLICIT = 0; + private static final int AUTO = 1; + private static final int AUTO_EVEN = 2; + private static final int AUTO_ODD = 3; + + // + // associations + // + /** + * The parent root object + */ + private Root root; + + /** + * the set of layout masters (provided by the root object) + */ + private LayoutMasterSet layoutMasterSet; + + // There doesn't seem to be anything in the spec requiring flows + // to be in the order given, only that they map to the regions + // defined in the page sequence, so all we need is this one hashmap + // the set of flows includes StaticContent flows also + + /** + * Map of flows to their flow name (flow-name, Flow) + */ + private HashMap flowMap; + + // according to communication from Paul Grosso (XSL-List, + // 001228, Number 406), confusion in spec section 6.4.5 about + // multiplicity of fo:flow in XSL 1.0 is cleared up - one (1) + // fo:flow per fo:page-sequence only. +// private boolean isFlowSet = false; + + // for structure handler + private boolean sequenceStarted = false; + + // + // state attributes used during layout + // + + private PageViewport currentPage; + + // page number and related formatting variables + private String ipnValue; + private int currentPageNumber = 0; + private int explicitFirstNumber = 0; // explicitly specified + private int firstPageNumber = 0; // actual + private PageNumberGenerator pageNumberGenerator; + + private int forcePageCount = 0; + private int pageCount = 0; + private boolean isForcing = false; + + /** + * specifies page numbering type (auto|auto-even|auto-odd|explicit) + */ + private int pageNumberType; + + /** + * used to determine whether to calculate auto, auto-even, auto-odd + */ + private boolean thisIsFirstPage; + + /** + * The currentSimplePageMaster is either the page master for the + * whole page sequence if master-reference refers to a simple-page-master, + * or the simple page master produced by the page sequence mster otherwise. + * The pageSequenceMaster is null if master-reference refers to a + * simple-page-master. + */ + private SimplePageMaster currentSimplePageMaster; + private PageSequenceMaster pageSequenceMaster; + + /** + * The main content flow for this page-sequence. + */ + private Flow mainFlow = null; + + /** + * The fo:title object for this page-sequence. + */ + private Title titleFO; + + /** + * Create a page sequence FO node. + * + * @param parent the parent FO node + */ + public PageSequence(FONode parent) { + super(parent); + } + + /** + * Handle the attributes for this xml element. + * For the page sequence this gets all the appropriate properties + * for dealing with the page sequence. + * + * @param attlist the attribute list + * @throws FOPException if there is an error with the properties + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + if (parent.getName().equals("fo:root")) { + this.root = (Root)parent; + // this.root.addPageSequence(this); + } else { + throw new FOPException("page-sequence must be child of root, not " + + parent.getName()); + } + + layoutMasterSet = root.getLayoutMasterSet(); + + // best time to run some checks on LayoutMasterSet + layoutMasterSet.checkRegionNames(); + + flowMap = new HashMap(); + + // we are now on the first page of the page sequence + thisIsFirstPage = true; + ipnValue = this.properties.get("initial-page-number").getString(); + + if (ipnValue.equals("auto")) { + pageNumberType = AUTO; + } else if (ipnValue.equals("auto-even")) { + pageNumberType = AUTO_EVEN; + } else if (ipnValue.equals("auto-odd")) { + pageNumberType = AUTO_ODD; + } else { + pageNumberType = EXPLICIT; + try { + int pageStart = new Integer(ipnValue).intValue(); + this.explicitFirstNumber = (pageStart > 0) ? pageStart - 1 : 0; + } catch (NumberFormatException nfe) { + throw new FOPException("\"" + ipnValue + + "\" is not a valid value for initial-page-number"); + } + } + + + String masterName = this.properties.get("master-reference").getString(); + this.currentSimplePageMaster = + this.layoutMasterSet.getSimplePageMaster(masterName); + if (this.currentSimplePageMaster == null) { + this.pageSequenceMaster = + this.layoutMasterSet.getPageSequenceMaster(masterName); + if (this.pageSequenceMaster == null) { + throw new FOPException("master-reference '" + masterName + + "' for fo:page-sequence matches no" + + " simple-page-master or page-sequence-master"); + } + } + + // get the 'format' properties + this.pageNumberGenerator = + new PageNumberGenerator(this.properties.get("format").getString(), + this.properties.get("grouping-separator").getCharacter(), + this.properties.get("grouping-size").getNumber().intValue(), + this.properties.get("letter-value").getEnum()); + this.pageNumberGenerator.enableLogging(getLogger()); + + this.forcePageCount = + this.properties.get("force-page-count").getEnum(); + + // this.properties.get("country"); + // this.properties.get("language"); + setupID(); + } + + + /** + * Add a flow or static content, mapped by its flow-name. + * The flow-name is used to associate the flow with a region on a page, + * based on the names given to the regions in the page-master used to + * generate that page. + */ +// private void addFlow(Flow flow) throws FOPException { +// if (flowMap.containsKey(flow.getFlowName())) { +// throw new FOPException("flow-names must be unique within an fo:page-sequence"); +// } +// if (!this.layoutMasterSet.regionNameExists(flow.getFlowName())) { +// getLogger().error("region-name '" +// + flow.getFlowName() +// + "' doesn't exist in the layout-master-set."); +// } +// flowMap.put(flow.getFlowName(), flow); +// //setIsFlowSet(true); +// } + + + /** + * Validate the child being added and initialize internal variables. + * XSL content model for page-sequence: + * <pre>(title?,static-content*,flow)</pre> + * + * @param child The flow object child to be added to the PageSequence. + */ + public void addChild(FONode child) { + try { + String childName = child.getName(); + if (childName.equals("fo:title")) { + if (this.flowMap.size() > 0) { + getLogger().warn("fo:title should be first in page-sequence"); + } else { + this.titleFO = (Title)child; + } + } else if (childName.equals("fo:flow")) { + if (this.mainFlow != null) { + throw new FOPException("Only a single fo:flow permitted" + + " per fo:page-sequence"); + } else { + this.mainFlow = (Flow)child; + String flowName = this.mainFlow.getFlowName(); + if (flowMap.containsKey(flowName)) { + throw new FOPException("flow-name " + + flowName + + " is not unique within an fo:page-sequence"); + } + if (!this.layoutMasterSet.regionNameExists(flowName)) { + getLogger().error("region-name '" + + flowName + + "' doesn't exist in the layout-master-set."); + } + // Don't add main flow to the flow map +// addFlow(mainFlow); + if (!sequenceStarted) { + structHandler.startPageSequence(this, titleFO, layoutMasterSet); + sequenceStarted = true; + } + super.addChild(child); // For getChildren + } + } else if (childName.equals("fo:static-content")) { + if (this.mainFlow != null) { + throw new FOPException(childName + + " must precede fo:flow; ignoring"); + } + String flowName = ((StaticContent)child).getFlowName(); + if (flowMap.containsKey(flowName)) { + throw new FOPException("flow-name " + flowName + + " is not unique within an fo:page-sequence"); + } + if (!this.layoutMasterSet.regionNameExists(flowName)) { + getLogger().error("region-name '" + flowName + + "' doesn't exist in the layout-master-set."); + } + flowMap.put(flowName, child); +// addFlow((Flow)child); + if (!sequenceStarted) { + structHandler.startPageSequence(this, titleFO, layoutMasterSet); + sequenceStarted = true; + } + } else { + // Ignore it! + getLogger().warn("FO '" + childName + + "' not a legal page-sequence child."); + return; + } + } catch (FOPException fopex) { + getLogger().error("Error in PageSequence.addChild(): " + + fopex.getMessage(), fopex); + } + } + + /** + * Signal end of this xml element. + * This passes the end page sequence to the structure handler + * so it can act upon that. + */ + public void end() { + try { + this.structHandler.endPageSequence(this); + } catch (FOPException fopex) { + getLogger().error("Error in PageSequence.end(): " + + fopex.getMessage(), fopex); + } + } + + /** + * Runs the formatting of this page sequence into the given area tree + * + * @param areaTree the area tree to format this page sequence into + * @throws FOPException if there is an error formatting the contents + */ + public void format(AreaTree areaTree) throws FOPException { + // Make a new PageLayoutManager and a FlowLayoutManager + // Run the PLM in a thread + // Wait for them to finish. + + // If no main flow, nothing to layout! + if (this.mainFlow == null) { + return; + } + + // Initialize if already used? + // this.layoutMasterSet.resetPageMasters(); + if (pageSequenceMaster != null) { + pageSequenceMaster.reset(); + } + + int firstAvailPageNumber = 0; + initPageNumber(); + + // This will layout pages and add them to the area tree + PageLayoutManager pageLM = new PageLayoutManager(areaTree, this); + pageLM.setUserAgent(getUserAgent()); + pageLM.setFObj(this); + pageLM.setPageCounting(currentPageNumber, pageNumberGenerator); + + // For now, skip the threading and just call run directly. + pageLM.run(); + + // Thread layoutThread = new Thread(pageLM); +// layoutThread.start(); +// log.debug("Layout thread started"); + +// // wait on both managers +// try { +// layoutThread.join(); +// log.debug("Layout thread done"); +// } catch (InterruptedException ie) { +// log.error("PageSequence.format() interrupted waiting on layout"); +// } + this.currentPageNumber = pageLM.getPageCount(); + // Tell the root the last page number we created. + this.root.setRunningPageNumberCounter(this.currentPageNumber); + } + + /** + * Initialize the current page number for the start of the page sequence. + */ + private void initPageNumber() { + this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1; + + if (this.pageNumberType == AUTO_ODD) { + // Next page but force odd. May force empty page creation! + // Whose master is used for this??? Assume no. + // Use force-page-count = auto + // on preceding page-sequence to make sure that there is no gap! + if (currentPageNumber % 2 == 0) { + this.currentPageNumber++; + } + } else if (pageNumberType == AUTO_EVEN) { + if (currentPageNumber % 2 == 1) { + this.currentPageNumber++; + } + } else if (pageNumberType == EXPLICIT) { + this.currentPageNumber = this.explicitFirstNumber; + } + this.firstPageNumber = this.currentPageNumber; + } + + /** + * Called by PageLayoutManager when it needs a new page on which to + * place content. The PageSequence manages the page number (odd/even), + * but the PLM tells it if the page is blank or is the last page. + * + * @param pageNumber the page number to create page for + * @param bIsBlank If true, use a master for a blank page. + * @param firstPage true if this is the first page + * @param bIsLast If true, use the master for the last page in the sequence. + * @return the page viewport created for the page number + * @throws FOPException if there is an error creating page + */ + public PageViewport createPage(int pageNumber, boolean bIsBlank, + boolean firstPage, boolean bIsLast) + throws FOPException { + if (this.pageSequenceMaster != null) { + this.currentSimplePageMaster = this.pageSequenceMaster + .getNextSimplePageMaster(((pageNumber % 2) == 1), + firstPage, + bIsBlank); + } + Region body = currentSimplePageMaster.getRegion(Region.BODY); + if (!this.mainFlow.getFlowName().equals(body.getRegionName())) { + throw new FOPException("Flow '" + this.mainFlow.getFlowName() + + "' does not map to the region-body in page-master '" + + currentSimplePageMaster.getMasterName() + "'"); + } + PageMaster pageMaster = this.currentSimplePageMaster.getPageMaster(); + PageViewport p = pageMaster.makePage(); + return p; + // The page will have a viewport/reference area pair defined + // for each region in the master. + // Set up the page itself +// SKIP ALL THIS FOR NOW!!! +// //this.root.setRunningPageNumberCounter(this.currentPageNumber); + +// this.pageCount++; // used for 'force-page-count' calculations + + // handle the 'force-page-count' + //forcePage(areaTree, firstAvailPageNumber); + } + + /** + * Creates a new page area for the given parameters + * @param areaTree the area tree the page should be contained in + * @param firstAvailPageNumber the page number for this page + * @param isFirstPage true when this is the first page in the sequence + * @param isEmptyPage true if this page will be empty + * (e.g. forced even or odd break) + * @return a Page layout object based on the page master selected + * from the params + * @todo modify the other methods to use even/odd flag and bIsLast + */ +// private PageViewport makePage(int firstAvailPageNumber, +// boolean isFirstPage, boolean bIsLast, +// boolean isEmptyPage) throws FOPException { +// // layout this page sequence + +// // while there is still stuff in the flow, ask the +// // layoutMasterSet for a new page + +// // page number is 0-indexed +// PageMaster pageMaster = getNextPageMaster(masterName, +// firstAvailPageNumber, +// isFirstPage, isEmptyPage); + +// // a legal alternative is to use the last sub-sequence +// // specification which should be handled in getNextSubsequence. +// // That's not done here. +// if (pageMaster == null) { +// throw new FOPException("page masters exhausted. Cannot recover."); +// } +// PageViewport p = pageMaster.makePage(); +// return p; +// } + + /** + * Returns the next SubSequenceSpecifier for the given page sequence master. + * The result is bassed on the current state of this page sequence. + */ +// private SubSequenceSpecifier getNextSubsequence(PageSequenceMaster master) { +// if (master.getSubSequenceSpecifierCount() +// > currentSubsequenceNumber + 1) { + +// currentSubsequence = +// master.getSubSequenceSpecifier(currentSubsequenceNumber + 1); +// currentSubsequenceNumber++; +// return currentSubsequence; +// } else { +// return null; +// } +// } + + /** + * Returns the next simple page master for the given sequence master, page number and + * other state information + */ +// private SimplePageMaster getNextSimplePageMaster(PageSequenceMaster sequenceMaster, +// int pageNumber, boolean thisIsFirstPage, +// boolean isEmptyPage) { +// // handle forcing +// if (isForcing) { +// String nextPageMaster = getNextPageMasterName(sequenceMaster, +// pageNumber, false, true); +// return this.layoutMasterSet.getSimplePageMaster(nextPageMaster); +// } +// String nextPageMaster = getNextPageMasterName(sequenceMaster, +// pageNumber, thisIsFirstPage, isEmptyPage); +// return this.layoutMasterSet.getSimplePageMaster(nextPageMaster); + +// } + + /** + * Get the next page master name. + * This gets the name of the next page master. If the sequence + * is exhausted then an error is indicated and the last page + * master name is used. + */ +// private String getNextPageMasterName(PageSequenceMaster sequenceMaster, +// int pageNumber, +// boolean thisIsFirstPage, +// boolean isEmptyPage) { + +// if (null == currentSubsequence) { +// currentSubsequence = getNextSubsequence(sequenceMaster); +// } + +// String nextPageMaster = +// currentSubsequence.getNextPageMaster(pageNumber, +// thisIsFirstPage, +// isEmptyPage); + + +// if (null == nextPageMaster +// || isFlowForMasterNameDone(currentPageMasterName)) { +// SubSequenceSpecifier nextSubsequence = +// getNextSubsequence(sequenceMaster); +// if (nextSubsequence == null) { +// getLogger().error("Page subsequences exhausted. Using previous subsequence."); +// thisIsFirstPage = +// true; // this becomes the first page in the new (old really) page master +// currentSubsequence.reset(); + +// // we leave currentSubsequence alone +// } +// else { +// currentSubsequence = nextSubsequence; +// } + +// nextPageMaster = +// currentSubsequence.getNextPageMaster(pageNumber, +// thisIsFirstPage, +// isEmptyPage); +// } +// currentPageMasterName = nextPageMaster; + +// return nextPageMaster; + +// } + +// private SimplePageMaster getCurrentSimplePageMaster() { +// return this.layoutMasterSet.getSimplePageMaster(currentPageMasterName); +// } + +// private String getCurrentPageMasterName() { +// return currentPageMasterName; +// } + + // refactored from LayoutMasterSet +// private PageMaster getNextPageMaster(String pageSequenceName, +// int pageNumber, +// boolean thisIsFirstPage, +// boolean isEmptyPage) throws FOPException { +// PageMaster pageMaster = null; + +// // see if there is a page master sequence for this master name +// PageSequenceMaster sequenceMaster = +// this.layoutMasterSet.getPageSequenceMaster(pageSequenceName); + +// if (sequenceMaster != null) { +// pageMaster = getNextSimplePageMaster(sequenceMaster, +// pageNumber, +// thisIsFirstPage, +// isEmptyPage).getPageMaster(); + +// } else { // otherwise see if there's a simple master by the given name +// SimplePageMaster simpleMaster = +// this.layoutMasterSet.getSimplePageMaster(pageSequenceName); +// if (simpleMaster == null) { +// throw new FOPException("'master-reference' for 'fo:page-sequence'" +// + "matches no 'simple-page-master'" +// + " or 'page-sequence-master'"); +// } +// currentPageMasterName = pageSequenceName; + +// pageMaster = simpleMaster.getNextPageMaster(); +// } +// return pageMaster; +// } + + +// /** +// * Returns true when there is more flow elements left to lay out. +// */ +// private boolean flowsAreIncomplete() { +// boolean isIncomplete = false; + +// for (Iterator e = flowMap.values().iterator(); e.hasNext(); ) { +// Flow flow = (Flow)e.next(); +// if (flow instanceof StaticContent) { +// continue; +// } + +// Status status = flow.getStatus(); +// isIncomplete |= status.isIncomplete(); +// } +// return isIncomplete; +// } + +// /** +// * Returns the flow that maps to the given region class for the current +// * page master. +// */ +// private Flow getCurrentFlow(String regionClass) { +// Region region = getCurrentSimplePageMaster().getRegion(regionClass); +// if (region != null) { +// Flow flow = (Flow)flowMap.get(region.getRegionName()); +// return flow; + +// } else { + +// getLogger().error("flow is null. regionClass = '" + regionClass +// + "' currentSPM = " +// + getCurrentSimplePageMaster()); + +// return null; +// } + +// } + +// private boolean isFlowForMasterNameDone(String masterName) { +// // parameter is master-name of PMR; we need to locate PM +// // referenced by this, and determine whether flow(s) are OK +// if (isForcing) +// return false; +// if (masterName != null) { + +// SimplePageMaster spm = +// this.layoutMasterSet.getSimplePageMaster(masterName); +// Region region = spm.getRegion(Region.BODY); + + +// Flow flow = (Flow)flowMap.get(region.getRegionName()); +// /*if ((null == flow) || flow.getStatus().isIncomplete()) +// return false; +// else +// return true;*/ +// } +// return false; +// } + +// public boolean isFlowSet() { +// return isFlowSet; +// } + +// public void setIsFlowSet(boolean isFlowSet) { +// this.isFlowSet = isFlowSet; +// } + + /** + * Get the "initial-page-number" value. + * + * @return the initial-page-number property value + */ + public String getIpnValue() { + return ipnValue; + } + + /** + * Get the current page number for this page sequence. + * + * @return the current page number + */ + public int getCurrentPageNumber() { + return currentPageNumber; + } + +// private void forcePage(AreaTree areaTree, int firstAvailPageNumber) { +// boolean makePage = false; +// if (this.forcePageCount == ForcePageCount.AUTO) { +// PageSequence nextSequence = +// this.root.getSucceedingPageSequence(this); +// if (nextSequence != null) { +// if (nextSequence.getIpnValue().equals("auto")) { +// // do nothing special +// } +// else if (nextSequence.getIpnValue().equals("auto-odd")) { +// if (firstAvailPageNumber % 2 == 0) { +// makePage = true; +// } +// } else if (nextSequence.getIpnValue().equals("auto-even")) { +// if (firstAvailPageNumber % 2 != 0) { +// makePage = true; +// } +// } else { +// int nextSequenceStartPageNumber = +// nextSequence.getCurrentPageNumber(); +// if ((nextSequenceStartPageNumber % 2 == 0) +// && (firstAvailPageNumber % 2 == 0)) { +// makePage = true; +// } else if ((nextSequenceStartPageNumber % 2 != 0) +// && (firstAvailPageNumber % 2 != 0)) { +// makePage = true; +// } +// } +// } +// } else if ((this.forcePageCount == ForcePageCount.EVEN) +// && (this.pageCount % 2 != 0)) { +// makePage = true; +// } else if ((this.forcePageCount == ForcePageCount.ODD) +// && (this.pageCount % 2 == 0)) { +// makePage = true; +// } else if ((this.forcePageCount == ForcePageCount.END_ON_EVEN) +// && (firstAvailPageNumber % 2 == 0)) { +// makePage = true; +// } else if ((this.forcePageCount == ForcePageCount.END_ON_ODD) +// && (firstAvailPageNumber % 2 != 0)) { +// makePage = true; +// } else if (this.forcePageCount == ForcePageCount.NO_FORCE) { +// // do nothing +// } + +// if (makePage) { +// try { +// this.isForcing = true; +// this.currentPageNumber++; +// firstAvailPageNumber = this.currentPageNumber; +// currentPage = makePage(areaTree, firstAvailPageNumber, false, +// true); +// String formattedPageNumber = +// pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber); +// currentPage.setFormattedNumber(formattedPageNumber); +// currentPage.setPageSequence(this); +// formatStaticContent(areaTree); +// log.debug("[forced-" + firstAvailPageNumber + "]"); +// areaTree.addPage(currentPage); +// this.root.setRunningPageNumberCounter(this.currentPageNumber); +// this.isForcing = false; +// } catch (FOPException fopex) { +// log.debug("'force-page-count' failure"); +// } +// } +// } + + /** + * Get the current simple page master + * that is active for the last page created. + * + * @return the current simple page master + */ + public SimplePageMaster getCurrentSimplePageMaster() { + return currentSimplePageMaster; + } + + /** + * Get the static content FO node from the flow map. + * This gets the static content flow for the given flow name. + * + * @param name the flow name to find + * @return the static content FO node + */ + public StaticContent getStaticContent(String name) { + return (StaticContent)flowMap.get(name); + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java new file mode 100644 index 000000000..86624ef1f --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -0,0 +1,200 @@ +/* + * $Id: PageSequenceMaster.java,v 1.13 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.util.List; + +// SAX +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.apps.FOPException; + +/** + * The page-sequence-master formatting object. + * This class handles a list of subsequence specifiers + * which are simple or complex references to page-masters. + */ +public class PageSequenceMaster extends FObj { + + private LayoutMasterSet layoutMasterSet; + private List subSequenceSpecifiers; + private SubSequenceSpecifier currentSubSequence; + private int currentSubSequenceNumber; + private String masterName; + + // The terminology may be confusing. A 'page-sequence-master' consists + // of a sequence of what the XSL spec refers to as + // 'sub-sequence-specifiers'. These are, in fact, simple or complex + // references to page-masters. So the methods use the former + // terminology ('sub-sequence-specifiers', or SSS), + // but the actual FO's are MasterReferences. + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public PageSequenceMaster(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + subSequenceSpecifiers = new java.util.ArrayList(); + + if (parent.getName().equals("fo:layout-master-set")) { + this.layoutMasterSet = (LayoutMasterSet)parent; + String pm = this.properties.get("master-name").getString(); + if (pm == null) { + getLogger().warn("page-sequence-master does not have " + + "a master-name and so is being ignored"); + } else { + this.layoutMasterSet.addPageSequenceMaster(pm, this); + } + } else { + throw new FOPException("fo:page-sequence-master must be child " + + "of fo:layout-master-set, not " + + parent.getName()); + } + } + + /** + * Adds a new suqsequence specifier to the page sequence master. + * @param pageMasterReference the subsequence to add + */ + protected void addSubsequenceSpecifier(SubSequenceSpecifier pageMasterReference) { + subSequenceSpecifiers.add(pageMasterReference); + } + + /** + * Returns the next subsequence specifier + * @return a subsequence specifier + */ + private SubSequenceSpecifier getNextSubSequence() { + currentSubSequenceNumber++; + if (currentSubSequenceNumber >= 0 + && currentSubSequenceNumber < subSequenceSpecifiers.size()) { + return (SubSequenceSpecifier)subSequenceSpecifiers + .get(currentSubSequenceNumber); + } + return null; + } + + /** + * Resets the subsequence specifiers subsystem. + */ + public void reset() { + currentSubSequenceNumber = -1; + currentSubSequence = null; + for (int i = 0; i < subSequenceSpecifiers.size(); i++) { + ((SubSequenceSpecifier)subSequenceSpecifiers.get(i)).reset(); + } + } + + /** + * Returns the next simple-page-master. + * @param isOddPage True if the next page number is odd + * @param isFirstPage True if the next page is the first + * @param isBlankPage True if the next page is blank + * @return the requested page master + * @throws FOPException if there's a problem determining the next page master + */ + public SimplePageMaster getNextSimplePageMaster(boolean isOddPage, + boolean isFirstPage, + boolean isBlankPage) + throws FOPException { + if (currentSubSequence == null) { + currentSubSequence = getNextSubSequence(); + if (currentSubSequence == null) { + throw new FOPException("no subsequences in page-sequence-master '" + + masterName + "'"); + } + } + String pageMasterName = currentSubSequence + .getNextPageMasterName(isOddPage, isFirstPage, isBlankPage); + boolean canRecover = true; + while (pageMasterName == null) { + SubSequenceSpecifier nextSubSequence = getNextSubSequence(); + if (nextSubSequence == null) { + if (!canRecover) { + throw new FOPException("subsequences exhausted in page-sequence-master '" + + masterName + + "', cannot recover"); + } + getLogger().warn("subsequences exhausted in page-sequence-master '" + + masterName + + "', use previous subsequence"); + currentSubSequence.reset(); + canRecover = false; + } else { + currentSubSequence = nextSubSequence; + } + pageMasterName = currentSubSequence + .getNextPageMasterName(isOddPage, isFirstPage, isBlankPage); + } + SimplePageMaster pageMaster = this.layoutMasterSet + .getSimplePageMaster(pageMasterName); + if (pageMaster == null) { + throw new FOPException("No simple-page-master matching '" + + pageMasterName + "' in page-sequence-master '" + + masterName + "'"); + } + return pageMaster; + } + +} + diff --git a/src/java/org/apache/fop/fo/pagination/Region.java b/src/java/org/apache/fop/fo/pagination/Region.java new file mode 100644 index 000000000..682595a47 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/Region.java @@ -0,0 +1,289 @@ +/* + * $Id: Region.java,v 1.18 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; + +// FOP +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FONode; +import org.apache.fop.layout.BorderAndPadding; +import org.apache.fop.layout.BackgroundProps; +import org.apache.fop.apps.FOPException; +import org.apache.fop.area.CTM; +import org.apache.fop.area.RegionViewport; +import org.apache.fop.area.RegionReference; +import org.apache.fop.layoutmgr.TraitSetter; + +// SAX +import org.xml.sax.Attributes; + +/** + * This is an abstract base class for pagination regions + */ +public abstract class Region extends FObj { + + private static final String PROP_REGION_NAME = "region-name"; + + /** Key for before regions */ + public static final String BEFORE = "before"; + /** Key for start regions */ + public static final String START = "start"; + /** Key for end regions */ + public static final String END = "end"; + /** Key for after regions */ + public static final String AFTER = "after"; + /** Key for body regions */ + public static final String BODY = "body"; + + private SimplePageMaster layoutMaster; + private String regionName; + + /** Holds the overflow attribute */ + protected int overflow; + /** Holds the writing mode */ + protected int wm; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + protected Region(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + // regions may have name, or default + if (null == this.properties.get(PROP_REGION_NAME)) { + setRegionName(getDefaultRegionName()); + } else if (this.properties.get(PROP_REGION_NAME).getString().equals("")) { + setRegionName(getDefaultRegionName()); + } else { + setRegionName(this.properties.get(PROP_REGION_NAME).getString()); + // check that name is OK. Not very pretty. + if (isReserved(getRegionName()) + && !getRegionName().equals(getDefaultRegionName())) { + throw new FOPException(PROP_REGION_NAME + " '" + regionName + + "' for " + this.name + + " not permitted."); + } + } + + if (parent instanceof SimplePageMaster) { + layoutMaster = (SimplePageMaster)parent; + } else { + throw new FOPException(this.name + " must be child " + + "of simple-page-master, not " + + parent.getName()); + } + this.wm = this.properties.get("writing-mode").getEnum(); + } + + /** + * Creates a RegionViewport Area object for this pagination Region. + * @param reldims relative dimensions + * @param pageCTM page coordinate transformation matrix + * @return the new region viewport + */ + public RegionViewport makeRegionViewport(FODimension reldims, CTM pageCTM) { + Rectangle2D relRegionRect = getViewportRectangle(reldims); + Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); + // Get the region viewport rectangle in absolute coords by + // transforming it using the page CTM + RegionViewport rv = new RegionViewport(absRegionRect); + setRegionViewportTraits(rv); + return rv; + } + + /** + * Set the region viewport traits. + * The viewport has the border, background and + * clipping overflow traits. + * + * @param r the region viewport + */ + protected void setRegionViewportTraits(RegionViewport r) { + // Common Border, Padding, and Background Properties + BorderAndPadding bap = propMgr.getBorderAndPadding(); + BackgroundProps bProps = propMgr.getBackgroundProps(); + TraitSetter.addBorders(r, bap); + TraitSetter.addBackground(r, bProps); + + // this.properties.get("clip"); + // this.properties.get("display-align"); + this.overflow = this.properties.get("overflow").getEnum(); + } + + protected abstract Rectangle getViewportRectangle(FODimension pageRefRect); + + /** + * Create the region reference area for this region master. + * @param absRegVPRect The region viewport rectangle is "absolute" coordinates + * where x=distance from left, y=distance from bottom, width=right-left + * height=top-bottom + * @return a new region reference area + */ + public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) { + RegionReference r = new RegionReference(getRegionAreaClass()); + setRegionPosition(r, absRegVPRect); + return r; + } + + /** + * Set the region position inside the region viewport. + * This sets the trasnform that is used to place the contents of + * the region. + * + * @param r the region reference area + * @param absRegVPRect the rectangle to place the region contents + */ + protected void setRegionPosition(RegionReference r, Rectangle2D absRegVPRect) { + FODimension reldims = new FODimension(0, 0); + r.setCTM(propMgr.getCTMandRelDims(absRegVPRect, reldims)); + } + + /** + * Return the enumerated value designating this type of region in the + * Area tree. + * @return the region area class + */ + protected abstract int getRegionAreaClass(); + + /** + * Returns the default region name (xsl-region-before, xsl-region-start, + * etc.) + * @return the default region name + */ + protected abstract String getDefaultRegionName(); + + + /** + * Returns the region class name. + * @return the region class name + */ + public abstract String getRegionClass(); + + + /** + * Returns the name of this region. + * @return the region name + */ + public String getRegionName() { + return this.regionName; + } + + /** + * Sets the name of the region. + * @param name the name + */ + private void setRegionName(String name) { + this.regionName = name; + } + + /** + * Returns the page master associated with this region. + * @return a simple-page-master + */ + protected SimplePageMaster getPageMaster() { + return this.layoutMaster; + } + + /** + * Checks to see if a given region name is one of the reserved names + * + * @param name a region name to check + * @return true if the name parameter is a reserved region name + */ + protected boolean isReserved(String name) /*throws FOPException*/ { + return (name.equals("xsl-region-before") + || name.equals("xsl-region-start") + || name.equals("xsl-region-end") + || name.equals("xsl-region-after") + || name.equals("xsl-before-float-separator") + || name.equals("xsl-footnote-separator")); + } + + /** + * @see org.apache.fop.fo.FObj#generatesReferenceAreas() + */ + public boolean generatesReferenceAreas() { + return true; + } + + /** + * Returns a sibling region for this region. + * @param regionClass the class of the requested region + * @return the requested region + */ + protected Region getSiblingRegion(String regionClass) { + // Ask parent for region + return layoutMaster.getRegion(regionClass); + } + + /** + * Indicates if this region gets precedence. + * @return True if it gets precedence + */ + public boolean getPrecedence() { + return false; + } + + public int getExtent() { + return 0; + } +} diff --git a/src/java/org/apache/fop/fo/pagination/RegionAfter.java b/src/java/org/apache/fop/fo/pagination/RegionAfter.java new file mode 100644 index 000000000..55003c139 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionAfter.java @@ -0,0 +1,112 @@ +/* + * $Id: RegionAfter.java,v 1.17 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.area.RegionReference; + +/** + * The fo:region-after element. + */ +public class RegionAfter extends RegionBA { + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RegionAfter(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + */ + protected Rectangle getViewportRectangle (FODimension reldims) { + // Depends on extent, precedence ans writing mode + Rectangle vpRect; + if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB) { + vpRect = new Rectangle(0, reldims.bpd - getExtent(), reldims.ipd, getExtent()); + } else { + vpRect = new Rectangle(0, reldims.bpd - getExtent(), getExtent(), reldims.ipd); + } + if (getPrecedence() == false) { + adjustIPD(vpRect, this.wm); + } + return vpRect; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getDefaultRegionName() + */ + protected String getDefaultRegionName() { + return "xsl-region-after"; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionAreaClass() + */ + public int getRegionAreaClass() { + return RegionReference.AFTER; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionClass() + */ + public String getRegionClass() { + return Region.AFTER; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RegionBA.java b/src/java/org/apache/fop/fo/pagination/RegionBA.java new file mode 100644 index 000000000..6023be995 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionBA.java @@ -0,0 +1,120 @@ +/* + * $Id: RegionBA.java,v 1.6 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.properties.Precedence; +import org.apache.fop.fo.properties.WritingMode; + +/** + * Abstract base class for fo:region-before and fo:region-after. + */ +public abstract class RegionBA extends RegionBASE { + + private boolean bPrecedence; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + protected RegionBA(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getPrecedence() + */ + public boolean getPrecedence() { + return bPrecedence; + } + + /** + * @see org.apache.fop.fo.FONode#end() + */ + public void end() { + super.end(); + bPrecedence = + (this.properties.get("precedence").getEnum() == Precedence.TRUE); + } + + /** + * Adjust the viewport reference rectangle for a region as a function + * of precedence. + * If precedence is false on a before or after region, its + * inline-progression-dimension is limited by the extent of the start + * and end regions if they are present. + * @param vpRect viewport rectangle + * @param wm writing mode + */ + protected void adjustIPD(Rectangle vpRect, int wm) { + int offset = 0; + Region start = getSiblingRegion(Region.START); + if (start != null) { + offset = start.getExtent(); + vpRect.translate(offset, 0); + } + Region end = getSiblingRegion(Region.END); + if (end != null) { + offset += end.getExtent(); + } + if (offset > 0) { + if (wm == WritingMode.LR_TB || wm == WritingMode.RL_TB) { + vpRect.width -= offset; + } else { + vpRect.height -= offset; + } + } + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RegionBASE.java b/src/java/org/apache/fop/fo/pagination/RegionBASE.java new file mode 100644 index 000000000..550f55e9e --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionBASE.java @@ -0,0 +1,86 @@ +/* + * $Id: RegionBASE.java,v 1.5 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.fo.FONode; + +/** + * Base class for Before, After, Start and End regions (BASE). + */ +public abstract class RegionBASE extends Region { + + private int extent; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + protected RegionBASE(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#end() + */ + public void end() { + // The problem with this is that it might not be known yet.... + // Supposing extent is calculated in terms of percentage + this.extent = this.properties.get("extent").getLength().getValue(); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getExtent() + */ + public int getExtent() { + return this.extent; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RegionBefore.java b/src/java/org/apache/fop/fo/pagination/RegionBefore.java new file mode 100644 index 000000000..258cffb67 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionBefore.java @@ -0,0 +1,117 @@ +/* + * $Id: RegionBefore.java,v 1.18 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.fo.FONode; +import org.apache.fop.area.RegionReference; + +// Java +import java.awt.Rectangle; + +/** + * The fo:region-before element. + */ +public class RegionBefore extends RegionBA { + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RegionBefore(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getDefaultRegionName() + */ + protected String getDefaultRegionName() { + return "xsl-region-before"; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionClass() + */ + public String getRegionClass() { + return Region.BEFORE; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionAreaClass() + */ + public int getRegionAreaClass() { + return RegionReference.BEFORE; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + */ + protected Rectangle getViewportRectangle (FODimension reldims) { + // Depends on extent, precedence and writing mode + // This should return rectangle in writing-mode coordinates relative + // to the page-reference area rectangle + // This means the origin is (start, before) and the dimensions are (ipd,bpd) + // Before is always 0, start depends on extent + // ipd depends on precedence, bpd=extent + Rectangle vpRect; + if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB) { + vpRect = new Rectangle(0, 0, reldims.ipd, getExtent()); + } else { + vpRect = new Rectangle(0, 0, getExtent(), reldims.ipd); + } + if (getPrecedence() == false) { + adjustIPD(vpRect, this.wm); + } + return vpRect; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RegionBody.java b/src/java/org/apache/fop/fo/pagination/RegionBody.java new file mode 100644 index 000000000..e7b278c30 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionBody.java @@ -0,0 +1,173 @@ +/* + * $Id: RegionBody.java,v 1.23 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.Property; +import org.apache.fop.fo.properties.Overflow; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.area.RegionReference; +import org.apache.fop.area.BodyRegion; +import org.apache.fop.layout.MarginProps; + +/** + * The fo:region-body element. + */ +public class RegionBody extends Region { + + private ColorType backgroundColor; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RegionBody(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + */ + protected Rectangle getViewportRectangle (FODimension reldims) { + /* + * Use space-before and space-after which will use corresponding + * absolute margin properties if specified. For indents: + * try to get corresponding absolute margin property using the + * writing-mode on the page (not on the region-body!). If that's not + * set but indent is explicitly set, it will return that. + */ + MarginProps mProps = propMgr.getMarginProps(); + int start = getRelMargin(PropertyList.START, "start-indent"); + Rectangle vpRect; + if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB) { + vpRect = new Rectangle(start, mProps.spaceBefore, + reldims.ipd - start + - getRelMargin(PropertyList.END, "end-indent"), + reldims.bpd - mProps.spaceBefore - mProps.spaceAfter); + } else { + vpRect = new Rectangle(start, mProps.spaceBefore, + reldims.bpd - mProps.spaceBefore - mProps.spaceAfter, + reldims.ipd - start + - getRelMargin(PropertyList.END, "end-indent")); + } + return vpRect; + } + + /** + * Get the relative margin using parent's writing mode, not own + * writing mode. + */ + private int getRelMargin(int reldir, String sRelPropName) { + FObj parent = (FObj) getParent(); + String sPropName = "margin-" + + parent.properties.wmRelToAbs(reldir); + Property prop = properties.getExplicitBaseProp(sPropName); + if (prop == null) { + prop = properties.getExplicitBaseProp(sRelPropName); + } + return ((prop != null) ? prop.getLength().getValue() : 0); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getDefaultRegionName() + */ + protected String getDefaultRegionName() { + return "xsl-region-body"; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionClass() + */ + public String getRegionClass() { + return Region.BODY; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionAreaClass() + */ + public int getRegionAreaClass() { + return RegionReference.BODY; + } + + /** + * Override the inherited method. + * @see org.apache.fop.fo.pagination.Region#makeRegionReferenceArea(Rectangle2D) + */ + public RegionReference makeRegionReferenceArea(Rectangle2D absRegVPRect) { + // Should set some column stuff here I think, or put it elsewhere + BodyRegion body = new BodyRegion(); + setRegionPosition(body, absRegVPRect); + int columnCount = + this.properties.get("column-count").getNumber().intValue(); + if ((columnCount > 1) && (overflow == Overflow.SCROLL)) { + // recover by setting 'column-count' to 1. This is allowed but + // not required by the spec. + getLogger().error("Setting 'column-count' to 1 because " + + "'overflow' is set to 'scroll'"); + columnCount = 1; + } + body.setColumnCount(columnCount); + + int columnGap = + this.properties.get("column-gap").getLength().getValue(); + body.setColumnGap(columnGap); + return body; + } + +} diff --git a/src/java/org/apache/fop/fo/pagination/RegionEnd.java b/src/java/org/apache/fop/fo/pagination/RegionEnd.java new file mode 100644 index 000000000..d7039e59c --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionEnd.java @@ -0,0 +1,113 @@ +/* + * $Id: RegionEnd.java,v 1.11 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.area.RegionReference; + +/** + * The fo:region-end element. + */ +public class RegionEnd extends RegionSE { + + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RegionEnd(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + */ + protected Rectangle getViewportRectangle (FODimension reldims) { + // Depends on extent, precedence and writing mode + Rectangle vpRect; + if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB) { + vpRect = new Rectangle(reldims.ipd - getExtent(), 0, + getExtent(), reldims.bpd); + } else { + vpRect = new Rectangle(reldims.ipd - getExtent(), 0, + reldims.bpd, getExtent()); + } + adjustIPD(vpRect, this.wm); + return vpRect; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getDefaultRegionName() + */ + protected String getDefaultRegionName() { + return "xsl-region-end"; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionClass() + */ + public String getRegionClass() { + return Region.END; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionAreaClass() + */ + public int getRegionAreaClass() { + return RegionReference.END; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RegionSE.java b/src/java/org/apache/fop/fo/pagination/RegionSE.java new file mode 100644 index 000000000..b137a5d86 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionSE.java @@ -0,0 +1,102 @@ +/* + * $Id: RegionSE.java,v 1.5 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.properties.WritingMode; + +/** + * Abstract base class for fo:region-start and fo:region-end. + */ +public abstract class RegionSE extends RegionBASE { + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + protected RegionSE(FONode parent) { + super(parent); + } + + /** + * Adjust the viewport reference rectangle for a region as a function + * of precedence. + * If before and after have precedence = true, the start and end + * regions only go to the limits of their extents, otherwise + * they extend in the BPD to the page reference rectangle + * diminish by extend of start and end if present. + * @param refRect reference rectangle + * @param wm writing mode + */ + protected void adjustIPD(Rectangle refRect, int wm) { + int offset = 0; + Region before = getSiblingRegion(Region.BEFORE); + if (before != null && before.getPrecedence()) { + offset = before.getExtent(); + refRect.translate(0, offset); + } + Region after = getSiblingRegion(Region.AFTER); + if (after != null && after.getPrecedence()) { + offset += after.getExtent(); + } + if (offset > 0) { + if (wm == WritingMode.LR_TB || wm == WritingMode.RL_TB) { + refRect.height -= offset; + } else { + refRect.width -= offset; + } + } + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RegionStart.java b/src/java/org/apache/fop/fo/pagination/RegionStart.java new file mode 100644 index 000000000..665e522c8 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RegionStart.java @@ -0,0 +1,112 @@ +/* + * $Id: RegionStart.java,v 1.12 2003/03/11 04:08:17 vmote Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.properties.WritingMode; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.area.RegionReference; + +/** + * The fo:region-start element. + */ +public class RegionStart extends RegionSE { + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RegionStart(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + */ + protected Rectangle getViewportRectangle (FODimension reldims) { + // Depends on extent, precedence and writing mode + // This is the rectangle relative to the page-reference area in + // writing-mode relative coordinates + Rectangle vpRect; + if (this.wm == WritingMode.LR_TB || this.wm == WritingMode.RL_TB) { + vpRect = new Rectangle(0, 0, getExtent(), reldims.bpd); + } else { + vpRect = new Rectangle(0, 0, reldims.bpd, getExtent()); + } + adjustIPD(vpRect, this.wm); + return vpRect; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getDefaultRegionName() + */ + protected String getDefaultRegionName() { + return "xsl-region-start"; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionClass() + */ + public String getRegionClass() { + return Region.START; + } + + /** + * @see org.apache.fop.fo.pagination.Region#getRegionAreaClass() + */ + public int getRegionAreaClass() { + return RegionReference.START; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java new file mode 100644 index 000000000..e976590b5 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java @@ -0,0 +1,168 @@ +/* + * $Id: RepeatablePageMasterAlternatives.java,v 1.12 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.util.ArrayList; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.apps.FOPException; + +/** + * A repeatable-page-master-alternatives formatting object. + * This contains a list of conditional-page-master-reference + * and the page master is found from the reference that + * matches the page number and emptyness. + */ +public class RepeatablePageMasterAlternatives extends FObj + implements SubSequenceSpecifier { + + private static final int INFINITE = -1; + + /** + * Max times this page master can be repeated. + * INFINITE is used for the unbounded case + */ + private int maximumRepeats; + private int numberConsumed = 0; + + private ArrayList conditionalPageMasterRefs; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RepeatablePageMasterAlternatives(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + conditionalPageMasterRefs = new ArrayList(); + + if (parent.getName().equals("fo:page-sequence-master")) { + PageSequenceMaster pageSequenceMaster = (PageSequenceMaster)parent; + pageSequenceMaster.addSubsequenceSpecifier(this); + } else { + throw new FOPException("fo:repeatable-page-master-alternatives " + + "must be child of fo:page-sequence-master, not " + + parent.getName()); + } + + String mr = getProperty("maximum-repeats").getString(); + if (mr.equals("no-limit")) { + this.maximumRepeats = INFINITE; + } else { + try { + this.maximumRepeats = Integer.parseInt(mr); + if (this.maximumRepeats < 0) { + getLogger().debug("negative maximum-repeats: " + + this.maximumRepeats); + this.maximumRepeats = 0; + } + } catch (NumberFormatException nfe) { + throw new FOPException("Invalid number for " + + "'maximum-repeats' property"); + } + } + } + + /** + * Get the next matching page master from the conditional + * page master references. + * @see org.apache.fop.fo.pagination.SubSequenceSpecifier + */ + public String getNextPageMasterName(boolean isOddPage, + boolean isFirstPage, + boolean isBlankPage) { + if (maximumRepeats != INFINITE) { + if (numberConsumed < maximumRepeats) { + numberConsumed++; + } else { + return null; + } + } + + for (int i = 0; i < conditionalPageMasterRefs.size(); i++) { + ConditionalPageMasterReference cpmr = + (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i); + if (cpmr.isValid(isOddPage, isFirstPage, isBlankPage)) { + return cpmr.getMasterName(); + } + } + return null; + } + + + /** + * Adds a new conditional page master reference. + * @param cpmr the new conditional reference + */ + public void addConditionalPageMasterReference(ConditionalPageMasterReference cpmr) { + this.conditionalPageMasterRefs.add(cpmr); + } + + /** + * @see org.apache.fop.fo.pagination.SubSequenceSpecifier#reset() + */ + public void reset() { + this.numberConsumed = 0; + } + +} diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java new file mode 100644 index 000000000..3dcc76728 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -0,0 +1,129 @@ +/* + * $Id: RepeatablePageMasterReference.java,v 1.8 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.fo.FONode; +import org.apache.fop.apps.FOPException; + +/** + * A repeatable-page-master-reference formatting object. + * This handles a reference with a specified number of repeating + * instances of the referenced page master (may have no limit). + */ +public class RepeatablePageMasterReference extends PageMasterReference + implements SubSequenceSpecifier { + + private static final int INFINITE = -1; + + private PageSequenceMaster pageSequenceMaster; + + private int maximumRepeats; + private int numberConsumed = 0; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public RepeatablePageMasterReference(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + String mr = getProperty("maximum-repeats").getString(); + if (mr.equals("no-limit")) { + this.maximumRepeats = INFINITE; + } else { + try { + this.maximumRepeats = Integer.parseInt(mr); + if (this.maximumRepeats < 0) { + getLogger().debug("negative maximum-repeats: " + + this.maximumRepeats); + this.maximumRepeats = 0; + } + } catch (NumberFormatException nfe) { + throw new FOPException("Invalid number for " + + "'maximum-repeats' property"); + } + } + } + + /** + * @see org.apache.fop.fo.pagination.SubSequenceSpecifier + */ + public String getNextPageMasterName(boolean isOddPage, + boolean isFirstPage, + boolean isEmptyPage) { + if (maximumRepeats != INFINITE) { + if (numberConsumed < maximumRepeats) { + numberConsumed++; + } else { + return null; + } + } + return getMasterName(); + } + + /** + * @see org.apache.fop.fo.pagination.SubSequenceSpecifier#reset() + */ + public void reset() { + this.numberConsumed = 0; + } + +} diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java new file mode 100644 index 000000000..e5f2a79be --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -0,0 +1,141 @@ +/* + * $Id: Root.java,v 1.24 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FONode; + +// Java +import java.util.List; + +/** + * The fo:root formatting object. Contains page masters, page-sequences. + */ +public class Root extends FObj { + private LayoutMasterSet layoutMasterSet; + private List pageSequences; + + /** + * Keeps count of page number from over PageSequence instances + */ + private int runningPageNumberCounter = 0; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public Root(FONode parent) { + super(parent); + // this.properties.get("media-usage"); + pageSequences = new java.util.ArrayList(); + if (parent != null) { + //throw new FOPException("root must be root element"); + } + } + + /** + * Returns the number of pages generated (over all PageSequence instances). + * @return the number of pages + */ + protected int getRunningPageNumberCounter() { + return this.runningPageNumberCounter; + } + + /** + * Sets the overall page number counter. + * @param count the new page count + */ + protected void setRunningPageNumberCounter(int count) { + this.runningPageNumberCounter = count; + } + + /** + * Returns the number of PageSequence instances. + * @return the number of PageSequence instances + */ + public int getPageSequenceCount() { + return pageSequences.size(); + } + + /** + * Some properties, such as 'force-page-count', require a + * page-sequence to know about some properties of the next. + * @param current the current PageSequence + * @return succeeding PageSequence; null if none + */ + public PageSequence getSucceedingPageSequence(PageSequence current) { + int currentIndex = pageSequences.indexOf(current); + if (currentIndex == -1) { + return null; + } + if (currentIndex < (pageSequences.size() - 1)) { + return (PageSequence)pageSequences.get(currentIndex + 1); + } else { + return null; + } + } + + /** + * Returns the associated LayoutMasterSet. + * @return the LayoutMasterSet instance + */ + public LayoutMasterSet getLayoutMasterSet() { + return this.layoutMasterSet; + } + + /** + * Sets the associated LayoutMasterSet. + * @param layoutMasterSet the LayoutMasterSet to use + */ + public void setLayoutMasterSet(LayoutMasterSet layoutMasterSet) { + this.layoutMasterSet = layoutMasterSet; + } +} diff --git a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java new file mode 100644 index 000000000..3353fe1f8 --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -0,0 +1,273 @@ +/* + * $Id: SimplePageMaster.java,v 1.30 2003/03/06 13:42:41 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +// Java +import java.awt.Rectangle; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +// XML +import org.xml.sax.Attributes; + +// FOP +import org.apache.fop.area.CTM; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.area.PageViewport; +import org.apache.fop.area.Page; +import org.apache.fop.area.RegionViewport; +import org.apache.fop.area.RegionReference; +import org.apache.fop.layout.MarginProps; +import org.apache.fop.layout.PageMaster; +import org.apache.fop.apps.FOPException; + +/** + * A simple-page-master formatting object. + * This creates a simple page from the specified regions + * and attributes. + */ +public class SimplePageMaster extends FObj { + /** + * Page regions (regionClass, Region) + */ + private Map regions; + + private PageMaster pageMaster; + private String masterName; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public SimplePageMaster(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FONode#handleAttrs(Attributes) + */ + public void handleAttrs(Attributes attlist) throws FOPException { + super.handleAttrs(attlist); + + if (parent.getName().equals("fo:layout-master-set")) { + LayoutMasterSet layoutMasterSet = (LayoutMasterSet)parent; + masterName = this.properties.get("master-name").getString(); + if (masterName == null) { + getLogger().warn("simple-page-master does not have " + + "a master-name and so is being ignored"); + } else { + layoutMasterSet.addSimplePageMaster(this); + } + } else { + throw new FOPException("fo:simple-page-master must be child " + + "of fo:layout-master-set, not " + + parent.getName()); + } + //Well, there are only 5 regions so we can save a bit of memory here + regions = new HashMap(5); + } + + /** + * At the end of this element read all the information and create + * the page master. + */ + protected void end() { + int pageWidth = + this.properties.get("page-width").getLength().getValue(); + int pageHeight = + this.properties.get("page-height").getLength().getValue(); + // this.properties.get("reference-orientation"); + // this.properties.get("writing-mode"); + + // Get absolute margin properties (top, left, bottom, right) + MarginProps mProps = propMgr.getMarginProps(); + + /* Create the page reference area rectangle (0,0 is at top left + * of the "page media" and y increases + * when moving towards the bottom of the page. + * The media rectangle itself is (0,0,pageWidth,pageHeight). + */ + Rectangle pageRefRect = + new Rectangle(mProps.marginLeft, mProps.marginTop, + pageWidth - mProps.marginLeft - mProps.marginRight, + pageHeight - mProps.marginTop - mProps.marginBottom); + + // ??? KL shouldn't this take the viewport too??? + Page page = new Page(); // page reference area + + // Set up the CTM on the page reference area based on writing-mode + // and reference-orientation + FODimension reldims = new FODimension(0, 0); + CTM pageCTM = propMgr.getCTMandRelDims(pageRefRect, reldims); + + // Create a RegionViewport/ reference area pair for each page region + + boolean bHasBody = false; + + for (Iterator regenum = regions.values().iterator(); + regenum.hasNext();) { + Region r = (Region)regenum.next(); + RegionViewport rvp = r.makeRegionViewport(reldims, pageCTM); + rvp.setRegion(r.makeRegionReferenceArea(rvp.getViewArea())); + page.setRegion(r.getRegionAreaClass(), rvp); + if (r.getRegionAreaClass() == RegionReference.BODY) { + bHasBody = true; + } + } + + if (!bHasBody) { + getLogger().error("simple-page-master has no region-body"); + } + + this.pageMaster = new PageMaster(new PageViewport(page, + new Rectangle(0, 0, pageWidth, pageHeight))); + + // regions = null; // PageSequence access SimplePageMaster.... + children = null; + properties = null; + } + + /** + * @see org.apache.fop.fo.FObj#generatesReferenceAreas() + */ + public boolean generatesReferenceAreas() { + return true; + } + + /** + * Returns the page master. + * @return the page master + */ + public PageMaster getPageMaster() { + return this.pageMaster; + } + + /** + * Returns the next page master. For simple-page-master this is always the + * same as the previous. + * @return the page master + */ + public PageMaster getNextPageMaster() { + return this.pageMaster; + } + + /** + * Returns the name of the simple-page-master. + * @return the page master name + */ + public String getMasterName() { + return masterName; + } + + /** + * @see org.apache.fop.fo.FONode#addChild(FONode) + */ + protected void addChild(FONode child) { + if (child instanceof Region) { + addRegion((Region)child); + } else { + getLogger().error("SimplePageMaster cannot have child of type " + + child.getName()); + } + } + + /** + * Adds a region to this simple-page-master. + * @param region region to add + */ + protected void addRegion(Region region) { + String key = region.getRegionClass(); + if (regions.containsKey(key)) { + getLogger().error("Only one region of class " + key + + " allowed within a simple-page-master. The duplicate" + + " region (" + region.getName() + ") is ignored."); + } else { + regions.put(key, region); + } + } + + /** + * Returns the region for a given region class. + * @param regionClass region class to lookup + * @return the region, null if it doesn't exist + */ + public Region getRegion(String regionClass) { + return (Region)regions.get(regionClass); + } + + /** + * Returns a Map of regions associated with this simple-page-master + * @return the regions + */ + protected Map getRegions() { + return regions; + } + + /** + * Indicates if a region with a given name exists in this + * simple-page-master. + * @param regionName name of the region to lookup + * @return True if a region with this name exists + */ + protected boolean regionNameExists(String regionName) { + for (Iterator regenum = regions.values().iterator(); + regenum.hasNext();) { + Region r = (Region)regenum.next(); + if (r.getRegionName().equals(regionName)) { + return true; + } + } + return false; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java new file mode 100644 index 000000000..2f10a102f --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -0,0 +1,97 @@ +/* + * $Id: SinglePageMasterReference.java,v 1.9 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +import org.apache.fop.fo.FONode; + +/** + * A single-page-master-reference formatting object. + * This is a reference for a single page. It returns the + * master name only once until reset. + */ +public class SinglePageMasterReference extends PageMasterReference + implements SubSequenceSpecifier { + + private static final int FIRST = 0; + private static final int DONE = 1; + + private int state; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public SinglePageMasterReference(FONode parent) { + super(parent); + this.state = FIRST; + } + + /** + * @see org.apache.fop.fo.pagination.SubSequenceSpecifier + */ + public String getNextPageMasterName(boolean isOddPage, + boolean isFirstPage, + boolean isEmptyPage) { + if (this.state == FIRST) { + this.state = DONE; + return getMasterName(); + } else { + return null; + } + } + + /** + * @see org.apache.fop.fo.pagination.SubSequenceSpecifier#reset() + */ + public void reset() { + this.state = FIRST; + } +} + diff --git a/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java b/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java new file mode 100644 index 000000000..98f2ef4dd --- /dev/null +++ b/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java @@ -0,0 +1,81 @@ +/* + * $Id: SubSequenceSpecifier.java,v 1.5 2003/03/06 13:42:42 jeremias Exp $ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber <jtauber@jtauber.com>. For more information on the Apache + * Software Foundation, please see <http://www.apache.org/>. + */ +package org.apache.fop.fo.pagination; + +import org.apache.fop.apps.FOPException; + +/** + * Classes that implement this interface can be added to a PageSequenceMaster, + * and are capable of looking up an appropriate PageMaster. + */ +public interface SubSequenceSpecifier { + + /** + * Returns the name of the next page master. + * @param isOddPage True if the next page number is odd + * @param isFirstPage True if the next page is the first + * @param isBlankPage True if the next page is blank + * @return the page master name + * @throws FOPException if there's a problem determining the next page master + */ + String getNextPageMasterName(boolean isOddPage, + boolean isFirstPage, + boolean isBlankPage) + throws FOPException; + + /** + * Called before a new page sequence is rendered so subsequences can reset + * any state they keep during the formatting process. + */ + void reset(); + +} + |