Skip to content

Commit bc34212

Browse files
FOP-1760: Change bar generation
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ChangeBars2@1835125 13f79535-47bb-0310-9956-ffa450edef68
1 parent 08af4b7 commit bc34212

File tree

55 files changed

+2272
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2272
-20
lines changed

fop-core/src/main/java/org/apache/fop/area/Area.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
package org.apache.fop.area;
2121

2222
import java.io.Serializable;
23+
import java.util.List;
2324
import java.util.Map;
2425
import java.util.TreeMap;
2526

2627
import org.apache.commons.logging.Log;
2728
import org.apache.commons.logging.LogFactory;
2829

30+
import org.apache.fop.fo.flow.ChangeBar;
2931
import org.apache.fop.traits.BorderProps;
3032
import org.apache.fop.traits.WritingModeTraitsGetter;
3133

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

133+
/**
134+
* The active change bar list
135+
*/
136+
private List<ChangeBar> changeBarList;
137+
138+
/**
139+
* Returns the active change bar list.
140+
*
141+
* @return The active change bar list
142+
*/
143+
public List<ChangeBar> getChangeBarList() {
144+
return changeBarList;
145+
}
146+
147+
/**
148+
* Sets the active change bar list.
149+
*
150+
* @param changeBarList The active change bar list
151+
*/
152+
public void setChangeBarList(List<ChangeBar> changeBarList) {
153+
this.changeBarList = changeBarList;
154+
}
155+
131156
/**
132157
* Get the area class of this area.
133158
*

fop-core/src/main/java/org/apache/fop/area/AreaTreeParser.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.apache.fop.area.inline.ForeignObject;
6767
import org.apache.fop.area.inline.Image;
6868
import org.apache.fop.area.inline.InlineArea;
69+
import org.apache.fop.area.inline.InlineBlock;
6970
import org.apache.fop.area.inline.InlineBlockParent;
7071
import org.apache.fop.area.inline.InlineParent;
7172
import org.apache.fop.area.inline.InlineViewport;
@@ -80,6 +81,7 @@
8081
import org.apache.fop.fonts.Font;
8182
import org.apache.fop.fonts.FontInfo;
8283
import org.apache.fop.traits.BorderProps;
84+
import org.apache.fop.traits.Direction;
8385
import org.apache.fop.traits.Visibility;
8486
import org.apache.fop.util.ColorUtil;
8587
import org.apache.fop.util.ContentHandlerFactory;
@@ -190,6 +192,7 @@ public Handler(AreaTreeModel treeModel, FOUserAgent userAgent,
190192
makers.put("block", new BlockMaker());
191193
makers.put("lineArea", new LineAreaMaker());
192194
makers.put("inline", new InlineMaker());
195+
makers.put("inlineblock", new InlineBlockMaker());
193196
makers.put("inlineparent", new InlineParentMaker());
194197
makers.put("inlineblockparent", new InlineBlockParentMaker());
195198
makers.put("text", new TextMaker());
@@ -594,6 +597,17 @@ public void startElement(Attributes attributes) {
594597
BodyRegion body = getCurrentBodyRegion();
595598
Span span = new Span(columnCount,
596599
body.getColumnGap(), ipd);
600+
601+
String blockDirection = attributes.getValue("block-progression-direction");
602+
if (blockDirection != null) {
603+
span.addTrait(Trait.BLOCK_PROGRESSION_DIRECTION, Direction.valueOf(blockDirection));
604+
}
605+
606+
String inlineDirection = attributes.getValue("inline-progression-direction");
607+
if (inlineDirection != null) {
608+
span.addTrait(Trait.INLINE_PROGRESSION_DIRECTION, Direction.valueOf(inlineDirection));
609+
}
610+
597611
transferForeignObjects(attributes, span);
598612
setAreaAttributes(attributes, span);
599613
body.getMainReference().getSpans().add(span);
@@ -723,6 +737,34 @@ public void endElement() {
723737
}
724738
}
725739

740+
private class InlineBlockMaker extends AbstractMaker {
741+
742+
public void startElement(Attributes attributes) {
743+
744+
Block block = new Block();
745+
746+
if (attributes.getValue("left-offset") != null) {
747+
block.setXOffset(XMLUtil.getAttributeAsInt(attributes, "left-offset", 0));
748+
}
749+
if (attributes.getValue("top-offset") != null) {
750+
block.setYOffset(XMLUtil.getAttributeAsInt(attributes, "top-offset", 0));
751+
}
752+
transferForeignObjects(attributes, block);
753+
setAreaAttributes(attributes, block);
754+
setTraits(attributes, block, SUBSET_COMMON);
755+
setTraits(attributes, block, SUBSET_BOX);
756+
setTraits(attributes, block, SUBSET_COLOR);
757+
Area parent = (Area)areaStack.peek();
758+
InlineBlock inlineBlock = new InlineBlock(block);
759+
parent.addChildArea(inlineBlock);
760+
areaStack.push(inlineBlock);
761+
}
762+
763+
public void endElement() {
764+
assertObjectOfClass(areaStack.pop(), InlineBlock.class);
765+
}
766+
}
767+
726768
private class InlineParentMaker extends AbstractMaker {
727769

728770
public void startElement(Attributes attributes) {

fop-core/src/main/java/org/apache/fop/area/Span.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ public int getColumnCount() {
8181
return colCount;
8282
}
8383

84+
/**
85+
* Get the column gap for this span area.
86+
*
87+
* @return the column gap for this span area
88+
*/
89+
public int getColumnGap() {
90+
return colGap;
91+
}
92+
8493
/**
8594
* Get the width of a single column within this Span
8695
*
@@ -206,6 +215,8 @@ public void setWritingModeTraits(WritingModeTraitsGetter wmtg) {
206215
}
207216
break;
208217
}
218+
addTrait(Trait.INLINE_PROGRESSION_DIRECTION, wmtg.getInlineProgressionDirection());
219+
addTrait(Trait.BLOCK_PROGRESSION_DIRECTION, wmtg.getBlockProgressionDirection());
209220
}
210221

211222
/** {@inheritDoc} */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/* $Id$ */
19+
20+
package org.apache.fop.area.inline;
21+
22+
import org.apache.fop.area.Block;
23+
24+
/**
25+
* This is the inline block area class.
26+
* It wraps the child block when it has to be placed into inline parent.
27+
*/
28+
public class InlineBlock extends InlineParent {
29+
30+
private final Block block;
31+
32+
public InlineBlock(Block block) {
33+
this.block = block;
34+
}
35+
36+
/**
37+
* @return the wrapped block
38+
*/
39+
public Block getBlock() {
40+
return block;
41+
}
42+
}

