Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp change bars2 #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions fop-core/src/main/java/org/apache/fop/area/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
package org.apache.fop.area;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.fop.fo.flow.ChangeBar;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.traits.WritingModeTraitsGetter;

Expand Down Expand Up @@ -128,6 +130,29 @@ public class Area extends AreaTreeObject implements Serializable {
*/
protected static final Log log = LogFactory.getLog(Area.class);

/**
* The active change bar list
*/
private List<ChangeBar> changeBarList;

/**
* Returns the active change bar list.
*
* @return The active change bar list
*/
public List<ChangeBar> getChangeBarList() {
return changeBarList;
}

/**
* Sets the active change bar list.
*
* @param changeBarList The active change bar list
*/
public void setChangeBarList(List<ChangeBar> changeBarList) {
this.changeBarList = changeBarList;
}

/**
* Get the area class of this area.
*
Expand Down
42 changes: 42 additions & 0 deletions fop-core/src/main/java/org/apache/fop/area/AreaTreeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.fop.area.inline.ForeignObject;
import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.InlineBlock;
import org.apache.fop.area.inline.InlineBlockParent;
import org.apache.fop.area.inline.InlineParent;
import org.apache.fop.area.inline.InlineViewport;
Expand All @@ -80,6 +81,7 @@
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.traits.Direction;
import org.apache.fop.traits.Visibility;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.ContentHandlerFactory;
Expand Down Expand Up @@ -190,6 +192,7 @@ public Handler(AreaTreeModel treeModel, FOUserAgent userAgent,
makers.put("block", new BlockMaker());
makers.put("lineArea", new LineAreaMaker());
makers.put("inline", new InlineMaker());
makers.put("inlineblock", new InlineBlockMaker());
makers.put("inlineparent", new InlineParentMaker());
makers.put("inlineblockparent", new InlineBlockParentMaker());
makers.put("text", new TextMaker());
Expand Down Expand Up @@ -594,6 +597,17 @@ public void startElement(Attributes attributes) {
BodyRegion body = getCurrentBodyRegion();
Span span = new Span(columnCount,
body.getColumnGap(), ipd);

String blockDirection = attributes.getValue("block-progression-direction");
if (blockDirection != null) {
span.addTrait(Trait.BLOCK_PROGRESSION_DIRECTION, Direction.valueOf(blockDirection));
}

String inlineDirection = attributes.getValue("inline-progression-direction");
if (inlineDirection != null) {
span.addTrait(Trait.INLINE_PROGRESSION_DIRECTION, Direction.valueOf(inlineDirection));
}

transferForeignObjects(attributes, span);
setAreaAttributes(attributes, span);
body.getMainReference().getSpans().add(span);
Expand Down Expand Up @@ -723,6 +737,34 @@ public void endElement() {
}
}

private class InlineBlockMaker extends AbstractMaker {

public void startElement(Attributes attributes) {

Block block = new Block();

if (attributes.getValue("left-offset") != null) {
block.setXOffset(XMLUtil.getAttributeAsInt(attributes, "left-offset", 0));
}
if (attributes.getValue("top-offset") != null) {
block.setYOffset(XMLUtil.getAttributeAsInt(attributes, "top-offset", 0));
}
transferForeignObjects(attributes, block);
setAreaAttributes(attributes, block);
setTraits(attributes, block, SUBSET_COMMON);
setTraits(attributes, block, SUBSET_BOX);
setTraits(attributes, block, SUBSET_COLOR);
Area parent = (Area)areaStack.peek();
InlineBlock inlineBlock = new InlineBlock(block);
parent.addChildArea(inlineBlock);
areaStack.push(inlineBlock);
}

public void endElement() {
assertObjectOfClass(areaStack.pop(), InlineBlock.class);
}
}

private class InlineParentMaker extends AbstractMaker {

public void startElement(Attributes attributes) {
Expand Down
11 changes: 11 additions & 0 deletions fop-core/src/main/java/org/apache/fop/area/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public int getColumnCount() {
return colCount;
}

/**
* Get the column gap for this span area.
*
* @return the column gap for this span area
*/
public int getColumnGap() {
return colGap;
}

/**
* Get the width of a single column within this Span
*
Expand Down Expand Up @@ -206,6 +215,8 @@ public void setWritingModeTraits(WritingModeTraitsGetter wmtg) {
}
break;
}
addTrait(Trait.INLINE_PROGRESSION_DIRECTION, wmtg.getInlineProgressionDirection());
addTrait(Trait.BLOCK_PROGRESSION_DIRECTION, wmtg.getBlockProgressionDirection());
}

/** {@inheritDoc} */
Expand Down
43 changes: 43 additions & 0 deletions fop-core/src/main/java/org/apache/fop/area/inline/InlineBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.area.inline;

import org.apache.fop.area.Block;

/**
* This is the inline block area class.
* It wraps the child block when it has to be placed into inline parent.
*/
public class InlineBlock extends InlineParent {

private static final long serialVersionUID = -3725062353292109517L;
private final Block block;

public InlineBlock(Block block) {
this.block = block;
}

/**
* @return the wrapped block
*/
public Block getBlock() {
return block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void addWord(
WordArea wordArea = new WordArea(
blockProgressionOffset, minWordLevel, word, letterAdjust, levels, gposAdjustments);
wordArea.setIPD(ipd);
wordArea.setChangeBarList(getChangeBarList());
addChildArea(wordArea);
wordArea.setParentArea(this);
updateLevel(minWordLevel);
Expand All @@ -113,6 +114,7 @@ public void addSpace(
char space, int ipd, boolean adjustable, int blockProgressionOffset, int level) {
SpaceArea spaceArea = new SpaceArea(blockProgressionOffset, level, space, adjustable);
spaceArea.setIPD(ipd);
spaceArea.setChangeBarList(getChangeBarList());
addChildArea(spaceArea);
spaceArea.setParentArea(this);
updateLevel(level);
Expand Down
16 changes: 16 additions & 0 deletions fop-core/src/main/java/org/apache/fop/fo/FOElementMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ protected void initialize() {
foObjs.put("marker", new MarkerMaker());
foObjs.put("retrieve-marker", new RetrieveMarkerMaker());
foObjs.put("retrieve-table-marker", new RetrieveTableMarkerMaker());

// change bars
foObjs.put("change-bar-begin", new ChangeBarBeginMaker());
foObjs.put("change-bar-end", new ChangeBarEndMaker());
}
}

Expand Down Expand Up @@ -527,4 +531,16 @@ public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.RetrieveTableMarker(parent);
}
}

static class ChangeBarBeginMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ChangeBarBegin(parent);
}
}

