diff options
Diffstat (limited to 'src')
10 files changed, 33 insertions, 413 deletions
diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java index d285744e4..af1db5c6d 100644 --- a/src/java/org/apache/fop/fo/Constants.java +++ b/src/java/org/apache/fop/fo/Constants.java @@ -817,13 +817,10 @@ public interface Constants { int PR_X_HEADER_COLUMN = 290; /** Property constant */ - int PR_X_FITTING_STRATEGY = 291; - - /** Property constant */ - int PR_X_AUTO_TOGGLE = 292; + int PR_X_AUTO_TOGGLE = 291; /** Number of property constants defined */ - int PROPERTY_COUNT = 292; + int PROPERTY_COUNT = 291; // compound property constants diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 31166abd7..c10d9caaa 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -2617,12 +2617,6 @@ public final class FOPropertyMapping implements Constants { m.setDefault(""); addPropertyMaker("fox:alt-text", m); - // fox:fitting-strategy, used only in fox:best-fit - m = new StringProperty.Maker(PR_X_FITTING_STRATEGY); - m.setInherited(false); - m.setDefault("first-fit"); - addPropertyMaker("fox:fitting-strategy", m); - // fox:auto-toggle, used only in fo:multi-switch m = new StringProperty.Maker(PR_X_AUTO_TOGGLE); m.setInherited(false); diff --git a/src/java/org/apache/fop/fo/extensions/BestFit.java b/src/java/org/apache/fop/fo/extensions/BestFit.java deleted file mode 100644 index 461dd7a26..000000000 --- a/src/java/org/apache/fop/fo/extensions/BestFit.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.fop.fo.extensions; - -import org.xml.sax.Locator; - -import org.apache.fop.apps.FOPException; -import org.apache.fop.fo.FONode; -import org.apache.fop.fo.FObj; -import org.apache.fop.fo.ValidationException; -import org.apache.fop.fo.flow.MultiCaseHandler; -import org.apache.fop.fo.flow.MultiSwitch; -import org.apache.fop.layoutmgr.Alternative.FittingStrategy; - -public class BestFit extends FObj implements MultiCaseHandler { - - public static final String OBJECT_NAME = "best-fit"; - private FittingStrategy strategy; - - public BestFit(FONode parent) { - super(parent); - } - - public void setFittingStrategy(String strategyName) { - strategy = FittingStrategy.make(strategyName); - if (strategy == null) { - strategy = FittingStrategy.FIRST_FIT; - if (log.isWarnEnabled()) { - log.warn("Unrecognized strategy name => " + strategyName + ". Using default strategy (first-fit"); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - protected void validateChildNode(Locator loc, String nsURI, String localName) - throws ValidationException { - } - - @Override - public String getLocalName() { - return OBJECT_NAME; - } - - @Override - public String getNormalNamespacePrefix() { - return ExtensionElementMapping.STANDARD_PREFIX; - } - - @Override - public String getNamespaceURI() { - return ExtensionElementMapping.URI; - } - - public void filter(MultiSwitch multiSwitch) throws FOPException { - // Modifying the FO tree is not advised... -// FONodeIterator nodeIter = multiSwitch.getChildNodes(); -// while (nodeIter.hasNext()) { -// FONode childNode = (FONode) nodeIter.next(); -// this.addChildNode(childNode); -// } -// multiSwitch.clearChildNodes(); - } - - public FittingStrategy getStrategy() { - return strategy; - } - -} - diff --git a/src/java/org/apache/fop/fo/flow/MultiCase.java b/src/java/org/apache/fop/fo/flow/MultiCase.java index 053e0d6f2..09a854c3e 100644 --- a/src/java/org/apache/fop/fo/flow/MultiCase.java +++ b/src/java/org/apache/fop/fo/flow/MultiCase.java @@ -44,8 +44,6 @@ public class MultiCase extends FObj { // private CommonAccessibility commonAccessibility; // End of property values - private static boolean notImplementedWarningGiven = false; - /** * Base constructor * @@ -53,12 +51,6 @@ public class MultiCase extends FObj { */ public MultiCase(FONode parent) { super(parent); - - if (!notImplementedWarningGiven) { - getFOValidationEventProducer().unimplementedFeature(this, getName(), - getName(), getLocator()); - notImplementedWarningGiven = true; - } } @Override @@ -134,7 +126,7 @@ public class MultiCase extends FObj { return caseTitle; } - public boolean isActuated() { + public boolean hasToggle() { return multiCaseHandler != null; } diff --git a/src/java/org/apache/fop/fo/flow/MultiSwitch.java b/src/java/org/apache/fop/fo/flow/MultiSwitch.java index 0c1bb2cde..4197b8675 100644 --- a/src/java/org/apache/fop/fo/flow/MultiSwitch.java +++ b/src/java/org/apache/fop/fo/flow/MultiSwitch.java @@ -38,7 +38,6 @@ public class MultiSwitch extends FObj { // private CommonAccessibility commonAccessibility; // End of property values - private static boolean notImplementedWarningGiven; private FONode currentlyVisibleMultiCase; private String autoToggle; private String fittingStrategy; @@ -50,12 +49,6 @@ public class MultiSwitch extends FObj { */ public MultiSwitch(FONode parent) { super(parent); - - if (!notImplementedWarningGiven) { - getFOValidationEventProducer().unimplementedFeature(this, getName(), - getName(), getLocator()); - notImplementedWarningGiven = true; - } } /** {@inheritDoc} */ @@ -63,7 +56,6 @@ public class MultiSwitch extends FObj { public void bind(PropertyList pList) throws FOPException { super.bind(pList); autoToggle = pList.get(PR_X_AUTO_TOGGLE).getString(); - fittingStrategy = pList.get(PR_X_FITTING_STRATEGY).getString(); // autoRestore = pList.get(PR_AUTO_RESTORE); } @@ -85,7 +77,7 @@ public class MultiSwitch extends FObj { FONodeIterator nodeIter = getChildNodes(); while (nodeIter.hasNext()) { MultiCase multiCase = (MultiCase) nodeIter.next(); - if (multiCase.isActuated()) { + if (multiCase.hasToggle()) { multiCase.getHandler().filter(this); } } diff --git a/src/java/org/apache/fop/layoutmgr/Alternative.java b/src/java/org/apache/fop/layoutmgr/Alternative.java deleted file mode 100644 index 9487b7462..000000000 --- a/src/java/org/apache/fop/layoutmgr/Alternative.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.layoutmgr; - -import java.util.LinkedList; -import java.util.List; - -/** - * An alternative has a set of fitness traits (e.g. occupied bpd and ipd, - * adjustment ratio, remaining size, etc.) that determine how good its - * eligibility is when evaluated by a fitting strategy. - */ -public class Alternative { - - /** Remaining BPD after inserting the alternative. */ - private int remainingBPD; - /** Size of the alternative in block-progression-direction. */ - private final int length; - private final List<ListElement> knuthList; - private boolean enabled = true; - - public Alternative(List<ListElement> knuthList, int length) { - this.knuthList = knuthList; - this.length = length; - this.remainingBPD = 0; - } - - public List<ListElement> getKnuthList() { - return knuthList; - } - - public int getRemainingBPD() { - return remainingBPD; - } - - public int getLength() { - return length; - } - - public void setRemainingBPD(int remainingBPD) { - this.remainingBPD = remainingBPD; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public boolean isEnabled() { - return enabled; - } - - public static enum FittingStrategy { - - FIRST_FIT("first-fit") { - - @Override - public List<Alternative> filter(List<Alternative> alternatives) { - List<Alternative> alts = new LinkedList<Alternative>(); - for (Alternative alt : alternatives) { - if (alt.isEnabled()) { - alts.add(alt); - break; - } - } - return alts; - } - }, - - SMALLEST_FIT("smallest-fit") { - - @Override - public List<Alternative> filter(List<Alternative> alternatives) { - int biggestDiff = -Integer.MAX_VALUE; - Alternative bestAlt = null; - - for (Alternative alt : alternatives) { - if (alt.isEnabled() && alt.getRemainingBPD() > biggestDiff) { - biggestDiff = alt.getRemainingBPD(); - bestAlt = alt; - } - } - List<Alternative> alts = new LinkedList<Alternative>(); - alts.add(bestAlt); - return alts; - } - }, - - BIGGEST_FIT("biggest-fit") { - - @Override - public List<Alternative> filter(List<Alternative> alternatives) { - int smallestDiff = Integer.MAX_VALUE; - Alternative bestAlt = null; - - for (Alternative alt : alternatives) { - if (alt.isEnabled() && alt.getRemainingBPD() < smallestDiff) { - smallestDiff = alt.getRemainingBPD(); - bestAlt = alt; - } - } - List<Alternative> alts = new LinkedList<Alternative>(); - alts.add(bestAlt); - return alts; - } - }, - - ANY("any") { - - @Override - public List<Alternative> filter(List<Alternative> alternatives) { - List<Alternative> alts = new LinkedList<Alternative>(); - - int remainingSpace = Integer.MAX_VALUE; - for (Alternative alt : alternatives) { - if (alt.isEnabled() && alt.getLength() <= remainingSpace) { - alts.add(alt); - remainingSpace = alt.getRemainingBPD(); - } - } - return alts; - } - }; - - private String strategyName; - - FittingStrategy(String strategyName) { - this.strategyName = strategyName; - } - - public String getStrategyName() { - return strategyName; - } - - public static FittingStrategy make(String strategyName) { - for (FittingStrategy fs : FittingStrategy.values()) { - if (fs.getStrategyName().equals(strategyName)) { - return fs; - } - } - return null; - } - - /** - * @param alternatives the list of potential candidate {@link Alternative} - * @return the best alternative according to the strategy being employed - */ - public abstract List<Alternative> filter(List<Alternative> alternatives); - - } -} diff --git a/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java b/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java index af82df386..352a876d4 100644 --- a/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java +++ b/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java @@ -21,8 +21,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import org.apache.fop.layoutmgr.Alternative.FittingStrategy; - /* * Utility class used in {@link MultiSwitchLayoutManager} * to handle the <i>best-fit</i> property value if specified in {@link MultiSwitch} @@ -38,13 +36,14 @@ public final class BestFitLayoutUtils { public BestFitPosition(LayoutManager lm) { super(lm); } - + public BestFitPosition(LayoutManager lm, List<ListElement> knuthList) { + super(lm); + this.knuthList = knuthList; + } public List<Position> getPositionList() { List<Position> positions = new LinkedList<Position>(); if (knuthList != null) { - SpaceResolver.performConditionalsNotification(knuthList, 0, knuthList.size() - 1, -1); - for (ListElement elem : knuthList) { if (elem.getPosition() != null && elem.getLayoutManager() != null) { positions.add(elem.getPosition()); @@ -53,50 +52,31 @@ public final class BestFitLayoutUtils { } return positions; } - public void setKnuthList(List<ListElement> knuthList) { this.knuthList = knuthList; } - - public List<ListElement> getKnuthList() { - return knuthList; - } - - } - - public static Alternative makeAlternative(List<ListElement> childList) { - // Add a zero penalty to make the SpaceResolver - // transform Space elements into Knuth glues. - childList.add(KnuthPenalty.DUMMY_ZERO_PENALTY); - SpaceResolver.resolveElementList(childList); - int contentLength = ElementListUtils.calcContentLength(childList); - return new Alternative(childList, contentLength); } public static List<ListElement> getKnuthList(LayoutManager lm, - List<List<ListElement>> childrenLists, - FittingStrategy strategy) { + List<List<ListElement>> childrenLists) { + List<ListElement> knuthList = new LinkedList<ListElement>(); + Iterator<List<ListElement>> iter = childrenLists.iterator(); - BestFitPenalty bestFitPenalty = new BestFitPenalty(strategy, new BestFitPosition(lm)); while (iter.hasNext()) { + List<ListElement> childList = iter.next(); - bestFitPenalty.addAlternative(makeAlternative(childList)); + SpaceResolver.resolveElementList(childList); + int contentLength = ElementListUtils.calcContentLength(childList); + BestFitPenalty bestFitPenalty = + new BestFitPenalty(contentLength, childList, + new BestFitPosition(lm)); + knuthList.add(bestFitPenalty); } - // A penalty must always be preceded by a box - // to be considered as a valid breakpoint. - addKnuthPenalty(lm, knuthList, bestFitPenalty); + knuthList.add(new KnuthBox(0, new Position(lm), false)); return knuthList; } - public static void addKnuthPenalty(LayoutManager lm, List<ListElement> list, - KnuthPenalty bestFitPenalty) { - - list.add(0, new KnuthBox(0, new Position(lm), false)); - list.add(bestFitPenalty); - list.add(new KnuthBox(0, new Position(lm), false)); - } - public static List<Position> getPositionList(LayoutManager lm, PositionIterator posIter) { // "unwrap" the NonLeafPositions stored in parentIter diff --git a/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java b/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java index d3ee6f722..13c88e82c 100644 --- a/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java +++ b/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java @@ -19,10 +19,8 @@ package org.apache.fop.layoutmgr; -import java.util.LinkedList; import java.util.List; -import org.apache.fop.layoutmgr.Alternative.FittingStrategy; import org.apache.fop.layoutmgr.BestFitLayoutUtils.BestFitPosition; /** @@ -33,59 +31,24 @@ import org.apache.fop.layoutmgr.BestFitLayoutUtils.BestFitPosition; */ public class BestFitPenalty extends KnuthPenalty { - private final LinkedList<Alternative> alternatives; - private final FittingStrategy strategy; - public boolean canFit = true; - private int currentAltIndex; + private final List<ListElement> knuthList; + public boolean ignorePenalty; - public BestFitPenalty(FittingStrategy strategy, Position pos) { - super(0, 0, false, pos, false); - this.strategy = strategy; - alternatives = new LinkedList<Alternative>(); + public BestFitPenalty(int width, List<ListElement> knuthList, Position pos) { + super(width, 0, false, pos, false); + this.knuthList = knuthList; } - public void addAlternative(Alternative alternative) { - alternatives.add(alternative); + public void activateContent() { + BestFitPosition pos = getBestFitPosition(); + pos.setKnuthList(knuthList); } - public List<Alternative> getAlternatives() { - return alternatives; - } - - public FittingStrategy getFittingStrategy() { - return strategy; - } - - @Override public int getWidth() { - if (currentAltIndex == -1) { + if (ignorePenalty) { return 0; } - return alternatives.get(currentAltIndex).getLength(); - } - - public boolean hasMoreAlternatives() { - return currentAltIndex != -1; - } - - public void considerNextAlternative() { - if (currentAltIndex < alternatives.size() - 1) { - currentAltIndex++; - } else { - currentAltIndex = -1; - } - } - - @Override - public Position getPosition() { - if (currentAltIndex != -1) { - Position pos = super.getPosition(); - if (alternatives.size() > 0) { - getBestFitPosition().setKnuthList(alternatives.get(currentAltIndex).getKnuthList()); - } - return pos; - } - return null; + return super.getWidth(); } public BestFitPosition getBestFitPosition() { @@ -103,8 +66,8 @@ public class BestFitPenalty extends KnuthPenalty { public String toString() { String str = super.toString(); StringBuffer buffer = new StringBuffer(64); - buffer.append(" number of alternatives = " + getAlternatives().size()); - buffer.append(" fitting-strategy = " + strategy.getStrategyName()); +// buffer.append(" number of alternatives = " + alternatives.size()); +// buffer.append(" fitting-strategy = " + strategy.getStrategyName()); return str + buffer.toString(); } diff --git a/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java b/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java index 6f628d1f5..50dee48b4 100644 --- a/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java @@ -28,7 +28,6 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FONode.FONodeIterator; import org.apache.fop.fo.FObj; import org.apache.fop.fo.flow.MultiSwitch; -import org.apache.fop.layoutmgr.Alternative.FittingStrategy; public class MultiSwitchLayoutManager extends BlockStackingLayoutManager { @@ -56,7 +55,7 @@ public class MultiSwitchLayoutManager extends BlockStackingLayoutManager { } } setFinished(true); - return BestFitLayoutUtils.getKnuthList(this, childrenLists, FittingStrategy.FIRST_FIT); + return BestFitLayoutUtils.getKnuthList(this, childrenLists); } @Override diff --git a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java index d441b37bd..b7e2413bb 100644 --- a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java @@ -149,9 +149,6 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { /** Index of the last inserted element of the last inserted footnote. */ public int footnoteElementIndex; - public boolean bestFitNode = false; - public boolean skipNode = false; - public KnuthPageNode(int position, int line, int fitness, int totalWidth, int totalStretch, int totalShrink, @@ -165,12 +162,6 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { this.totalFootnotes = totalFootnotes; this.footnoteListIndex = footnoteListIndex; this.footnoteElementIndex = footnoteElementIndex; - if (getElement(position) instanceof BestFitPenalty) { - if (log.isDebugEnabled()) { - log.debug("Creating a KnuthPageNode for a BestFitPenalty."); - } - bestFitNode = true; - } } } @@ -403,25 +394,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { /** {@inheritDoc} */ @Override protected int restartFrom(KnuthNode restartingNode, int currentIndex) { - if (getLastTooLong() != null) { - KnuthPageNode lastTooLong = (KnuthPageNode) getLastTooLong(); - if (lastTooLong.skipNode) { - if (log.isDebugEnabled()) { - log.debug("Alternative does not fit in the current page. " - + "Switching to the next one in the list"); - } - int penaltyIndex = currentIndex; - // In case the paragraph has changed... - if (lastTooLong.previous.previous == null) { - if (par.get(0) == KnuthPenalty.DUMMY_ZERO_PENALTY) { - ++penaltyIndex; - } - } - BestFitPenalty bestFitPenalty = (BestFitPenalty) getElement(penaltyIndex); - bestFitPenalty.considerNextAlternative(); - restartingNode = restartingNode.previous; - } - } + int returnValue = super.restartFrom(restartingNode, currentIndex); newFootnotes = false; if (footnotesPending) { @@ -519,22 +492,6 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { } /** {@inheritDoc} */ - protected void forceNode(KnuthNode node, int line, int elementIdx, - int difference, double r, double demerits, int fitnessClass, - int availableShrink, int availableStretch) { - - super.forceNode(node, line, elementIdx, difference, r, demerits, - fitnessClass, availableShrink, availableStretch); - - KnuthPageNode lastTooLong = (KnuthPageNode) getLastTooLong(); - if (lastTooLong != null) { - if (lastTooLong.bestFitNode) { - lastTooLong.skipNode = true; - } - } - } - - /** {@inheritDoc} */ @Override protected int computeDifference(KnuthNode activeNode, KnuthElement element, int elementIndex) { |