fop-core/src/main/java/org/apache/fop/area/inline/TextArea.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public void addWord(
9595
WordArea wordArea = new WordArea(
9696
blockProgressionOffset, minWordLevel, word, letterAdjust, levels, gposAdjustments);
9797
wordArea.setIPD(ipd);
98+
wordArea.setChangeBarList(getChangeBarList());
9899
addChildArea(wordArea);
99100
wordArea.setParentArea(this);
100101
updateLevel(minWordLevel);
@@ -113,6 +114,7 @@ public void addSpace(
113114
char space, int ipd, boolean adjustable, int blockProgressionOffset, int level) {
114115
SpaceArea spaceArea = new SpaceArea(blockProgressionOffset, level, space, adjustable);
115116
spaceArea.setIPD(ipd);
117+
spaceArea.setChangeBarList(getChangeBarList());
116118
addChildArea(spaceArea);
117119
spaceArea.setParentArea(this);
118120
updateLevel(level);

fop-core/src/main/java/org/apache/fop/fo/FOElementMapping.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ protected void initialize() {
141141
foObjs.put("marker", new MarkerMaker());
142142
foObjs.put("retrieve-marker", new RetrieveMarkerMaker());
143143
foObjs.put("retrieve-table-marker", new RetrieveTableMarkerMaker());
144+
145+
// change bars
146+
foObjs.put("change-bar-begin", new ChangeBarBeginMaker());
147+
foObjs.put("change-bar-end", new ChangeBarEndMaker());
144148
}
145149
}
146150

@@ -527,4 +531,16 @@ public FONode make(FONode parent) {
527531
return new org.apache.fop.fo.flow.RetrieveTableMarker(parent);
528532
}
529533
}
534+
535+
static class ChangeBarBeginMaker extends ElementMapping.Maker {
536+
public FONode make(FONode parent) {
537+
return new org.apache.fop.fo.flow.ChangeBarBegin(parent);
538+
}
539+
}
540+
541+
static class ChangeBarEndMaker extends ElementMapping.Maker {
542+
public FONode make(FONode parent) {
543+
return new org.apache.fop.fo.flow.ChangeBarEnd(parent);
544+
}
545+
}
530546
}

