From: fotis Date: Sat, 25 Nov 2000 17:05:49 +0000 (+0000) Subject: adds support for properties leader-align, leader-pattern-width, leader-length.minimu... X-Git-Tag: pre-columns~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fae2cca323afc3f7b10f98a59e5f3c582a717f98;p=xmlgraphics-fop.git adds support for properties leader-align, leader-pattern-width, leader-length.minimum, leader-length.maximum and leader-pattern (values: dots, space) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193837 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/examples/fo/leader.fo b/docs/examples/fo/leader.fo index 0fe7ee16f..2ba7ff964 100644 --- a/docs/examples/fo/leader.fo +++ b/docs/examples/fo/leader.fo @@ -6,79 +6,679 @@ - + - - - + - - - - - - + + + Leader examples + + + + leader with leader-pattern="space" + + + + Entry 1 + p. 12 + + + + Entry 2 + p. 24 + + + + Left side + middle + right side + + + + + Using fo:leader with leader-pattern="dots" + + + + Entry 1 + p. 12 + + + + Entry 2 + p. 24 + + + + + Using fo:leader with leader-pattern="dots" and leader-pattern-width="5pt" and "8pt" + + + + Entry 1 + p. 12 + + + + Entry 2 + p. 24 + + + + + Entry 1 + p. 12 + + + + Entry 2 + p. 24 + + + + Using fo:leader with leader-pattern="dots" in a list + + + + Using fo:leader with leader-pattern="dots", leader-pattern-width="5pt" and "8pt", leader-alignment="reference-area" + + + + Entry 1 + p. 12 + + + + Entry 2 + p. 24 + + + + Entry 3 is longer + p. 36 + + + + Entry 4 is even longer + p. 48 + + + + + 1 + p. 12 + + + + Entry 2 + p. 24 + + + + + Entry 3 is longer + p. 36 + + + + Entry 4 is even longer + p. 48 + + + + + + + + + + + + + + · + + + + + + Entry 1 + p. 12 + + + + + + + + + + · + + + + + + Entry 2 + p. 24 + + + + + + + - This document has been reviewed by W3C Members and other interested parties and has been endorsed by the Director as a - W3C Recommendation. It is a stable document and may be used as reference material or cited as a normative reference from - another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its - widespread deployment. - Here comes a line (thickness: 3pt). + Using fo:leader with leader-pattern="dots" in a table + + + + + + + + + + + Entry 1 + + + + + + p. 12 + + + Entry 2 + + + + + + p. 24 + + + Entry 3 + + + + + + p. 36 + + + + + + + + Leader with leader-pattern="rule" - + text before the rule (start) + end-indent="2cm" + background-color="blue" + color="yellow"/> + text after the rule + + + + text before the rule (center) + + text after the rule + + + + text before the rule (end) + + text after the rule + + + + Here are 3 fo:leader with the property rule and no text + + + + + + + + + + + + + + + - This document specifies a syntax created by subsetting an existing, widely used international text processing standard - (Standard Generalized Markup Language, ISO 8879:1986(E) as amended and corrected) for use on the World Wide Web. It - is a product of the W3C XML Activity, details of which can be found at http://www.w3.org/XML. A list of current W3C - Recommendations and other technical documents can be found at http://www.w3.org/TR. - Here comes a line (thickness: 1pt (default)) + Here are 4 fo:leader with increasing rule-thickness (1pt, 2pt, 3pt, 4pt) + - + + + + + + space-after.optimum="12pt"> + + + + + + + + + + + + + + + Using leader in combination with justified text + + + + Here is some longer text. Here is some longer text. + Here is some longer text. Here comes the leader (dots width 8pt): + Here is some longer text. Here is some longer text. + Here is some longer text. Here is some longer text. Here is some longer text. + + + Here is some longer text. Here is some longer text. + Here is some longer text. Here comes the leader (dots width 5pt): + Here is some longer text. Here is some longer text. + Here is some longer text. Here is some longer text. Here is some longer text. + + + Here is some longer text. Here is some longer text. + Here is some longer text. Here comes the leader (dots): + Here is some longer text. Here is some longer text. + Here is some longer text. Here is some longer text. Here is some longer text. + + + + Here is some longer text. Here is some longer text. + Here is some longer text. Here comes the leader (rule): + Here is some longer text. Here is some longer text. + Here is some longer text. Here is some longer text. Here is some longer text. + + + Here is some longer text. Here is some longer text. + Here is some longer text. Here comes the leader (space): + Here is some longer text. Here is some longer text. + Here is some longer text. Here is some longer text. Here is some longer text. + + + + + Table of Content + + + + shows the use of leader properties in combination to build a table of content. + Following values are used for the leader: + leader-pattern="dots" + leader-pattern-width="8pt" + leader-alignment="reference-area" + leader-length.maximum="14cm" + + + + + + + + + + + + A) + What is FOP? + 1 + + + + + B) + Downloading FOP + 2 + + + + C) + Running FOP + 3 + + + + D) + Embedding FOP + 4 + + + + E) + What is Implemented? + 5 + + + + + + + + Table of Content 2 + + + + shows the use of leader-length.minimum in the middle column. Values are increased from 0cm (default) + to 0.5 and then to 1cm + + + + + + + + + + + + A) + What is FOP doing here in the middle? + 1 + + + + A) + What is FOP doing here in the middle? + 1 + + + + A) + What is FOP doing here in the middle? + 1 + + + + + + + The text/leader combination from table 1 without the table + + + +What is FOP? + +Downloading FOP + +Running FOP + +Embedding FOP + +What is Implemented? + + + diff --git a/src/codegen/foproperties.xml b/src/codegen/foproperties.xml index b938ca924..59e1d4358 100644 --- a/src/codegen/foproperties.xml +++ b/src/codegen/foproperties.xml @@ -753,8 +753,33 @@ Length + + + leader-pattern-width + LeaderPatternWidth + true + Length + use-font-metrics + 0pt + + + + + leader-alignment + true + Enum + + none + reference-area + page + + none + + scaling true diff --git a/src/org/apache/fop/fo/flow/Leader.java b/src/org/apache/fop/fo/flow/Leader.java index 0f07a6ffa..4608254e4 100644 --- a/src/org/apache/fop/fo/flow/Leader.java +++ b/src/org/apache/fop/fo/flow/Leader.java @@ -56,128 +56,113 @@ import org.apache.fop.fo.properties.*; import org.apache.fop.datatypes.*; import org.apache.fop.layout.Area; import org.apache.fop.layout.BlockArea; -import org.apache.fop.layout.RuleArea; +import org.apache.fop.layout.LeaderArea; import org.apache.fop.layout.FontState; import org.apache.fop.apps.FOPException; import org.apache.fop.messaging.MessageHandler; /** - * This is just a basic implementation mostly based on the code of display-rule - * It only supports the property leader-pattern="rule", nothing else, not even - * leader-pattern="space" - * + * Implements fo:leader; main property of leader leader-pattern. + * The following patterns are treated: rule, space, dots. + * The pattern use-content is ignored, i.e. it still must be implemented. */ -public class Leader extends FObj { +public class Leader extends FObjMixed { - public static class Maker extends FObj.Maker { - public FObj make(FObj parent, PropertyList propertyList) - throws FOPException { - return new Leader(parent, propertyList); - } - } - - public static FObj.Maker maker() { - return new Leader.Maker(); - } - - public Leader(FObj parent, PropertyList propertyList) { - super(parent, propertyList); - this.name = "fo:leader"; - } - - public Status layout(Area area) throws FOPException { - - 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(); - - FontState fs = new FontState(area.getFontInfo(), fontFamily, - fontStyle, fontWeight, fontSize); - - int align = this.properties.get("text-align").getEnum(); - int startIndent = - this.properties.get("start-indent").getLength().mvalue(); - int endIndent = - this.properties.get("end-indent").getLength().mvalue(); - int spaceBefore = - this.properties.get("space-before.optimum").getLength().mvalue(); - int spaceAfter = - this.properties.get("space-after.optimum").getLength().mvalue(); - int ruleThickness = - this.properties.get("rule-thickness").getLength().mvalue(); - int ruleLength = this.properties.get("leader-length").getLength().mvalue(); - int leaderPattern = this.properties.get("leader-pattern").getEnum(); - - - ColorType c = this.properties.get("color").getColorType(); - float red = c.red(); - float green = c.green(); - float blue = c.blue(); - - if (area instanceof BlockArea) { - area.end(); - } - - if (spaceBefore != 0) { - area.addDisplaySpace(spaceBefore); + public static class Maker extends FObj.Maker { + public FObj make(FObj parent, + PropertyList propertyList) throws FOPException { + return new Leader(parent, propertyList); + } } - if (this.isInLabel) { - startIndent += bodyIndent; - endIndent += (area.getAllocationWidth() - - distanceBetweenStarts - startIndent) + - labelSeparation; + public static FObj.Maker maker() { + return new Leader.Maker(); } - if (this.isInListBody) { - startIndent += bodyIndent + distanceBetweenStarts; + public Leader(FObj parent, PropertyList propertyList) { + super(parent, propertyList); + this.name = "fo:leader"; } - if (this.isInTableCell) { - startIndent += forcedStartOffset; - endIndent += area.getAllocationWidth() - forcedWidth - - forcedStartOffset; + public Status layout(Area area) throws FOPException { + BlockArea blockArea; + //restriction in this version + if (!(area instanceof BlockArea)) { + MessageHandler.errorln("WARNING: in this version of Fop fo:leader must be a direct child of fo:block "); + return new Status(Status.OK); + } else { + blockArea = (BlockArea) area; + } + + //retrieving font property information for fo:leader + 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(); + //wrapping it up into Fontstate + FontState fontstate = new FontState(area.getFontInfo(), fontFamily, + fontStyle, fontWeight, fontSize); + //color properties + ColorType c = this.properties.get("color").getColorType(); + float red = c.red(); + float green = c.green(); + float blue = c.blue(); + + //fo:leader specific properties + //determines the pattern of leader; allowed values: space, rule,dots, use-content + int leaderPattern = this.properties.get("leader-pattern").getEnum(); + //length of the leader + int leaderLengthOptimum = this.properties.get( + "leader-length.optimum").getLength().mvalue(); + int leaderLengthMinimum = this.properties.get( + "leader-length.minimum").getLength().mvalue(); + //brute force method to set default, because default values cannot be set + //in the properties classes for all subtypes + if (leaderLengthMinimum == 12000) { + leaderLengthMinimum = 0; + } + int leaderLengthMaximum = this.properties.get( + "leader-length.maximum").getLength().mvalue(); + //here too + if (leaderLengthMaximum == 12000) { + leaderLengthMaximum = 24000; + } + //the following properties only apply for leader-pattern = "rule" + int ruleThickness = this.properties.get( + "rule-thickness").getLength().mvalue(); + int ruleStyle = this.properties.get("rule-style").getEnum(); + // if leaderPatternWidth = 0 = default = use-font-metric + int leaderPatternWidth = this.properties.get( + "leader-pattern-width").getLength().mvalue(); + int leaderAlignment = + this.properties.get("leader-alignment").getEnum(); + + // initialize id + String id = this.properties.get("id").getString(); + blockArea.getIDReferences().initializeID(id, blockArea); + + //adds leader to blockarea, there the leaderArea is generated + int succeeded = blockArea.addLeader(fontstate, red, green, blue, + leaderPattern, leaderLengthMinimum, + leaderLengthOptimum, leaderLengthMaximum, + ruleThickness, ruleStyle, leaderPatternWidth, + leaderAlignment); + if (succeeded == 1) { + return new Status(Status.OK); + } else { + //not sure that this is the correct Status here + return new Status(Status.AREA_FULL_SOME); + } } - // initialize id - String id = this.properties.get("id").getString(); - area.getIDReferences().initializeID(id,area); - - switch (leaderPattern) { - case LeaderPattern.SPACE: - ruleThickness = 0; - MessageHandler.errorln("leader-pattern=\"space\" not supported by this version of Fop"); - break; - case LeaderPattern.RULE: - break; - case LeaderPattern.DOTS: - MessageHandler.errorln("leader-pattern=\"dots\" not supported by this version of Fop"); - break; - case LeaderPattern.USECONTENT: - MessageHandler.errorln("leader-pattern=\"use-content\" not supported by this version of Fop"); - break; - } - RuleArea ruleArea = new RuleArea(fs, - area.getAllocationWidth(), - area.spaceLeft(), - startIndent, endIndent, - align, ruleThickness, - ruleLength, red, green, - blue); - - area.addChild(ruleArea); - area.increaseHeight(ruleArea.getHeight()); - - if (spaceAfter != 0) { - area.addDisplaySpace(spaceAfter); - } + /* //should only be necessary for use-content + protected void addCharacters(char data[], int start, int length) { + FOText textNode = new FOText(data,start,length, this); + children.addElement(textNode); + } + */ - if (area instanceof BlockArea) { - area.start(); - } - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/layout/BlockArea.java b/src/org/apache/fop/layout/BlockArea.java index faafc454f..214d95c20 100644 --- a/src/org/apache/fop/layout/BlockArea.java +++ b/src/org/apache/fop/layout/BlockArea.java @@ -56,6 +56,7 @@ import org.apache.fop.render.Renderer; // Java import java.util.Vector; import java.util.Enumeration; +import org.apache.fop.messaging.MessageHandler; public class BlockArea extends Area { @@ -190,6 +191,78 @@ public class BlockArea extends Area { return -1; } + + /** + * adds a leader to current line area of containing block area + * the actual leader area is created in the line area + * + * @return int +1 for success and -1 for none + */ + public int addLeader(FontState fontState, float red, float green, + float blue, int leaderPattern, int leaderLengthMinimum, + int leaderLengthOptimum, int leaderLengthMaximum, + int ruleThickness, int ruleStyle, int leaderPatternWidth, + int leaderAlignment) { + + //this should start a new page + if (currentHeight + currentLineArea.getHeight() > maxHeight) { + return -1; + } + + this.currentLineArea.changeFont(fontState); + this.currentLineArea.changeColor(red, green, blue); + + //check whether leader fits into the (rest of the) line + //if leader is longer then create a new LineArea and put leader there + if (leaderLengthMinimum <= (this.getContentWidth() - + this.currentLineArea.finalWidth - + this.currentLineArea.pendingWidth)) { + this.currentLineArea.addLeader(leaderPattern, + leaderLengthMinimum, leaderLengthOptimum, + leaderLengthMaximum, ruleStyle, ruleThickness, + leaderPatternWidth, leaderAlignment); + } else { + //finish current line area and put it into children vector + this.currentLineArea.align(this.align); + this.addLineArea(this.currentLineArea); + + //create new line area + this.currentLineArea = + new LineArea(fontState, lineHeight, halfLeading, + allocationWidth, startIndent, endIndent, + currentLineArea); + this.currentLineArea.changeFont(fontState); + this.currentLineArea.changeColor(red, green, blue); + + if (currentHeight + currentLineArea.getHeight() > + this.maxHeight) { + return -1; + } + + //check whether leader fits into LineArea at all, otherwise + //clip it (should honor the clip option of containing area) + if (leaderLengthMinimum <= + this.currentLineArea.getContentWidth()) { + this.currentLineArea.addLeader(leaderPattern, + leaderLengthMinimum, leaderLengthOptimum, + leaderLengthMaximum, ruleStyle, ruleThickness, + leaderPatternWidth, leaderAlignment); + } else { + MessageHandler.errorln("Leader doesn't fit into line, it will be clipped to fit."); + this.currentLineArea.addLeader(leaderPattern, + this.currentLineArea.getContentWidth() - + this.currentLineArea.finalWidth - + this.currentLineArea.pendingWidth, + leaderLengthOptimum, leaderLengthMaximum, + ruleStyle, ruleThickness, leaderPatternWidth, + leaderAlignment); + } + } + this.hasLines = true; + return 1; + } + + public void end() { if (this.hasLines) { this.currentLineArea.addPending(); diff --git a/src/org/apache/fop/layout/InlineSpace.java b/src/org/apache/fop/layout/InlineSpace.java index 4ff64cd43..95a9efb96 100644 --- a/src/org/apache/fop/layout/InlineSpace.java +++ b/src/org/apache/fop/layout/InlineSpace.java @@ -54,11 +54,17 @@ import org.apache.fop.render.Renderer; public class InlineSpace extends Space { private int size; // in millipoints + private boolean resizeable = true; //to disallow size changes during justification of a line public InlineSpace(int amount) { this.size = amount; } + public InlineSpace(int amount, boolean resizeable) { + this.resizeable = resizeable; + this.size = amount; + } + public int getSize() { return size; } @@ -67,6 +73,14 @@ public class InlineSpace extends Space { this.size = amount; } + public boolean getResizeable() { + return resizeable; + } + + public void setResizeable(boolean resizeable) { + this.resizeable = resizeable; + } + public void render(Renderer renderer) { renderer.renderInlineSpace(this); } diff --git a/src/org/apache/fop/layout/LeaderArea.java b/src/org/apache/fop/layout/LeaderArea.java new file mode 100644 index 000000000..ff8b31520 --- /dev/null +++ b/src/org/apache/fop/layout/LeaderArea.java @@ -0,0 +1,95 @@ +/*-- $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 + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.layout; + +import org.apache.fop.render.Renderer; + +import java.util.Vector; +import java.util.Enumeration; + +public class LeaderArea extends InlineArea { + + int ruleThickness; + int leaderLengthOptimum; + int leaderPattern; + int ruleStyle; + + float red, green, blue; + public LeaderArea(FontState fontState, float red, float green, + float blue, String text, int leaderLengthOptimum, + int leaderPattern, int ruleThickness, int ruleStyle) { + super(fontState, red, green, blue, text, leaderLengthOptimum); + + this.ruleThickness = ruleThickness; + this.leaderPattern = leaderPattern; + this.leaderLengthOptimum = leaderLengthOptimum; + this.ruleStyle = ruleStyle; + } + + public void render(Renderer renderer) { + renderer.renderLeaderArea(this); + } + public int getRuleThickness() { + return this.ruleThickness; + } + public int getRuleStyle() { + return this.ruleStyle; + } + public int getLeaderPattern() { + return this.leaderPattern; + } + public int getLeaderLength() { + return this.contentRectangleWidth; + } + + + +} diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index 5197b03b6..923e549e6 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -53,6 +53,7 @@ package org.apache.fop.layout; import org.apache.fop.render.Renderer; import org.apache.fop.messaging.MessageHandler; +import org.apache.fop.layout.LeaderArea; import java.util.Vector; import java.util.Enumeration; @@ -66,6 +67,8 @@ import org.apache.fop.fo.properties.TextAlign; // for enumerated // values import org.apache.fop.fo.properties.TextAlignLast; // for enumerated // values +import org.apache.fop.fo.properties.LeaderPattern; +import org.apache.fop.fo.properties.LeaderAlignment; import org.apache.fop.datatypes.IDNode; @@ -179,6 +182,11 @@ public class LineArea extends Area { } + /** + * adds text to line area + * + * @return int character position + */ public int addText(char odata[], int start, int end, LinkSet ls, boolean ul) { boolean overrun = false; @@ -248,17 +256,19 @@ public class LineArea extends Area { 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); + Box box = (Box) e.nextElement(); + if (box instanceof InlineArea) { + if (ls != null) { + Rectangle lr = new Rectangle(finalWidth, 0, + ((InlineArea) box). + getContentWidth(), + fontState.getFontSize()); + ls.addRect(lr, this); + } } - - addChild(inlineArea); + addChild(box); } + finalWidth += pendingWidth; // reset pending areas array @@ -300,9 +310,9 @@ public class LineArea extends Area { if (this.spaceTreatment == SpaceTreatment.IGNORE) { // do nothing - } else { + } else { spaceWidth = currentFontState.width(32); - } + } */ @@ -406,6 +416,113 @@ public class LineArea extends Area { return -1; } + /** + * adds a Leader; actually the method receives the leader properties + * and creates a leader area or an inline area which is appended to + * the children of the containing line area.
+ * leader pattern use-content is not implemented. + */ + public void addLeader(int leaderPattern, int leaderLengthMinimum, + int leaderLengthOptimum, int leaderLengthMaximum, + int ruleStyle, int ruleThickness, int leaderPatternWidth, + int leaderAlignment) { + InlineArea leaderPatternArea; + int leaderLength; + int remainingWidth = this.getContentWidth() - this.getCurrentXPosition(); + + //here is the point to decide which leader-length is to be used, either + //optimum or maximum. At the moment maximum is used if the remaining + //width isn't smaller. In this case only the remaining width is used for + //the leader. Actually this means, optimum is never used at the moment. + if (remainingWidth < leaderLengthMaximum) { + leaderLength = remainingWidth; + } else { + leaderLength = leaderLengthMaximum; + } + switch (leaderPattern) { + case LeaderPattern.SPACE: + //whitespace setting must be false for this + int whiteSpaceSetting = this.whiteSpaceCollapse; + this.changeWhiteSpaceCollapse(WhiteSpaceCollapse.FALSE); + pendingAreas.addElement(this.buildSimpleLeader(32,leaderLength)); + this.changeWhiteSpaceCollapse(whiteSpaceSetting); + break; + case LeaderPattern.RULE: + LeaderArea leaderArea = + new LeaderArea(fontState, red, green, blue, "", + leaderLength, leaderPattern, ruleThickness, + ruleStyle); + pendingAreas.addElement(leaderArea); + break; + case LeaderPattern.DOTS: + //if the width of a dot is larger than leader-pattern-width + //ignore this property + if (leaderPatternWidth < this.currentFontState.width(46)) { + leaderPatternWidth = 0; + } + //if value of leader-pattern-width is 'use-font-metrics' (0) + if (leaderPatternWidth == 0) { + pendingAreas.addElement(this.buildSimpleLeader(46,leaderLength)); + } else { + //if leader-alignment is used, calculate space to insert before leader + //so that all dots will be parallel. + if (leaderAlignment == LeaderAlignment.REFERENCE_AREA) { + int spaceBeforeLeader = + this.getLeaderAlignIndent(leaderLength, + leaderPatternWidth); + //appending indent space leader-alignment + //setting InlineSpace to false, so it is not used in line justification + if (spaceBeforeLeader != 0) { + pendingAreas.addElement( + new InlineSpace(spaceBeforeLeader,false)); + pendingWidth += spaceBeforeLeader; + //shorten leaderLength, otherwise - in case of + //leaderLength=remaining length - it will cut off the end of + //leaderlength + leaderLength -= spaceBeforeLeader; + } + } + + // calculate the space to insert between the dots and create a + //inline area with this width + InlineSpace spaceBetweenDots = + new InlineSpace(leaderPatternWidth - + this.currentFontState.width(46),false); + leaderPatternArea = new InlineArea(currentFontState, this.red, + this.green, this.blue, new String ("."), + this.currentFontState.width(46)); + int dotsFactor = (int) Math.floor (((double) leaderLength )/ + ((double)leaderPatternWidth)); + + //add combination of dot + space to fill leader + //is there a way to do this in a more effective way? + for (int i = 0; i < dotsFactor; i++) { + pendingAreas.addElement(leaderPatternArea); + pendingAreas.addElement(spaceBetweenDots); + } + //append at the end some space to fill up to leader length + pendingAreas.addElement( new InlineSpace(leaderLength - + dotsFactor * leaderPatternWidth)); + } + break; + //leader pattern use-content not implemented. + case LeaderPattern.USECONTENT: + MessageHandler.errorln("leader-pattern=\"use-content\" not " + + "supported by this version of Fop"); + return; + } + //adds leader length to length of pending inline areas + pendingWidth += leaderLength; + //sets prev to TEXT and makes so sure, that also blocks only + //containing leaders are processed + prev = TEXT; + } + + /** + * adds pending inline areas to the line area + * normally done,if the line area is filled and + * added as child to the parent block area + */ public void addPending() { if (spaceWidth > 0) { addChild(new InlineSpace(spaceWidth)); @@ -415,9 +532,10 @@ public class LineArea extends Area { Enumeration e = pendingAreas.elements(); while (e.hasMoreElements()) { - InlineArea inlineArea = (InlineArea) e.nextElement(); - addChild(inlineArea); + Box box = (Box) e.nextElement(); + addChild(box); } + finalWidth += pendingWidth; // reset pending areas array @@ -425,6 +543,10 @@ public class LineArea extends Area { pendingAreas = new Vector(); } + /** + * aligns line area + * + */ public void align(int type) { int padding = 0; @@ -451,8 +573,10 @@ public class LineArea extends Area { Box b = (Box) e.nextElement(); if (b instanceof InlineSpace) { InlineSpace space = (InlineSpace) b; - spaceList.addElement(space); - spaceCount++; + if (space.getResizeable()) { + spaceList.addElement(space); + spaceCount++; + } } } if (spaceCount > 0) { @@ -524,4 +648,51 @@ public class LineArea extends Area { pendingWidth = width; } + /** + * creates a leader as String out of the given char and the leader length + * and wraps it in an InlineArea which is returned + */ + private InlineArea buildSimpleLeader(int charNumber,int leaderLength) { + int factor = (int) Math.floor (leaderLength / + this.currentFontState.width(charNumber)); + char [] leaderChars = new char [factor]; + char fillChar = (char) charNumber; + for (int i = 0; i < factor; i ++) { + leaderChars[i] = fillChar; + } + InlineArea leaderPatternArea = new InlineArea(currentFontState, this.red, + this.green, this.blue, new String (leaderChars), + leaderLength); + return leaderPatternArea; + } + + /** + * calculates the width of space which has to be inserted before the + * start of the leader, so that all leader characters are aligned. + * is used if property leader-align is set. At the moment only the value + * for leader-align="reference-area" is supported. + * + */ + private int getLeaderAlignIndent (int leaderLength, + int leaderPatternWidth ) { + //calculate position of used space in line area + double position = getCurrentXPosition(); + //calculate factor of next leader pattern cycle + double nextRepeatedLeaderPatternCycle = + Math.ceil(position / leaderPatternWidth); + //calculate difference between start of next leader + //pattern cycle and already used space + double difference = (leaderPatternWidth * + nextRepeatedLeaderPatternCycle) - position; + return (int) difference; + } + + /** + * calculates the used space in this line area + */ + private int getCurrentXPosition() { + return finalWidth + spaceWidth + startIndent + pendingWidth; + } + + } diff --git a/src/org/apache/fop/layout/RuleArea.java b/src/org/apache/fop/layout/RuleArea.java deleted file mode 100644 index 5c8c19d26..000000000 --- a/src/org/apache/fop/layout/RuleArea.java +++ /dev/null @@ -1,109 +0,0 @@ -/*-- $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 - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . - - */ -package org.apache.fop.layout; - -import org.apache.fop.render.Renderer; - -import java.util.Vector; -import java.util.Enumeration; - -public class RuleArea extends Area { - - int align; // text-align - int length; // length in millipoints - int ruleThickness; - - int startIndent; - int endIndent; - - float red, green, blue; - public RuleArea(FontState fontState, int allocationWidth, int maxHeight, int startIndent, int endIndent, int align, int ruleThickness, int length, float red, float green, float blue) { - super(fontState,allocationWidth,maxHeight); - - this.contentRectangleWidth = allocationWidth - startIndent - endIndent; - this.align = align; - - this.startIndent = startIndent; - this.endIndent = endIndent; - this.ruleThickness = ruleThickness; - this.length = length; - this.currentHeight = maxHeight; - - this.red = red; - this.green = green; - this.blue = blue; - } - - public void render(Renderer renderer) { - renderer.renderRuleArea(this); - } - public float getBlue() { - return this.blue; - } - public int getEndIndent() { - return endIndent; - } - public float getGreen() { - return this.green; - } - public int getHeight() { - return this.ruleThickness; - } - public float getRed() { - return this.red; - } - public int getRuleThickness() { - return this.ruleThickness; - } - public int getStartIndent() { - return startIndent; - } -} diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index 7be02db74..8afac542d 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -107,6 +107,7 @@ public interface Renderer { /** render the given page */ public void renderPage(Page page); - /** render the given rule area */ - public void renderRuleArea(RuleArea area); + /** render the given leader area */ + public void renderLeaderArea(LeaderArea area); + } diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index 809bcff7f..ce0559d77 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -613,29 +613,31 @@ public class AWTRenderer implements Renderer, Printable, Pageable { this.currentYPosition = ry - h; } - /** - * render rule area into PDF - * - * @param area area to render - */ - public void renderRuleArea(RuleArea area) { - int rx = this.currentAreaContainerXPosition + area.getStartIndent(); - int ry = this.currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - int th = area.getRuleThickness(); - float r = area.getRed(); - float g = area.getGreen(); - float b = area.getBlue(); - Color oldColor = graphics.getColor(); + /** + * render leader area into AWT + * + * @param area area to render + */ + public void renderLeaderArea(LeaderArea area) { + + int rx = this.currentXPosition; + int ry = this.currentYPosition; + int w = area.getLeaderLength(); + int h = area.getHeight(); + int th = area.getRuleThickness(); + int st = area.getRuleStyle(); //not used at the moment + float r = area.getRed(); + float g = area.getGreen(); + float b = area.getBlue(); + Color oldColor = graphics.getColor(); + + graphics.setColor(new Color(r, g, b)); + graphics.fillRect((int)(rx / 1000f), (int)(pageHeight - ry / 1000f), + (int)(w / 1000f), (int)(th / 1000f)); + graphics.setColor(oldColor); + this.currentXPosition += area.getContentWidth(); + } - graphics.setColor(new Color(r, g, b)); - graphics.fillRect((int)(rx / 1000f), - (int)(pageHeight - ry / 1000f), (int)(w / 1000f), - (int)(th / 1000f)); - graphics.setColor(oldColor); - - } public void renderSVGArea(SVGArea area) { diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 0de1cfab0..c83d5f147 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -665,19 +665,20 @@ public class PDFRenderer implements Renderer { } /** - * render rule area into PDF + * render leader area into PDF * * @param area area to render */ - public void renderRuleArea(RuleArea area) { - int rx = this.currentAreaContainerXPosition - + area.getStartIndent(); + public void renderLeaderArea(LeaderArea area) { + int rx = this.currentXPosition;; int ry = this.currentYPosition; int w = area.getContentWidth(); int h = area.getHeight(); int th = area.getRuleThickness(); - + int st = area.getRuleStyle(); //not used at the moment + addLine(rx, ry, rx+w, ry, th, new PDFColor(area.getRed(), area.getGreen(),area.getBlue())); + this.currentXPosition += area.getContentWidth(); } /** diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index aff72e19a..85b83f459 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -59,6 +59,7 @@ import org.apache.fop.render.Renderer; import org.apache.fop.image.ImageArea; import org.apache.fop.layout.*; import org.apache.fop.pdf.*; +import org.apache.fop.fo.properties.LeaderPattern; // Java import java.io.IOException; @@ -317,20 +318,32 @@ public class XMLRenderer implements Renderer { } /** - * render a rule area to XML - * - * @param area the area to render - */ - public void renderRuleArea(RuleArea area) { - writeEmptyElementTag(""); + * render a leader area to XML + * + * @param area the area to render + */ + public void renderLeaderArea(LeaderArea area) { + String leaderPattern = ""; + switch (area.getLeaderPattern()) { + case LeaderPattern.SPACE: + leaderPattern = "space"; + break; + case LeaderPattern.RULE: + leaderPattern = "rule"; + break; + case LeaderPattern.DOTS: + leaderPattern = "dots"; + break; + case LeaderPattern.USECONTENT: + leaderPattern = "use-content"; + break; + } + + writeEmptyElementTag(""); } }