static class ChangeBarEndMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.ChangeBarEnd(parent);
}
}
}
29 changes: 29 additions & 0 deletions fop-core/src/main/java/org/apache/fop/fo/FONode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.fop.fo;

// Java
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Stack;
Expand All @@ -42,6 +43,7 @@
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fo.extensions.InternalElementMapping;
import org.apache.fop.fo.extensions.svg.SVGElementMapping;
import org.apache.fop.fo.flow.ChangeBar;
import org.apache.fop.fo.pagination.Root;
import org.apache.fop.util.CharUtilities;
import org.apache.fop.util.ContentHandlerFactory;
Expand All @@ -63,6 +65,12 @@ public abstract class FONode implements Cloneable {
/** pointer to the sibling nodes */
protected FONode[] siblings;

/** The list of active change bars for the given node */
protected List<ChangeBar> nodeChangeBarList;

/** The list of active change bars for the start of the given node */
protected List<ChangeBar> startOfNodeChangeBarList;

/**
* Marks the location of this object from the input FO
* <br>Call <code>locator.getSystemId()</code>,
Expand Down Expand Up @@ -173,6 +181,18 @@ protected boolean inMarker() {
return getBuilderContext().inMarker();
}

/**
* Tests if the given element is a change bar element.
*
* @param namespaceURI The name space of the element
* @param localName The local name of the element
* @return A boolean value true if the given element is a change bar element
*/
public boolean isChangeBarElement(String namespaceURI, String localName) {
return FO_URI.equals(namespaceURI)
&& (localName.equals("change-bar-begin") || localName.equals("change-bar-end"));
}

/**
* Returns the user agent that is associated with the
* tree's <code>FOEventHandler</code>.
Expand Down Expand Up @@ -1082,6 +1102,15 @@ public interface FONodeIterator extends ListIterator<FONode> {

}

/**
* Returns the list of active change bars.
*
* @return The list of active change bars
*/
public List<ChangeBar> getChangeBarList() {
return nodeChangeBarList;
}

/**
* Sets the structure tree element.
*
Expand Down
51 changes: 51 additions & 0 deletions fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ private Property getEnumProperty(int enumValue, String text) {
gp.createTableProperties();
gp.createWritingModeProperties();
gp.createMiscProperties();
gp.createChangeBarProperties();

// Hardcode the subproperties.
addSubpropMakerName("length", CP_LENGTH);
Expand Down Expand Up @@ -2588,6 +2589,56 @@ private void createWritingModeProperties() {
addPropertyMaker("writing-mode", m);
}

private void createChangeBarProperties() {
PropertyMaker m;

// change-bar-class
m = new StringProperty.Maker(PR_CHANGE_BAR_CLASS);
m.setInherited(false);
m.setDefault("");
addPropertyMaker("change-bar-class", m);

// change-bar-color
m = new ColorProperty.Maker(PR_CHANGE_BAR_COLOR);

m.setInherited(true);
// TODO: fall back to "color" property
m.setDefault("black");
addPropertyMaker("change-bar-color", m);

// change-bar-placement
m = new EnumProperty.Maker(PR_CHANGE_BAR_PLACEMENT);
m.setInherited(true);
m.setDefault("start");
m.addEnum("start", getEnumProperty(EN_START, "START"));
m.addEnum("end", getEnumProperty(EN_END, "END"));
m.addEnum("left", getEnumProperty(EN_LEFT, "LEFT"));
m.addEnum("right", getEnumProperty(EN_RIGHT, "RIGHT"));
m.addEnum("inside", getEnumProperty(EN_INSIDE, "INSIDE"));
m.addEnum("outside", getEnumProperty(EN_OUTSIDE, "OUTSIDE"));
m.addEnum("alternate", getEnumProperty(EN_ALTERNATE, "ALTERNATE"));
addPropertyMaker("change-bar-placement", m);

// change-bar-style
m = new EnumProperty.Maker(PR_CHANGE_BAR_STYLE);
m.useGeneric(genericBorderStyle);
m.setInherited(true);
m.setDefault("solid");
addPropertyMaker("change-bar-style", m);

// change-bar-width
m = new LengthProperty.Maker(PR_CHANGE_BAR_WIDTH);
m.setInherited(true);
m.setDefault("6pt");
addPropertyMaker("change-bar-width", m);

// change-bar-offset
m = new LengthProperty.Maker(PR_CHANGE_BAR_OFFSET);
m.setInherited(true);
m.setDefault("6pt");
addPropertyMaker("change-bar-offset", m);
}

private void createMiscProperties() {
PropertyMaker m;

Expand Down
6 changes: 6 additions & 0 deletions fop-core/src/main/java/org/apache/fop/fo/FOText.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
import org.apache.fop.datatypes.Length;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.fo.properties.CommonHyphenation;
import org.apache.fop.fo.properties.CommonTextDecoration;
Expand Down Expand Up @@ -109,6 +110,11 @@ public class FOText extends FONode implements CharSequence, TextFragment {
*/
public FOText(FONode parent) {
super(parent);

PageSequence pageSequence = getRoot().getLastPageSequence();
if (pageSequence != null && pageSequence.hasChangeBars()) {
nodeChangeBarList = getRoot().getLastPageSequence().getClonedChangeBarList();
}
}

/** {@inheritDoc} */
Expand Down
4 changes: 3 additions & 1 deletion fop-core/src/main/java/org/apache/fop/fo/FOTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ public void startElement(String namespaceURI, String localName, String rawName,
if (currentFObj.getNamespaceURI().equals(FOElementMapping.URI)
|| currentFObj.getNamespaceURI().equals(ExtensionElementMapping.URI)
|| currentFObj.getNamespaceURI().equals(PDFElementMapping.NAMESPACE)) {
currentFObj.validateChildNode(locator, namespaceURI, localName);
if (!currentFObj.isChangeBarElement(namespaceURI, localName)) {
currentFObj.validateChildNode(locator, namespaceURI, localName);
}
}
}

Expand Down
Loading