git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1062901 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_1rc1old
@@ -132,7 +132,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
/** | |||
* Traits for this area stored in a HashMap | |||
*/ | |||
protected Map props = null; | |||
protected Map<Integer, Object> props = null; | |||
/** | |||
* logging instance | |||
@@ -239,7 +239,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE); | |||
if (padWidth != null) { | |||
margin += padWidth.intValue(); | |||
margin += padWidth; | |||
} | |||
return margin; | |||
@@ -260,7 +260,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER); | |||
if (padWidth != null) { | |||
margin += padWidth.intValue(); | |||
margin += padWidth; | |||
} | |||
return margin; | |||
@@ -280,7 +280,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
Integer padWidth = (Integer) getTrait(Trait.PADDING_START); | |||
if (padWidth != null) { | |||
margin += padWidth.intValue(); | |||
margin += padWidth; | |||
} | |||
return margin; | |||
@@ -300,7 +300,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
Integer padWidth = (Integer) getTrait(Trait.PADDING_END); | |||
if (padWidth != null) { | |||
margin += padWidth.intValue(); | |||
margin += padWidth; | |||
} | |||
return margin; | |||
@@ -315,7 +315,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
int margin = 0; | |||
Integer space = (Integer) getTrait(Trait.SPACE_BEFORE); | |||
if (space != null) { | |||
margin = space.intValue(); | |||
margin = space; | |||
} | |||
return margin; | |||
} | |||
@@ -329,7 +329,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
int margin = 0; | |||
Integer space = (Integer) getTrait(Trait.SPACE_AFTER); | |||
if (space != null) { | |||
margin = space.intValue(); | |||
margin = space; | |||
} | |||
return margin; | |||
} | |||
@@ -343,7 +343,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
int margin = 0; | |||
Integer space = (Integer) getTrait(Trait.SPACE_START); | |||
if (space != null) { | |||
margin = space.intValue(); | |||
margin = space; | |||
} | |||
return margin; | |||
} | |||
@@ -357,7 +357,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
int margin = 0; | |||
Integer space = (Integer) getTrait(Trait.SPACE_END); | |||
if (space != null) { | |||
margin = space.intValue(); | |||
margin = space; | |||
} | |||
return margin; | |||
} | |||
@@ -380,9 +380,9 @@ public class Area extends AreaTreeObject implements Serializable { | |||
*/ | |||
public void addTrait(Object traitCode, Object prop) { | |||
if (props == null) { | |||
props = new java.util.HashMap(20); | |||
props = new java.util.HashMap<Integer, Object>(20); | |||
} | |||
props.put(traitCode, prop); | |||
props.put((Integer)traitCode, prop); | |||
} | |||
/** | |||
@@ -390,7 +390,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
* | |||
* @return the map of traits | |||
*/ | |||
public Map getTraits() { | |||
public Map<Integer, Object> getTraits() { | |||
return this.props; | |||
} | |||
@@ -402,44 +402,44 @@ public class Area extends AreaTreeObject implements Serializable { | |||
/** | |||
* Get a trait from this area. | |||
* | |||
* @param oTraitCode the trait key | |||
* @param traitCode the trait key | |||
* @return the trait value | |||
*/ | |||
public Object getTrait(Object oTraitCode) { | |||
return (props != null ? props.get(oTraitCode) : null); | |||
public Object getTrait(Integer traitCode) { | |||
return (props != null ? props.get(traitCode) : null); | |||
} | |||
/** | |||
* Checks whether a certain trait is set on this area. | |||
* @param oTraitCode the trait key | |||
* @param traitCode the trait key | |||
* @return true if the trait is set | |||
*/ | |||
public boolean hasTrait(Object oTraitCode) { | |||
return (getTrait(oTraitCode) != null); | |||
public boolean hasTrait(Integer traitCode) { | |||
return (getTrait(traitCode) != null); | |||
} | |||
/** | |||
* Get a boolean trait from this area. | |||
* @param oTraitCode the trait key | |||
* @param traitCode the trait key | |||
* @return the trait value | |||
*/ | |||
public boolean getTraitAsBoolean(Object oTraitCode) { | |||
return Boolean.TRUE.equals(getTrait(oTraitCode)); | |||
public boolean getTraitAsBoolean(Integer traitCode) { | |||
return Boolean.TRUE.equals(getTrait(traitCode)); | |||
} | |||
/** | |||
* Get a trait from this area as an integer. | |||
* | |||
* @param oTraitCode the trait key | |||
* @param traitCode the trait key | |||
* @return the trait value | |||
*/ | |||
public int getTraitAsInteger(Object oTraitCode) { | |||
final Object obj = getTrait(oTraitCode); | |||
public int getTraitAsInteger(Integer traitCode) { | |||
final Object obj = getTrait(traitCode); | |||
if (obj instanceof Integer) { | |||
return ((Integer)obj).intValue(); | |||
return (Integer) obj; | |||
} else { | |||
throw new IllegalArgumentException("Trait " | |||
+ oTraitCode.getClass().getName() | |||
+ traitCode.getClass().getName() | |||
+ " could not be converted to an integer"); | |||
} | |||
} | |||
@@ -447,7 +447,8 @@ public class Area extends AreaTreeObject implements Serializable { | |||
/** | |||
* {@inheritDoc} | |||
* @return ipd and bpd of area | |||
* */ | |||
*/ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(super.toString()); | |||
sb.append(" {ipd=").append(Integer.toString(getIPD())); |
@@ -21,7 +21,6 @@ package org.apache.fop.area; | |||
// Java | |||
import java.io.OutputStream; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import org.xml.sax.SAXException; | |||
@@ -175,6 +174,7 @@ public class AreaTreeHandler extends FOEventHandler { | |||
* @throws SAXException | |||
* if there is an error | |||
*/ | |||
@Override | |||
public void startDocument() throws SAXException { | |||
// Initialize statistics | |||
if (statistics != null) { | |||
@@ -194,6 +194,7 @@ public class AreaTreeHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void startPageSequence(PageSequence pageSequence) { | |||
startAbstractPageSequence(pageSequence); | |||
} | |||
@@ -210,10 +211,8 @@ public class AreaTreeHandler extends FOEventHandler { | |||
} | |||
} | |||
private void wrapAndAddExtensionAttachments(List list) { | |||
Iterator it = list.iterator(); | |||
while (it.hasNext()) { | |||
ExtensionAttachment attachment = (ExtensionAttachment) it.next(); | |||
private void wrapAndAddExtensionAttachments(List<ExtensionAttachment> list) { | |||
for (ExtensionAttachment attachment : list) { | |||
addOffDocumentItem(new OffDocumentExtensionAttachment(attachment)); | |||
} | |||
} | |||
@@ -224,6 +223,7 @@ public class AreaTreeHandler extends FOEventHandler { | |||
* | |||
* @param pageSequence the page sequence ending | |||
*/ | |||
@Override | |||
public void endPageSequence(PageSequence pageSequence) { | |||
if (statistics != null) { | |||
@@ -243,11 +243,13 @@ public class AreaTreeHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void startExternalDocument(ExternalDocument document) { | |||
startAbstractPageSequence(document); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void endExternalDocument(ExternalDocument document) { | |||
if (statistics != null) { | |||
statistics.end(); | |||
@@ -282,15 +284,16 @@ public class AreaTreeHandler extends FOEventHandler { | |||
* | |||
* @throws SAXException if there is some error | |||
*/ | |||
@Override | |||
public void endDocument() throws SAXException { | |||
finishPrevPageSequence(null); | |||
// process fox:destination elements | |||
if (rootFObj != null) { | |||
List destinationList = rootFObj.getDestinationList(); | |||
List<Destination> destinationList = rootFObj.getDestinationList(); | |||
if (destinationList != null) { | |||
while (destinationList.size() > 0) { | |||
Destination destination = (Destination) destinationList.remove(0); | |||
Destination destination = destinationList.remove(0); | |||
DestinationData destinationData = new DestinationData(destination); | |||
addOffDocumentItem(destinationData); | |||
} | |||
@@ -325,15 +328,15 @@ public class AreaTreeHandler extends FOEventHandler { | |||
if (odi instanceof Resolvable) { | |||
Resolvable res = (Resolvable) odi; | |||
String[] ids = res.getIDRefs(); | |||
for (int count = 0; count < ids.length; count++) { | |||
List pageVPList = idTracker.getPageViewportsContainingID(ids[count]); | |||
for (String id : ids) { | |||
List<PageViewport> pageVPList = idTracker.getPageViewportsContainingID(id); | |||
if (pageVPList != null) { | |||
res.resolveIDRef(ids[count], pageVPList); | |||
res.resolveIDRef(id, pageVPList); | |||
} else { | |||
AreaEventProducer eventProducer = AreaEventProducer.Provider.get( | |||
getUserAgent().getEventBroadcaster()); | |||
eventProducer.unresolvedIDReference(this, odi.getName(), ids[count]); | |||
idTracker.addUnresolvedIDRef(ids[count], res); | |||
eventProducer.unresolvedIDReference(this, odi.getName(), id); | |||
idTracker.addUnresolvedIDRef(id, res); | |||
} | |||
} | |||
// check to see if ODI is now fully resolved, if so process it | |||
@@ -414,13 +417,13 @@ public class AreaTreeHandler extends FOEventHandler { | |||
} | |||
/** | |||
* Get the list of page viewports that have an area with a given id. | |||
* Get the set of page viewports that have an area with a given id. | |||
* | |||
* @param id the id to lookup | |||
* @return the list of PageViewports | |||
* @deprecated use getIDTracker().getPageViewportsContainingID(id) instead | |||
*/ | |||
public List getPageViewportsContainingID(String id) { | |||
public List<PageViewport> getPageViewportsContainingID(String id) { | |||
return idTracker.getPageViewportsContainingID(id); | |||
} | |||
@@ -36,7 +36,7 @@ import org.apache.commons.logging.LogFactory; | |||
* the life of the area tree model. | |||
*/ | |||
public class AreaTreeModel { | |||
private List/*<PageSequence>*/ pageSequenceList = null; | |||
private List<PageSequence> pageSequenceList = null; | |||
private int currentPageSequenceIndex = -1; | |||
/** the current page sequence */ | |||
protected PageSequence currentPageSequence; | |||
@@ -48,7 +48,7 @@ public class AreaTreeModel { | |||
* Create a new store pages model | |||
*/ | |||
public AreaTreeModel() { | |||
pageSequenceList = new java.util.ArrayList/*<PageSequence>*/(); | |||
pageSequenceList = new java.util.ArrayList<PageSequence>(); | |||
} | |||
/** | |||
@@ -72,7 +72,7 @@ public class AreaTreeModel { | |||
currentPageSequence.addPage(page); | |||
int pageIndex = 0; | |||
for (int i = 0; i < currentPageSequenceIndex; i++) { | |||
pageIndex += ((PageSequence)pageSequenceList.get(i)).getPageCount(); | |||
pageIndex += pageSequenceList.get(i).getPageCount(); | |||
} | |||
pageIndex += currentPageSequence.getPageCount() - 1; | |||
page.setPageIndex(pageIndex); | |||
@@ -113,8 +113,7 @@ public class AreaTreeModel { | |||
* @return returns the number of pages in a page sequence | |||
*/ | |||
public int getPageCount(int seq) { | |||
PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1); | |||
return sequence.getPageCount(); | |||
return pageSequenceList.get(seq - 1).getPageCount(); | |||
} | |||
/** | |||
@@ -124,7 +123,6 @@ public class AreaTreeModel { | |||
* @return the PageViewport for the particular page | |||
*/ | |||
public PageViewport getPage(int seq, int count) { | |||
PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1); | |||
return sequence.getPage(count); | |||
return pageSequenceList.get(seq - 1).getPage(count); | |||
} | |||
} |
@@ -34,10 +34,10 @@ import org.apache.fop.fo.extensions.ExtensionAttachment; | |||
public abstract class AreaTreeObject { | |||
/** Foreign attributes */ | |||
protected Map foreignAttributes = null; | |||
protected Map<QName, String> foreignAttributes = null; | |||
/** Extension attachments */ | |||
protected List/*<ExtensionAttachment>*/ extensionAttachments = null; | |||
protected List<ExtensionAttachment> extensionAttachments = null; | |||
/** | |||
* Sets a foreign attribute. | |||
@@ -46,25 +46,22 @@ public abstract class AreaTreeObject { | |||
*/ | |||
public void setForeignAttribute(QName name, String value) { | |||
if (this.foreignAttributes == null) { | |||
this.foreignAttributes = new java.util.HashMap(); | |||
this.foreignAttributes = new java.util.HashMap<QName, String>(); | |||
} | |||
this.foreignAttributes.put(name, value); | |||
} | |||
/** | |||
* Set foreign attributes from a Map. | |||
* Add foreign attributes from a Map. | |||
* | |||
* @param atts a Map with attributes (keys: QName, values: String) | |||
*/ | |||
public void setForeignAttributes(Map atts) { | |||
if (atts.size() == 0) { | |||
public void setForeignAttributes(Map<QName, String> atts) { | |||
if (atts == null || atts.size() == 0) { | |||
return; | |||
} | |||
Iterator iter = atts.entrySet().iterator(); | |||
while (iter.hasNext()) { | |||
Map.Entry entry = (Map.Entry)iter.next(); | |||
String value = (String)entry.getValue(); | |||
//The casting is only to ensure type safety (too bad we can't use generics, yet) | |||
setForeignAttribute((QName)entry.getKey(), value); | |||
for (Map.Entry<QName, String> e : atts.entrySet()) { | |||
setForeignAttribute(e.getKey(), e.getValue()); | |||
} | |||
} | |||
@@ -75,24 +72,24 @@ public abstract class AreaTreeObject { | |||
*/ | |||
public String getForeignAttributeValue(QName name) { | |||
if (this.foreignAttributes != null) { | |||
return (String)this.foreignAttributes.get(name); | |||
return this.foreignAttributes.get(name); | |||
} else { | |||
return null; | |||
} | |||
} | |||
/** @return the foreign attributes associated with this area */ | |||
public Map getForeignAttributes() { | |||
public Map<QName, String> getForeignAttributes() { | |||
if (this.foreignAttributes != null) { | |||
return Collections.unmodifiableMap(this.foreignAttributes); | |||
} else { | |||
return Collections.EMPTY_MAP; | |||
return Collections.emptyMap(); | |||
} | |||
} | |||
private void prepareExtensionAttachmentContainer() { | |||
if (this.extensionAttachments == null) { | |||
this.extensionAttachments = new java.util.ArrayList/*<ExtensionAttachment>*/(); | |||
this.extensionAttachments = new java.util.ArrayList<ExtensionAttachment>(); | |||
} | |||
} | |||
@@ -109,17 +106,17 @@ public abstract class AreaTreeObject { | |||
* Set extension attachments from a List | |||
* @param extensionAttachments a List with extension attachments | |||
*/ | |||
public void setExtensionAttachments(List extensionAttachments) { | |||
public void setExtensionAttachments(List<ExtensionAttachment> extensionAttachments) { | |||
prepareExtensionAttachmentContainer(); | |||
this.extensionAttachments.addAll(extensionAttachments); | |||
} | |||
/** @return the extension attachments associated with this area */ | |||
public List getExtensionAttachments() { | |||
public List<ExtensionAttachment> getExtensionAttachments() { | |||
if (this.extensionAttachments != null) { | |||
return Collections.unmodifiableList(this.extensionAttachments); | |||
} else { | |||
return Collections.EMPTY_LIST; | |||
return Collections.emptyList(); | |||
} | |||
} | |||
@@ -75,7 +75,6 @@ import org.apache.fop.area.inline.SpaceArea; | |||
import org.apache.fop.area.inline.TextArea; | |||
import org.apache.fop.area.inline.Viewport; | |||
import org.apache.fop.area.inline.WordArea; | |||
import org.apache.fop.fo.Constants; | |||
import org.apache.fop.fo.ElementMappingRegistry; | |||
import org.apache.fop.fo.expr.PropertyException; | |||
import org.apache.fop.fo.extensions.ExtensionAttachment; | |||
@@ -91,6 +90,12 @@ import org.apache.fop.util.DelegatingContentHandler; | |||
import org.apache.fop.util.XMLConstants; | |||
import org.apache.fop.util.XMLUtil; | |||
import static org.apache.fop.fo.Constants.FO_REGION_AFTER; | |||
import static org.apache.fop.fo.Constants.FO_REGION_BEFORE; | |||
import static org.apache.fop.fo.Constants.FO_REGION_BODY; | |||
import static org.apache.fop.fo.Constants.FO_REGION_END; | |||
import static org.apache.fop.fo.Constants.FO_REGION_START; | |||
/** | |||
* This is a parser for the area tree XML (intermediate format) which is used to reread an area | |||
* tree (or part of it) into memory again for rendering to the final output format. | |||
@@ -136,7 +141,7 @@ public class AreaTreeParser { | |||
private static class Handler extends DefaultHandler { | |||
private Map makers = new java.util.HashMap(); | |||
private Map<String, AbstractMaker> makers = new java.util.HashMap<String, AbstractMaker>(); | |||
private AreaTreeModel treeModel; | |||
private FOUserAgent userAgent; | |||
@@ -148,14 +153,15 @@ public class AreaTreeParser { | |||
private boolean ignoreCharacters = true; | |||
private PageViewport currentPageViewport; | |||
private Map pageViewportsByKey = new java.util.HashMap(); | |||
private Map<String, PageViewport> pageViewportsByKey | |||
= new java.util.HashMap<String, PageViewport>(); | |||
// set of "ID firsts" that have already been assigned to a PV: | |||
private Set idFirstsAssigned = new java.util.HashSet(); | |||
private Set<String> idFirstsAssigned = new java.util.HashSet<String>(); | |||
private Stack areaStack = new Stack(); | |||
private Stack<Object> areaStack = new Stack<Object>(); | |||
private boolean firstFlow; | |||
private Stack delegateStack = new Stack(); | |||
private Stack<String> delegateStack = new Stack<String>(); | |||
private ContentHandler delegate; | |||
private DOMImplementation domImplementation; | |||
private Locator locator; | |||
@@ -228,9 +234,9 @@ public class AreaTreeParser { | |||
if (areaStack.size() > 0) { | |||
int pos = areaStack.size() - 1; | |||
Object obj = null; | |||
while ( pos >= 0 ) { | |||
while (pos >= 0) { | |||
obj = areaStack.get(pos); | |||
if ( clazz.isInstance ( obj ) ) { | |||
if (clazz.isInstance(obj)) { | |||
break; | |||
} else { | |||
pos--; | |||
@@ -358,7 +364,7 @@ public class AreaTreeParser { | |||
private boolean startAreaTreeElement(String localName, Attributes attributes) | |||
throws SAXException { | |||
lastAttributes = new AttributesImpl(attributes); | |||
Maker maker = (Maker)makers.get(localName); | |||
Maker maker = makers.get(localName); | |||
content.clear(); | |||
ignoreCharacters = true; | |||
if (maker != null) { | |||
@@ -387,7 +393,7 @@ public class AreaTreeParser { | |||
} | |||
} else { | |||
if ("".equals(uri)) { | |||
Maker maker = (Maker)makers.get(localName); | |||
Maker maker = makers.get(localName); | |||
if (maker != null) { | |||
maker.endElement(); | |||
content.clear(); | |||
@@ -525,7 +531,7 @@ public class AreaTreeParser { | |||
private class RegionBeforeMaker extends AbstractMaker { | |||
public void startElement(Attributes attributes) { | |||
pushNewRegionReference(attributes, Constants.FO_REGION_BEFORE); | |||
pushNewRegionReference(attributes, FO_REGION_BEFORE); | |||
} | |||
public void endElement() { | |||
@@ -536,7 +542,7 @@ public class AreaTreeParser { | |||
private class RegionAfterMaker extends AbstractMaker { | |||
public void startElement(Attributes attributes) { | |||
pushNewRegionReference(attributes, Constants.FO_REGION_AFTER); | |||
pushNewRegionReference(attributes, FO_REGION_AFTER); | |||
} | |||
public void endElement() { | |||
@@ -547,7 +553,7 @@ public class AreaTreeParser { | |||
private class RegionStartMaker extends AbstractMaker { | |||
public void startElement(Attributes attributes) { | |||
pushNewRegionReference(attributes, Constants.FO_REGION_START); | |||
pushNewRegionReference(attributes, FO_REGION_START); | |||
} | |||
public void endElement() { | |||
@@ -558,7 +564,7 @@ public class AreaTreeParser { | |||
private class RegionEndMaker extends AbstractMaker { | |||
public void startElement(Attributes attributes) { | |||
pushNewRegionReference(attributes, Constants.FO_REGION_END); | |||
pushNewRegionReference(attributes, FO_REGION_END); | |||
} | |||
public void endElement() { | |||
@@ -577,15 +583,13 @@ public class AreaTreeParser { | |||
int columnCount = XMLUtil.getAttributeAsInt(attributes, "columnCount", 1); | |||
int columnGap = XMLUtil.getAttributeAsInt(attributes, "columnGap", 0); | |||
RegionViewport rv = getCurrentRegionViewport(); | |||
body = new BodyRegion(Constants.FO_REGION_BODY, | |||
regionName, rv, columnCount, columnGap); | |||
body = new BodyRegion(FO_REGION_BODY, regionName, rv, columnCount, columnGap); | |||
transferForeignObjects(attributes, body); | |||
body.setCTM(getAttributeAsCTM(attributes, "ctm")); | |||
setAreaAttributes(attributes, body); | |||
setTraits(attributes, body, SUBSET_BORDER_PADDING); | |||
rv.setRegionReference(body); | |||
currentPageViewport.getPage().setRegionViewport( | |||
Constants.FO_REGION_BODY, rv); | |||
currentPageViewport.getPage().setRegionViewport(FO_REGION_BODY, rv); | |||
areaStack.push(body); | |||
} | |||
@@ -982,7 +986,7 @@ public class AreaTreeParser { | |||
attributes, "show-children", false); | |||
String[] linkdata | |||
= InternalLink.parseXMLAttribute(attributes.getValue("internal-link")); | |||
PageViewport pv = (PageViewport) pageViewportsByKey.get(linkdata[0]); | |||
PageViewport pv = pageViewportsByKey.get(linkdata[0]); | |||
BookmarkData bm = new BookmarkData(title, showChildren, pv, linkdata[1]); | |||
Object tos = areaStack.peek(); | |||
if (tos instanceof BookmarkData) { | |||
@@ -1002,9 +1006,9 @@ public class AreaTreeParser { | |||
public void startElement(Attributes attributes) { | |||
String[] linkdata | |||
= InternalLink.parseXMLAttribute(lastAttributes.getValue("internal-link")); | |||
PageViewport pv = (PageViewport) pageViewportsByKey.get(linkdata[0]); | |||
PageViewport pv = pageViewportsByKey.get(linkdata[0]); | |||
DestinationData dest = new DestinationData(linkdata[1]); | |||
List pages = new java.util.ArrayList(); | |||
List<PageViewport> pages = new java.util.ArrayList<PageViewport>(); | |||
pages.add(pv); | |||
dest.resolveIDRef(linkdata[1], pages); | |||
areaStack.push(dest); | |||
@@ -1096,7 +1100,7 @@ public class AreaTreeParser { | |||
private void setTraits(Attributes attributes, Area area, Object[] traitSubset) { | |||
for (int i = traitSubset.length; --i >= 0;) { | |||
Object trait = traitSubset[i]; | |||
Integer trait = (Integer) traitSubset[i]; | |||
String traitName = Trait.getTraitName(trait); | |||
String value = attributes.getValue(traitName); | |||
if (value != null) { | |||
@@ -1107,7 +1111,7 @@ public class AreaTreeParser { | |||
area.addTrait(trait, Boolean.valueOf(value)); | |||
} else if (cl == String.class) { | |||
area.addTrait(trait, value); | |||
if (trait == Trait.PROD_ID | |||
if (Trait.PROD_ID.equals(trait) | |||
&& !idFirstsAssigned.contains(value) | |||
&& currentPageViewport != null) { | |||
currentPageViewport.setFirstWithID(value); | |||
@@ -1173,7 +1177,7 @@ public class AreaTreeParser { | |||
area.addTrait(trait, BorderProps.valueOf(this.userAgent, value)); | |||
} | |||
} else { | |||
if (trait == Trait.FONT) { | |||
if (Trait.FONT.equals(trait)) { | |||
String fontName = attributes.getValue("font-name"); | |||
if (fontName != null) { | |||
String fontStyle = attributes.getValue("font-style"); |
@@ -57,6 +57,7 @@ public class BeforeFloat extends BlockParent { | |||
* | |||
* @return the height of the before float including separator | |||
*/ | |||
@Override | |||
public int getBPD() { | |||
int h = super.getBPD(); | |||
if (separator != null) { | |||
@@ -66,6 +67,7 @@ public class BeforeFloat extends BlockParent { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public boolean isEmpty() { | |||
return true; // before floats are not yet implemented | |||
} |
@@ -50,15 +50,13 @@ public class BlockParent extends Area { | |||
/** | |||
* The children of this block parent area. | |||
*/ | |||
protected List children = null; | |||
// orientation if reference area | |||
// private int orientation = ORIENT_0; | |||
protected List<Area> children = null; | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void addChildArea(Area childArea) { | |||
if (children == null) { | |||
children = new ArrayList(); | |||
children = new ArrayList<Area>(); | |||
} | |||
children.add(childArea); | |||
} |
@@ -19,8 +19,6 @@ | |||
package org.apache.fop.area; | |||
import java.util.Collection; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
@@ -34,13 +32,13 @@ import org.apache.fop.fo.pagination.bookmarks.BookmarkTree; | |||
*/ | |||
public class BookmarkData extends AbstractOffDocumentItem implements Resolvable { | |||
private List subData = new java.util.ArrayList(); | |||
private List<BookmarkData> subData = new java.util.ArrayList<BookmarkData>(); | |||
// bookmark-title for this fo:bookmark | |||
private String bookmarkTitle = null; | |||
// indicator of whether to initially display/hide child bookmarks of this object | |||
private boolean bShow = true; | |||
private boolean showChildren = true; | |||
// ID Reference for this bookmark | |||
private String idRef; | |||
@@ -49,7 +47,8 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
private PageViewport pageRef = null; | |||
// unresolved idrefs by this bookmark and child bookmarks below it | |||
private Map unresolvedIDRefs = new java.util.HashMap(); | |||
private Map<String, List<Resolvable>> unresolvedIDRefs | |||
= new java.util.HashMap<String, List<Resolvable>>(); | |||
/** | |||
* Create a new bookmark data object. | |||
@@ -59,10 +58,10 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
* @param bookmarkTree fo:bookmark-tree for this document | |||
*/ | |||
public BookmarkData(BookmarkTree bookmarkTree) { | |||
idRef = null; | |||
whenToProcess = END_OF_DOC; | |||
this.idRef = null; | |||
this.whenToProcess = END_OF_DOC; | |||
// top level defined in Rec to show all child bookmarks | |||
bShow = true; | |||
this.showChildren = true; | |||
for (int count = 0; count < bookmarkTree.getBookmarks().size(); count++) { | |||
Bookmark bkmk = (Bookmark)(bookmarkTree.getBookmarks()).get(count); | |||
@@ -79,15 +78,15 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
* @param bookmark the fo:bookmark object | |||
*/ | |||
public BookmarkData(Bookmark bookmark) { | |||
bookmarkTitle = bookmark.getBookmarkTitle(); | |||
bShow = bookmark.showChildItems(); | |||
this.bookmarkTitle = bookmark.getBookmarkTitle(); | |||
this.showChildren = bookmark.showChildItems(); | |||
this.idRef = bookmark.getInternalDestination(); | |||
} | |||
private void putUnresolved(String id, BookmarkData bd) { | |||
List refs = (List)unresolvedIDRefs.get(id); | |||
List<Resolvable> refs = unresolvedIDRefs.get(id); | |||
if (refs == null) { | |||
refs = new java.util.ArrayList(); | |||
refs = new java.util.ArrayList<Resolvable>(); | |||
unresolvedIDRefs.put(id, refs); | |||
} | |||
refs.add(bd); | |||
@@ -101,7 +100,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
public BookmarkData() { | |||
idRef = null; | |||
whenToProcess = END_OF_DOC; | |||
bShow = true; | |||
showChildren = true; | |||
} | |||
/** | |||
@@ -116,7 +115,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
*/ | |||
public BookmarkData(String title, boolean showChildren, PageViewport pv, String idRef) { | |||
bookmarkTitle = title; | |||
bShow = showChildren; | |||
this.showChildren = showChildren; | |||
pageRef = pv; | |||
this.idRef = idRef; | |||
} | |||
@@ -138,11 +137,11 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
*/ | |||
public void addSubData(BookmarkData sub) { | |||
subData.add(sub); | |||
if (sub.pageRef == null || sub.pageRef.equals("")) { | |||
if (sub.pageRef == null) { | |||
putUnresolved(sub.getIDRef(), sub); | |||
String[] ids = sub.getIDRefs(); | |||
for (int count = 0; count < ids.length; count++) { | |||
putUnresolved(ids[count], sub); | |||
for (String id : ids) { | |||
putUnresolved(id, sub); | |||
} | |||
} | |||
} | |||
@@ -162,7 +161,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
* @return true to initially display child bookmarks, false otherwise | |||
*/ | |||
public boolean showChildItems() { | |||
return bShow; | |||
return showChildren; | |||
} | |||
/** | |||
@@ -181,7 +180,7 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
* @return the child bookmark data | |||
*/ | |||
public BookmarkData getSubData(int count) { | |||
return (BookmarkData) subData.get(count); | |||
return subData.get(count); | |||
} | |||
/** | |||
@@ -208,7 +207,8 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
* {@inheritDoc} | |||
*/ | |||
public String[] getIDRefs() { | |||
return (String[])unresolvedIDRefs.keySet().toArray(new String[] {}); | |||
return unresolvedIDRefs.keySet().toArray( | |||
new String[unresolvedIDRefs.keySet().size()]); | |||
} | |||
/** | |||
@@ -217,22 +217,20 @@ public class BookmarkData extends AbstractOffDocumentItem implements Resolvable | |||
* resolves id references of child elements that have the same | |||
* id reference. | |||
* | |||
* {@inheritDoc} List) | |||
* {@inheritDoc} | |||
*/ | |||
public void resolveIDRef(String id, List pages) { | |||
public void resolveIDRef(String id, List<PageViewport> pages) { | |||
if (id.equals(idRef)) { | |||
//Own ID has been resolved, so note the page | |||
pageRef = (PageViewport) pages.get(0); | |||
pageRef = pages.get(0); | |||
//Note: Determining the placement inside the page is the renderer's job. | |||
} | |||
//Notify all child bookmarks | |||
Collection refs = (Collection)unresolvedIDRefs.get(id); | |||
List<Resolvable> refs = unresolvedIDRefs.get(id); | |||
if (refs != null) { | |||
Iterator iter = refs.iterator(); | |||
while (iter.hasNext()) { | |||
BookmarkData bd = (BookmarkData)iter.next(); | |||
bd.resolveIDRef(id, pages); | |||
for (Resolvable res : refs) { | |||
res.resolveIDRef(id, pages); | |||
} | |||
} | |||
unresolvedIDRefs.remove(id); |
@@ -25,7 +25,10 @@ import java.awt.geom.Rectangle2D; | |||
import java.io.Serializable; | |||
import org.apache.fop.datatypes.FODimension; | |||
import org.apache.fop.fo.Constants; | |||
import static org.apache.fop.fo.Constants.EN_LR_TB; | |||
import static org.apache.fop.fo.Constants.EN_RL_TB; | |||
import static org.apache.fop.fo.Constants.EN_TB_RL; | |||
/** | |||
* Describe a PDF or PostScript style coordinate transformation matrix (CTM). | |||
@@ -133,14 +136,14 @@ public class CTM implements Serializable { | |||
public static CTM getWMctm(int wm, int ipd, int bpd) { | |||
CTM wmctm; | |||
switch (wm) { | |||
case Constants.EN_LR_TB: | |||
case EN_LR_TB: | |||
return new CTM(CTM_LRTB); | |||
case Constants.EN_RL_TB: | |||
case EN_RL_TB: | |||
wmctm = new CTM(CTM_RLTB); | |||
wmctm.e = ipd; | |||
return wmctm; | |||
//return CTM_RLTB.translate(ipd, 0); | |||
case Constants.EN_TB_RL: // CJK | |||
case EN_TB_RL: // CJK | |||
wmctm = new CTM(CTM_TBRL); | |||
wmctm.e = bpd; | |||
return wmctm; | |||
@@ -157,13 +160,12 @@ public class CTM implements Serializable { | |||
* @return CTM The result of multiplying premult * this. | |||
*/ | |||
public CTM multiply(CTM premult) { | |||
CTM result = new CTM ((premult.a * a) + (premult.b * c), | |||
return new CTM ((premult.a * a) + (premult.b * c), | |||
(premult.a * b) + (premult.b * d), | |||
(premult.c * a) + (premult.d * c), | |||
(premult.c * b) + (premult.d * d), | |||
(premult.e * a) + (premult.f * c) + e, | |||
(premult.e * b) + (premult.f * d) + f); | |||
return result; | |||
} | |||
/** | |||
@@ -249,6 +251,7 @@ public class CTM implements Serializable { | |||
* | |||
* @return a string with the transform values | |||
*/ | |||
@Override | |||
public String toString() { | |||
return "[" + a + " " + b + " " + c + " " + d + " " + e + " " | |||
+ f + "]"; | |||
@@ -332,7 +335,7 @@ public class CTM implements Serializable { | |||
* can set ipd and bpd appropriately based on the writing mode. | |||
*/ | |||
if (writingMode == Constants.EN_LR_TB || writingMode == Constants.EN_RL_TB) { | |||
if (writingMode == EN_LR_TB || writingMode == EN_RL_TB) { | |||
reldims.ipd = width; | |||
reldims.bpd = height; | |||
} else { |
@@ -48,7 +48,8 @@ import org.apache.fop.fonts.FontInfo; | |||
* the contents are reloaded. | |||
*/ | |||
public class CachedRenderPagesModel extends RenderPagesModel { | |||
private Map pageMap = new HashMap(); | |||
private Map<PageViewport, String> pageMap = new HashMap<PageViewport, String>(); | |||
/** Base directory to save temporary file in, typically points to the user's temp dir. */ | |||
protected File baseDir; | |||
@@ -64,12 +65,12 @@ public class CachedRenderPagesModel extends RenderPagesModel { | |||
public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat, | |||
FontInfo fontInfo, OutputStream stream) throws FOPException { | |||
super(userAgent, outputFormat, fontInfo, stream); | |||
//TODO: Avoid System.getProperty()? | |||
this.baseDir = new File(System.getProperty("java.io.tmpdir")); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
/** {@inheritDoc} */ | |||
@Override | |||
protected boolean checkPreparedPages(PageViewport newpage, boolean renderUnresolved) { | |||
for (Iterator iter = prepared.iterator(); iter.hasNext();) { | |||
PageViewport pageViewport = (PageViewport)iter.next(); | |||
@@ -77,7 +78,7 @@ public class CachedRenderPagesModel extends RenderPagesModel { | |||
if (pageViewport != newpage) { | |||
try { | |||
// load page from cache | |||
String name = (String)pageMap.get(pageViewport); | |||
String name = pageMap.get(pageViewport); | |||
File tempFile = new File(baseDir, name); | |||
log.debug("Loading page from: " + tempFile); | |||
ObjectInputStream in = new ObjectInputStream( | |||
@@ -152,6 +153,7 @@ public class CachedRenderPagesModel extends RenderPagesModel { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void endDocument() throws SAXException { | |||
super.endDocument(); | |||
} |
@@ -66,9 +66,7 @@ public class DestinationData extends AbstractOffDocumentItem implements Resolvab | |||
return idRef; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
/** {@inheritDoc} */ | |||
public String[] getIDRefs() { | |||
return idRefs; | |||
} | |||
@@ -97,12 +95,12 @@ public class DestinationData extends AbstractOffDocumentItem implements Resolvab | |||
* Resolves the idref of this object by getting the PageViewport | |||
* object that corresponds to the IDRef | |||
* | |||
* {@inheritDoc} List) | |||
* {@inheritDoc} | |||
* TODO check to make sure it works if multiple bookmark-items | |||
* have the same idref | |||
*/ | |||
public void resolveIDRef(String id, List pages) { | |||
pageRef = (PageViewport) pages.get(0); | |||
public void resolveIDRef(String id, List<PageViewport> pages) { | |||
pageRef = pages.get(0); | |||
// TODO get rect area of id on page | |||
} | |||
@@ -80,6 +80,7 @@ public class Footnote extends BlockParent { | |||
* | |||
* @param child the block area. | |||
*/ | |||
@Override | |||
public void addBlock(Block child) { | |||
addChildArea(child); | |||
this.setBPD(this.getBPD() + child.getBPD()); |
@@ -19,8 +19,7 @@ | |||
package org.apache.fop.area; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
@@ -36,18 +35,20 @@ public class IDTracker { | |||
private static final Log LOG = LogFactory.getLog(IDTracker.class); | |||
// HashMap of ID's whose area is located on one or more consecutive | |||
// PageViewports. Each ID has an arraylist of PageViewports that | |||
// Map of ID's whose area is located on one or more consecutive | |||
// PageViewports. Each ID has a list of PageViewports that | |||
// form the defined area of this ID | |||
private Map idLocations = new java.util.HashMap(); | |||
private Map<String, List<PageViewport>> idLocations | |||
= new java.util.HashMap<String, List<PageViewport>>(); | |||
// idref's whose target PageViewports have yet to be identified | |||
// Each idref has a HashSet of Resolvable objects containing that idref | |||
private Map unresolvedIDRefs = new java.util.HashMap(); | |||
private Map<String, Set<Resolvable>> unresolvedIDRefs | |||
= new java.util.HashMap<String, Set<Resolvable>>(); | |||
private Set unfinishedIDs = new java.util.HashSet(); | |||
private Set<String> unfinishedIDs = new java.util.HashSet<String>(); | |||
private Set alreadyResolvedIDs = new java.util.HashSet(); | |||
private Set<String> alreadyResolvedIDs = new java.util.HashSet<String>(); | |||
/** | |||
* Tie a PageViewport with an ID found on a child area of the PV. Note that | |||
@@ -61,9 +62,9 @@ public class IDTracker { | |||
if (LOG.isDebugEnabled()) { | |||
LOG.debug("associateIDWithPageViewport(" + id + ", " + pv + ")"); | |||
} | |||
List pvList = (List) idLocations.get(id); | |||
List<PageViewport> pvList = idLocations.get(id); | |||
if (pvList == null) { // first time ID located | |||
pvList = new ArrayList(); | |||
pvList = new java.util.ArrayList<PageViewport>(); | |||
idLocations.put(id, pvList); | |||
pvList.add(pv); | |||
// signal the PageViewport that it is the first PV to contain this id: | |||
@@ -73,7 +74,7 @@ public class IDTracker { | |||
* Resolvable objects tied to it. | |||
*/ | |||
if (!unfinishedIDs.contains(id)) { | |||
tryIDResolution(id, pv, pvList); | |||
tryIDResolution(id, pvList); | |||
} | |||
} else { | |||
/* TODO: The check is a quick-fix to avoid a waste | |||
@@ -116,12 +117,11 @@ public class IDTracker { | |||
} | |||
unfinishedIDs.remove(id); | |||
List pvList = (List) idLocations.get(id); | |||
Set todo = (Set) unresolvedIDRefs.get(id); | |||
List<PageViewport> idLocs = idLocations.get(id); | |||
Set<Resolvable> todo = unresolvedIDRefs.get(id); | |||
if (todo != null) { | |||
for (Iterator iter = todo.iterator(); iter.hasNext();) { | |||
Resolvable res = (Resolvable) iter.next(); | |||
res.resolveIDRef(id, pvList); | |||
for (Resolvable res : todo) { | |||
res.resolveIDRef(id, idLocs); | |||
} | |||
unresolvedIDRefs.remove(id); | |||
} | |||
@@ -138,17 +138,15 @@ public class IDTracker { | |||
} | |||
/** | |||
* Tries to resolve all unresolved ID references on the given page. | |||
* Tries to resolve all unresolved ID references on the given set of pages. | |||
* | |||
* @param id ID to resolve | |||
* @param pv page viewport whose ID refs to resolve | |||
* @param pvList of PageViewports | |||
* @param pvList list of PageViewports | |||
*/ | |||
private void tryIDResolution(String id, PageViewport pv, List pvList) { | |||
Set todo = (Set) unresolvedIDRefs.get(id); | |||
private void tryIDResolution(String id, List<PageViewport> pvList) { | |||
Set<Resolvable> todo = unresolvedIDRefs.get(id); | |||
if (todo != null) { | |||
for (Iterator iter = todo.iterator(); iter.hasNext();) { | |||
Resolvable res = (Resolvable) iter.next(); | |||
for (Resolvable res : todo) { | |||
if (!unfinishedIDs.contains(id)) { | |||
res.resolveIDRef(id, pvList); | |||
} else { | |||
@@ -168,10 +166,10 @@ public class IDTracker { | |||
public void tryIDResolution(PageViewport pv) { | |||
String[] ids = pv.getIDRefs(); | |||
if (ids != null) { | |||
for (int i = 0; i < ids.length; i++) { | |||
List pvList = (List) idLocations.get(ids[i]); | |||
if (pvList != null) { | |||
tryIDResolution(ids[i], pv, pvList); | |||
for (String id : ids) { | |||
List<PageViewport> pvList = idLocations.get(id); | |||
if (!(pvList == null || pvList.isEmpty())) { | |||
tryIDResolution(id, pvList); | |||
} | |||
} | |||
} | |||
@@ -183,8 +181,46 @@ public class IDTracker { | |||
* @param id the id to lookup | |||
* @return the list of PageViewports | |||
*/ | |||
public List getPageViewportsContainingID(String id) { | |||
return (List) idLocations.get(id); | |||
public List<PageViewport> getPageViewportsContainingID(String id) { | |||
if (!(idLocations == null || idLocations.isEmpty())) { | |||
List<PageViewport> idLocs = idLocations.get(id); | |||
if (idLocs != null) { | |||
return idLocs; | |||
} | |||
} | |||
return Collections.emptyList(); | |||
} | |||
/** | |||
* Get the first {@link PageViewport} containing content generated | |||
* by the FO with the given {@code id}. | |||
* | |||
* @param id the id | |||
* @return the first {@link PageViewport} for the id; {@code null} if | |||
* no matching {@link PageViewport} was found | |||
*/ | |||
public PageViewport getFirstPageViewportContaining(String id) { | |||
List<PageViewport> list = getPageViewportsContainingID(id); | |||
if (!(list == null || list.isEmpty())) { | |||
return list.get(0); | |||
} | |||
return null; | |||
} | |||
/** | |||
* Get the last {@link PageViewport} containing content generated | |||
* by the FO with the given {@code id}. | |||
* | |||
* @param id the id | |||
* @return the last {@link PageViewport} for the id; {@code null} if | |||
* no matching {@link PageViewport} was found | |||
*/ | |||
public PageViewport getLastPageViewportContaining(String id) { | |||
List<PageViewport> list = getPageViewportsContainingID(id); | |||
if (!(list == null || list.isEmpty())) { | |||
return list.get(list.size() - 1); | |||
} | |||
return null; | |||
} | |||
/** | |||
@@ -194,9 +230,9 @@ public class IDTracker { | |||
* @param res the Resolvable object needing the idref to be resolved | |||
*/ | |||
public void addUnresolvedIDRef(String idref, Resolvable res) { | |||
Set todo = (Set) unresolvedIDRefs.get(idref); | |||
Set<Resolvable> todo = unresolvedIDRefs.get(idref); | |||
if (todo == null) { | |||
todo = new java.util.HashSet(); | |||
todo = new java.util.HashSet<Resolvable>(); | |||
unresolvedIDRefs.put(idref, todo); | |||
} | |||
// add Resolvable object to this HashSet |
@@ -24,7 +24,11 @@ import java.util.ArrayList; | |||
import java.util.List; | |||
import org.apache.fop.area.inline.InlineArea; | |||
import org.apache.fop.fo.Constants; | |||
import static org.apache.fop.fo.Constants.EN_START; | |||
import static org.apache.fop.fo.Constants.EN_CENTER; | |||
import static org.apache.fop.fo.Constants.EN_END; | |||
import static org.apache.fop.fo.Constants.EN_JUSTIFY; | |||
/** | |||
* The line area. | |||
@@ -75,7 +79,7 @@ public class LineArea extends Area { | |||
// this class can contain the dominant char styling info | |||
// this means that many renderers can optimise a bit | |||
private List inlineAreas = new ArrayList(); | |||
private List<InlineArea> inlineAreas = new ArrayList<InlineArea>(); | |||
/** | |||
* default constructor: | |||
@@ -102,11 +106,12 @@ public class LineArea extends Area { | |||
* | |||
* @param childArea the inline child area to add | |||
*/ | |||
@Override | |||
public void addChildArea(Area childArea) { | |||
if (childArea instanceof InlineArea) { | |||
addInlineArea((InlineArea)childArea); | |||
// set the parent area for the child area | |||
((InlineArea) childArea).setParentArea(this); | |||
((InlineArea)childArea).setParentArea(this); | |||
} | |||
} | |||
@@ -150,8 +155,8 @@ public class LineArea extends Area { | |||
int ipd = 0; | |||
int bpd = 0; | |||
for (int i = 0, len = inlineAreas.size(); i < len; i++) { | |||
ipd = Math.max(ipd, ((InlineArea)inlineAreas.get(i)).getAllocIPD()); | |||
bpd += ((InlineArea)inlineAreas.get(i)).getAllocBPD(); | |||
ipd = Math.max(ipd, inlineAreas.get(i).getAllocIPD()); | |||
bpd += inlineAreas.get(i).getAllocBPD(); | |||
} | |||
setIPD(ipd); | |||
setBPD(bpd); | |||
@@ -174,18 +179,18 @@ public class LineArea extends Area { | |||
*/ | |||
public void handleIPDVariation(int ipdVariation) { | |||
switch (adjustingInfo.lineAlignment) { | |||
case Constants.EN_START: | |||
case EN_START: | |||
// nothing to do in this case | |||
break; | |||
case Constants.EN_CENTER: | |||
case EN_CENTER: | |||
// re-compute indent | |||
addTrait(Trait.START_INDENT, new Integer(getStartIndent() - ipdVariation / 2)); | |||
addTrait(Trait.START_INDENT, getStartIndent() - ipdVariation / 2); | |||
break; | |||
case Constants.EN_END: | |||
case EN_END: | |||
// re-compute indent | |||
addTrait(Trait.START_INDENT, new Integer(getStartIndent() - ipdVariation)); | |||
addTrait(Trait.START_INDENT, getStartIndent() - ipdVariation); | |||
break; | |||
case Constants.EN_JUSTIFY: | |||
case EN_JUSTIFY: | |||
// compute variation factor | |||
adjustingInfo.variationFactor *= (float) (adjustingInfo.difference - ipdVariation) | |||
/ adjustingInfo.difference; | |||
@@ -207,7 +212,7 @@ public class LineArea extends Area { | |||
* no UnresolvedAreas left | |||
*/ | |||
public void finalise() { | |||
if (adjustingInfo.lineAlignment == Constants.EN_JUSTIFY) { | |||
if (adjustingInfo.lineAlignment == EN_JUSTIFY) { | |||
if (log.isTraceEnabled()) { | |||
log.trace("Applying variation factor to justified line: " + adjustingInfo); | |||
} |
@@ -23,12 +23,6 @@ package org.apache.fop.area; | |||
import java.util.List; | |||
import java.io.Serializable; | |||
// FOP | |||
import org.apache.fop.area.Trait; | |||
import org.apache.fop.area.Resolvable; | |||
import org.apache.fop.area.PageViewport; | |||
import org.apache.fop.area.Area; | |||
/** | |||
* Link resolving for resolving internal links. | |||
*/ | |||
@@ -72,8 +66,8 @@ public class LinkResolver implements Resolvable, Serializable { | |||
* | |||
* {@inheritDoc} | |||
*/ | |||
public void resolveIDRef(String id, List pages) { | |||
resolveIDRef(id, (PageViewport)pages.get(0)); | |||
public void resolveIDRef(String id, List<PageViewport> pages) { | |||
resolveIDRef(id, pages.get(0)); | |||
} | |||
/** |
@@ -34,7 +34,7 @@ public class MainReference extends Area { | |||
private static final long serialVersionUID = 7635126485620012448L; | |||
private BodyRegion parent; | |||
private List spanAreas = new java.util.ArrayList(); | |||
private List<Span> spanAreas = new java.util.ArrayList<Span>(); | |||
private boolean isEmpty = true; | |||
/** | |||
@@ -59,7 +59,7 @@ public class MainReference extends Area { | |||
spanAreas.remove(spanAreas.size() - 1); | |||
} | |||
RegionViewport rv = parent.getRegionViewport(); | |||
int ipdWidth = (int) parent.getIPD() | |||
int ipdWidth = parent.getIPD() | |||
- rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd(); | |||
Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()), | |||
@@ -84,8 +84,8 @@ public class MainReference extends Area { | |||
* | |||
* @param spans content already laid out | |||
*/ | |||
public void setSpans(List spans) { | |||
spanAreas = new ArrayList(spans); | |||
public void setSpans(List<Span> spans) { | |||
spanAreas = new ArrayList<Span>(spans); | |||
} | |||
/** | |||
@@ -93,7 +93,7 @@ public class MainReference extends Area { | |||
* @return the active span. | |||
*/ | |||
public Span getCurrentSpan() { | |||
return (Span) spanAreas.get(spanAreas.size() - 1); | |||
return spanAreas.get(spanAreas.size() - 1); | |||
} | |||
/** | |||
@@ -103,16 +103,13 @@ public class MainReference extends Area { | |||
* @return true if no child areas have been added yet. | |||
*/ | |||
public boolean isEmpty() { | |||
if (isEmpty) { | |||
boolean nonEmptyFound = false; | |||
if (spanAreas != null) { | |||
for (Iterator spaniter = spanAreas.iterator(); spaniter.hasNext();) { | |||
Span spanArea = (Span) spaniter.next(); | |||
nonEmptyFound |= !spanArea.isEmpty(); | |||
if (isEmpty && spanAreas != null) { | |||
for (Span spanArea : spanAreas) { | |||
if (!spanArea.isEmpty()) { | |||
isEmpty = false; | |||
break; | |||
} | |||
} | |||
isEmpty = !nonEmptyFound; | |||
} | |||
return isEmpty; | |||
} |
@@ -22,19 +22,26 @@ package org.apache.fop.area; | |||
import java.awt.Rectangle; | |||
import java.awt.geom.Rectangle2D; | |||
import java.io.Serializable; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.fop.datatypes.FODimension; | |||
import org.apache.fop.datatypes.LengthBase; | |||
import org.apache.fop.datatypes.SimplePercentBaseContext; | |||
import org.apache.fop.fo.Constants; | |||
import org.apache.fop.fo.pagination.Region; | |||
import org.apache.fop.fo.pagination.RegionBody; | |||
import org.apache.fop.fo.pagination.SimplePageMaster; | |||
import org.apache.fop.fo.properties.CommonMarginBlock; | |||
import org.apache.fop.layoutmgr.TraitSetter; | |||
import static org.apache.fop.fo.Constants.FO_REGION_AFTER; | |||
import static org.apache.fop.fo.Constants.FO_REGION_BEFORE; | |||
import static org.apache.fop.fo.Constants.FO_REGION_BODY; | |||
import static org.apache.fop.fo.Constants.FO_REGION_END; | |||
import static org.apache.fop.fo.Constants.FO_REGION_START; | |||
import static org.apache.fop.fo.Constants.EN_ERROR_IF_OVERFLOW; | |||
import static org.apache.fop.fo.Constants.EN_HIDDEN; | |||
/** | |||
* The page. | |||
* This holds the contents of the page. Each region is added. | |||
@@ -58,7 +65,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
private RegionViewport regionAfter = null; | |||
// temporary map of unresolved objects used when serializing the page | |||
private Map unresolved = null; | |||
private Map<String, List<Resolvable>> unresolved = null; | |||
/** Set to true to make this page behave as if it were not empty. */ | |||
private boolean fakeNonEmpty = false; | |||
@@ -119,12 +126,10 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
spm.getWritingMode(), pageRefRect, reldims); | |||
// Create a RegionViewport/ reference area pair for each page region | |||
RegionReference rr = null; | |||
for (Iterator regenum = spm.getRegions().values().iterator(); | |||
regenum.hasNext();) { | |||
Region r = (Region)regenum.next(); | |||
RegionReference rr; | |||
for (Region r : spm.getRegions().values()) { | |||
RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM); | |||
if (r.getNameId() == Constants.FO_REGION_BODY) { | |||
if (r.getNameId() == FO_REGION_BODY) { | |||
rr = new BodyRegion((RegionBody) r, rvp); | |||
} else { | |||
rr = new RegionReference(r, rvp); | |||
@@ -155,7 +160,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
* @param pageCTM page coordinate transformation matrix | |||
* @return the new region viewport | |||
*/ | |||
private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) { | |||
private static RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) { | |||
Rectangle2D relRegionRect = r.getViewportRectangle(reldims); | |||
Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); | |||
// Get the region viewport rectangle in absolute coords by | |||
@@ -164,8 +169,8 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
rv.setBPD((int)relRegionRect.getHeight()); | |||
rv.setIPD((int)relRegionRect.getWidth()); | |||
TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground(), null); | |||
rv.setClip(r.getOverflow() == Constants.EN_HIDDEN | |||
|| r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); | |||
rv.setClip(r.getOverflow() == EN_HIDDEN | |||
|| r.getOverflow() == EN_ERROR_IF_OVERFLOW); | |||
return rv; | |||
} | |||
@@ -180,7 +185,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
* where x=distance from left, y=distance from bottom, width=right-left | |||
* height=top-bottom | |||
*/ | |||
private void setRegionReferencePosition(RegionReference rr, Region r, | |||
private static void setRegionReferencePosition(RegionReference rr, Region r, | |||
Rectangle2D absRegVPRect) { | |||
FODimension reldims = new FODimension(0, 0); | |||
rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), | |||
@@ -200,15 +205,15 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
* @param port the region viewport to set | |||
*/ | |||
public void setRegionViewport(int areaclass, RegionViewport port) { | |||
if (areaclass == Constants.FO_REGION_BEFORE) { | |||
if (areaclass == FO_REGION_BEFORE) { | |||
regionBefore = port; | |||
} else if (areaclass == Constants.FO_REGION_START) { | |||
} else if (areaclass == FO_REGION_START) { | |||
regionStart = port; | |||
} else if (areaclass == Constants.FO_REGION_BODY) { | |||
} else if (areaclass == FO_REGION_BODY) { | |||
regionBody = port; | |||
} else if (areaclass == Constants.FO_REGION_END) { | |||
} else if (areaclass == FO_REGION_END) { | |||
regionEnd = port; | |||
} else if (areaclass == Constants.FO_REGION_AFTER) { | |||
} else if (areaclass == FO_REGION_AFTER) { | |||
regionAfter = port; | |||
} | |||
} | |||
@@ -221,15 +226,15 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
*/ | |||
public RegionViewport getRegionViewport(int areaClass) { | |||
switch (areaClass) { | |||
case Constants.FO_REGION_BEFORE: | |||
case FO_REGION_BEFORE: | |||
return regionBefore; | |||
case Constants.FO_REGION_START: | |||
case FO_REGION_START: | |||
return regionStart; | |||
case Constants.FO_REGION_BODY: | |||
case FO_REGION_BODY: | |||
return regionBody; | |||
case Constants.FO_REGION_END: | |||
case FO_REGION_END: | |||
return regionEnd; | |||
case Constants.FO_REGION_AFTER: | |||
case FO_REGION_AFTER: | |||
return regionAfter; | |||
default: | |||
throw new IllegalArgumentException("No such area class with ID = " + areaClass); | |||
@@ -284,7 +289,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
* | |||
* @param unres the Map of unresolved objects | |||
*/ | |||
public void setUnresolvedReferences(Map unres) { | |||
public void setUnresolvedReferences(Map<String, List<Resolvable>> unres) { | |||
unresolved = unres; | |||
} | |||
@@ -295,7 +300,7 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable { | |||
* | |||
* @return the de-serialized HashMap of unresolved objects | |||
*/ | |||
public Map getUnresolvedReferences() { | |||
public Map<String, List<Resolvable>> getUnresolvedReferences() { | |||
return unresolved; | |||
} | |||
@@ -26,7 +26,7 @@ import java.util.List; | |||
*/ | |||
public class PageSequence extends AreaTreeObject { | |||
private List pages = new java.util.ArrayList(); | |||
private List<PageViewport> pages = new java.util.ArrayList<PageViewport>(); | |||
private LineArea title; | |||
private String language; | |||
private String country; | |||
@@ -75,7 +75,7 @@ public class PageSequence extends AreaTreeObject { | |||
* @return the requested page or null if it was not found | |||
*/ | |||
public PageViewport getPage(int idx) { | |||
return (PageViewport)this.pages.get(idx); | |||
return this.pages.get(idx); | |||
} | |||
/** |
@@ -25,7 +25,6 @@ import java.io.ObjectInputStream; | |||
import java.io.ObjectOutputStream; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
@@ -33,9 +32,15 @@ import java.util.Set; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.fop.fo.Constants; | |||
import org.apache.fop.fo.flow.Marker; | |||
import org.apache.fop.fo.pagination.SimplePageMaster; | |||
import static org.apache.fop.fo.Constants.FO_REGION_BODY; | |||
import static org.apache.fop.fo.Constants.EN_FSWP; | |||
import static org.apache.fop.fo.Constants.EN_FIC; | |||
import static org.apache.fop.fo.Constants.EN_LSWP; | |||
import static org.apache.fop.fo.Constants.EN_LEWP; | |||
/** | |||
* Page viewport that specifies the viewport area and holds the page contents. | |||
* This is the top level object for a page and remains valid for the life | |||
@@ -63,26 +68,24 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
private transient PageSequence pageSequence; | |||
// list of id references and the rectangle on the page | |||
//private Map idReferences = null; | |||
// set of IDs that appear first (or exclusively) on this page: | |||
private Set idFirsts = new java.util.HashSet(); | |||
private Set<String> idFirsts = new java.util.HashSet<String>(); | |||
// this keeps a list of currently unresolved areas or extensions | |||
// once an idref is resolved it is removed | |||
// when this is empty the page can be rendered | |||
private Map unresolvedIDRefs = new java.util.HashMap(); | |||
private Map<String, List<Resolvable>> unresolvedIDRefs | |||
= new java.util.HashMap<String, List<Resolvable>>(); | |||
private Map pendingResolved = null; | |||
private Map<String, List<PageViewport>> pendingResolved = null; | |||
// hashmap of markers for this page | |||
// start and end are added by the fo that contains the markers | |||
private Map markerFirstStart = null; | |||
private Map markerLastStart = null; | |||
private Map markerFirstAny = null; | |||
private Map markerLastEnd = null; | |||
private Map markerLastAny = null; | |||
private Map<String, Marker> markerFirstStart = null; | |||
private Map<String, Marker> markerLastStart = null; | |||
private Map<String, Marker> markerFirstAny = null; | |||
private Map<String, Marker> markerLastEnd = null; | |||
private Map<String, Marker> markerLastAny = null; | |||
/** | |||
* logging instance | |||
@@ -254,8 +257,8 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
/** | |||
* Add an "ID-first" to this page. | |||
* This is typically called by the AreaTreeHandler when associating | |||
* an ID with a PageViewport. | |||
* This is typically called by the {@link AreaTreeHandler} when associating | |||
* an ID with a {@link PageViewport}. | |||
* | |||
* @param id the id to be registered as first appearing on this page | |||
*/ | |||
@@ -277,9 +280,9 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
/** | |||
* Add an idref to this page. | |||
* All idrefs found for child areas of this PageViewport are added | |||
* to unresolvedIDRefs, for subsequent resolution by AreaTreeHandler | |||
* calls to this object's resolveIDRef(). | |||
* All idrefs found for child areas of this {@link PageViewport} are added | |||
* to unresolvedIDRefs, for subsequent resolution by {@link AreaTreeHandler} | |||
* calls to this object's {@code resolveIDRef()}. | |||
* | |||
* @param idref the idref | |||
* @param res the child element of this page that needs this | |||
@@ -287,14 +290,14 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
*/ | |||
public void addUnresolvedIDRef(String idref, Resolvable res) { | |||
if (unresolvedIDRefs == null) { | |||
unresolvedIDRefs = new HashMap(); | |||
unresolvedIDRefs = new HashMap<String, List<Resolvable>>(); | |||
} | |||
List list = (List)unresolvedIDRefs.get(idref); | |||
if (list == null) { | |||
list = new ArrayList(); | |||
unresolvedIDRefs.put(idref, list); | |||
List<Resolvable> pageViewports = unresolvedIDRefs.get(idref); | |||
if (pageViewports == null) { | |||
pageViewports = new ArrayList<Resolvable>(); | |||
unresolvedIDRefs.put(idref, pageViewports); | |||
} | |||
list.add(res); | |||
pageViewports.add(res); | |||
} | |||
/** | |||
@@ -312,24 +315,22 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
*/ | |||
public String[] getIDRefs() { | |||
return (unresolvedIDRefs == null) ? null | |||
: (String[]) unresolvedIDRefs.keySet().toArray(new String[] {}); | |||
: unresolvedIDRefs.keySet().toArray( | |||
new String[unresolvedIDRefs.keySet().size()]); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public void resolveIDRef(String id, List pages) { | |||
/** {@inheritDoc} */ | |||
public void resolveIDRef(String id, List<PageViewport> pages) { | |||
if (page == null) { | |||
if (pendingResolved == null) { | |||
pendingResolved = new HashMap(); | |||
pendingResolved = new HashMap<String, List<PageViewport>>(); | |||
} | |||
pendingResolved.put(id, pages); | |||
} else { | |||
if (unresolvedIDRefs != null) { | |||
List todo = (List)unresolvedIDRefs.get(id); | |||
List<Resolvable> todo = unresolvedIDRefs.get(id); | |||
if (todo != null) { | |||
for (int count = 0; count < todo.size(); count++) { | |||
Resolvable res = (Resolvable)todo.get(count); | |||
for (Resolvable res : todo) { | |||
res.resolveIDRef(id, pages); | |||
} | |||
} | |||
@@ -363,7 +364,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
* @param isfirst if the area being added has is-first trait | |||
* @param islast if the area being added has is-last trait | |||
*/ | |||
public void addMarkers(Map marks, boolean starting, | |||
public void addMarkers(Map<String, Marker> marks, boolean starting, | |||
boolean isfirst, boolean islast) { | |||
if (marks == null) { | |||
@@ -380,14 +381,13 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
if (starting) { | |||
if (isfirst) { | |||
if (markerFirstStart == null) { | |||
markerFirstStart = new HashMap(); | |||
markerFirstStart = new HashMap<String, Marker>(); | |||
} | |||
if (markerFirstAny == null) { | |||
markerFirstAny = new HashMap(); | |||
markerFirstAny = new HashMap<String, Marker>(); | |||
} | |||
// first on page: only put in new values, leave current | |||
for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) { | |||
Object key = iter.next(); | |||
for (String key : marks.keySet()) { | |||
if (!markerFirstStart.containsKey(key)) { | |||
markerFirstStart.put(key, marks.get(key)); | |||
if (log.isTraceEnabled()) { | |||
@@ -404,7 +404,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
} | |||
} | |||
if (markerLastStart == null) { | |||
markerLastStart = new HashMap(); | |||
markerLastStart = new HashMap<String, Marker>(); | |||
} | |||
// last on page: replace all | |||
markerLastStart.putAll(marks); | |||
@@ -414,11 +414,10 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
} | |||
} else { | |||
if (markerFirstAny == null) { | |||
markerFirstAny = new HashMap(); | |||
markerFirstAny = new HashMap<String, Marker>(); | |||
} | |||
// first on page: only put in new values, leave current | |||
for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) { | |||
Object key = iter.next(); | |||
for (String key : marks.keySet()) { | |||
if (!markerFirstAny.containsKey(key)) { | |||
markerFirstAny.put(key, marks.get(key)); | |||
if (log.isTraceEnabled()) { | |||
@@ -432,7 +431,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
// at the end of the area, register is-last and any areas | |||
if (islast) { | |||
if (markerLastEnd == null) { | |||
markerLastEnd = new HashMap(); | |||
markerLastEnd = new HashMap<String, Marker>(); | |||
} | |||
// last on page: replace all | |||
markerLastEnd.putAll(marks); | |||
@@ -442,7 +441,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
} | |||
} | |||
if (markerLastAny == null) { | |||
markerLastAny = new HashMap(); | |||
markerLastAny = new HashMap<String, Marker>(); | |||
} | |||
// last on page: replace all | |||
markerLastAny.putAll(marks); | |||
@@ -462,11 +461,11 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
* @param pos the position to retrieve | |||
* @return Object the marker found or null | |||
*/ | |||
public Object getMarker(String name, int pos) { | |||
Object mark = null; | |||
public Marker getMarker(String name, int pos) { | |||
Marker mark = null; | |||
String posName = null; | |||
switch (pos) { | |||
case Constants.EN_FSWP: | |||
case EN_FSWP: | |||
if (markerFirstStart != null) { | |||
mark = markerFirstStart.get(name); | |||
posName = "FSWP"; | |||
@@ -476,13 +475,13 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
posName = "FirstAny after " + posName; | |||
} | |||
break; | |||
case Constants.EN_FIC: | |||
case EN_FIC: | |||
if (markerFirstAny != null) { | |||
mark = markerFirstAny.get(name); | |||
posName = "FIC"; | |||
} | |||
break; | |||
case Constants.EN_LSWP: | |||
case EN_LSWP: | |||
if (markerLastStart != null) { | |||
mark = markerLastStart.get(name); | |||
posName = "LSWP"; | |||
@@ -492,7 +491,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
posName = "LastAny after " + posName; | |||
} | |||
break; | |||
case Constants.EN_LEWP: | |||
case EN_LEWP: | |||
if (markerLastEnd != null) { | |||
mark = markerLastEnd.get(name); | |||
posName = "LEWP"; | |||
@@ -503,7 +502,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
} | |||
break; | |||
default: | |||
throw new RuntimeException(); | |||
assert false; | |||
} | |||
if (log.isTraceEnabled()) { | |||
log.trace("page " + pageNumberString + ": " + "Retrieving marker " + name | |||
@@ -550,10 +549,8 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
page = (Page) in.readObject(); | |||
unresolvedIDRefs = page.getUnresolvedReferences(); | |||
if (unresolvedIDRefs != null && pendingResolved != null) { | |||
for (Iterator iter = pendingResolved.keySet().iterator(); | |||
iter.hasNext();) { | |||
String id = (String) iter.next(); | |||
resolveIDRef(id, (List)pendingResolved.get(id)); | |||
for (String id : pendingResolved.keySet()) { | |||
resolveIDRef(id, pendingResolved.get(id)); | |||
} | |||
pendingResolved = null; | |||
} | |||
@@ -577,9 +574,8 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
page = null; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
/** {@inheritDoc} */ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(64); | |||
sb.append("PageViewport: page="); | |||
@@ -602,8 +598,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
* @return BodyRegion object | |||
*/ | |||
public BodyRegion getBodyRegion() { | |||
return (BodyRegion) getPage().getRegionViewport( | |||
Constants.FO_REGION_BODY).getRegionReference(); | |||
return (BodyRegion) getPage().getRegionViewport(FO_REGION_BODY).getRegionReference(); | |||
} | |||
/** | |||
@@ -659,5 +654,4 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl | |||
public RegionReference getRegionReference(int id) { | |||
return getPage().getRegionViewport(id).getRegionReference(); | |||
} | |||
} |
@@ -38,7 +38,7 @@ public class RegionReference extends Area implements Cloneable { | |||
private CTM ctm; | |||
// the list of block areas from the static flow | |||
private ArrayList blocks = new ArrayList(); | |||
private ArrayList<Area> blocks = new ArrayList<Area>(); | |||
/** the parent {@link RegionViewport} for this object */ | |||
protected RegionViewport regionViewport; | |||
@@ -68,6 +68,7 @@ public class RegionReference extends Area implements Cloneable { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void addChildArea(Area child) { | |||
blocks.add(child); | |||
} | |||
@@ -106,7 +107,7 @@ public class RegionReference extends Area implements Cloneable { | |||
* | |||
* @return the list of blocks in this region | |||
*/ | |||
public List getBlocks() { | |||
public List<Area> getBlocks() { | |||
return blocks; | |||
} | |||
@@ -143,11 +144,12 @@ public class RegionReference extends Area implements Cloneable { | |||
RegionReference rr = new RegionReference(regionClass, regionName, regionViewport); | |||
rr.ctm = ctm; | |||
rr.setIPD(getIPD()); | |||
rr.blocks = (ArrayList)blocks.clone(); | |||
rr.blocks = (ArrayList<Area>)blocks.clone(); | |||
return rr; | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(super.toString()); | |||
sb.append(" {regionName=").append(regionName); |
@@ -50,9 +50,10 @@ public class RenderPagesModel extends AreaTreeModel { | |||
/** | |||
* Pages that have been prepared but not rendered yet. | |||
*/ | |||
protected List/*<PageViewport>*/ prepared = new java.util.ArrayList/*<PageViewport>*/(); | |||
private List/*<OffDocumentItem>*/ pendingODI = new java.util.ArrayList/*<OffDocumentItem>*/(); | |||
private List/*<OffDocumentItem>*/ endDocODI = new java.util.ArrayList/*<OffDocumentItem>*/(); | |||
protected List<PageViewport> prepared = new java.util.ArrayList<PageViewport>(); | |||
private List<OffDocumentItem> pendingODI = new java.util.ArrayList<OffDocumentItem>(); | |||
private List<OffDocumentItem> endDocODI = new java.util.ArrayList<OffDocumentItem>(); | |||
/** | |||
* Create a new render pages model with the given renderer. | |||
@@ -83,6 +84,7 @@ public class RenderPagesModel extends AreaTreeModel { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void startPageSequence(PageSequence pageSequence) { | |||
super.startPageSequence(pageSequence); | |||
if (renderer.supportsOutOfOrder()) { | |||
@@ -98,6 +100,7 @@ public class RenderPagesModel extends AreaTreeModel { | |||
* the page is added to a queue. | |||
* @param page the page to add to the model | |||
*/ | |||
@Override | |||
public void addPage(PageViewport page) { | |||
super.addPage(page); | |||
@@ -183,11 +186,11 @@ public class RenderPagesModel extends AreaTreeModel { | |||
renderer.renderPage(pageViewport); | |||
if (!pageViewport.isResolved()) { | |||
String[] idrefs = pageViewport.getIDRefs(); | |||
for (int count = 0; count < idrefs.length; count++) { | |||
for (String idref : idrefs) { | |||
AreaEventProducer eventProducer = AreaEventProducer.Provider.get( | |||
renderer.getUserAgent().getEventBroadcaster()); | |||
eventProducer.unresolvedIDReferenceOnPage(this, | |||
pageViewport.getPageNumberString(), idrefs[count]); | |||
pageViewport.getPageNumberString(), idref); | |||
} | |||
} | |||
} catch (Exception e) { | |||
@@ -214,9 +217,8 @@ public class RenderPagesModel extends AreaTreeModel { | |||
prepared.add(page); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void handleOffDocumentItem(OffDocumentItem oDI) { | |||
switch(oDI.getWhenToProcess()) { | |||
case OffDocumentItem.IMMEDIATELY: | |||
@@ -233,9 +235,8 @@ public class RenderPagesModel extends AreaTreeModel { | |||
} | |||
} | |||
private void processOffDocumentItems(List list) { | |||
for (int count = 0; count < list.size(); count++) { | |||
OffDocumentItem oDI = (OffDocumentItem)list.get(count); | |||
private void processOffDocumentItems(List<OffDocumentItem> list) { | |||
for (OffDocumentItem oDI : list) { | |||
renderer.processOffDocumentItem(oDI); | |||
} | |||
} | |||
@@ -244,6 +245,7 @@ public class RenderPagesModel extends AreaTreeModel { | |||
* End the document. Render any end document OffDocumentItems | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
public void endDocument() throws SAXException { | |||
// render any pages that had unresolved ids | |||
checkPreparedPages(null, true); |
@@ -59,5 +59,5 @@ public interface Resolvable { | |||
* @param pages the list of PageViewports with the given ID | |||
* | |||
*/ | |||
void resolveIDRef(String id, List pages); | |||
void resolveIDRef(String id, List<PageViewport> pages); | |||
} |
@@ -34,7 +34,7 @@ public class Span extends Area { | |||
private static final long serialVersionUID = -5551430053660081549L; | |||
// the list of flow reference areas in this span area | |||
private List flowAreas; | |||
private List<NormalFlow> flowAreas; | |||
private int colCount; | |||
private int colGap; | |||
private int colWidth; // width for each normal flow, calculated value | |||
@@ -60,7 +60,7 @@ public class Span extends Area { | |||
* Create the normal flows for this Span | |||
*/ | |||
private void createNormalFlows() { | |||
flowAreas = new java.util.ArrayList(colCount); | |||
flowAreas = new java.util.ArrayList<NormalFlow>(colCount); | |||
colWidth = (ipd - ((colCount - 1) * colGap)) / colCount; | |||
for (int i = 0; i < colCount; i++) { | |||
@@ -105,7 +105,7 @@ public class Span extends Area { | |||
*/ | |||
public NormalFlow getNormalFlow(int colRequested) { | |||
if (colRequested >= 0 && colRequested < colCount) { | |||
return (NormalFlow) flowAreas.get(colRequested); | |||
return flowAreas.get(colRequested); | |||
} else { // internal error | |||
throw new IllegalArgumentException("Invalid column number " | |||
+ colRequested + " requested; only 0-" + (colCount - 1) | |||
@@ -184,6 +184,7 @@ public class Span extends Area { | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(super.toString()); | |||
if (colCount > 1) { |
@@ -24,11 +24,15 @@ import java.io.Serializable; | |||
import org.apache.xmlgraphics.image.loader.ImageInfo; | |||
import org.apache.fop.fo.Constants; | |||
import org.apache.fop.fonts.FontTriplet; | |||
import org.apache.fop.traits.BorderProps; | |||
import org.apache.fop.util.ColorUtil; | |||
import static org.apache.fop.fo.Constants.EN_REPEAT; | |||
import static org.apache.fop.fo.Constants.EN_REPEATX; | |||
import static org.apache.fop.fo.Constants.EN_REPEATY; | |||
import static org.apache.fop.fo.Constants.EN_NOREPEAT; | |||
// properties should be serialized by the holder | |||
/** | |||
* Area traits used for rendering. | |||
@@ -142,8 +146,10 @@ public final class Trait implements Serializable { | |||
/** Trait for color of underline decorations when rendering inline parent. */ | |||
public static final Integer UNDERLINE_COLOR = 34; | |||
/** Trait for color of overline decorations when rendering inline parent. */ | |||
public static final Integer OVERLINE_COLOR = 35; | |||
/** Trait for color of linethrough decorations when rendering inline parent. */ | |||
public static final Integer LINETHROUGH_COLOR = 36; | |||
@@ -367,6 +373,7 @@ public final class Trait implements Serializable { | |||
* Return the human-friendly string for debugging. | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("pvKey=").append(pvKey); | |||
@@ -441,6 +448,7 @@ public final class Trait implements Serializable { | |||
* @return a <code>String</code> of the form | |||
* "org.apache.fop.area.Trait.ExternalLink[dest=someURL,newWindow=false]" | |||
*/ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(64); | |||
sb.append("newWindow=").append(newWindow); | |||
@@ -581,23 +589,23 @@ public final class Trait implements Serializable { | |||
private String getRepeatString() { | |||
switch (getRepeat()) { | |||
case Constants.EN_REPEAT: return "repeat"; | |||
case Constants.EN_REPEATX: return "repeat-x"; | |||
case Constants.EN_REPEATY: return "repeat-y"; | |||
case Constants.EN_NOREPEAT: return "no-repeat"; | |||
case EN_REPEAT: return "repeat"; | |||
case EN_REPEATX: return "repeat-x"; | |||
case EN_REPEATY: return "repeat-y"; | |||
case EN_NOREPEAT: return "no-repeat"; | |||
default: throw new IllegalStateException("Illegal repeat style: " + getRepeat()); | |||
} | |||
} | |||
private static int getConstantForRepeat(String repeat) { | |||
if ("repeat".equalsIgnoreCase(repeat)) { | |||
return Constants.EN_REPEAT; | |||
return EN_REPEAT; | |||
} else if ("repeat-x".equalsIgnoreCase(repeat)) { | |||
return Constants.EN_REPEATX; | |||
return EN_REPEATX; | |||
} else if ("repeat-y".equalsIgnoreCase(repeat)) { | |||
return Constants.EN_REPEATY; | |||
return EN_REPEATY; | |||
} else if ("no-repeat".equalsIgnoreCase(repeat)) { | |||
return Constants.EN_NOREPEAT; | |||
return EN_NOREPEAT; | |||
} else { | |||
throw new IllegalStateException("Illegal repeat style: " + repeat); | |||
} | |||
@@ -607,6 +615,7 @@ public final class Trait implements Serializable { | |||
* Return the string for debugging. | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
if (color != null) { |
@@ -38,7 +38,7 @@ public class Container extends Area { | |||
/** | |||
* The list of block areas stacked inside this container | |||
*/ | |||
protected List blocks = new ArrayList(); | |||
protected List<Block> blocks = new ArrayList<Block>(); | |||
/** | |||
* The width of this container |
@@ -39,9 +39,7 @@ public class FilledArea extends InlineParent { | |||
private int unitWidth; | |||
/** | |||
* Create a new filled area. | |||
*/ | |||
/** Create a new filled area. */ | |||
public FilledArea() { | |||
} | |||
@@ -88,13 +86,11 @@ public class FilledArea extends InlineParent { | |||
return this.unitWidth; | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
/** {@inheritDoc} */ | |||
@Override | |||
public int getBPD() { | |||
int bpd = 0; | |||
for (Iterator childAreaIt = getChildAreas().iterator(); childAreaIt.hasNext();) { | |||
InlineArea area = (InlineArea)childAreaIt.next(); | |||
for (InlineArea area : getChildAreas()) { | |||
if (bpd < area.getBPD()) { | |||
bpd = area.getBPD(); | |||
} | |||
@@ -110,9 +106,10 @@ public class FilledArea extends InlineParent { | |||
* | |||
* @return the list of child areas copied to fill the width | |||
*/ | |||
public List getChildAreas() { | |||
int units = (int)(getIPD() / unitWidth); | |||
List newList = new ArrayList(); | |||
@Override | |||
public List<InlineArea> getChildAreas() { | |||
int units = getIPD() / unitWidth; | |||
List<InlineArea> newList = new ArrayList<InlineArea>(); | |||
for (int count = 0; count < units; count++) { | |||
newList.addAll(inlines); | |||
} | |||
@@ -126,6 +123,7 @@ public class FilledArea extends InlineParent { | |||
* @param lineShrink the total shrink of the line | |||
* @return true if there is an UnresolvedArea descendant | |||
*/ | |||
@Override | |||
public boolean applyVariationFactor(double variationFactor, | |||
int lineStretch, int lineShrink) { | |||
setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor)); |
@@ -178,6 +178,7 @@ public class InlineArea extends Area { | |||
* | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
public void addChildArea(Area childArea) { | |||
super.addChildArea(childArea); | |||
if (childArea instanceof InlineArea) { | |||
@@ -185,9 +186,7 @@ public class InlineArea extends Area { | |||
} | |||
} | |||
/** | |||
*@return true if the inline area is underlined. | |||
*/ | |||
/** @return true if the inline area is underlined. */ | |||
public boolean hasUnderline() { | |||
return getTraitAsBoolean(Trait.UNDERLINE); | |||
} |
@@ -48,6 +48,7 @@ public class InlineBlockParent extends InlineArea { | |||
* | |||
* @param childArea the child area to add | |||
*/ | |||
@Override | |||
public void addChildArea(Area childArea) { | |||
if (child != null) { | |||
throw new IllegalStateException("InlineBlockParent may have only one child area."); |
@@ -48,9 +48,7 @@ public class SpaceArea extends InlineArea { | |||
isAdjustable = a; | |||
} | |||
/** | |||
* @return Returns the space. | |||
*/ | |||
/** @return Returns the space. */ | |||
public String getSpace() { | |||
return String.valueOf(space); | |||
} |
@@ -99,20 +99,19 @@ public class TextArea extends AbstractTextArea { | |||
*/ | |||
public String getText() { | |||
StringBuffer text = new StringBuffer(); | |||
InlineArea child; | |||
// assemble the text | |||
for (int i = 0; i < inlines.size(); i++) { | |||
child = (InlineArea) inlines.get(i); | |||
if (child instanceof WordArea) { | |||
text.append(((WordArea) child).getWord()); | |||
for (InlineArea inline : inlines) { | |||
if (inline instanceof WordArea) { | |||
text.append(((WordArea) inline).getWord()); | |||
} else { | |||
text.append(((SpaceArea) child).getSpace()); | |||
text.append(((SpaceArea) inline).getSpace()); | |||
} | |||
} | |||
return text.toString(); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public String toString() { | |||
return "TextArea{text=" + getText() + "}"; | |||
} |
@@ -92,18 +92,14 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable { | |||
* @param id an id whose PageViewports have been determined | |||
* @param pages the list of PageViewports associated with this ID | |||
*/ | |||
public void resolveIDRef(String id, List pages) { | |||
public void resolveIDRef(String id, List<PageViewport> pages) { | |||
if (!resolved && pageIDRef.equals(id) && pages != null) { | |||
if (log.isDebugEnabled()) { | |||
log.debug("Resolving pageNumber: " + id); | |||
} | |||
resolved = true; | |||
PageViewport page; | |||
if (pageType == FIRST) { | |||
page = (PageViewport)pages.get(0); | |||
} else { | |||
page = (PageViewport)pages.get(pages.size() - 1); | |||
} | |||
int pageIndex = pageType ? 0 : pages.size() - 1; | |||
PageViewport page = pages.get(pageIndex); | |||
// replace the text | |||
removeText(); | |||
text = page.getPageNumberString(); | |||
@@ -136,6 +132,7 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable { | |||
* @param lineShrink the total shrink of the line | |||
* @return true if there is an UnresolvedArea descendant | |||
*/ | |||
@Override | |||
public boolean applyVariationFactor(double variationFactor, | |||
int lineStretch, int lineShrink) { | |||
return true; |
@@ -47,22 +47,18 @@ public class WordArea extends InlineArea { | |||
this.letterAdjust = la; | |||
} | |||
/** | |||
* @return Returns the word. | |||
*/ | |||
/** @return Returns the word. */ | |||
public String getWord() { | |||
return word; | |||
} | |||
/** | |||
* @return Returns the offset. | |||
*/ | |||
/** @return Returns the offset. */ | |||
@Override | |||
public int getOffset() { | |||
return offset; | |||
} | |||
/** | |||
* @param o The offset to set. | |||
*/ | |||
/** @param o The offset to set. */ | |||
@Override | |||
public void setOffset(int o) { | |||
offset = o; | |||
} |