From 7dff238a9a6c6e02faee0d4cdc4f1b2be6514bd5 Mon Sep 17 00:00:00 2001 From: fotis Date: Wed, 15 Nov 2000 21:44:16 +0000 Subject: [PATCH] renames white-space-treatment to white-space-collapse git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193812 13f79535-47bb-0310-9956-ffa450edef68 --- src/codegen/foproperties.xml | 9 +- src/codegen/properties.xml | 14 +- src/org/apache/fop/apps/PrintCommandLine.java | 7 +- src/org/apache/fop/fo/FOText.java | 126 ++- src/org/apache/fop/fo/flow/PageNumber.java | 115 +-- .../fop/fo/flow/PageNumberCitation.java | 158 ++-- src/org/apache/fop/layout/BlockArea.java | 231 +++--- src/org/apache/fop/layout/LineArea.java | 756 +++++++++--------- src/org/apache/fop/layout/LinkSet.java | 169 ++-- 9 files changed, 789 insertions(+), 796 deletions(-) diff --git a/src/codegen/foproperties.xml b/src/codegen/foproperties.xml index 046aae9a8..b938ca924 100644 --- a/src/codegen/foproperties.xml +++ b/src/codegen/foproperties.xml @@ -298,15 +298,14 @@ start - white-space-treatment + white-space-collapse true Enum - preserve - collapse - ignore + true + false - collapse + true break-after diff --git a/src/codegen/properties.xml b/src/codegen/properties.xml index 8ae1205df..7f5ec2c9f 100644 --- a/src/codegen/properties.xml +++ b/src/codegen/properties.xml @@ -204,17 +204,15 @@ start - white-space-treatment - WhiteSpaceTreatment + white-space-collapse + WhiteSpaceCollapse true - + Enum - preserve - collapse - ignore + true + false - - collapse + true break-after diff --git a/src/org/apache/fop/apps/PrintCommandLine.java b/src/org/apache/fop/apps/PrintCommandLine.java index f3a524396..124e0f0eb 100755 --- a/src/org/apache/fop/apps/PrintCommandLine.java +++ b/src/org/apache/fop/apps/PrintCommandLine.java @@ -36,13 +36,12 @@ import org.apache.fop.messaging.MessageHandler; * */ public class PrintCommandLine extends CommandLine { + public PrintCommandLine(String args []) { super (args); } - public static void main(String[] args) { - String version = Version.getVersion(); MessageHandler.errorln(version); @@ -75,8 +74,8 @@ public class PrintCommandLine extends CommandLine { driver.setRenderer(renderer); driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping"); - driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); + driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping"); + driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); driver.buildFOTree(parser, fileInputSource(args[0])); driver.format(); driver.render(); diff --git a/src/org/apache/fop/fo/FOText.java b/src/org/apache/fop/fo/FOText.java index 904c315cb..90b79671a 100644 --- a/src/org/apache/fop/fo/FOText.java +++ b/src/org/apache/fop/fo/FOText.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 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 @@ -41,12 +41,12 @@ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.fo; @@ -74,7 +74,7 @@ public class FOText extends FONode { float green; float blue; int wrapOption; - int whiteSpaceTreatment; + int whiteSpaceCollapse; // Textdecoration protected boolean underlined = false; @@ -83,12 +83,12 @@ public class FOText extends FONode { public FOText(char[] chars, int s, int e, FObj parent) { - super(parent); - this.start = 0; - this.ca = new char[e - s]; - for (int i = s; i < e; i++) - this.ca[i - s] = chars[i]; - this.length = e - s; + super(parent); + this.start = 0; + this.ca = new char[e - s]; + for (int i = s; i < e; i++) + this.ca[i - s] = chars[i]; + this.length = e - s; } public void setUnderlined(boolean ul) { @@ -96,50 +96,48 @@ public class FOText extends FONode { } public Status layout(Area area) throws FOPException { - if (!(area instanceof BlockArea)) { - MessageHandler.errorln("WARNING: text outside block area" + new String(ca, start, length)); - return new Status(Status.OK); - } - if (this.marker == START) { - String fontFamily = - this.parent.properties.get("font-family").getString(); - String fontStyle = - this.parent.properties.get("font-style").getString(); - String fontWeight = - this.parent.properties.get("font-weight").getString(); - int fontSize = - this.parent.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, fontStyle, - fontWeight, fontSize); - - ColorType c = - this.parent.properties.get("color").getColorType(); - this.red = c.red(); - this.green = c.green(); - this.blue = c.blue(); - - this.wrapOption = - this.parent.properties.get("wrap-option").getEnum(); - this.whiteSpaceTreatment = - this.parent.properties.get("white-space-treatment").getEnum(); - - this.marker = this.start; - } - int orig_start = this.marker; - this.marker = ((BlockArea) area).addText(fs, red, green, blue, - wrapOption, - this.getLinkSet(), - whiteSpaceTreatment, - ca, this.marker, length, - underlined); - if (this.marker == -1) { - this.marker = 0; - return new Status(Status.OK); - } else if (this.marker != orig_start) { - return new Status(Status.AREA_FULL_SOME); - } else { - return new Status(Status.AREA_FULL_NONE); - } + if (!(area instanceof BlockArea)) { + MessageHandler.errorln("WARNING: text outside block area" + + new String(ca, start, length)); + return new Status(Status.OK); + } + if (this.marker == START) { + String fontFamily = + this.parent.properties.get("font-family").getString(); + String fontStyle = + this.parent.properties.get("font-style").getString(); + String fontWeight = + this.parent.properties.get("font-weight").getString(); + int fontSize = this.parent.properties.get( + "font-size").getLength().mvalue(); + + this.fs = new FontState(area.getFontInfo(), fontFamily, + fontStyle, fontWeight, fontSize); + + ColorType c = + this.parent.properties.get("color").getColorType(); + this.red = c.red(); + this.green = c.green(); + this.blue = c.blue(); + + this.wrapOption = + this.parent.properties.get("wrap-option").getEnum(); + this.whiteSpaceCollapse = this.parent.properties.get( + "white-space-collapse").getEnum(); + + this.marker = this.start; + } + int orig_start = this.marker; + this.marker = ((BlockArea) area).addText(fs, red, green, blue, + wrapOption, this.getLinkSet(), whiteSpaceCollapse, ca, + this.marker, length, underlined); + if (this.marker == -1) { + this.marker = 0; + return new Status(Status.OK); + } else if (this.marker != orig_start) { + return new Status(Status.AREA_FULL_SOME); + } else { + return new Status(Status.AREA_FULL_NONE); + } } } diff --git a/src/org/apache/fop/fo/flow/PageNumber.java b/src/org/apache/fop/fo/flow/PageNumber.java index 9e826791d..a8b0b2189 100644 --- a/src/org/apache/fop/fo/flow/PageNumber.java +++ b/src/org/apache/fop/fo/flow/PageNumber.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 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 @@ -41,12 +41,12 @@ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.fo.flow; @@ -65,14 +65,14 @@ import java.util.Enumeration; public class PageNumber extends FObj { public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new PageNumber(parent, propertyList); - } + public FObj make(FObj parent, + PropertyList propertyList) throws FOPException { + return new PageNumber(parent, propertyList); + } } public static FObj.Maker maker() { - return new PageNumber.Maker(); + return new PageNumber.Maker(); } FontState fs; @@ -80,50 +80,51 @@ public class PageNumber extends FObj { float green; float blue; int wrapOption; - int whiteSpaceTreatment; + int whiteSpaceCollapse; public PageNumber(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:page-number"; + super(parent, propertyList); + this.name = "fo:page-number"; } public Status layout(Area area) throws FOPException { - if (!(area instanceof BlockArea)) { - MessageHandler.errorln("WARNING: page-number outside block area"); - return new Status(Status.OK); - } - if (this.marker == START) { - String fontFamily = this.properties.get("font-family").getString(); - String fontStyle = this.properties.get("font-style").getString(); - String fontWeight = this.properties.get("font-weight").getString(); - int fontSize = this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - ColorType c = this.properties.get("color").getColorType(); - this.red = c.red(); - this.green = c.green(); - this.blue = c.blue(); - - this.wrapOption = this.properties.get("wrap-option").getEnum(); - this.whiteSpaceTreatment = this.properties.get("white-space-treatment").getEnum(); - - this.marker = 0; - - // initialize id - String id = this.properties.get("id").getString(); - area.getIDReferences().initializeID(id,area); - } - - String p = Integer.toString(area.getPage().getNumber()); - this.marker = ((BlockArea) area).addText(fs, red, green, blue, - wrapOption, - null, - whiteSpaceTreatment, - p.toCharArray(), 0, - p.length(), - false); - return new Status(Status.OK); + if (!(area instanceof BlockArea)) { + MessageHandler.errorln("WARNING: page-number outside block area"); + return new Status(Status.OK); + } + if (this.marker == START) { + String fontFamily = + this.properties.get("font-family").getString(); + String fontStyle = + this.properties.get("font-style").getString(); + String fontWeight = + this.properties.get("font-weight").getString(); + int fontSize = + this.properties.get("font-size").getLength().mvalue(); + + this.fs = new FontState(area.getFontInfo(), fontFamily, + fontStyle, fontWeight, fontSize); + + ColorType c = this.properties.get("color").getColorType(); + this.red = c.red(); + this.green = c.green(); + this.blue = c.blue(); + + this.wrapOption = this.properties.get("wrap-option").getEnum(); + this.whiteSpaceCollapse = + this.properties.get("white-space-collapse").getEnum(); + + this.marker = 0; + + // initialize id + String id = this.properties.get("id").getString(); + area.getIDReferences().initializeID(id, area); + } + + String p = Integer.toString(area.getPage().getNumber()); + this.marker = ((BlockArea) area).addText(fs, red, green, blue, + wrapOption, null, whiteSpaceCollapse, p.toCharArray(), + 0, p.length(), false); + return new Status(Status.OK); } } diff --git a/src/org/apache/fop/fo/flow/PageNumberCitation.java b/src/org/apache/fop/fo/flow/PageNumberCitation.java index 797c294cf..cfcb2c51d 100644 --- a/src/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/org/apache/fop/fo/flow/PageNumberCitation.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 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 @@ -41,12 +41,12 @@ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.fo.flow; @@ -64,16 +64,16 @@ import org.apache.fop.apps.FOPException; /** * 6.6.11 fo:page-number-citation * -* Common Usage: +* Common Usage: * The fo:page-number-citation is used to reference the page-number for the page containing the first normal area returned by * the cited formatting object. * -* NOTE: +* NOTE: * It may be used to provide the page-numbers in the table of contents, cross-references, and index entries. * -* Areas: +* Areas: * The fo:page-number-citation formatting object generates and returns a single normal inline-area. -* Constraints: +* Constraints: * * The cited page-number is the number of the page containing, as a descendant, the first normal area returned by the * formatting object with an id trait matching the ref-id trait of the fo:page-number-citation (the referenced formatting @@ -86,46 +86,45 @@ import org.apache.fop.apps.FOPException; * fo:character flow objects; one for each character in the cited page-number string and with only the "character" property * specified. * -* Contents: +* Contents: * * EMPTY * -* The following properties apply to this formatting object: +* The following properties apply to this formatting object: * -* [7.3 Common Accessibility Properties] -* [7.5 Common Aural Properties] -* [7.6 Common Border, Padding, and Background Properties] -* [7.7 Common Font Properties] -* [7.10 Common Margin Properties-Inline] -* [7.11.1 "alignment-adjust"] -* [7.11.2 "baseline-identifier"] -* [7.11.3 "baseline-shift"] -* [7.11.5 "dominant-baseline"] -* [7.36.2 "id"] -* [7.17.4 "keep-with-next"] -* [7.17.5 "keep-with-previous"] -* [7.14.2 "letter-spacing"] -* [7.13.4 "line-height"] -* [7.13.5 "line-height-shift-adjustment"] -* [7.36.5 "ref-id"] -* [7.18.4 "relative-position"] -* [7.36.6 "score-spaces"] -* [7.14.4 "text-decoration"] -* [7.14.5 "text-shadow"] -* [7.14.6 "text-transform"] -* [7.14.8 "word-spacing"] +* [7.3 Common Accessibility Properties] +* [7.5 Common Aural Properties] +* [7.6 Common Border, Padding, and Background Properties] +* [7.7 Common Font Properties] +* [7.10 Common Margin Properties-Inline] +* [7.11.1 "alignment-adjust"] +* [7.11.2 "baseline-identifier"] +* [7.11.3 "baseline-shift"] +* [7.11.5 "dominant-baseline"] +* [7.36.2 "id"] +* [7.17.4 "keep-with-next"] +* [7.17.5 "keep-with-previous"] +* [7.14.2 "letter-spacing"] +* [7.13.4 "line-height"] +* [7.13.5 "line-height-shift-adjustment"] +* [7.36.5 "ref-id"] +* [7.18.4 "relative-position"] +* [7.36.6 "score-spaces"] +* [7.14.4 "text-decoration"] +* [7.14.5 "text-shadow"] +* [7.14.6 "text-transform"] +* [7.14.8 "word-spacing"] */ public class PageNumberCitation extends FObj { public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) throws FOPException - { + public FObj make(FObj parent, + PropertyList propertyList) throws FOPException { return new PageNumberCitation(parent, propertyList); } } - public static FObj.Maker maker() - { + public static FObj.Maker maker() { return new PageNumberCitation.Maker(); } @@ -134,36 +133,39 @@ public class PageNumberCitation extends FObj { float green; float blue; int wrapOption; - int whiteSpaceTreatment; + int whiteSpaceCollapse; Area area; String pageNumber; String refId; - String id; + String id; - public PageNumberCitation(FObj parent, PropertyList propertyList) - { + public PageNumberCitation(FObj parent, PropertyList propertyList) { super(parent, propertyList); this.name = "fo:page-number-citation"; } - public Status layout(Area area) throws FOPException - { - if ( !(area instanceof BlockArea) ) { + public Status layout(Area area) throws FOPException { + if (!(area instanceof BlockArea)) { MessageHandler.errorln("WARNING: page-number-citation outside block area"); return new Status(Status.OK); } - IDReferences idReferences = area.getIDReferences(); + IDReferences idReferences = area.getIDReferences(); this.area = area; - if ( this.marker == START ) { - String fontFamily = this.properties.get("font-family").getString(); - String fontStyle = this.properties.get("font-style").getString(); - String fontWeight = this.properties.get("font-weight").getString(); - int fontSize = this.properties.get("font-size").getLength().mvalue(); - - this.fs = new FontState(area.getFontInfo(), fontFamily, fontStyle, fontWeight, fontSize); + if (this.marker == START) { + String fontFamily = + this.properties.get("font-family").getString(); + String fontStyle = + this.properties.get("font-style").getString(); + String fontWeight = + this.properties.get("font-weight").getString(); + int fontSize = + this.properties.get("font-size").getLength().mvalue(); + + this.fs = new FontState(area.getFontInfo(), fontFamily, + fontStyle, fontWeight, fontSize); ColorType c = this.properties.get("color").getColorType(); this.red = c.red(); @@ -171,40 +173,44 @@ public class PageNumberCitation extends FObj { this.blue = c.blue(); this.wrapOption = this.properties.get("wrap-option").getEnum(); - this.whiteSpaceTreatment = this.properties.get("white-space-treatment").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\""); + if (this.refId.equals("")) { + throw new FOPException("page-number-citation must contain \"ref-id\""); } - // create id - this.id = this.properties.get("id").getString(); - idReferences.createID(id); + // create id + this.id = this.properties.get("id").getString(); + idReferences.createID(id); this.marker = 0; } - if ( marker == 0 ) { - idReferences.configureID(id,area); + if (marker == 0) { + idReferences.configureID(id, area); } - pageNumber=idReferences.getPageNumber(refId); + pageNumber = idReferences.getPageNumber(refId); - if ( pageNumber!=null ) { // if we already know the page number - this.marker = ((BlockArea) area).addText(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, pageNumber.toCharArray(), 0, pageNumber.length(), false); - } - else { // add pageNumberCitation to area to be resolved during rendering - this.marker = ((BlockArea) area).addPageNumberCitation(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, refId); + if (pageNumber != null) { // if we already know the page number + this.marker = ((BlockArea) area).addText(fs, red, green, blue, + wrapOption, null, whiteSpaceCollapse, + pageNumber.toCharArray(), 0, pageNumber.length(), + false); + } else { // add pageNumberCitation to area to be resolved during rendering + this.marker = ((BlockArea) area).addPageNumberCitation(fs, red, + green, blue, wrapOption, null, whiteSpaceCollapse, + refId); } - if ( this.marker == -1 ) { + if (this.marker == -1) { return new Status(Status.OK); - } - else { + } else { return new Status(Status.AREA_FULL_NONE); } diff --git a/src/org/apache/fop/layout/BlockArea.java b/src/org/apache/fop/layout/BlockArea.java index 782580eb3..faafc454f 100644 --- a/src/org/apache/fop/layout/BlockArea.java +++ b/src/org/apache/fop/layout/BlockArea.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 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 @@ -41,12 +41,12 @@ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.layout; @@ -58,7 +58,7 @@ import java.util.Vector; import java.util.Enumeration; public class BlockArea extends Area { - + /* relative to area container */ protected int startIndent; protected int endIndent; @@ -67,16 +67,16 @@ public class BlockArea extends Area { protected int textIndent; protected int lineHeight; - + protected int halfLeading; - + /* text-align of all but the last line */ protected int align; /* text-align of the last line */ protected int alignLastLine; - + protected LineArea currentLineArea; protected LinkSet currentLinkSet; @@ -84,146 +84,145 @@ public class BlockArea extends Area { protected boolean hasLines = false; public BlockArea(FontState fontState, int allocationWidth, - int maxHeight, int startIndent, int endIndent, - int textIndent, int align, int alignLastLine, - int lineHeight) { - super(fontState, allocationWidth, maxHeight); - - this.startIndent = startIndent; - this.endIndent = endIndent; - this.textIndent = textIndent; - this.contentRectangleWidth = allocationWidth - startIndent - endIndent; - this.align = align; - this.alignLastLine = alignLastLine; - this.lineHeight = lineHeight; + int maxHeight, int startIndent, int endIndent, + int textIndent, int align, int alignLastLine, int lineHeight) { + super(fontState, allocationWidth, maxHeight); + + this.startIndent = startIndent; + this.endIndent = endIndent; + this.textIndent = textIndent; + this.contentRectangleWidth = + allocationWidth - startIndent - endIndent; + this.align = align; + this.alignLastLine = alignLastLine; + this.lineHeight = lineHeight; if (fontState != null) - this.halfLeading = (lineHeight - fontState.getFontSize())/2; + this.halfLeading = (lineHeight - fontState.getFontSize()) / 2; } public void render(Renderer renderer) { - renderer.renderBlockArea(this); + renderer.renderBlockArea(this); } public void addLineArea(LineArea la) { - if (!la.isEmpty()) { - this.addDisplaySpace(this.halfLeading); - int size = la.getHeight(); - this.addChild(la); - this.increaseHeight(size); - this.addDisplaySpace(this.halfLeading); - } + if (!la.isEmpty()) { + this.addDisplaySpace(this.halfLeading); + int size = la.getHeight(); + this.addChild(la); + this.increaseHeight(size); + this.addDisplaySpace(this.halfLeading); + } } - public int addPageNumberCitation(FontState fontState, float red, float green, - float blue, int wrapOption, LinkSet ls, - int whiteSpaceTreatment, String refid) { + public int addPageNumberCitation(FontState fontState, float red, + float green, float blue, int wrapOption, LinkSet ls, + int whiteSpaceCollapse, String refid) { this.currentLineArea.changeFont(fontState); - this.currentLineArea.changeColor(red, green, blue); - this.currentLineArea.changeWrapOption(wrapOption); - this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment); + this.currentLineArea.changeColor(red, green, blue); + this.currentLineArea.changeWrapOption(wrapOption); + this.currentLineArea.changeWhiteSpaceCollapse(whiteSpaceCollapse); if (ls != null) { this.currentLinkSet = ls; - ls.setYOffset(currentHeight); - } + ls.setYOffset(currentHeight); + } + + this.currentLineArea.addPageNumberCitation(refid, ls); + this.hasLines = true; - this.currentLineArea.addPageNumberCitation(refid,ls); - this.hasLines = true; - return -1; } public int addText(FontState fontState, float red, float green, - float blue, int wrapOption, LinkSet ls, - int whiteSpaceTreatment, char data[], - int start, int end, boolean ul) { - int ts, te; - char[] ca; - - ts = start; - te = end; - ca = data; - - if (currentHeight + currentLineArea.getHeight() > maxHeight) { - return start; - } - - this.currentLineArea.changeFont(fontState); - this.currentLineArea.changeColor(red, green, blue); - this.currentLineArea.changeWrapOption(wrapOption); - this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment); - - if (ls != null) { + float blue, int wrapOption, LinkSet ls, + int whiteSpaceCollapse, char data[], int start, int end, + boolean ul) { + int ts, te; + char[] ca; + + ts = start; + te = end; + ca = data; + + if (currentHeight + currentLineArea.getHeight() > maxHeight) { + return start; + } + + this.currentLineArea.changeFont(fontState); + this.currentLineArea.changeColor(red, green, blue); + this.currentLineArea.changeWrapOption(wrapOption); + this.currentLineArea.changeWhiteSpaceCollapse(whiteSpaceCollapse); + + if (ls != null) { this.currentLinkSet = ls; - ls.setYOffset(currentHeight); - } - - ts = this.currentLineArea.addText(ca, ts, te, ls, ul); - this.hasLines = true; - - while (ts != -1) { - this.currentLineArea.align(this.align); - this.addLineArea(this.currentLineArea); - - this.currentLineArea = new - LineArea(fontState, lineHeight, halfLeading, - allocationWidth, startIndent, endIndent, - currentLineArea); - if (currentHeight + currentLineArea.getHeight() > - this.maxHeight) { - return ts; - } - this.currentLineArea.changeFont(fontState); - this.currentLineArea.changeColor(red, green, blue); - this.currentLineArea.changeWrapOption(wrapOption); - this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment); - if (ls != null) { - ls.setYOffset(currentHeight); - } - - ts = this.currentLineArea.addText(ca, ts, te, ls, ul); - } - return -1; + ls.setYOffset(currentHeight); + } + + ts = this.currentLineArea.addText(ca, ts, te, ls, ul); + this.hasLines = true; + + while (ts != -1) { + this.currentLineArea.align(this.align); + this.addLineArea(this.currentLineArea); + + this.currentLineArea = + new LineArea(fontState, lineHeight, halfLeading, + allocationWidth, startIndent, endIndent, + currentLineArea); + if (currentHeight + currentLineArea.getHeight() > + this.maxHeight) { + return ts; + } + this.currentLineArea.changeFont(fontState); + this.currentLineArea.changeColor(red, green, blue); + this.currentLineArea.changeWrapOption(wrapOption); + this.currentLineArea.changeWhiteSpaceCollapse( + whiteSpaceCollapse); + if (ls != null) { + ls.setYOffset(currentHeight); + } + + ts = this.currentLineArea.addText(ca, ts, te, ls, ul); + } + return -1; } public void end() { - if (this.hasLines) { - this.currentLineArea.addPending(); - this.currentLineArea.align(this.alignLastLine); - this.addLineArea(this.currentLineArea); - } + if (this.hasLines) { + this.currentLineArea.addPending(); + this.currentLineArea.align(this.alignLastLine); + this.addLineArea(this.currentLineArea); + } } public void start() { - currentLineArea = new LineArea(fontState, lineHeight, - halfLeading, allocationWidth, - startIndent + textIndent, - endIndent,null); + currentLineArea = new LineArea(fontState, lineHeight, halfLeading, + allocationWidth, startIndent + textIndent, endIndent, null); } public int getEndIndent() { - return endIndent; + return endIndent; } public int getStartIndent() { - return startIndent + paddingLeft + borderWidthLeft; + return startIndent + paddingLeft + borderWidthLeft; } public void setIndents(int startIndent, int endIndent) { - this.startIndent = startIndent; - this.endIndent = endIndent; - this.contentRectangleWidth = allocationWidth - startIndent - endIndent; + this.startIndent = startIndent; + this.endIndent = endIndent; + this.contentRectangleWidth = + allocationWidth - startIndent - endIndent; } - + public int spaceLeft() { - return maxHeight - currentHeight; + return maxHeight - currentHeight; } - - public int getHalfLeading() - { + + public int getHalfLeading() { return halfLeading; } diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index e27651b33..5197b03b6 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 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 @@ -41,12 +41,12 @@ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.layout; @@ -59,41 +59,41 @@ import java.util.Enumeration; import java.awt.Rectangle; import org.apache.fop.fo.properties.WrapOption; // for enumerated -// values -import org.apache.fop.fo.properties.WhiteSpaceTreatment; // for -// enumerated values +// values +import org.apache.fop.fo.properties.WhiteSpaceCollapse; // for +// enumerated values import org.apache.fop.fo.properties.TextAlign; // for enumerated -// values +// values import org.apache.fop.fo.properties.TextAlignLast; // for enumerated -// values +// values import org.apache.fop.datatypes.IDNode; public class LineArea extends Area { - + protected int lineHeight; protected int halfLeading; protected int nominalFontSize; protected int nominalGlyphHeight; - + protected int allocationHeight; protected int startIndent; protected int endIndent; - + private int placementOffset; - + private FontState currentFontState; // not the nominal, which is - // in this.fontState + // in this.fontState private float red, green, blue; private int wrapOption; - private int whiteSpaceTreatment; + private int whiteSpaceCollapse; /* the width of text that has definitely made it into the line area */ protected int finalWidth = 0; /* the position to shift a link rectangle in order to compensate for links embedded within a word*/ - protected int embeddedLinkStart=0; + protected int embeddedLinkStart = 0; /* the width of the current word so far */ protected int wordWidth = 0; @@ -123,56 +123,53 @@ public class LineArea extends Area { /* the width of the pendingAreas */ protected int pendingWidth = 0; - public LineArea(FontState fontState, int lineHeight, int - halfLeading, int allocationWidth, int startIndent, - int endIndent,LineArea prevLineArea) { - super(fontState); - - this.currentFontState = fontState; - this.lineHeight = lineHeight; - this.nominalFontSize = fontState.getFontSize(); - this.nominalGlyphHeight = fontState.getAscender() - - fontState.getDescender(); - - this.placementOffset = fontState.getAscender(); - this.contentRectangleWidth = allocationWidth - startIndent - - endIndent; - this.fontState = fontState; - - this.allocationHeight = this.nominalGlyphHeight; - this.halfLeading = this.lineHeight - this.allocationHeight; - - this.startIndent = startIndent; - this.endIndent = endIndent; - - if(prevLineArea != null){ - Enumeration e=prevLineArea.pendingAreas.elements(); - while( e.hasMoreElements() ){ - pendingAreas.addElement(e.nextElement()); - } - pendingWidth=prevLineArea.getPendingWidth(); - } + public LineArea(FontState fontState, int lineHeight, + int halfLeading, int allocationWidth, int startIndent, + int endIndent, LineArea prevLineArea) { + super(fontState); + + this.currentFontState = fontState; + this.lineHeight = lineHeight; + this.nominalFontSize = fontState.getFontSize(); + this.nominalGlyphHeight = + fontState.getAscender() - fontState.getDescender(); + + this.placementOffset = fontState.getAscender(); + this.contentRectangleWidth = + allocationWidth - startIndent - endIndent; + this.fontState = fontState; + + this.allocationHeight = this.nominalGlyphHeight; + this.halfLeading = this.lineHeight - this.allocationHeight; + + this.startIndent = startIndent; + this.endIndent = endIndent; + + if (prevLineArea != null) { + Enumeration e = prevLineArea.pendingAreas.elements(); + while (e.hasMoreElements()) { + pendingAreas.addElement(e.nextElement()); + } + pendingWidth = prevLineArea.getPendingWidth(); + } } - + public void render(Renderer renderer) { - renderer.renderLineArea(this); + renderer.renderLineArea(this); } - public int addPageNumberCitation(String refid, LinkSet ls) - { - - /* We should add code here to handle the case where the page number doesn't fit on the current line - */ - - //Space must be alloted to the page number, so currently we give it 3 spaces - int width= currentFontState.width(32) * 3; - - PageNumberInlineArea pia = new PageNumberInlineArea(currentFontState, - this.red, this.green, - this.blue, - refid, - width); - + public int addPageNumberCitation(String refid, LinkSet ls) { + + /* We should add code here to handle the case where the page number doesn't fit on the current line + */ + + //Space must be alloted to the page number, so currently we give it 3 spaces + int width = currentFontState.width(32) * 3; + + PageNumberInlineArea pia = + new PageNumberInlineArea(currentFontState, this.red, + this.green, this.blue, refid, width); + pendingAreas.addElement(pia); pendingWidth += width; wordWidth = 0; @@ -182,352 +179,349 @@ public class LineArea extends Area { } - public int addText(char odata[], int start, int end, LinkSet ls, boolean ul) { - boolean overrun = false; - - wordStart = start; - wordLength = 0; - wordWidth = 0; - char[] data = new char[odata.length]; - for(int count=0;count 127) { - /* this class shouldn't be hard coded */ - char d = - org.apache.fop.render.pdf.CodePointMapping.map[c]; - if (d != 0) { - c = data[i] = d; - } else { - MessageHandler.error("ch" - + (int)c + "?"); - c = data[i] = '#'; - } - } - - charWidth = currentFontState.width(c); - - if ((c == ' ') || - (c == '\n') || - (c == '\r') || - (c == '\t')) { // whitespace - - if (prev == WHITESPACE) { - - // if current & previous are WHITESPACE - - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.PRESERVE) { - if (c == ' ') { - spaceWidth += currentFontState.width(32); - } else if (c == '\n') { - // force line break - return i; - } else if (c == '\t') { - spaceWidth += 8 * currentFontState.width(32); - } - } // else ignore it - - } else if (prev == TEXT) { - - // if current is WHITESPACE and previous TEXT - - // the current word made it, so - - // add the space before the current word (if there - // was some) - - if (spaceWidth > 0) { - addChild(new InlineSpace(spaceWidth)); - finalWidth += spaceWidth; - spaceWidth = 0; - } - - // add any pending areas - - Enumeration e = pendingAreas.elements(); - while (e.hasMoreElements()) { - InlineArea inlineArea = (InlineArea) e.nextElement(); - if (ls != null) { - Rectangle lr = - new Rectangle(finalWidth, - 0, - inlineArea.getContentWidth(), - fontState.getFontSize()); - ls.addRect(lr, this); - } - - addChild(inlineArea); - } - finalWidth += pendingWidth; - - // reset pending areas array - pendingWidth = 0; - pendingAreas = new Vector(); - - // add the current word - - if (wordLength > 0) { - InlineArea ia = new InlineArea(currentFontState, - this.red, this.green, - this.blue, new - String(data, wordStart, - wordLength), - wordWidth); - ia.setUnderlined(ul); - addChild(ia); - if (ls != null) { - Rectangle lr = - new Rectangle(finalWidth, - 0, - ia.getContentWidth(), - fontState.getFontSize()); - ls.addRect(lr, this); - } - finalWidth += wordWidth; - - // reset word width - wordWidth = 0; - } - - // deal with this new whitespace following the - // word we just added - - prev = WHITESPACE; - - embeddedLinkStart=0; //reset embeddedLinkStart since a space was encountered - - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.IGNORE) { - // do nothing - } else { - spaceWidth = currentFontState.width(32); - } - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.PRESERVE) { - if (c == '\n') { - // force a line break - return i; - } else if (c == '\t') { - spaceWidth = currentFontState.width(32); - } - } - - } else { - - // if current is WHITESPACE and no previous - - if (this.whiteSpaceTreatment == - WhiteSpaceTreatment.PRESERVE) { - prev = WHITESPACE; - spaceWidth = currentFontState.width(32); - } else { - // skip over it - start++; - } - } - - } else { // current is TEXT - - if (prev == WHITESPACE) { - - // if current is TEXT and previous WHITESPACE - - wordWidth = charWidth; - if ((finalWidth + spaceWidth + wordWidth) > - this.getContentWidth()) { - if (overrun) - MessageHandler.error(">"); - if (this.wrapOption == WrapOption.WRAP) - return i; - } - prev = TEXT; - wordStart = i; - wordLength = 1; - } else if (prev == TEXT) { - - wordLength++; - wordWidth += charWidth; - } else { // nothing previous - - prev = TEXT; - wordStart = i; - wordLength = 1; - wordWidth = charWidth; - } - - if ((finalWidth + spaceWidth + pendingWidth + wordWidth) > - this.getContentWidth()) { - - // BREAK MID WORD - if (wordStart == start) { // if couldn't even fit - // first word - overrun = true; - // if not at start of line, return word start - // to try again on a new line - if (finalWidth > 0) { - return wordStart; - } - } else if (this.wrapOption == WrapOption.WRAP) { - return wordStart; - } - } - - } - } // end of iteration over text - - if (prev == TEXT) { - - InlineArea pia = new InlineArea(currentFontState, this.red, - this.green, this.blue, new - String(data, wordStart, - wordLength), wordWidth); - - pia.setUnderlined(ul); - - if (ls != null) { - Rectangle lr = - new Rectangle(finalWidth + spaceWidth + embeddedLinkStart, - spaceWidth, - pia.getContentWidth(), - fontState.getFontSize()); - ls.addRect(lr, this); - } - - embeddedLinkStart += wordWidth; - pendingAreas.addElement(pia); - pendingWidth += wordWidth; - wordWidth = 0; - } - - if (overrun) - MessageHandler.error(">"); - return -1; + public int addText(char odata[], int start, int end, LinkSet ls, + boolean ul) { + boolean overrun = false; + + wordStart = start; + wordLength = 0; + wordWidth = 0; + char[] data = new char[odata.length]; + for (int count = 0; count < odata.length; count++) { + data[count] = odata[count]; + } + + /* iterate over each character */ + for (int i = start; i < end; i++) { + int charWidth; + /* get the character */ + char c = data[i]; + + if (c > 127) { + /* this class shouldn't be hard coded */ + char d = org.apache.fop.render.pdf.CodePointMapping.map[c]; + if (d != 0) { + c = data[i] = d; + } else { + MessageHandler.error("ch" + (int) c + "?"); + c = data[i] = '#'; + } + } + + charWidth = currentFontState.width(c); + + if ((c == ' ') || (c == '\n') || (c == '\r') || + (c == '\t')) { // whitespace + + if (prev == WHITESPACE) { + + // if current & previous are WHITESPACE + + if (this.whiteSpaceCollapse == + WhiteSpaceCollapse.FALSE) { + if (c == ' ') { + spaceWidth += currentFontState.width(32); + } else if (c == '\n') { + // force line break + return i; + } else if (c == '\t') { + spaceWidth += 8 * currentFontState.width(32); + } + } // else ignore it + + } else if (prev == TEXT) { + + // if current is WHITESPACE and previous TEXT + + // the current word made it, so + + // add the space before the current word (if there + // was some) + + if (spaceWidth > 0) { + addChild(new InlineSpace(spaceWidth)); + finalWidth += spaceWidth; + spaceWidth = 0; + } + + // add any pending areas + + Enumeration e = pendingAreas.elements(); + while (e.hasMoreElements()) { + InlineArea inlineArea = + (InlineArea) e.nextElement(); + if (ls != null) { + Rectangle lr = new Rectangle(finalWidth, 0, + inlineArea.getContentWidth(), + fontState.getFontSize()); + ls.addRect(lr, this); + } + + addChild(inlineArea); + } + finalWidth += pendingWidth; + + // reset pending areas array + pendingWidth = 0; + pendingAreas = new Vector(); + + // add the current word + + if (wordLength > 0) { + InlineArea ia = new InlineArea(currentFontState, + this.red, this.green, this.blue, + new String(data, wordStart, + wordLength), wordWidth); + ia.setUnderlined(ul); + addChild(ia); + if (ls != null) { + Rectangle lr = new Rectangle(finalWidth, 0, + ia.getContentWidth(), + fontState.getFontSize()); + ls.addRect(lr, this); + } + finalWidth += wordWidth; + + // reset word width + wordWidth = 0; + } + + // deal with this new whitespace following the + // word we just added + + prev = WHITESPACE; + + embeddedLinkStart = 0; //reset embeddedLinkStart since a space was encountered + + spaceWidth = currentFontState.width(32); + + /* + here is the place for space-treatment value 'ignore': + if (this.spaceTreatment == + SpaceTreatment.IGNORE) { + // do nothing + } else { + spaceWidth = currentFontState.width(32); + } + + */ + + + if (this.whiteSpaceCollapse == + WhiteSpaceCollapse.FALSE) { + if (c == '\n') { + // force a line break + return i; + } else if (c == '\t') { + spaceWidth = currentFontState.width(32); + } + } + + } else { + + // if current is WHITESPACE and no previous + + if (this.whiteSpaceCollapse == + WhiteSpaceCollapse.FALSE) { + prev = WHITESPACE; + spaceWidth = currentFontState.width(32); + } else { + // skip over it + start++; + } + } + + } else { // current is TEXT + + if (prev == WHITESPACE) { + + // if current is TEXT and previous WHITESPACE + + wordWidth = charWidth; + if ((finalWidth + spaceWidth + wordWidth) > + this.getContentWidth()) { + if (overrun) + MessageHandler.error(">"); + if (this.wrapOption == WrapOption.WRAP) + return i; + } + prev = TEXT; + wordStart = i; + wordLength = 1; + } else if (prev == TEXT) { + + wordLength++; + wordWidth += charWidth; + } else { // nothing previous + + prev = TEXT; + wordStart = i; + wordLength = 1; + wordWidth = charWidth; + } + + if ((finalWidth + spaceWidth + pendingWidth + + wordWidth) > this.getContentWidth()) { + + // BREAK MID WORD + if (wordStart == start) { // if couldn't even fit + // first word + overrun = true; + // if not at start of line, return word start + // to try again on a new line + if (finalWidth > 0) { + return wordStart; + } + } else if (this.wrapOption == WrapOption.WRAP) { + return wordStart; + } + } + + } + } // end of iteration over text + + if (prev == TEXT) { + + InlineArea pia = new InlineArea(currentFontState, this.red, + this.green, this.blue, + new String(data, wordStart, wordLength), wordWidth); + + pia.setUnderlined(ul); + + if (ls != null) { + Rectangle lr = new Rectangle(finalWidth + spaceWidth + + embeddedLinkStart, spaceWidth, + pia.getContentWidth(), fontState.getFontSize()); + ls.addRect(lr, this); + } + + embeddedLinkStart += wordWidth; + pendingAreas.addElement(pia); + pendingWidth += wordWidth; + wordWidth = 0; + } + + if (overrun) + MessageHandler.error(">"); + return -1; } public void addPending() { - if (spaceWidth > 0) { - addChild(new InlineSpace(spaceWidth)); - finalWidth += spaceWidth; - spaceWidth = 0; - } - - Enumeration e = pendingAreas.elements(); - while (e.hasMoreElements()) { - InlineArea inlineArea = (InlineArea) e.nextElement(); - addChild(inlineArea); - } - finalWidth += pendingWidth; - - // reset pending areas array - pendingWidth = 0; - pendingAreas = new Vector(); + if (spaceWidth > 0) { + addChild(new InlineSpace(spaceWidth)); + finalWidth += spaceWidth; + spaceWidth = 0; + } + + Enumeration e = pendingAreas.elements(); + while (e.hasMoreElements()) { + InlineArea inlineArea = (InlineArea) e.nextElement(); + addChild(inlineArea); + } + finalWidth += pendingWidth; + + // reset pending areas array + pendingWidth = 0; + pendingAreas = new Vector(); } public void align(int type) { - int padding = 0; - - switch (type) { - case TextAlign.START: // left - padding = this.getContentWidth() - finalWidth; - endIndent += padding; - break; - case TextAlign.END: // right - padding = this.getContentWidth() - finalWidth; - startIndent += padding; - break; - case TextAlign.CENTER: // center - padding = (this.getContentWidth() - finalWidth)/2; - startIndent += padding; - endIndent += padding; - break; - case TextAlign.JUSTIFY: // justify - Vector spaceList = new Vector(); - - int spaceCount = 0; - Enumeration e = children.elements(); - while (e.hasMoreElements()) { - Box b = (Box)e.nextElement(); - if (b instanceof InlineSpace) { - InlineSpace space = (InlineSpace)b; - spaceList.addElement(space); - spaceCount++; - } - } - if (spaceCount > 0) { - padding = (this.getContentWidth() - finalWidth) / - spaceCount; - } else { // no spaces - padding = 0; - } - Enumeration f = spaceList.elements(); - while (f.hasMoreElements()) { - InlineSpace space2 = (InlineSpace)f.nextElement(); - int i = space2.getSize(); - space2.setSize(i + padding); - } - } + int padding = 0; + + switch (type) { + case TextAlign.START: // left + padding = this.getContentWidth() - finalWidth; + endIndent += padding; + break; + case TextAlign.END: // right + padding = this.getContentWidth() - finalWidth; + startIndent += padding; + break; + case TextAlign.CENTER: // center + padding = (this.getContentWidth() - finalWidth) / 2; + startIndent += padding; + endIndent += padding; + break; + case TextAlign.JUSTIFY: // justify + Vector spaceList = new Vector(); + + int spaceCount = 0; + Enumeration e = children.elements(); + while (e.hasMoreElements()) { + Box b = (Box) e.nextElement(); + if (b instanceof InlineSpace) { + InlineSpace space = (InlineSpace) b; + spaceList.addElement(space); + spaceCount++; + } + } + if (spaceCount > 0) { + padding = (this.getContentWidth() - finalWidth) / + spaceCount; + } else { // no spaces + padding = 0; + } + Enumeration f = spaceList.elements(); + while (f.hasMoreElements()) { + InlineSpace space2 = (InlineSpace) f.nextElement(); + int i = space2.getSize(); + space2.setSize(i + padding); + } + } } - + public void changeColor(float red, float green, float blue) { - this.red = red; - this.green = green; - this.blue = blue; + this.red = red; + this.green = green; + this.blue = blue; } - + public void changeFont(FontState fontState) { - this.currentFontState = fontState; + this.currentFontState = fontState; } - - public void changeWhiteSpaceTreatment(int whiteSpaceTreatment) { - this.whiteSpaceTreatment = whiteSpaceTreatment; + + public void changeWhiteSpaceCollapse(int whiteSpaceCollapse) { + this.whiteSpaceCollapse = whiteSpaceCollapse; } - + public void changeWrapOption(int wrapOption) { - this.wrapOption = wrapOption; + this.wrapOption = wrapOption; } - + public int getEndIndent() { - return endIndent; + return endIndent; } - + public int getHeight() { - return this.allocationHeight; + return this.allocationHeight; } - + public int getPlacementOffset() { - return this.placementOffset; + return this.placementOffset; } - + public int getStartIndent() { - return startIndent; + return startIndent; } - + public boolean isEmpty() { - return (prev==0); + return (prev == 0); } public Vector getPendingAreas() { - return pendingAreas; + return pendingAreas; } public int getPendingWidth() { - return pendingWidth; + return pendingWidth; } public void setPendingAreas(Vector areas) { - pendingAreas = areas; + pendingAreas = areas; } public void setPendingWidth(int width) { - pendingWidth = width; + pendingWidth = width; } } diff --git a/src/org/apache/fop/layout/LinkSet.java b/src/org/apache/fop/layout/LinkSet.java index 3277899a0..771ce4486 100644 --- a/src/org/apache/fop/layout/LinkSet.java +++ b/src/org/apache/fop/layout/LinkSet.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ - + Copyright (C) 1999 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 @@ -41,12 +41,12 @@ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ /* this class contributed by Arved Sandstrom with minor modifications @@ -60,13 +60,13 @@ import java.util.Enumeration; import java.awt.Rectangle; import org.apache.fop.fo.properties.WrapOption; // for enumerated -// values -import org.apache.fop.fo.properties.WhiteSpaceTreatment; // for -// enumerated values +// values +// import org.apache.fop.fo.properties.WhiteSpaceCollapse; // for +// enumerated values import org.apache.fop.fo.properties.TextAlign; // for enumerated -// values +// values import org.apache.fop.fo.properties.TextAlignLast; // for enumerated -// values +// values /** * a set of rectangles on a page that are linked to a common @@ -82,7 +82,7 @@ public class LinkSet { private int xoffset = 0; private int yoffset = 0; - + /* the maximum Y offset value encountered for this LinkSet*/ private int maxY = 0; @@ -93,110 +93,109 @@ public class LinkSet { private Area area; - public final static int - INTERNAL = 0, // represents internal link - EXTERNAL = 1; // represents external link + public final static int INTERNAL = 0, // represents internal link + EXTERNAL = 1; // represents external link // property required for alignment adjustments int contentRectangleWidth = 0; public LinkSet(String destination, Area area, int linkType) { - this.destination = destination; - this.area = area; + this.destination = destination; + this.area = area; this.linkType = linkType; } - + public void addRect(Rectangle r, LineArea lineArea) { - LinkedRectangle linkedRectangle = - new LinkedRectangle(r, lineArea); - linkedRectangle.setY(this.yoffset); - if(this.yoffset>maxY) - { - maxY=this.yoffset; + LinkedRectangle linkedRectangle = new LinkedRectangle(r, lineArea); + linkedRectangle.setY(this.yoffset); + if (this.yoffset > maxY) { + maxY = this.yoffset; } - rects.addElement(linkedRectangle); + rects.addElement(linkedRectangle); } - + public void setYOffset(int y) { - this.yoffset = y; + this.yoffset = y; } - + public void setXOffset(int x) { - this.xoffset = x; + this.xoffset = x; } - + public void setContentRectangleWidth(int contentRectangleWidth) { - this.contentRectangleWidth = contentRectangleWidth; + this.contentRectangleWidth = contentRectangleWidth; } - - public void applyAreaContainerOffsets(AreaContainer ac, Area area) { - int height=area.getAbsoluteHeight(); - BlockArea ba = (BlockArea)area; - Enumeration re = rects.elements(); + + public void applyAreaContainerOffsets(AreaContainer ac, Area area) { + int height = area.getAbsoluteHeight(); + BlockArea ba = (BlockArea) area; + Enumeration re = rects.elements(); while (re.hasMoreElements()) { - LinkedRectangle r = (LinkedRectangle)re.nextElement(); - r.setX(r.getX() + ac.getXPosition() + area.getTableCellXOffset()); - r.setY( ac.getYPosition() - height +(maxY-r.getY()) - ba.getHalfLeading()); - } + LinkedRectangle r = (LinkedRectangle) re.nextElement(); + r.setX(r.getX() + ac.getXPosition() + + area.getTableCellXOffset()); + r.setY(ac.getYPosition() - height + (maxY - r.getY()) - + ba.getHalfLeading()); + } } - + // intermediate implementation for joining all sublinks on same line public void mergeLinks() { - int numRects = rects.size(); - if (numRects == 1) - return; - - LinkedRectangle curRect = - new LinkedRectangle((LinkedRectangle)rects.elementAt(0)); - Vector nv = new Vector(); - - for (int ri=1; ri < numRects; ri++) { - LinkedRectangle r = (LinkedRectangle)rects.elementAt(ri); - - // yes, I'm really happy with comparing refs... - if (r.getLineArea() == curRect.getLineArea()) { - curRect.setWidth( r.getX() + r.getWidth() - curRect.getX() ); - } else { - nv.addElement(curRect); - curRect = new LinkedRectangle(r); - } - - if (ri == numRects-1) - nv.addElement(curRect); - } - - rects = nv; + int numRects = rects.size(); + if (numRects == 1) + return; + + LinkedRectangle curRect = + new LinkedRectangle((LinkedRectangle) rects.elementAt(0)); + Vector nv = new Vector(); + + for (int ri = 1; ri < numRects; ri++) { + LinkedRectangle r = (LinkedRectangle) rects.elementAt(ri); + + // yes, I'm really happy with comparing refs... + if (r.getLineArea() == curRect.getLineArea()) { + curRect.setWidth(r.getX() + r.getWidth() - curRect.getX()); + } else { + nv.addElement(curRect); + curRect = new LinkedRectangle(r); + } + + if (ri == numRects - 1) + nv.addElement(curRect); + } + + rects = nv; } - + public void align() { - Enumeration re = rects.elements(); - while (re.hasMoreElements()) { - LinkedRectangle r = (LinkedRectangle)re.nextElement(); - r.setX( r.getX() + r.getLineArea().getStartIndent() ); - } + Enumeration re = rects.elements(); + while (re.hasMoreElements()) { + LinkedRectangle r = (LinkedRectangle) re.nextElement(); + r.setX(r.getX() + r.getLineArea().getStartIndent()); + } } public String getDest() { - return this.destination; + return this.destination; } public Vector getRects() { - return this.rects; + return this.rects; } public int getEndIndent() { - return endIndent; + return endIndent; } - + public int getStartIndent() { - return startIndent; + return startIndent; } - + public Area getArea() { - return area; + return area; } - public int getLinkType(){ + public int getLinkType() { return linkType; } } -- 2.39.5