diff options
Diffstat (limited to 'src/java/org/apache/fop')
20 files changed, 519 insertions, 106 deletions
diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java index 2bf60edf3..c09105f40 100644 --- a/src/java/org/apache/fop/area/inline/InlineArea.java +++ b/src/java/org/apache/fop/area/inline/InlineArea.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.apache.fop.area.inline; import org.apache.fop.area.Area; +import org.apache.fop.area.Trait; /** * Inline Area @@ -65,5 +66,22 @@ public class InlineArea extends Area { public int getOffset() { return verticalPosition; } + + public boolean hasUnderline() { + return getBooleanTrait(Trait.UNDERLINE); + } + + public boolean hasOverline() { + return getBooleanTrait(Trait.OVERLINE); + } + + public boolean hasLineThrough() { + return getBooleanTrait(Trait.LINETHROUGH); + } + + public boolean isBlinking() { + return getBooleanTrait(Trait.BLINK); + } + } diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index fc2e326aa..f7ae53372 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -46,6 +46,7 @@ import org.apache.fop.fo.properties.PropertyMaker; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.fo.properties.SpacingPropertyMaker; import org.apache.fop.fo.properties.StringProperty; +import org.apache.fop.fo.properties.TextDecorationProperty; import org.apache.fop.fo.properties.ToBeImplementedProperty; /** @@ -1701,7 +1702,8 @@ public class FOPropertyMapping implements Constants { addPropertyMaker("suppress-at-line-break", m); // text-decoration - m = new EnumProperty.Maker(PR_TEXT_DECORATION); + //m = new EnumProperty.Maker(PR_TEXT_DECORATION); + m = new TextDecorationProperty.Maker(PR_TEXT_DECORATION); m.setInherited(false); m.addEnum("none", getEnumProperty(EN_NONE, "NONE")); m.addEnum("underline", getEnumProperty(EN_UNDERLINE, "UNDERLINE")); diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index 43ecc76df..793a7b8bd 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.pagination.Root; import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonHyphenation; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.layoutmgr.TextLayoutManager; @@ -110,6 +111,9 @@ public class FOText extends FONode { */ private Block ancestorBlock = null; + /** Holds the text decoration values. May be null */ + private CommonTextDecoration textDecoration; + private static final int IS_WORD_CHAR_FALSE = 0; private static final int IS_WORD_CHAR_TRUE = 1; private static final int IS_WORD_CHAR_MAYBE = 2; @@ -144,6 +148,7 @@ public class FOText extends FONode { textTransform = pList.get(Constants.PR_TEXT_TRANSFORM).getEnum(); wordSpacing = pList.get(Constants.PR_WORD_SPACING); wrapOption = pList.get(Constants.PR_WRAP_OPTION).getEnum(); + textDecoration = pList.getTextDecorationProps(); } protected void startOfNode() { @@ -520,51 +525,57 @@ public class FOText extends FONode { } /** - * Return the Common Font Properties. + * @return the Common Font Properties. */ public CommonFont getCommonFont() { return commonFont; } /** - * Return the Common Hyphenation Properties. + * @return the Common Hyphenation Properties. */ public CommonHyphenation getCommonHyphenation() { return commonHyphenation; } /** - * Return the "color" property. + * @return the "color" property. */ public ColorType getColor() { return color; } /** - * Return the "letter-spacing" property. + * @return the "letter-spacing" property. */ public Property getLetterSpacing() { return letterSpacing; } /** - * Return the "line-height" property. + * @return the "line-height" property. */ public SpaceProperty getLineHeight() { return lineHeight; } /** - * Return the "word-spacing" property. + * @return the "word-spacing" property. */ public Property getWordSpacing() { return wordSpacing; } /** - * Return the "wrap-option" property. + * @return the "wrap-option" property. */ public int getWrapOption() { return wrapOption; } -} + + /** @return the "text-decoration" property. */ + public CommonTextDecoration getTextDecoration() { + return textDecoration; + } + +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java index cd7a37b0d..0a0c50ae4 100644 --- a/src/java/org/apache/fop/fo/PropertyList.java +++ b/src/java/org/apache/fop/fo/PropertyList.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ import org.apache.fop.fo.properties.CommonHyphenation; import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.PropertyMaker; @@ -396,6 +397,7 @@ abstract public class PropertyList { /** * @param propId ID of property * @return new Property object + * @throws PropertyException if there's a problem while processing the property */ private Property getShorthand(int propId) throws PropertyException { PropertyMaker propertyMaker = findMaker(propId); @@ -411,7 +413,7 @@ abstract public class PropertyList { /** * @param propID ID of property * @return new Property object - * @throws FOPException for errors in the input + * @throws PropertyException if there's a problem while processing the property */ private Property makeProperty(int propId) throws PropertyException { PropertyMaker propertyMaker = findMaker(propId); @@ -457,16 +459,17 @@ abstract public class PropertyList { /** * Constructs a BorderAndPadding object. * @return a BorderAndPadding object + * @throws PropertyException if there's a problem while processing the properties */ - public CommonBorderPaddingBackground getBorderPaddingBackgroundProps() throws PropertyException { + public CommonBorderPaddingBackground getBorderPaddingBackgroundProps() + throws PropertyException { return new CommonBorderPaddingBackground(this, getFObj()); } - - /** * Constructs a HyphenationProps objects. * @return a HyphenationProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonHyphenation getHyphenationProps() throws PropertyException { return new CommonHyphenation(this); @@ -475,6 +478,7 @@ abstract public class PropertyList { /** * Constructs a MarginProps objects. * @return a MarginProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonMarginBlock getMarginBlockProps() throws PropertyException { return new CommonMarginBlock(this); @@ -483,6 +487,7 @@ abstract public class PropertyList { /** * Constructs a MarginInlineProps objects. * @return a MarginInlineProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonMarginInline getMarginInlineProps() throws PropertyException { return new CommonMarginInline(this); @@ -491,6 +496,7 @@ abstract public class PropertyList { /** * Constructs a AccessibilityProps objects. * @return a AccessibilityProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonAccessibility getAccessibilityProps() throws PropertyException { return new CommonAccessibility(this); @@ -499,6 +505,7 @@ abstract public class PropertyList { /** * Constructs a AuralProps objects. * @return a AuralProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonAural getAuralProps() throws PropertyException { CommonAural props = new CommonAural(this); @@ -508,6 +515,7 @@ abstract public class PropertyList { /** * Constructs a RelativePositionProps objects. * @return a RelativePositionProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonRelativePosition getRelativePositionProps() throws PropertyException { return new CommonRelativePosition(this); @@ -516,6 +524,7 @@ abstract public class PropertyList { /** * Constructs a AbsolutePositionProps objects. * @return a AbsolutePositionProps object + * @throws PropertyException if there's a problem while processing the properties */ public CommonAbsolutePosition getAbsolutePositionProps() throws PropertyException { return new CommonAbsolutePosition(this); @@ -525,9 +534,19 @@ abstract public class PropertyList { /** * Constructs a CommonFont object. * @return A CommonFont object + * @throws PropertyException if there's a problem while processing the properties */ public CommonFont getFontProps() throws PropertyException { return new CommonFont(this); } + + /** + * Constructs a CommonTextDecoration object. + * @return a CommonTextDecoration object + * @throws PropertyException if there's a problem while processing the properties + */ + public CommonTextDecoration getTextDecorationProps() throws PropertyException { + return CommonTextDecoration.createFromPropertyList(this); + } } diff --git a/src/java/org/apache/fop/fo/flow/Character.java b/src/java/org/apache/fop/fo/flow/Character.java index e4f67726a..04c289735 100644 --- a/src/java/org/apache/fop/fo/flow/Character.java +++ b/src/java/org/apache/fop/fo/flow/Character.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ package org.apache.fop.fo.flow; -// Java -import java.util.List; - import org.xml.sax.Locator; import org.apache.fop.apps.FOPException; @@ -38,9 +35,9 @@ import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonHyphenation; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.Property; -import org.apache.fop.layoutmgr.CharacterLayoutManager; /** * This class represents the flow object 'fo:character'. Its use is defined by @@ -81,7 +78,8 @@ public class Character extends FObj { private Length lineHeight; private int scoreSpaces; private int suppressAtLineBreak; - private int textDecoration; + /** Holds the text decoration values. May be null */ + private CommonTextDecoration textDecoration; // private ToBeImplementedProperty textShadow; private int textTransform; private int verticalAlign; @@ -130,7 +128,7 @@ public class Character extends FObj { lineHeight = pList.get(PR_LINE_HEIGHT).getLength(); scoreSpaces = pList.get(PR_SCORE_SPACES).getEnum(); suppressAtLineBreak = pList.get(PR_SUPPRESS_AT_LINE_BREAK).getEnum(); - textDecoration = pList.get(PR_TEXT_DECORATION).getEnum(); + textDecoration = pList.getTextDecorationProps(); // textShadow = pList.get(PR_TEXT_SHADOW); textTransform = pList.get(PR_TEXT_TRANSFORM).getEnum(); verticalAlign = pList.get(PR_VERTICAL_ALIGN).getEnum(); @@ -164,70 +162,68 @@ public class Character extends FObj { } /** - * Return the Common Border, Padding, and Background Properties. + * @return the Common Border, Padding, and Background Properties. */ public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { return commonBorderPaddingBackground; } /** - * Return the Common Font Properties. + * @return the Common Font Properties. */ public CommonFont getCommonFont() { return commonFont; } /** - * Return the Common Hyphenation Properties. + * @return the Common Hyphenation Properties. */ public CommonHyphenation getCommonHyphenation() { return commonHyphenation; } /** - * Return the "character" property. + * @return the "character" property. */ public char getCharacter() { return character; } /** - * Return the "color" property. + * @return the "color" property. */ public ColorType getColor() { return color; } /** - * Return the "id" property. + * @return the "id" property. */ public String getId() { return id; } /** - * Return the "letter-spacing" property. + * @return the "letter-spacing" property. */ public Property getLetterSpacing() { return letterSpacing; } - /** - * Return the "text-decoration" property. - */ - public int getTextDecoration() { + /** @return the "text-decoration" property. */ + public CommonTextDecoration getTextDecoration() { return textDecoration; } - + /** - * Return the "word-spacing" property. + * @return the "word-spacing" property. */ public Property getWordSpacing() { return wordSpacing; } /** - * Return the "vertical-align" property. + * @return the "vertical-align" property. */ public int getVerticalAlign() { return verticalAlign; @@ -246,4 +242,5 @@ public class Character extends FObj { public int getNameId() { return FO_CHARACTER; } + } diff --git a/src/java/org/apache/fop/fo/flow/Inline.java b/src/java/org/apache/fop/fo/flow/Inline.java index 477e00e37..82d1db9fe 100644 --- a/src/java/org/apache/fop/fo/flow/Inline.java +++ b/src/java/org/apache/fop/fo/flow/Inline.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ package org.apache.fop.fo.flow; -import java.util.List; - import org.xml.sax.Locator; import org.apache.fop.apps.FOPException; @@ -30,9 +28,9 @@ import org.apache.fop.fo.InlineCharIterator; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; import org.apache.fop.fo.properties.CommonRelativePosition; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.LengthRangeProperty; -import org.apache.fop.layoutmgr.InlineLayoutManager; /** * Class modelling the fo:inline formatting object. @@ -52,7 +50,6 @@ public class Inline extends InlineLevel { private KeepProperty keepTogether; private KeepProperty keepWithNext; private KeepProperty keepWithPrevious; - private int textDecoration; private int verticalAlign; private Length width; private int wrapOption; @@ -86,7 +83,6 @@ public class Inline extends InlineLevel { keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep(); keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); - textDecoration = pList.get(PR_TEXT_DECORATION).getEnum(); verticalAlign = pList.get(PR_VERTICAL_ALIGN).getEnum(); width = pList.get(PR_WIDTH).getLength(); wrapOption = pList.get(PR_WRAP_OPTION).getEnum(); @@ -161,13 +157,6 @@ public class Inline extends InlineLevel { } /** - * Return the "text-decoration" property. - */ - public int getTextDecoration() { - return textDecoration; - } - - /** * Return the "vertical-align" property. */ public int getVerticalAlign() { diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index 3215113c2..2384a779b 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ package org.apache.fop.fo.flow; -// Java -import java.util.List; - import org.xml.sax.Locator; import org.apache.fop.apps.FOPException; @@ -35,9 +32,9 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.layoutmgr.PageNumberLayoutManager; /** * Class modelling the fo:page-number object. @@ -61,7 +58,8 @@ public class PageNumber extends FObj { private Length lineHeight; private int scoreSpaces; private Length textAltitude; - private int textDecoration; + /** Holds the text decoration values. May be null */ + private CommonTextDecoration textDecoration; private Length textDepth; // private ToBeImplementedProperty textShadow; private int textTransform; @@ -98,7 +96,7 @@ public class PageNumber extends FObj { lineHeight = pList.get(PR_LINE_HEIGHT).getLength(); scoreSpaces = pList.get(PR_SCORE_SPACES).getEnum(); textAltitude = pList.get(PR_TEXT_ALTITUDE).getLength(); - textDecoration = pList.get(PR_TEXT_DECORATION).getEnum(); + textDecoration = pList.getTextDecorationProps(); textDepth = pList.get(PR_TEXT_DEPTH).getLength(); // textShadow = pList.get(PR_TEXT_SHADOW); textTransform = pList.get(PR_TEXT_TRANSFORM).getEnum(); @@ -146,20 +144,13 @@ public class PageNumber extends FObj { } /** - * Return the "id" property. + * @return the "id" property. */ public String getId() { return id; } /** - * Return the "text-decoration" property. - */ - public int getTextDecoration() { - return textDecoration; - } - - /** * @see org.apache.fop.fo.FONode#getName() */ public String getName() { @@ -172,4 +163,10 @@ public class PageNumber extends FObj { public int getNameId() { return FO_PAGE_NUMBER; } + + /** @return the "text-decoration" property. */ + public CommonTextDecoration getTextDecoration() { + return textDecoration; + } + } diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java index e423045c1..178d5fdee 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ package org.apache.fop.fo.flow; -// Java -import java.util.List; - import org.xml.sax.Locator; import org.apache.fop.apps.FOPException; @@ -35,9 +32,9 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.CommonRelativePosition; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.layoutmgr.PageNumberCitationLayoutManager; /** * Class modelling the fo:page-number-citation object. @@ -65,7 +62,8 @@ public class PageNumberCitation extends FObj { private String refId; private int scoreSpaces; private Length textAltitude; - private int textDecoration; + /** Holds the text decoration values. May be null */ + private CommonTextDecoration textDecoration; private Length textDepth; // private ToBeImplementedProperty textShadow; private int textTransform; @@ -103,7 +101,7 @@ public class PageNumberCitation extends FObj { refId = pList.get(PR_REF_ID).getString(); scoreSpaces = pList.get(PR_SCORE_SPACES).getEnum(); textAltitude = pList.get(PR_TEXT_ALTITUDE).getLength(); - textDecoration = pList.get(PR_TEXT_DECORATION).getEnum(); + textDecoration = pList.getTextDecorationProps(); textDepth = pList.get(PR_TEXT_DEPTH).getLength(); // textShadow = pList.get(PR_TEXT_SHADOW); textTransform = pList.get(PR_TEXT_TRANSFORM).getEnum(); @@ -138,6 +136,11 @@ public class PageNumberCitation extends FObj { return commonFont; } + /** @return the "text-decoration" property. */ + public CommonTextDecoration getTextDecoration() { + return textDecoration; + } + /** * Return the "id" property. */ diff --git a/src/java/org/apache/fop/fo/properties/CommonTextDecoration.java b/src/java/org/apache/fop/fo/properties/CommonTextDecoration.java new file mode 100644 index 000000000..49df7b24c --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/CommonTextDecoration.java @@ -0,0 +1,142 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.properties; + +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.datatypes.ColorType; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.PropertyException; + +/** + * Stores all information concerning text-decoration. + */ +public class CommonTextDecoration { + + //using a bit-mask here + private static final int UNDERLINE = 1; + private static final int OVERLINE = 2; + private static final int LINE_THROUGH = 4; + private static final int BLINK = 8; + + private int decoration; + private ColorType underColor; + private ColorType overColor; + private ColorType throughColor; + + /** + * Creates a new CommonTextDecoration object with default values. + */ + public CommonTextDecoration() { + } + + /** + * Creates a CommonTextDecoration object from a property list. + * @param pList the property list to build the object for + * @return a CommonTextDecoration object or null if the obj would only have default values + * @throws PropertyException if there's a problem while processing the property + */ + public static CommonTextDecoration createFromPropertyList(PropertyList pList) + throws PropertyException { + return calcTextDecoration(pList); + } + + private static CommonTextDecoration calcTextDecoration(PropertyList pList) + throws PropertyException { + CommonTextDecoration deco = null; + PropertyList parentList = pList.getParentPropertyList(); + if (parentList != null) { + //Parent is checked first + deco = calcTextDecoration(parentList); + } + List list = pList.get(Constants.PR_TEXT_DECORATION).getList(); + Iterator i = list.iterator(); + while (i.hasNext()) { + Property prop = (Property)i.next(); + int enum = prop.getEnum(); + if (enum == Constants.EN_NONE) { + if (deco != null) { + deco.decoration = 0; + } + return deco; + } else if (enum == Constants.EN_UNDERLINE) { + if (deco == null) { + deco = new CommonTextDecoration(); + } + deco.decoration |= UNDERLINE; + } else if (enum == Constants.EN_NO_UNDERLINE) { + if (deco != null) { + deco.decoration &= OVERLINE | LINE_THROUGH | BLINK; + } + } else if (enum == Constants.EN_OVERLINE) { + if (deco == null) { + deco = new CommonTextDecoration(); + } + deco.decoration |= OVERLINE; + } else if (enum == Constants.EN_NO_OVERLINE) { + if (deco != null) { + deco.decoration &= UNDERLINE | LINE_THROUGH | BLINK; + } + } else if (enum == Constants.EN_LINE_THROUGH) { + if (deco == null) { + deco = new CommonTextDecoration(); + } + deco.decoration |= LINE_THROUGH; + } else if (enum == Constants.EN_NO_LINE_THROUGH) { + if (deco != null) { + deco.decoration &= UNDERLINE | OVERLINE | BLINK; + } + } else if (enum == Constants.EN_BLINK) { + if (deco == null) { + deco = new CommonTextDecoration(); + } + deco.decoration |= BLINK; + } else if (enum == Constants.EN_NO_BLINK) { + if (deco != null) { + deco.decoration &= UNDERLINE | OVERLINE | LINE_THROUGH; + } + } else { + throw new PropertyException("Illegal value encountered: " + prop.getString()); + } + } + return deco; + } + + /** @return true if underline is active */ + public boolean hasUnderline() { + return (this.decoration & UNDERLINE) != 0; + } + + /** @return true if overline is active */ + public boolean hasOverline() { + return (this.decoration & OVERLINE) != 0; + } + + /** @return true if line-through is active */ + public boolean hasLineThrough() { + return (this.decoration & LINE_THROUGH) != 0; + } + + /** @return true if blink is active */ + public boolean isBlinking() { + return (this.decoration & BLINK) != 0; + } +} diff --git a/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java b/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java index 47146e257..cc4546791 100644 --- a/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java +++ b/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.apache.fop.fo.properties; -import java.util.Enumeration; +import java.util.Iterator; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; @@ -37,7 +37,7 @@ public class GenericShorthandParser implements ShorthandParser { */ protected Property getElement(Property list, int index) { if (list.getList().size() > index) { - return (Property) list.getList().elementAt(index); + return (Property) list.getList().get(index); } else { return null; } @@ -49,9 +49,7 @@ public class GenericShorthandParser implements ShorthandParser { Property property, PropertyMaker maker, PropertyList propertyList) - throws PropertyException - { - Property prop = null; + throws PropertyException { // Check for keyword "inherit" if (property.getList().size() == 1) { String sval = getElement(property, 0).getString(); @@ -75,13 +73,12 @@ public class GenericShorthandParser implements ShorthandParser { Property property, PropertyMaker maker, PropertyList propertyList) - throws PropertyException - { + throws PropertyException { Property prop = null; // Try each of the stored values in turn - Enumeration eprop = property.getList().elements(); - while (eprop.hasMoreElements() && prop == null) { - Property p = (Property) eprop.nextElement(); + Iterator iprop = property.getList().iterator(); + while (iprop.hasNext() && prop == null) { + Property p = (Property)iprop.next(); prop = maker.convertShorthandProperty(propertyList, p, null); } return prop; diff --git a/src/java/org/apache/fop/fo/properties/ListProperty.java b/src/java/org/apache/fop/fo/properties/ListProperty.java index 50bc0a270..d400544e6 100644 --- a/src/java/org/apache/fop/fo/properties/ListProperty.java +++ b/src/java/org/apache/fop/fo/properties/ListProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.apache.fop.fo.properties; -import java.util.Vector; +import java.util.List; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; @@ -34,7 +34,7 @@ public class ListProperty extends Property { public static class Maker extends PropertyMaker { /** - * @param name name of property for which Maker should be created + * @param propId ID of the property for which Maker should be created */ public Maker(int propId) { super(propId); @@ -55,14 +55,21 @@ public class ListProperty extends Property { } /** Vector containing the list of sub-properties */ - protected Vector list; + protected List list = new java.util.Vector(); /** + * Simple constructor used by subclasses to do some special processing. + */ + protected ListProperty() { + //nop + } + + /** * @param prop the first Property to be added to the list */ public ListProperty(Property prop) { - list = new Vector(); - list.addElement(prop); + this(); + addProperty(prop); } /** @@ -70,13 +77,13 @@ public class ListProperty extends Property { * @param prop Property to be added to the list */ public void addProperty(Property prop) { - list.addElement(prop); + list.add(prop); } /** * @return this.list */ - public Vector getList() { + public List getList() { return list; } diff --git a/src/java/org/apache/fop/fo/properties/Property.java b/src/java/org/apache/fop/fo/properties/Property.java index b1c010f96..555b9ea3c 100644 --- a/src/java/org/apache/fop/fo/properties/Property.java +++ b/src/java/org/apache/fop/fo/properties/Property.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.apache.fop.fo.properties; -import java.util.Vector; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -31,6 +31,8 @@ import org.apache.fop.datatypes.Numeric; * @author unascribed */ public class Property { + + /** Logger for all property classes */ protected static Log log = LogFactory.getLog(PropertyMaker.class); /** @@ -136,7 +138,7 @@ public class Property { * This method expects to be overridden by subclasses * @return collection of other property (sub-property) objects */ - public Vector getList() { + public List getList() { return null; } @@ -180,10 +182,7 @@ public class Property { return null; } - /** - * Return a string representation of the property value. Only used - * for debugging. - */ + /** @see java.lang.Object#toString() */ public String toString() { Object obj = getObject(); if (obj != this) { diff --git a/src/java/org/apache/fop/fo/properties/TextDecorationProperty.java b/src/java/org/apache/fop/fo/properties/TextDecorationProperty.java new file mode 100644 index 000000000..ef5c08500 --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/TextDecorationProperty.java @@ -0,0 +1,159 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.fop.fo.properties; + +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.NCnameProperty; +import org.apache.fop.fo.expr.PropertyException; + +/** + * Special list property for text-decoration. + */ +public class TextDecorationProperty extends ListProperty { + + /** + * Inner class for creating instances of ListProperty + */ + public static class Maker extends PropertyMaker { + + /** + * @param propId ID of the property for which Maker should be created + */ + public Maker(int propId) { + super(propId); + } + + /** + * @see PropertyMaker#convertProperty + */ + public Property convertProperty(Property p, + PropertyList propertyList, FObj fo) + throws PropertyException { + if (p instanceof TextDecorationProperty) { + return p; + } else { + if (p instanceof ListProperty) { + ListProperty lst = (ListProperty)p; + lst = checkEnums(lst); + return new TextDecorationProperty((ListProperty)p); + } else if (p instanceof EnumProperty) { + ListProperty lst = new ListProperty(p); + return new TextDecorationProperty(lst); + } else { + throw new PropertyException("Cannot convert anything other " + + "than a list property, got a " + p.getClass().getName()); + } + } + } + + private ListProperty checkEnums(ListProperty lst) throws PropertyException { + List l = lst.getList(); + for (int i = 0; i < l.size(); i++) { + Property prop = (Property)l.get(i); + if (prop instanceof EnumProperty) { + //skip + } else if (prop instanceof NCnameProperty) { + Property enum = checkEnumValues(((NCnameProperty)prop).getString()); + if (enum == null) { + throw new PropertyException("Illegal enum value: " + prop.getString()); + } + l.set(i, enum); + } else { + throw new PropertyException("Invalid content for text-decoration " + + "property: " + prop); + } + } + return lst; + } + + } + + /** + * Constructs a new instance by converting a ListProperty. + * @param listProp the ListProperty to be converted + * @throws PropertyException in case the conversion fails + */ + public TextDecorationProperty(ListProperty listProp) throws PropertyException { + List lst = listProp.getList(); + boolean none = false; + boolean under = false; + boolean over = false; + boolean through = false; + boolean blink = false; + Iterator i = lst.iterator(); + while (i.hasNext()) { + Property prop = (Property)i.next(); + switch (prop.getEnum()) { + case Constants.EN_NONE: + if (under | over | through | blink) { + throw new PropertyException( + "Invalid combination of values"); + } + none = true; + break; + case Constants.EN_UNDERLINE: + case Constants.EN_NO_UNDERLINE: + if (none) { + throw new PropertyException("'none' specified, no additional values allowed"); + } + if (under) { + throw new PropertyException("Invalid combination of values"); + } + under = true; + break; + case Constants.EN_OVERLINE: + case Constants.EN_NO_OVERLINE: + if (none) { + throw new PropertyException("'none' specified, no additional values allowed"); + } + if (over) { + throw new PropertyException("Invalid combination of values"); + } + over = true; + break; + case Constants.EN_LINE_THROUGH: + case Constants.EN_NO_LINE_THROUGH: + if (none) { + throw new PropertyException("'none' specified, no additional values allowed"); + } + if (through) { + throw new PropertyException("Invalid combination of values"); + } + through = true; + break; + case Constants.EN_BLINK: + case Constants.EN_NO_BLINK: + if (none) { + throw new PropertyException("'none' specified, no additional values allowed"); + } + if (blink) { + throw new PropertyException("Invalid combination of values"); + } + blink = true; + break; + default: + throw new PropertyException("Invalid value specified: " + prop); + } + addProperty(prop); + } + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/CharacterLayoutManager.java b/src/java/org/apache/fop/layoutmgr/CharacterLayoutManager.java index fa72864bd..3a067d524 100644 --- a/src/java/org/apache/fop/layoutmgr/CharacterLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/CharacterLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,6 +59,7 @@ public class CharacterLayoutManager extends LeafNodeLayoutManager { private InlineArea getCharacterInlineArea(Character node) { org.apache.fop.area.inline.Character ch = new org.apache.fop.area.inline.Character(node.getCharacter()); + TraitSetter.addTextDecoration(ch, fobj.getTextDecoration()); return ch; } diff --git a/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java index b5f5d46b6..223151d9d 100644 --- a/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,6 +100,8 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { inline.addTrait(Trait.FONT_NAME, font.getFontName()); inline.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize())); } + TraitSetter.addTextDecoration(inline, fobj.getTextDecoration()); + return inline; } diff --git a/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java index 4beebb169..e2b8d6935 100644 --- a/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,6 +59,8 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager { inline.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize())); + TraitSetter.addTextDecoration(inline, fobj.getTextDecoration()); + return inline; } diff --git a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java index 09a6c6c94..bc78e15db 100644 --- a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -619,6 +619,7 @@ public class TextLayoutManager extends AbstractLayoutManager t.setTextLetterSpaceAdjust(iLetterSpaceDim); t.setTextWordSpaceAdjust(iWordSpaceDim - spaceCharIPD - 2 * t.getTextLetterSpaceAdjust()); + word = t; if (word != null) { parentLM.addChild(word); @@ -659,6 +660,9 @@ public class TextLayoutManager extends AbstractLayoutManager textArea.addTrait(Trait.FONT_NAME, fs.getFontName()); textArea.addTrait(Trait.FONT_SIZE, new Integer(fs.getFontSize())); textArea.addTrait(Trait.COLOR, foText.getColor()); + + TraitSetter.addTextDecoration(textArea, foText.getTextDecoration()); + return textArea; } diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index 4332c675f..dd0abea60 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -26,6 +26,7 @@ import org.apache.fop.area.Trait; import org.apache.fop.fo.Constants; import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.PercentLength; /** @@ -262,4 +263,27 @@ public class TraitSetter { area.addTrait(Trait.BREAK_AFTER, new Integer(breakAfter)); area.addTrait(Trait.BREAK_BEFORE, new Integer(breakBefore)); } + + /** + * Adds the text-decoration traits to the area. + * @param area the area to set the traits on + * @param deco the text decorations + */ + public static void addTextDecoration(Area area, CommonTextDecoration deco) { + //TODO Finish text-decoration + if (deco != null) { + if (deco.hasUnderline()) { + area.addTrait(Trait.UNDERLINE, Boolean.TRUE); + } + if (deco.hasOverline()) { + area.addTrait(Trait.OVERLINE, Boolean.TRUE); + } + if (deco.hasLineThrough()) { + area.addTrait(Trait.LINETHROUGH, Boolean.TRUE); + } + if (deco.isBlinking()) { + area.addTrait(Trait.BLINK, Boolean.TRUE); + } + } + } } diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 8a46bed11..ef7f7f672 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -50,6 +50,7 @@ import org.apache.fop.area.Trait; import org.apache.fop.area.OffDocumentItem; import org.apache.fop.area.BookmarkData; import org.apache.fop.area.inline.Character; +import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.TextArea; import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.ForeignObject; @@ -1041,6 +1042,8 @@ public class PDFRenderer extends PrintRenderer { currentStream.add(pdf.toString()); + renderTextDecoration(fs, ch, bl, rx); + super.renderCharacter(ch); } @@ -1053,7 +1056,7 @@ public class PDFRenderer extends PrintRenderer { String name = (String) text.getTrait(Trait.FONT_NAME); int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue(); - + // This assumes that *all* CIDFonts use a /ToUnicode mapping Typeface f = (Typeface) fontInfo.getFonts().get(name); boolean useMultiByte = f.isMultiByte(); @@ -1112,8 +1115,42 @@ public class PDFRenderer extends PrintRenderer { currentStream.add(pdf.toString()); + renderTextDecoration(fs, text, bl, rx); + super.renderText(text); } + + /** + * Paints the text decoration marks. + * @param fs Current font + * @param inline inline area to paint the marks for + * @param baseline position of the baseline + * @param startx start IPD + */ + protected void renderTextDecoration(Font fs, InlineArea inline, + int baseline, int startx) { + boolean hasTextDeco = inline.hasUnderline() + || inline.hasOverline() + || inline.hasLineThrough(); + if (hasTextDeco) { + endTextObject(); + updateLineStyle(Constants.EN_SOLID); + updateLineWidth(fs.getDescender() / -8 / 1000f); + float endx = (startx + inline.getIPD()) / 1000f; + if (inline.hasUnderline()) { + float y = baseline - fs.getDescender() / 2; + drawLine(startx / 1000f, y / 1000f, endx, y / 1000f); + } + if (inline.hasOverline()) { + float y = (float)(baseline - (1.1 * fs.getCapHeight())); + drawLine(startx / 1000f, y / 1000f, endx, y / 1000f); + } + if (inline.hasLineThrough()) { + float y = (float)(baseline - (0.45 * fs.getCapHeight())); + drawLine(startx / 1000f, y / 1000f, endx, y / 1000f); + } + } + } /** * Escapes text according to PDF rules. diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index 316d379d5..0c2cc05b9 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -94,7 +94,8 @@ class TextAttributesConverter { FOPRtfAttributes attrib = new FOPRtfAttributes(); attrFont(fobj.getCommonFont(), attrib); attrFontColor(fobj.getColor(), attrib); - attrTextDecoration(fobj.getTextDecoration(), attrib); + //TODO Fix text-decoration here! + //attrTextDecoration(fobj.getTextDecoration(), attrib); attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); return attrib; @@ -109,7 +110,8 @@ class TextAttributesConverter { FOPRtfAttributes attrib = new FOPRtfAttributes(); attrFont(fobj.getCommonFont(), attrib); - attrTextDecoration(fobj.getTextDecoration(), attrib); + //TODO Fix text-decoration here! + //attrTextDecoration(fobj.getTextDecoration(), attrib); attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); return attrib; } @@ -124,7 +126,8 @@ class TextAttributesConverter { FOPRtfAttributes attrib = new FOPRtfAttributes(); attrFont(fobj.getCommonFont(), attrib); attrFontColor(fobj.getColor(), attrib); - attrTextDecoration(fobj.getTextDecoration(), attrib); + //TODO Fix text-decoration here! + //attrTextDecoration(fobj.getTextDecoration(), attrib); attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); return attrib; } |