123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- /*
- * 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.fo.flow.table;
-
- import org.apache.fop.apps.FOPException;
- import org.apache.fop.datatypes.Numeric;
- import org.apache.fop.datatypes.ValidationPercentBaseContext;
- import org.apache.fop.fo.Constants;
- import org.apache.fop.fo.FONode;
- import org.apache.fop.fo.FObj;
- import org.apache.fop.fo.PropertyList;
- import org.apache.fop.fo.expr.PropertyException;
- import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
- import org.apache.fop.fo.properties.NumberProperty;
- import org.apache.fop.fo.properties.Property;
- import org.apache.fop.layoutmgr.table.CollapsingBorderModel;
-
- /**
- * Common base class for table-related FOs
- */
- public abstract class TableFObj extends FObj {
-
- private Numeric borderAfterPrecedence;
- private Numeric borderBeforePrecedence;
- private Numeric borderEndPrecedence;
- private Numeric borderStartPrecedence;
-
- ConditionalBorder borderBefore;
- ConditionalBorder borderAfter;
- BorderSpecification borderStart;
- BorderSpecification borderEnd;
-
- CollapsingBorderModel collapsingBorderModel;
-
- /**
- * Main constructor
- *
- * @param parent the parent node
- */
- public TableFObj(FONode parent) {
- super(parent);
- }
-
- /** {@inheritDoc} */
- public void bind(PropertyList pList) throws FOPException {
- super.bind(pList);
- borderAfterPrecedence = pList.get(PR_BORDER_AFTER_PRECEDENCE).getNumeric();
- borderBeforePrecedence = pList.get(PR_BORDER_BEFORE_PRECEDENCE).getNumeric();
- borderEndPrecedence = pList.get(PR_BORDER_END_PRECEDENCE).getNumeric();
- borderStartPrecedence = pList.get(PR_BORDER_START_PRECEDENCE).getNumeric();
- if (getNameId() != FO_TABLE //Separate check for fo:table in Table.java
- && getNameId() != FO_TABLE_CELL
- && getCommonBorderPaddingBackground().hasPadding(
- ValidationPercentBaseContext.getPseudoContext())) {
- TableEventProducer eventProducer = TableEventProducer.Provider.get(
- getUserAgent().getEventBroadcaster());
- eventProducer.paddingNotApplicable(this, getName(), getLocator());
- }
- }
-
- /**
- *
- * @param side the side for which to return the border precedence
- * @return the "border-precedence" value for the given side
- */
- public Numeric getBorderPrecedence(int side) {
- switch (side) {
- case CommonBorderPaddingBackground.BEFORE:
- return borderBeforePrecedence;
- case CommonBorderPaddingBackground.AFTER:
- return borderAfterPrecedence;
- case CommonBorderPaddingBackground.START:
- return borderStartPrecedence;
- case CommonBorderPaddingBackground.END:
- return borderEndPrecedence;
- default:
- return null;
- }
- }
-
- /**
- * Convenience method to returns a reference
- * to the base Table instance
- *
- * @return the base table instance
- *
- */
- public Table getTable() {
- // Will be overridden in Table; for any other Table-node, recursive call to
- // parent.getTable()
- return ((TableFObj) parent).getTable();
- }
-
- /**
- * @return the Common Border, Padding, and Background Properties.
- */
- public abstract CommonBorderPaddingBackground getCommonBorderPaddingBackground();
-
- /**
- * PropertyMaker subclass for the column-number property
- *
- */
- public static class ColumnNumberPropertyMaker extends NumberProperty.Maker {
-
- /**
- * Constructor
- * @param propId the id of the property for which the maker should
- * be created
- */
- public ColumnNumberPropertyMaker(int propId) {
- super(propId);
- }
-
- /** {@inheritDoc} */
- public Property make(PropertyList propertyList)
- throws PropertyException {
- FObj fo = propertyList.getFObj();
-
- return NumberProperty.getInstance(((ColumnNumberManagerHolder) fo.getParent())
- .getColumnNumberManager().getCurrentColumnNumber());
- }
-
-
- /**
- * Check the value of the column-number property.
- * Return the parent's column index (initial value) in case
- * of a negative or zero value
- *
- * @see org.apache.fop.fo.properties.PropertyMaker#make(PropertyList, String, FObj)
- */
- public Property make(PropertyList propertyList, String value, FObj fo)
- throws PropertyException {
- Property p = super.make(propertyList, value, fo);
-
- ColumnNumberManagerHolder parent
- = (ColumnNumberManagerHolder) propertyList.getParentFObj();
- ColumnNumberManager columnIndexManager = parent.getColumnNumberManager();
- int columnIndex = p.getNumeric().getValue();
- if (columnIndex <= 0) {
- /* No warning necessary as the spec clearly defines how to handle these cases.
- log.warn("Specified negative or zero value for "
- + "column-number on " + fo.getName() + ": "
- + columnIndex + " forced to "
- + columnIndexManager.getCurrentColumnNumber());*/
- return NumberProperty.getInstance(columnIndexManager.getCurrentColumnNumber());
- } else {
- double tmpIndex = p.getNumeric().getNumericValue();
- if (tmpIndex - columnIndex > 0.0) {
- columnIndex = (int) Math.round(tmpIndex);
- /* No warning necessary as the spec clearly defines how to handle these cases.
- log.warn("Rounding specified column-number of "
- + tmpIndex + " to " + columnIndex);*/
- p = NumberProperty.getInstance(columnIndex);
- }
- }
-
- int colSpan = propertyList.get(Constants.PR_NUMBER_COLUMNS_SPANNED)
- .getNumeric().getValue();
- int i = -1;
- while (++i < colSpan) {
- if (columnIndexManager.isColumnNumberUsed(columnIndex + i)) {
- /* if column-number is already in use by another
- * cell/column => error!
- */
- TableEventProducer eventProducer = TableEventProducer.Provider.get(
- fo.getUserAgent().getEventBroadcaster());
- eventProducer.cellOverlap(this, fo.getName(), columnIndex + 1, fo.getLocator());
- }
- }
-
- return p;
- }
- }
-
- /** {@inheritDoc} */
- public void startOfNode() throws FOPException {
- super.startOfNode();
- Table table = getTable();
- if (!inMarker() && !table.isSeparateBorderModel()) {
- collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table
- .getBorderCollapse());
- setCollapsedBorders();
- }
- }
-
- /*
- * TODO made public so that RetrieveMarker can access it.
- */
- /** {@inheritDoc} */
- public void endOfNode() throws FOPException {
- super.endOfNode();
- }
-
- /**
- * Prepares the borders of this element if the collapsing-border model is in use.
- * Conflict resolution with parent elements is done where applicable.
- */
- protected abstract void setCollapsedBorders();
-
- /**
- * Creates a BorderSpecification from the border set on the given side. If no border
- * is set, a BorderSpecification with border-style none is created.
- *
- * @param side one of CommonBorderPaddingBackground.BEFORE|AFTER|START|END
- */
- protected void createBorder(int side) {
- BorderSpecification borderSpec = new BorderSpecification(
- getCommonBorderPaddingBackground().getBorderInfo(side), getNameId());
- switch (side) {
- case CommonBorderPaddingBackground.BEFORE:
- borderBefore = new ConditionalBorder(borderSpec, collapsingBorderModel);
- break;
- case CommonBorderPaddingBackground.AFTER:
- borderAfter = new ConditionalBorder(borderSpec, collapsingBorderModel);
- break;
- case CommonBorderPaddingBackground.START:
- borderStart = borderSpec;
- break;
- case CommonBorderPaddingBackground.END:
- borderEnd = borderSpec;
- break;
- default: assert false;
- }
- }
-
- /**
- * Creates a BorderSpecification from the border set on the given side, performing
- * conflict resolution with the same border on the given object.
- *
- * @param side one of CommonBorderPaddingBackground.BEFORE|AFTER|START|END
- * @param competitor a parent table element whose side coincides with the given side
- * on this element
- */
- protected void createBorder(int side, TableFObj competitor) {
- createBorder(side);
- switch (side) {
- case CommonBorderPaddingBackground.BEFORE:
- borderBefore.integrateSegment(competitor.borderBefore, true, true, true);
- break;
- case CommonBorderPaddingBackground.AFTER:
- borderAfter.integrateSegment(competitor.borderAfter, true, true, true);
- break;
- case CommonBorderPaddingBackground.START:
- borderStart = collapsingBorderModel.determineWinner(borderStart,
- competitor.borderStart);
- break;
- case CommonBorderPaddingBackground.END:
- borderEnd = collapsingBorderModel.determineWinner(borderEnd,
- competitor.borderEnd);
- break;
- default: assert false;
- }
- }
- }
|