fop-core/src/main/java/org/apache/fop/fo/FONode.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.fop.fo;
2121

2222
// Java
23+
import java.util.List;
2324
import java.util.ListIterator;
2425
import java.util.Map;
2526
import java.util.Stack;
@@ -42,6 +43,7 @@
4243
import org.apache.fop.fo.extensions.ExtensionElementMapping;
4344
import org.apache.fop.fo.extensions.InternalElementMapping;
4445
import org.apache.fop.fo.extensions.svg.SVGElementMapping;
46+
import org.apache.fop.fo.flow.ChangeBar;
4547
import org.apache.fop.fo.pagination.Root;
4648
import org.apache.fop.util.CharUtilities;
4749
import org.apache.fop.util.ContentHandlerFactory;
@@ -63,6 +65,12 @@ public abstract class FONode implements Cloneable {
6365
/** pointer to the sibling nodes */
6466
protected FONode[] siblings;
6567

68+
/** The list of active change bars for the given node */
69+
protected List<ChangeBar> nodeChangeBarList;
70+
71+
/** The list of active change bars for the start of the given node */
72+
protected List<ChangeBar> startOfNodeChangeBarList;
73+
6674
/**
6775
* Marks the location of this object from the input FO
6876
* <br>Call <code>locator.getSystemId()</code>,
@@ -173,6 +181,18 @@ protected boolean inMarker() {
173181
return getBuilderContext().inMarker();
174182
}
175183

184+
/**
185+
* Tests if the given element is a change bar element.
186+
*
187+
* @param namespaceURI The name space of the element
188+
* @param localName The local name of the element
189+
* @return A boolean value true if the given element is a change bar element
190+
*/
191+
public boolean isChangeBarElement(String namespaceURI, String localName) {
192+
return FO_URI.equals(namespaceURI)
193+
&& (localName.equals("change-bar-begin") || localName.equals("change-bar-end"));
194+
}
195+
176196
/**
177197
* Returns the user agent that is associated with the
178198
* tree's <code>FOEventHandler</code>.
@@ -1082,6 +1102,15 @@ public interface FONodeIterator extends ListIterator<FONode> {
10821102

10831103
}
10841104

1105+
/**
1106+
* Returns the list of active change bars.
1107+
*
1108+
* @return The list of active change bars
1109+
*/
1110+
public List<ChangeBar> getChangeBarList() {
1111+
return nodeChangeBarList;
1112+
}
1113+
10851114
/**
10861115
* Sets the structure tree element.
10871116
*

fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ private Property getEnumProperty(int enumValue, String text) {
322322
gp.createTableProperties();
323323
gp.createWritingModeProperties();
324324
gp.createMiscProperties();
325+
gp.createChangeBarProperties();
325326

326327
// Hardcode the subproperties.
327328
addSubpropMakerName("length", CP_LENGTH);
@@ -2588,6 +2589,56 @@ private void createWritingModeProperties() {
25882589
addPropertyMaker("writing-mode", m);
25892590
}
25902591

2592+
private void createChangeBarProperties() {
2593+
PropertyMaker m;
2594+
2595+
// change-bar-class
2596+
m = new StringProperty.Maker(PR_CHANGE_BAR_CLASS);
2597+
m.setInherited(false);
2598+
m.setDefault("");
2599+
addPropertyMaker("change-bar-class", m);
2600+
2601+
// change-bar-color
2602+
m = new ColorProperty.Maker(PR_CHANGE_BAR_COLOR);
2603+
2604+
m.setInherited(true);
2605+
// TODO: fall back to "color" property
2606+
m.setDefault("black");
2607+
addPropertyMaker("change-bar-color", m);
2608+
2609+
// change-bar-placement
2610+
m = new EnumProperty.Maker(PR_CHANGE_BAR_PLACEMENT);
2611+
m.setInherited(true);
2612+
m.setDefault("start");
2613+
m.addEnum("start", getEnumProperty(EN_START, "START"));
2614+
m.addEnum("end", getEnumProperty(EN_END, "END"));
2615+
m.addEnum("left", getEnumProperty(EN_LEFT, "LEFT"));
2616+
m.addEnum("right", getEnumProperty(EN_RIGHT, "RIGHT"));
2617+
m.addEnum("inside", getEnumProperty(EN_INSIDE, "INSIDE"));
2618+
m.addEnum("outside", getEnumProperty(EN_OUTSIDE, "OUTSIDE"));
2619+
m.addEnum("alternate", getEnumProperty(EN_ALTERNATE, "ALTERNATE"));
2620+
addPropertyMaker("change-bar-placement", m);
2621+
2622+
// change-bar-style
2623+
m = new EnumProperty.Maker(PR_CHANGE_BAR_STYLE);
2624+
m.useGeneric(genericBorderStyle);
2625+
m.setInherited(true);
2626+
m.setDefault("solid");
2627+
addPropertyMaker("change-bar-style", m);
2628+
2629+
// change-bar-width
2630+
m = new LengthProperty.Maker(PR_CHANGE_BAR_WIDTH);
2631+
m.setInherited(true);
2632+
m.setDefault("6pt");
2633+
addPropertyMaker("change-bar-width", m);
2634+
2635+
// change-bar-offset
2636+
m = new LengthProperty.Maker(PR_CHANGE_BAR_OFFSET);
2637+
m.setInherited(true);
2638+
m.setDefault("6pt");
2639+
addPropertyMaker("change-bar-offset", m);
2640+
}
2641+
25912642
private void createMiscProperties() {
25922643
PropertyMaker m;
25932644

fop-core/src/main/java/org/apache/fop/fo/FOText.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
3434
import org.apache.fop.datatypes.Length;
3535
import org.apache.fop.fo.flow.Block;
36+
import org.apache.fop.fo.pagination.PageSequence;
3637
import org.apache.fop.fo.properties.CommonFont;
3738
import org.apache.fop.fo.properties.CommonHyphenation;
3839
import org.apache.fop.fo.properties.CommonTextDecoration;
@@ -109,6 +110,11 @@ public class FOText extends FONode implements CharSequence, TextFragment {
109110
*/
110111
public FOText(FONode parent) {
111112
super(parent);
113+
114+
PageSequence pageSequence = getRoot().getLastPageSequence();
115+
if (pageSequence != null && pageSequence.hasChangeBars()) {
116+
nodeChangeBarList = getRoot().getLastPageSequence().getClonedChangeBarList();
117+
}
112118
}
113119

114120
/** {@inheritDoc} */

fop-core/src/main/java/org/apache/fop/fo/FOTreeBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ public void startElement(String namespaceURI, String localName, String rawName,
273273
if (currentFObj.getNamespaceURI().equals(FOElementMapping.URI)
274274
|| currentFObj.getNamespaceURI().equals(ExtensionElementMapping.URI)
275275
|| currentFObj.getNamespaceURI().equals(PDFElementMapping.NAMESPACE)) {
276-
currentFObj.validateChildNode(locator, namespaceURI, localName);
276+
if (!currentFObj.isChangeBarElement(namespaceURI, localName)) {
277+
currentFObj.validateChildNode(locator, namespaceURI, localName);
278+
}
277279
}
278280
}
279281

0 commit comments

Comments
 (0)