<default>start</default>
</property>
<property>
- <name>white-space-treatment</name>
+ <name>white-space-collapse</name>
<inherited>true</inherited>
<datatype>Enum</datatype>
<enumeration>
- <value const="PRESERVE">preserve</value>
- <value const="COLLAPSE">collapse</value>
- <value const="IGNORE">ignore</value>
+ <value const="TRUE">true</value>
+ <value const="FALSE">false</value>
</enumeration>
- <default>collapse</default>
+ <default>true</default>
</property>
<property>
<name>break-after</name>
<default>start</default>
</property>
<property>
- <name>white-space-treatment</name>
- <class-name>WhiteSpaceTreatment</class-name>
+ <name>white-space-collapse</name>
+ <class-name>WhiteSpaceCollapse</class-name>
<inherited>true</inherited>
- <datatype>
+ <datatype>Enum</datatype>
<enumeration>
- <value const="PRESERVE">preserve</value>
- <value const="COLLAPSE">collapse</value>
- <value const="IGNORE">ignore</value>
+ <value const="TRUE">true</value>
+ <value const="FALSE">false</value>
</enumeration>
- </datatype>
- <default>collapse</default>
+ <default>true</default>
</property>
<property>
<name>break-after</name>
*
*/
public class PrintCommandLine extends CommandLine {
+
public PrintCommandLine(String args []) {
super (args);
}
-
public static void main(String[] args) {
-
String version = Version.getVersion();
MessageHandler.errorln(version);
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();
-/*-- $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
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.fop.fo;
float green;
float blue;
int wrapOption;
- int whiteSpaceTreatment;
+ int whiteSpaceCollapse;
// Textdecoration
protected boolean underlined = false;
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) {
}
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);
+ }
}
}
-/*-- $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
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.fop.fo.flow;
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;
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);
}
}
-/*-- $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
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.fop.fo.flow;
/**
* 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
* 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();
}
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();
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);
}
-/*-- $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
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.fop.layout;
import java.util.Enumeration;
public class BlockArea extends Area {
-
+
/* relative to area container */
protected int startIndent;
protected int endIndent;
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;
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;
}
-/*-- $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
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.fop.layout;
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;
/* 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;
}
- 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.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;
}
}
-/*-- $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
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
/* this class contributed by Arved Sandstrom with minor modifications
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
private int xoffset = 0;
private int yoffset = 0;
-
+
/* the maximum Y offset value encountered for this LinkSet*/
private int maxY = 0;
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;
}
}