import org.apache.fop.render.pdf.PDFRenderer;
-import org.apache.fop.system.BufferManager;
-
import org.apache.log.*;
import org.apache.log.format.*;
import org.apache.log.output.io.*;
/**
* the system resources that FOP will use
*/
- private BufferManager _bufferManager;
-
private Logger log;
public static final String getParserClassName() {
*/
public Driver() {
_stream = null;
- _bufferManager = new BufferManager();
_treeBuilder = new FOTreeBuilder();
- _treeBuilder.setBufferManager(_bufferManager);
setupDefaultMappings();
}
/* Set up the system buffers */
public void setBufferFile(File bufferFile) {
- this._bufferManager.addBufferFile(bufferFile);
}
/**
if (dumpConfiguration) {
Configuration.put("dumpConfiguration", "true");
Configuration.dumpConfiguration();
- System.exit(0);
}
// quiet mode
import java.io.Serializable;
+// If the area appears more than once in the output
+// or if the area has external data it is cached
+// to keep track of it and to minimize rendered output
+// renderers can render the output once and display it
+// for every occurence
+// this should also extend to all outputs (including PDFGraphics2D)
+// and all types of renderers
+
/**
* Base object for all areas.
*/
// the information is kept for future reference
ArrayList idReferences = null;
+ // this keeps a list of currently unresolved areas or extensions
+ // once the things is resolved it is removed
+ // when this is empty the page can be rendered
+ ArrayList unresolved = null;
+
public void setClip(boolean c) {
clip = c;
}
package org.apache.fop.datatypes;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.messaging.MessageHandler;
return parentFO.getContentWidth();
case CONTAINING_REFAREA: // example: start-indent, end-indent
{
- FObj fo;
- for (fo = parentFO; fo != null &&!fo.generatesReferenceAreas();
- fo = fo.getParent());
- return (fo != null ? fo.getContentWidth() : 0);
+ //FONode fo;
+ //for (fo = parentFO; fo != null && !fo.generatesReferenceAreas();
+ // fo = fo.getParent());
+ //return (((fo != null) && (fo instanceof FObj)) ? ((FObj)fo).getContentWidth() : 0);
+ return 0;
}
case CUSTOM_BASE:
MessageHandler.errorln("!!! LengthBase.getBaseLength() called on CUSTOM_BASE type !!!");
package org.apache.fop.extensions;
-import org.apache.fop.fo.*;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.ElementMapping;
+import org.apache.fop.fo.FOTreeBuilder;
-import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
public class ExtensionElementMapping implements ElementMapping {
}
class O extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Outline(parent);
}
}
class L extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Label(parent);
}
}
import org.apache.fop.fo.*;
import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.fo.properties.ExtensionPropertyMapping;
-
-import org.xml.sax.Attributes;
/**
* base class for extension objects
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- public ExtensionObj(FObj parent) {
+ public ExtensionObj(FONode parent) {
super(parent);
}
* Called for extensions within a page sequence or flow. These extensions
* are allowed to generate visible areas within the layout.
*
- *
* @param area
*/
public Status layout(Area area) throws FOPException {
ExtensionArea extArea = new ExtensionArea(this);
areaTree.addExtension(this);
}
-
- protected PropertyListBuilder getListBuilder() {
- PropertyListBuilder plb = new PropertyListBuilder();
- plb.addList(ExtensionPropertyMapping.getGenericMappings());
- return plb;
- }
-
- public void handleAttrs(Attributes attlist) throws FOPException {
- String uri = ExtensionElementMapping.URI;
- properties =
- getListBuilder().makeList(uri, name, attlist,
- (parent == null) ? null
- : parent.properties, parent);
- }
}
+
import org.apache.fop.fo.*;
-
public class Label extends ExtensionObj {
private String _label = "";
- public Label(FObj parent) {
+ public Label(FONode parent) {
super(parent);
}
return _label;
}
-
}
public class Outline extends ExtensionObj {
private Label _label;
- private Vector _outlines = new Vector();
+ private ArrayList _outlines = new ArrayList();
private String _internalDestination;
private String _externalDestination;
*/
private Object _rendererObject;
- public Outline(FObj parent) {
+ public Outline(FONode parent) {
super(parent);
}
public void handleAttrs(Attributes attlist) throws FOPException {
- super.handleAttrs(attlist);
_internalDestination =
- this.properties.get("internal-destination").getString();
+ attlist.getValue(null, "internal-destination");
_externalDestination =
- this.properties.get("external-destination").getString();
+ attlist.getValue(null, "external-destination");
if (_externalDestination != null &&!_externalDestination.equals("")) {
log.warn("fox:outline external-destination not supported currently.");
}
if (obj instanceof Label) {
_label = (Label)obj;
} else if (obj instanceof Outline) {
- _outlines.addElement(obj);
+ _outlines.add(obj);
}
- super.addChild(obj);
}
-
public void setRendererObject(Object o) {
_rendererObject = o;
}
return _label == null ? new Label(this) : _label;
}
- public Vector getOutlines() {
+ public ArrayList getOutlines() {
return _outlines;
}
return _internalDestination;
}
-
-
}
import org.apache.fop.apps.FOPException;
/**
- * The fo:root formatting object. Contains page masters, root extensions,
- * page-sequences.
+ * The fo:color-profile formatting object.
*/
public class ColorProfile extends ToBeImplementedElement {
- protected ColorProfile(FObj parent) {
+ protected ColorProfile(FONode parent) {
super(parent);
- this.name = "fo:color-profile";
// this.properties.get("src");
// this.properties.get("color-profile-name");
*/
public class Declarations extends ToBeImplementedElement {
- protected Declarations(FObj parent) {
+ protected Declarations(FONode parent) {
super(parent);
- this.name = "fo:declarations";
}
}
* the given builder.
*/
public interface ElementMapping {
+ public static final String DEFAULT = "<default>";
+
public void addToBuilder(FOTreeBuilder builder);
public static class Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return null;
}
}
package org.apache.fop.fo;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
}
class R extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Root(parent);
}
}
class Dec extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Declarations(parent);
}
}
class CP extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ColorProfile(parent);
}
}
class PS extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new PageSequence(parent);
}
}
class LMS extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new LayoutMasterSet(parent);
}
}
class PSM extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new PageSequenceMaster(parent);
}
}
class SPMR extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new SinglePageMasterReference(parent);
}
}
class RPMR extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RepeatablePageMasterReference(parent);
}
}
class RPMA extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RepeatablePageMasterAlternatives(parent);
}
}
class CPMR extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ConditionalPageMasterReference(parent);
}
}
class SPM extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new SimplePageMaster(parent);
}
}
class RB extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RegionBody(parent);
}
}
class RBefore extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RegionBefore(parent);
}
}
class RA extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RegionAfter(parent);
}
}
class RS extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RegionStart(parent);
}
}
class RE extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RegionEnd(parent);
}
}
class Fl extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Flow(parent);
}
}
class SC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new StaticContent(parent);
}
}
class T extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Title(parent);
}
}
class B extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Block(parent);
}
}
class BC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new BlockContainer(parent);
}
}
class BO extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new BidiOverride(parent);
}
}
class Ch extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Character(parent);
}
}
class IPS extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new InitialPropertySet(parent);
}
}
class EG extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ExternalGraphic(parent);
}
}
class IFO extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new InstreamForeignObject(parent);
}
}
class In extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Inline(parent);
}
}
class IC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new InlineContainer(parent);
}
}
class L extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Leader(parent);
}
}
class PN extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new PageNumber(parent);
}
}
class PNC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new PageNumberCitation(parent);
}
}
class TAC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableAndCaption(parent);
}
}
class Ta extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Table(parent);
}
}
class TC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableColumn(parent);
}
}
class TCaption extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableCaption(parent);
}
}
class TH extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableHeader(parent);
}
}
class TF extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableFooter(parent);
}
}
class TB extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableBody(parent);
}
}
class TR extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableRow(parent);
}
}
class TCell extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new TableCell(parent);
}
}
class LB extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ListBlock(parent);
}
}
class LI extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ListItem(parent);
}
}
class LIB extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ListItemBody(parent);
}
}
class LIL extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new ListItemLabel(parent);
}
}
class BL extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new BasicLink(parent);
}
}
class MS extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new MultiSwitch(parent);
}
}
class MC extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new MultiCase(parent);
}
}
class MT extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new MultiToggle(parent);
}
}
class MP extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new MultiProperties(parent);
}
}
class MPS extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new MultiPropertySet(parent);
}
}
class F extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new org.apache.fop.fo.flow.Float(parent);
}
}
class Foot extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Footnote(parent);
}
}
class FB extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new FootnoteBody(parent);
}
}
class W extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Wrapper(parent);
}
}
class M extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Marker(parent);
}
}
class RM extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new RetrieveMarker(parent);
}
}
* LICENSE file included with these sources.
*/
-
package org.apache.fop.fo;
// FOP
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.StreamRenderer;
import org.apache.fop.layout.Area;
-import org.apache.fop.layout.AreaClass;
-import org.apache.fop.layout.LinkSet;
-import org.apache.fop.system.BufferManager;
-import org.apache.fop.fo.flow.Marker;
import org.apache.log.Logger;
-// Java
-import java.util.Vector;
-import java.util.Hashtable;
-
import org.xml.sax.Attributes;
/**
- * base class for nodes in the formatting object tree
+ * base class for nodes in the XML tree
*
- * Modified by Mark Lillywhite mark-fop@inomial.com. Made
- * Vector a protected member. (/me things this should be
- * a private member with an API for adding children;
- * this woudl save a lot of memory because the Vector
- * would not have to be instantiated unless the node had
- * children).
*/
abstract public class FONode {
-
- protected FObj parent;
-
- protected String areaClass = AreaClass.UNASSIGNED;
-
- public BufferManager bufferManager;
-
- protected Vector children = new Vector(); // made public for searching for id's
-
- /**
- * value of marker before layout begins
- */
- public final static int START = -1000;
-
- /**
- * value of marker after break-after
- */
- public final static int BREAK_AFTER = -1001;
-
- /**
- * where the layout was up to.
- * for FObjs it is the child number
- * for FOText it is the character number
- */
- protected int marker = START;
-
- protected boolean isInTableCell = false;
-
- protected int forcedStartOffset = 0;
- protected int forcedWidth = 0;
-
- protected int widows = 0;
- protected int orphans = 0;
-
- protected LinkSet linkSet;
-
- // count of areas generated-by/returned-by
- public int areasGenerated = 0;
-
- // markers
- protected Hashtable markers;
+ protected FONode parent;
+ protected String name;
protected Logger log;
- protected FONode(FObj parent) {
+ protected FONode(FONode parent) {
this.parent = parent;
- if (parent != null) {
- this.bufferManager = parent.bufferManager;
- }
-
- markers = new Hashtable();
+ }
- if (null != parent)
- this.areaClass = parent.areaClass;
+ public void setName(String str) {
+ name = str;
}
public void setLogger(Logger logger) {
log = logger;
}
- public void handleAttrs(Attributes attlist) throws FOPException {
+ public void setUserAgent(FOUserAgent ua) {
}
- public void setIsInTableCell() {
- this.isInTableCell = true;
- // made recursive by Eric Schaeffer
- for (int i = 0; i < this.children.size(); i++) {
- FONode child = (FONode)this.children.elementAt(i);
- child.setIsInTableCell();
- }
+ public void setStreamRenderer(StreamRenderer st) {
}
- public void forceStartOffset(int offset) {
- this.forcedStartOffset = offset;
- // made recursive by Eric Schaeffer
- for (int i = 0; i < this.children.size(); i++) {
- FONode child = (FONode)this.children.elementAt(i);
- child.forceStartOffset(offset);
- }
- }
-
- public void forceWidth(int width) {
- this.forcedWidth = width;
- // made recursive by Eric Schaeffer
- for (int i = 0; i < this.children.size(); i++) {
- FONode child = (FONode)this.children.elementAt(i);
- child.forceWidth(width);
- }
- }
-
- public void resetMarker() {
- this.marker = START;
- int numChildren = this.children.size();
- for (int i = 0; i < numChildren; i++) {
- ((FONode)children.elementAt(i)).resetMarker();
- }
- }
-
- public void setWidows(int wid) {
- widows = wid;
- }
-
- public void setOrphans(int orph) {
- orphans = orph;
- }
-
- public void removeAreas() {
- // still to do
- }
-
-
- protected void addChild(FONode child) {
- children.addElement(child);
- }
-
- public FObj getParent() {
- return this.parent;
- }
-
- public void setBufferManager(BufferManager bufferManager) {
- this.bufferManager = bufferManager;
- }
-
- public BufferManager getBufferManager() {
- return this.bufferManager;
- }
-
- public void setLinkSet(LinkSet linkSet) {
- this.linkSet = linkSet;
- for (int i = 0; i < this.children.size(); i++) {
- FONode child = (FONode)this.children.elementAt(i);
- child.setLinkSet(linkSet);
- }
+ public void handleAttrs(Attributes attlist) throws FOPException {
}
- public LinkSet getLinkSet() {
- return this.linkSet;
+ /**
+ * returns the name of the object
+ * @return the name of this object
+ */
+ public String getName() {
+ return this.name;
}
- abstract public Status layout(Area area) throws FOPException;
-
/**
- * lets outside sources access the property list
- * first used by PageNumberCitation to find the "id" property
- * returns null by default, overide this function when there is a property list
- * @param name - the name of the desired property to obtain
- * @returns the property
+ * adds characters (does nothing here)
+ * @param data text
+ * @param start start position
+ * @param length length of the text
*/
- public Property getProperty(String name) {
- return (null);
+ protected void addCharacters(char data[], int start, int length) {
+ // ignore
}
/**
- * At the start of a new span area layout may be partway through a
- * nested FO, and balancing requires rollback to this known point.
- * The snapshot records exactly where layout is at.
- * @param snapshot a Vector of markers (Integer)
- * @returns the updated Vector of markers (Integers)
+ * generates the area or areas for this formatting object
+ * and adds these to the area. This method should always be
+ * overridden by all sub classes
+ *
+ * @param area
*/
- public Vector getMarkerSnapshot(Vector snapshot) {
- snapshot.addElement(new Integer(this.marker));
-
- // terminate if no kids or child not yet accessed
- if (this.marker < 0)
- return snapshot;
- else if (children.isEmpty())
- return snapshot;
- else
- return ((FONode)children.elementAt(this.marker)).getMarkerSnapshot(snapshot);
+ public Status layout(Area area) throws FOPException {
+ // should always be overridden
+ return new Status(Status.OK);
}
/**
- * When balancing occurs, the flow layout() method restarts at the
- * point specified by the current marker snapshot, which is retrieved
- * and restored using this method.
- * @param snapshot the Vector of saved markers (Integers)
+ *
*/
- public void rollback(Vector snapshot) {
- this.marker = ((Integer)snapshot.elementAt(0)).intValue();
- snapshot.removeElementAt(0);
-
- if (this.marker == START) {
- // make sure all the children of this FO are also reset
- resetMarker();
- return;
- } else if ((this.marker == -1) || children.isEmpty())
- return;
-
- int numChildren = this.children.size();
-
- if (this.marker <= START) {
- return;
- }
-
- for (int i = this.marker + 1; i < numChildren; i++) {
- FONode fo = (FONode)children.elementAt(i);
- fo.resetMarker();
- }
- ((FONode)children.elementAt(this.marker)).rollback(snapshot);
+ protected void start() {
+ // do nothing by default
}
-
- public void addMarker(Marker marker) throws FOPException {
- String mcname = marker.getMarkerClassName();
- if (!markers.containsKey(mcname) && children.isEmpty()) {
- markers.put(mcname, marker);
- } else {
- log.error("fo:marker must be an initial child,"
- + "and 'marker-class-name' must be unique for same parent");
- throw new FOPException("fo:marker must be an initial child,"
- + "and 'marker-class-name' must be unique for same parent");
- }
+ /**
+ *
+ */
+ protected void end() {
+ // do nothing by default
}
- public boolean hasMarkers() {
- return !markers.isEmpty();
+ protected void addChild(FONode child) {
}
- public Vector getMarkers() {
- return new Vector(markers.values());
+ public FONode getParent() {
+ return this.parent;
}
}
* longer than the lifetime of the object itself, causing
* excessive memory consumption and OOM errors.
*/
-public class FOText extends FONode {
+public class FOText extends FObj {
protected char[] ca;
protected int start;
protected int length;
-
- FontState fs;
- float red;
- float green;
- float blue;
- int wrapOption;
- int whiteSpaceCollapse;
- int verticalAlign;
-
- // Textdecoration
- protected boolean underlined = false;
- protected boolean overlined = false;
- protected boolean lineThrough = false;
+ TextInfo textInfo;
+
+ public static class TextInfo {
+ FontState fs;
+ float red;
+ float green;
+ float blue;
+ int wrapOption;
+ int whiteSpaceCollapse;
+ int verticalAlign;
+
+ // Textdecoration
+ protected boolean underlined = false;
+ protected boolean overlined = false;
+ protected boolean lineThrough = false;
+ }
TextState ts;
-
- public FOText(char[] chars, int s, int e, FObj parent) {
- super(parent);
+ public FOText(char[] chars, int s, int e, TextInfo ti) {
+ super(null);
this.start = 0;
this.ca = new char[e - s];
for (int i = s; i < e; i++)
ca[i - s] = chars[i];
this.length = e - s;
-
- /* ML - remove refs to BufferManager
- this.bufferManager = parent.bufferManager;
- if (this.bufferManager != null) {
- bufferManager.writeBuffer((Object)this, ca);
- } else {
- System.out.println("abnormal exit");
- System.exit(0);
- }
- */
- }
-
- public void setUnderlined(boolean ul) {
- this.underlined = ul;
- }
-
- public void setOverlined(boolean ol) {
- this.overlined = ol;
+ textInfo = ti;
}
- public void setLineThrough(boolean lt) {
- this.lineThrough = lt;
- }
-
-
public boolean willCreateArea() {
- // ML - remove refs to BufferManager
- //char ca[] = this.bufferManager.readBuffer((Object)this);
-
- this.whiteSpaceCollapse =
- this.parent.properties.get("white-space-collapse").getEnum();
- if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE
+ if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE
&& length > 0) {
return true;
}
}
public Status layout(Area area) throws FOPException {
- // ML - remove refs to BufferManager
- // char ca[] = this.bufferManager.readBuffer((Object)this);
if (!(area instanceof BlockArea)) {
log.error("text outside block area"
+ new String(ca, start, length));
return new Status(Status.OK);
}
if (this.marker == START) {
- String fontFamily =
- this.parent.properties.get("font-family").getString();
- String fontStyle =
- this.parent.properties.get("font-style").getString();
- String fontWeight =
- this.parent.properties.get("font-weight").getString();
- int fontSize =
- this.parent.properties.get("font-size").getLength().mvalue();
- // font-variant support
- // added by Eric SCHAEFFER
- int fontVariant =
- this.parent.properties.get("font-variant").getEnum();
-
- this.fs = new FontState(area.getFontInfo(), fontFamily,
- fontStyle, fontWeight, fontSize,
- fontVariant);
-
- ColorType c = this.parent.properties.get("color").getColorType();
- this.red = c.red();
- this.green = c.green();
- this.blue = c.blue();
-
- this.verticalAlign =
- this.parent.properties.get("vertical-align").getEnum();
-
- this.wrapOption =
- this.parent.properties.get("wrap-option").getEnum();
- this.whiteSpaceCollapse =
- this.parent.properties.get("white-space-collapse").getEnum();
this.ts = new TextState();
- ts.setUnderlined(underlined);
- ts.setOverlined(overlined);
- ts.setLineThrough(lineThrough);
+ ts.setUnderlined(textInfo.underlined);
+ ts.setOverlined(textInfo.overlined);
+ ts.setLineThrough(textInfo.lineThrough);
this.marker = this.start;
}
int orig_start = this.marker;
- this.marker = addText((BlockArea)area, fs, red, green, blue,
- wrapOption, this.getLinkSet(),
- whiteSpaceCollapse, ca, this.marker, length,
- ts, verticalAlign);
+ this.marker = addText((BlockArea)area, textInfo.fs, textInfo.red, textInfo.green, textInfo.blue,
+ textInfo.wrapOption, this.getLinkSet(),
+ textInfo.whiteSpaceCollapse, ca, this.marker, length,
+ ts, textInfo.verticalAlign);
if (this.marker == -1) {
return -1;
}
-
}
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.StreamRenderer;
import org.apache.fop.fo.pagination.Root;
-import org.apache.fop.system.BufferManager;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.extensions.ExtensionObj;
/**
* current formatting object being handled
*/
- protected FObj currentFObj = null;
+ protected FONode currentFObj = null;
/**
* the root of the formatting object tree
*/
protected FObj rootFObj = null;
- public BufferManager bufferManager;
-
/**
* set of names of formatting objects encountered but unknown
*/
* (mark-fop@inomial.com)
*/
private StreamRenderer streamRenderer;
-
private Logger log;
+ private FOUserAgent userAgent;
public FOTreeBuilder() {}
throws SAXException {
currentFObj.end();
- currentFObj = (FObj)currentFObj.getParent();
+ currentFObj = currentFObj.getParent();
}
/**
public void startElement(String uri, String localName, String rawName,
Attributes attlist) throws SAXException {
/* the formatting object started */
- FObj fobj;
+ FONode fobj;
/* the maker for the formatting object started */
ElementMapping.Maker fobjMaker = null;
fobjMaker = (ElementMapping.Maker)table.get(localName);
// try default
if(fobjMaker == null) {
- fobjMaker = (ElementMapping.Maker)table.get("<default>");
+ fobjMaker = (ElementMapping.Maker)table.get(ElementMapping.DEFAULT);
}
}
String fullName = uri + "^" + localName;
if (!this.unknownFOs.containsKey(fullName)) {
this.unknownFOs.put(fullName, "");
- log.error("Unknown formatting object "
+ log.warn("Unknown formatting object "
+ fullName);
}
if(namespaces.contains(uri.intern())) {
fobj = fobjMaker.make(currentFObj);
fobj.setName(localName);
fobj.setLogger(log);
+ // set the user agent for resolving user agent values
+ fobj.setUserAgent(userAgent);
+ // set the stream renderer so that appropriate
+ // elements can add pages and handle resolving references
+ fobj.setStreamRenderer(streamRenderer);
+
fobj.handleAttrs(attlist);
} catch (FOPException e) {
throw new SAXException(e);
}
if (rootFObj == null) {
- rootFObj = fobj;
- rootFObj.setBufferManager(this.bufferManager);
if (!fobj.getName().equals("fo:root")) {
throw new SAXException(new FOPException("Root element must"
- + " be root, not "
+ + " be fo:root, not "
+ fobj.getName()));
}
- } else if(!(fobj instanceof org.apache.fop.fo.pagination.PageSequence)) {
+ rootFObj = (FObj)fobj;
+ } else {
currentFObj.addChild(fobj);
}
return (rootFObj != null);
}
- public void setBufferManager(BufferManager bufferManager) {
- this.bufferManager = bufferManager;
- }
-
}
// FOP
import org.apache.fop.layout.Area;
+import org.apache.fop.layout.AreaClass;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.IDReferences;
import org.apache.fop.fo.properties.FOPropertyMapping;
+import org.apache.fop.layout.Area;
+import org.apache.fop.layout.AreaClass;
+import org.apache.fop.layout.LinkSet;
+import org.apache.fop.system.BufferManager;
+import org.apache.fop.fo.flow.Marker;
import org.xml.sax.Attributes;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.Hashtable;
+
/**
* base class for representation of formatting objects and their processing
*/
public class FObj extends FONode {
-
public PropertyList properties;
protected PropertyManager propMgr;
+ protected String areaClass = AreaClass.UNASSIGNED;
+
+ /**
+ * value of marker before layout begins
+ */
+ public final static int START = -1000;
+
+ /**
+ * value of marker after break-after
+ */
+ public final static int BREAK_AFTER = -1001;
+
+ /**
+ * where the layout was up to.
+ * for FObjs it is the child number
+ * for FOText it is the character number
+ */
+ protected int marker = START;
+
+ protected Vector children = new Vector(); // made public for searching for id's
- protected String name;
+ protected boolean isInTableCell = false;
- public FObj(FObj parent) {
+ protected int forcedStartOffset = 0;
+ protected int forcedWidth = 0;
+
+ protected int widows = 0;
+ protected int orphans = 0;
+
+ protected LinkSet linkSet;
+
+ // count of areas generated-by/returned-by
+ public int areasGenerated = 0;
+
+ // markers
+ protected Hashtable markers;
+
+ public FObj(FONode parent) {
super(parent);
+ markers = new Hashtable();
+ if (parent instanceof FObj)
+ this.areaClass = ((FObj)parent).areaClass;
}
public void setName(String str) {
name = "fo:" + str;
}
+ protected static PropertyListBuilder plb = null;
+
protected PropertyListBuilder getListBuilder() {
- PropertyListBuilder plb = new PropertyListBuilder();
+ if(plb == null) {
+ plb = new PropertyListBuilder();
plb.addList(FOPropertyMapping.getGenericMappings());
+
+ for (Iterator iter = FOPropertyMapping.getElementMappings().iterator();
+ iter.hasNext(); ) {
+ String elem = (String)iter.next();
+ plb.addElementList(elem, FOPropertyMapping.getElementMapping(elem));
+ }
+ }
return plb;
}
*/
public void handleAttrs(Attributes attlist) throws FOPException {
String uri = "http://www.w3.org/1999/XSL/Format";
+ FONode par = parent;
+ while(par != null && !(par instanceof FObj)) {
+ par = par.parent;
+ }
+ PropertyList props = null;
+ if(par != null) {
+ props = ((FObj)par).properties;
+ }
properties =
getListBuilder().makeList(uri, name, attlist,
- (parent == null) ? null
- : parent.properties, parent);
+ props, (FObj)par);
properties.setFObj(this);
this.propMgr = makePropertyManager(properties);
setWritingMode();
return new PropertyManager(propertyList);
}
- /**
- * adds characters (does nothing here)
- * @param data text
- * @param start start position
- * @param length length of the text
- */
- protected void addCharacters(char data[], int start, int length) {
- // ignore
- }
-
- /**
- * generates the area or areas for this formatting object
- * and adds these to the area. This method should always be
- * overridden by all sub classes
- *
- * @param area
- */
- public Status layout(Area area) throws FOPException {
- // should always be overridden
- return new Status(Status.OK);
- }
-
- /**
- * returns the name of the formatting object
- * @return the name of this formatting objects
- */
- public String getName() {
- return this.name;
- }
-
- /**
- *
- */
- protected void start() {
- // do nothing by default
- }
-
- /**
- *
- */
- protected void end() {
- // do nothing by default
+ protected void addChild(FONode child) {
+ children.addElement(child);
}
/**
return (properties.get(name));
}
-
/**
* Return the "content width" of the areas generated by this FO.
* This is used by percent-based properties to get the dimension of
*/
protected void setWritingMode() {
FObj p;
- FObj parent;
+ FONode parent;
for (p = this;
- !p.generatesReferenceAreas() && (parent = p.getParent()) != null;
- p = parent);
+ !p.generatesReferenceAreas() && (parent = p.getParent()) != null && (parent instanceof FObj);
+ p = (FObj)parent);
this.properties.setWritingMode(p.getProperty("writing-mode").getEnum());
}
+ public void setIsInTableCell() {
+ this.isInTableCell = true;
+ // made recursive by Eric Schaeffer
+ for (int i = 0; i < this.children.size(); i++) {
+ Object obj = this.children.elementAt(i);
+ if(obj instanceof FObj) {
+ FObj child = (FObj)obj;
+ child.setIsInTableCell();
+ }
+ }
+ }
+
+ public void forceStartOffset(int offset) {
+ this.forcedStartOffset = offset;
+ // made recursive by Eric Schaeffer
+ for (int i = 0; i < this.children.size(); i++) {
+ Object obj = this.children.elementAt(i);
+ if(obj instanceof FObj) {
+ FObj child = (FObj)obj;
+ child.forceStartOffset(offset);
+ }
+ }
+ }
+
+ public void forceWidth(int width) {
+ this.forcedWidth = width;
+ // made recursive by Eric Schaeffer
+ for (int i = 0; i < this.children.size(); i++) {
+ Object obj = this.children.elementAt(i);
+ if(obj instanceof FObj) {
+ FObj child = (FObj)obj;
+ child.forceWidth(width);
+ }
+ }
+ }
+
+ public void resetMarker() {
+ this.marker = START;
+ int numChildren = this.children.size();
+ for (int i = 0; i < numChildren; i++) {
+ Object obj = this.children.elementAt(i);
+ if(obj instanceof FObj) {
+ FObj child = (FObj)obj;
+ child.resetMarker();
+ }
+ }
+ }
+
+ public void setWidows(int wid) {
+ widows = wid;
+ }
+
+ public void setOrphans(int orph) {
+ orphans = orph;
+ }
+
+ public void removeAreas() {
+ // still to do
+ }
+
+ public void setLinkSet(LinkSet linkSet) {
+ this.linkSet = linkSet;
+ for (int i = 0; i < this.children.size(); i++) {
+ Object obj = this.children.elementAt(i);
+ if(obj instanceof FObj) {
+ FObj child = (FObj)obj;
+ child.setLinkSet(linkSet);
+ }
+ }
+ }
+
+ public LinkSet getLinkSet() {
+ return this.linkSet;
+ }
+
+ /**
+ * At the start of a new span area layout may be partway through a
+ * nested FO, and balancing requires rollback to this known point.
+ * The snapshot records exactly where layout is at.
+ * @param snapshot a Vector of markers (Integer)
+ * @returns the updated Vector of markers (Integers)
+ */
+ public Vector getMarkerSnapshot(Vector snapshot) {
+ snapshot.addElement(new Integer(this.marker));
+
+ // terminate if no kids or child not yet accessed
+ if (this.marker < 0)
+ return snapshot;
+ else if (children.isEmpty())
+ return snapshot;
+ else
+ return ((FObj)children.elementAt(this.marker)).getMarkerSnapshot(snapshot);
+ }
+
+ /**
+ * When balancing occurs, the flow layout() method restarts at the
+ * point specified by the current marker snapshot, which is retrieved
+ * and restored using this method.
+ * @param snapshot the Vector of saved markers (Integers)
+ */
+ public void rollback(Vector snapshot) {
+ this.marker = ((Integer)snapshot.elementAt(0)).intValue();
+ snapshot.removeElementAt(0);
+
+ if (this.marker == START) {
+ // make sure all the children of this FO are also reset
+ resetMarker();
+ return;
+ } else if ((this.marker == -1) || children.isEmpty())
+ return;
+
+ int numChildren = this.children.size();
+
+ if (this.marker <= START) {
+ return;
+ }
+
+ for (int i = this.marker + 1; i < numChildren; i++) {
+ Object obj = this.children.elementAt(i);
+ if(obj instanceof FObj) {
+ FObj child = (FObj)obj;
+ child.resetMarker();
+ }
+ }
+ ((FObj)children.elementAt(this.marker)).rollback(snapshot);
+ }
+
+
+ public void addMarker(Marker marker) throws FOPException {
+ String mcname = marker.getMarkerClassName();
+ if (!markers.containsKey(mcname) && children.isEmpty()) {
+ markers.put(mcname, marker);
+ } else {
+ log.error("fo:marker must be an initial child,"
+ + "and 'marker-class-name' must be unique for same parent");
+ throw new FOPException("fo:marker must be an initial child,"
+ + "and 'marker-class-name' must be unique for same parent");
+ }
+ }
+
+ public boolean hasMarkers() {
+ return !markers.isEmpty();
+ }
+
+ public Vector getMarkers() {
+ return new Vector(markers.values());
+ }
}
package org.apache.fop.fo;
import org.apache.fop.layout.Area;
+import org.apache.fop.layout.FontState;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.ColorType;
/**
* base class for representation of mixed content formatting objects
* and their processing
*/
public class FObjMixed extends FObj {
+ FOText.TextInfo textInfo = null;
- public FObjMixed(FObj parent) {
+ public FObjMixed(FONode parent) {
super(parent);
}
protected void addCharacters(char data[], int start, int length) {
- addChild(new FOText(data, start, length, this));
+ if(textInfo == null) {
+ String fontFamily =
+ getProperty("font-family").getString();
+ String fontStyle =
+ getProperty("font-style").getString();
+ String fontWeight =
+ getProperty("font-weight").getString();
+ int fontSize =
+ getProperty("font-size").getLength().mvalue();
+ // font-variant support
+ // added by Eric SCHAEFFER
+ int fontVariant =
+ getProperty("font-variant").getEnum();
+
+ //textInfo.fs = new FontState(area.getFontInfo(), fontFamily,
+ // fontStyle, fontWeight, fontSize,
+ // fontVariant);
+
+ ColorType c = getProperty("color").getColorType();
+ textInfo.red = c.red();
+ textInfo.green = c.green();
+ textInfo.blue = c.blue();
+
+ textInfo.verticalAlign =
+ getProperty("vertical-align").getEnum();
+
+ textInfo.wrapOption =
+ getProperty("wrap-option").getEnum();
+ textInfo.whiteSpaceCollapse =
+ getProperty("white-space-collapse").getEnum();
+
+ }
+
+ FOText ft = new FOText(data, start, length, textInfo);
+ ft.setLogger(log);
+ addChild(ft);
}
public Status layout(Area area) throws FOPException {
*/
public class Title extends ToBeImplementedElement {
- public Title(FObj parent) {
+ public Title(FONode parent) {
super(parent);
- this.name = "fo:title";
}
public Status layout(Area area) throws FOPException {
*/
public class ToBeImplementedElement extends FObj {
- protected ToBeImplementedElement(FObj parent) {
+ protected ToBeImplementedElement(FONode parent) {
super(parent);
}
* This prevents any further problems arising from the unknown
* data.
*/
-public class Unknown extends FObj {
+public class Unknown extends FONode {
public static class Maker extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new Unknown(parent);
}
}
- public Unknown(FObj parent) {
+ public Unknown(FONode parent) {
super(parent);
}
space = sp;
}
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new UnknownXMLObj(parent, space);
}
}
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- protected UnknownXMLObj(FObj parent, String space) {
+ protected UnknownXMLObj(FONode parent, String space) {
super(parent);
this.namespace = space;
}
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- public XMLElement(FObj parent) {
+ public XMLElement(FONode parent) {
super(parent);
}
import java.util.*;
/**
- * Since SVG objects are not layed out then this class checks
- * that this element is not being layed out inside some incorrect
- * element.
+ * Generic XML object.
+ * This is used by xml objects (other than fo) than will build a DOM
+ * with each element.
*/
-public abstract class XMLObj extends FObj {
+public abstract class XMLObj extends FONode {
// temp reference for attributes
Attributes attr = null;
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- public XMLObj(FObj parent) {
+ public XMLObj(FONode parent) {
super(parent);
}
}
public abstract String getNameSpace();
- protected static Hashtable ns = new Hashtable();
+ protected static HashMap ns = new HashMap();
- public void addGraphic(Document doc, Element parent) {
+ public void addElement(Document doc, Element parent) {
this.doc = doc;
element = doc.createElementNS(getNameSpace(), name);
protected void addChild(FONode child) {
if (child instanceof XMLObj) {
- ((XMLObj)child).addGraphic(doc, element);
+ ((XMLObj)child).addElement(doc, element);
+ } else {
+ // in theory someone might want to embed some defined
+ // xml (eg. fo) inside the foreign xml
+ // they could use a different namespace
+ log.debug("Invalid element: " + child.getName() + " inside foreign xml markup");
}
}
*/
public Status layout(Area area) throws FOPException {
/* generate a warning */
- log.error("" + this.name + " outside foreign xml");
+ log.warn("" + this.name + " outside foreign xml");
/* return status */
return new Status(Status.OK);
}
-
- public void removeID(IDReferences idReferences) {}
-
- /**
- * These method overrides prevent problems with the different types.
- */
- public void setIsInTableCell() {}
-
- public void forceStartOffset(int offset) {}
-
- public void forceWidth(int width) {}
-
- public void resetMarker() {}
-
- public void setLinkSet(LinkSet linkSet) {}
-
- public Vector getMarkerSnapshot(Vector snapshot) {
- return snapshot;
- }
-
- public void rollback(Vector snapshot) {}
-
- protected void setWritingMode() {}
}
import org.apache.fop.fo.Property;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FONode;
import org.apache.fop.fo.flow.ListItem;
public class BodyStartFunction extends FunctionBase {
Numeric distance =
pInfo.getPropertyList().get("provisional-distance-between-starts").getNumeric();
- FObj item = pInfo.getFO();
+ FONode item = pInfo.getFO();
while (item != null &&!(item instanceof ListItem)) {
item = item.getParent();
}
}
Numeric startIndent =
- item.properties.get("start-indent").getNumeric();
+ ((ListItem)item).properties.get("start-indent").getNumeric();
return new NumericProperty(distance.add(startIndent));
}
import org.apache.fop.fo.Property;
import org.apache.fop.fo.LengthProperty;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FONode;
import org.apache.fop.fo.flow.ListItem;
public class LabelEndFunction extends FunctionBase {
Length separation =
pInfo.getPropertyList().getNearestSpecified("provisional-label-separation").getLength();
- FObj item = pInfo.getFO();
+ FONode item = pInfo.getFO();
while (item != null &&!(item instanceof ListItem)) {
item = item.getParent();
}
if (item == null) {
throw new PropertyException("label-end() called from outside an fo:list-item");
}
- Length startIndent = item.properties.get("start-indent").getLength();
+ Length startIndent = ((ListItem)item).properties.get("start-indent").getLength();
LinearCombinationLength labelEnd = new LinearCombinationLength();
// Should be CONTAINING_REFAREA but that doesn't work
- LengthBase base = new LengthBase(item, pInfo.getPropertyList(),
+ LengthBase base = new LengthBase((ListItem)item, pInfo.getPropertyList(),
LengthBase.CONTAINING_BOX);
PercentLength refWidth = new PercentLength(1.0, base);
public class BasicLink extends Inline {
- public BasicLink(FObj parent) {
+ public BasicLink(FONode parent) {
super(parent);
- this.name = "fo:basic-link";
}
public Status layout(Area area) throws FOPException {
int numChildren = this.children.size();
for (int i = this.marker; i < numChildren; i++) {
FONode fo = (FONode)children.elementAt(i);
- fo.setLinkSet(ls);
+ if(fo instanceof FObj)
+ ((FObj)fo).setLinkSet(ls);
Status status;
if ((status = fo.layout(area)).isIncomplete()) {
*/
public class BidiOverride extends ToBeImplementedElement {
- public BidiOverride(FObj parent) {
+ public BidiOverride(FONode parent) {
super(parent);
- this.name = "fo:bidi-override";
}
public Status layout(Area area) throws FOPException {
// this may be helpful on other FOs too
boolean anythingLaidOut = false;
- public Block(FObj parent) {
+ public Block(FONode parent) {
super(parent);
- this.name = "fo:block";
}
public void handleAttrs(Attributes attlist) throws FOPException {
this.blockOrphans =
this.properties.get("orphans").getNumber().intValue();
-
-
this.id = this.properties.get("id").getString();
if (area instanceof BlockArea) {
FONode fo = (FONode)children.elementAt(i);
if (fo instanceof FOText) {
if (((FOText)fo).willCreateArea()) {
- fo.setWidows(blockWidows);
+ //fo.setWidows(blockWidows);
break;
} else {
children.removeElementAt(i);
i--;
}
} else {
- fo.setWidows(blockWidows);
+ //fo.setWidows(blockWidows);
break;
}
}
FONode fo = (FONode)children.elementAt(i);
if (fo instanceof FOText) {
if (((FOText)fo).willCreateArea()) {
- fo.setOrphans(blockOrphans);
+ //fo.setOrphans(blockOrphans);
break;
}
} else {
- fo.setOrphans(blockOrphans);
+ //fo.setOrphans(blockOrphans);
break;
}
}
PageSequence pageSequence;
- public BlockContainer(FObj parent) {
+ public BlockContainer(FONode parent) {
super(parent);
- this.name = "fo:block-container";
}
public void handleAttrs(Attributes attlist) throws FOPException {
public final static int OK = 0;
public final static int DOESNOT_FIT = 1;
- public Character(FObj parent) {
+ public Character(FONode parent) {
super(parent);
this.name = "fo:character";
}
int whiteSpaceCollapse =
this.properties.get("white-space-collapse").getEnum();
- int wrapOption = this.parent.properties.get("wrap-option").getEnum();
+ int wrapOption = ((FObj)this.parent).properties.get("wrap-option").getEnum();
int tmp = this.properties.get("text-decoration").getEnum();
if (tmp == org.apache.fop.fo.properties.TextDecoration.UNDERLINE) {
ImageArea imageArea;
- public ExternalGraphic(FObj parent) {
+ public ExternalGraphic(FONode parent) {
super(parent);
- this.name = "fo:external-graphic";
}
public Status layout(Area area) throws FOPException {
*/
public class Float extends ToBeImplementedElement {
- public Float(FObj parent) {
+ public Float(FONode parent) {
super(parent);
this.name = "fo:float";
}
private Status _status = new Status(Status.AREA_FULL_NONE);
- public Flow(FObj parent) {
+ public Flow(FONode parent) {
super(parent);
this.name = getElementName();
}
public class Footnote extends FObj {
- public Footnote(FObj parent) {
+ public Footnote(FONode parent) {
super(parent);
this.name = "fo:footnote";
}
int endIndent;
int textIndent;
- public FootnoteBody(FObj parent) {
+ public FootnoteBody(FONode parent) {
super(parent);
this.name = "fo:footnote-body";
}
*/
public class InitialPropertySet extends ToBeImplementedElement {
- public InitialPropertySet(FObj parent) {
+ public InitialPropertySet(FONode parent) {
super(parent);
- this.name = "fo:initial-property-set";
}
public Status layout(Area area) throws FOPException {
protected boolean lineThrough = false;
- public Inline(FObj parent) {
+ public Inline(FONode parent) {
super(parent);
- this.name = "fo:inline";
}
public void handleAttrs(Attributes attlist) throws FOPException {
}
}
- protected void addCharacters(char data[], int start, int length) {
- FOText ft = new FOText(data, start, length, this);
- ft.setLogger(log);
- ft.setUnderlined(underlined);
- ft.setOverlined(overlined);
- ft.setLineThrough(lineThrough);
- children.addElement(ft);
- }
-
}
*/
public class InlineContainer extends ToBeImplementedElement {
- public InlineContainer(FObj parent) {
+ public InlineContainer(FONode parent) {
super(parent);
- this.name = "fo:inline-container";
}
public void handleAttrs(Attributes attlist) throws FOPException {
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- public InstreamForeignObject(FObj parent) {
+ public InstreamForeignObject(FONode parent) {
super(parent);
- this.name = "fo:instream-foreign-object";
}
/**
if (this.children.size() > 0) {
FONode fo = (FONode)children.elementAt(0);
Status status;
- // currently FONode must be an SVG
if ((status =
fo.layout(this.areaCurrent)).isIncomplete()) {
return status;
*/
public class Leader extends FObjMixed {
- public Leader(FObj parent) {
+ public Leader(FONode parent) {
super(parent);
- this.name = "fo:leader";
}
public Status layout(Area area) throws FOPException {
int spaceBetweenListRows = 0;
ColorType backgroundColor;
- public ListBlock(FObj parent) {
+ public ListBlock(FONode parent) {
super(parent);
- this.name = "fo:list-block";
}
public Status layout(Area area) throws FOPException {
String id;
BlockArea blockArea;
- public ListItem(FObj parent) {
+ public ListItem(FONode parent) {
super(parent);
this.name = "fo:list-item";
}
public class ListItemBody extends FObj {
- public ListItemBody(FObj parent) {
+ public ListItemBody(FONode parent) {
super(parent);
this.name = "fo:list-item-body";
}
public class ListItemLabel extends FObj {
- public ListItemLabel(FObj parent) {
+ public ListItemLabel(FONode parent) {
super(parent);
this.name = "fo:list-item-label";
}
private String markerClassName;
private Area registryArea;
- public Marker(FObj parent) {
+ public Marker(FONode parent) {
super(parent);
- this.name = "fo:marker";
}
public void handleAttrs(Attributes attlist) throws FOPException {
// check to ensure that no other marker with same parent
// has this 'marker-class-name' is in addMarker() method
try {
- parent.addMarker(this);
+ ((FObj)parent).addMarker(this);
} catch (FOPException fopex) {
- // log is null in constructor
- //log.error("marker cannot be added to '" + parent
- // + "'");
+ log.error("marker cannot be added to '" + parent
+ + "'");
}
}
*/
public class MultiCase extends ToBeImplementedElement {
- public MultiCase(FObj parent) {
+ public MultiCase(FONode parent) {
super(parent);
- this.name = "fo:multi-case";
}
public Status layout(Area area) throws FOPException {
*/
public class MultiProperties extends ToBeImplementedElement {
- public MultiProperties(FObj parent) {
+ public MultiProperties(FONode parent) {
super(parent);
this.name = "fo:multi-properties";
}
*/
public class MultiPropertySet extends ToBeImplementedElement {
- public MultiPropertySet(FObj parent) {
+ public MultiPropertySet(FONode parent) {
super(parent);
this.name = "fo:multi-property-set";
}
*/
public class MultiSwitch extends ToBeImplementedElement {
- public MultiSwitch(FObj parent) {
+ public MultiSwitch(FONode parent) {
super(parent);
this.name = "fo:multi-switch";
}
*/
public class MultiToggle extends ToBeImplementedElement {
- public MultiToggle(FObj parent) {
+ public MultiToggle(FONode parent) {
super(parent);
this.name = "fo:multi-toggle";
}
int whiteSpaceCollapse;
TextState ts;
- public PageNumber(FObj parent) {
+ public PageNumber(FONode parent) {
super(parent);
- this.name = "fo:page-number";
}
public Status layout(Area area) throws FOPException {
TextState ts;
- public PageNumberCitation(FObj parent) {
+ public PageNumberCitation(FONode parent) {
super(parent);
- this.name = "fo:page-number-citation";
}
public Status layout(Area area) throws FOPException {
private int retrievePosition;
private int retrieveBoundary;
- public RetrieveMarker(FObj parent) {
+ public RetrieveMarker(FONode parent) {
super(parent);
this.name = "fo:retrieve-marker";
}
public class StaticContent extends Flow {
- public StaticContent(FObj parent) {
+ public StaticContent(FONode parent) {
super(parent);
((PageSequence)parent).setIsFlowSet(false); // hacquery of sorts
}
AreaContainer areaContainer;
- public Table(FObj parent) {
+ public Table(FONode parent) {
super(parent);
this.name = "fo:table";
}
addedFooter = true;
tableFooter.resetMarker();
}
- fo.setWidows(widows);
- fo.setOrphans(orphans);
+ //fo.setWidows(widows);
+ //fo.setOrphans(orphans);
((TableBody)fo).setColumns(columns);
if ((status = fo.layout(areaContainer)).isIncomplete()) {
*/
public class TableAndCaption extends ToBeImplementedElement {
- public TableAndCaption(FObj parent) {
+ public TableAndCaption(FONode parent) {
super(parent);
- this.name = "fo:table-and-caption";
}
public Status layout(Area area) throws FOPException {
AreaContainer areaContainer;
- public TableBody(FObj parent) {
+ public TableBody(FONode parent) {
super(parent);
this.name = "fo:table-body";
}
*/
public class TableCaption extends ToBeImplementedElement {
- public TableCaption(FObj parent) {
+ public TableCaption(FONode parent) {
super(parent);
- this.name = "fo:table-caption";
}
public Status layout(Area area) throws FOPException {
AreaContainer cellArea;
- public TableCell(FObj parent) {
+ public TableCell(FONode parent) {
super(parent);
this.name = "fo:table-cell";
}
AreaContainer areaContainer;
- public TableColumn(FObj parent) {
+ public TableColumn(FONode parent) {
super(parent);
this.name = "fo:table-column";
}
areaContainer.setYPosition(value + 2 * spaceBefore);
}
- public TableFooter(FObj parent) {
+ public TableFooter(FONode parent) {
super(parent);
this.name = "fo:table-footer";
}
public class TableHeader extends TableBody {
- public TableHeader(FObj parent) {
+ public TableHeader(FONode parent) {
super(parent);
this.name = "fo:table-header";
}
}
- public TableRow(FObj parent) {
+ public TableRow(FONode parent) {
super(parent);
- this.name = "fo:table-row";
}
public void setColumns(Vector columns) {
*/
public class Wrapper extends FObjMixed {
- public Wrapper(FObj parent) {
+ public Wrapper(FONode parent) {
super(parent);
// check that this occurs inside an fo:flow
}
- protected void addCharacters(char data[], int start, int length) {
- FOText ft = new FOText(data, start, length, this);
- ft.setLogger(log);
- children.addElement(ft);
- }
-
}
private int oddOrEven;
private int blankOrNotBlank;
- public ConditionalPageMasterReference(FObj parent) {
+ public ConditionalPageMasterReference(FONode parent) {
super(parent);
this.name = getElementName();
}
- protected void validateParent(FObj parent) throws FOPException {
+ protected void validateParent(FONode parent) throws FOPException {
if (parent.getName().equals("fo:repeatable-page-master-alternatives")) {
this.repeatablePageMasterAlternatives =
(RepeatablePageMasterAlternatives)parent;
private Root root;
- public LayoutMasterSet(FObj parent) {
+ public LayoutMasterSet(FONode parent) {
super(parent);
- this.name = "fo:layout-master-set";
}
public void handleAttrs(Attributes attlist) throws FOPException {
/**
* Base PageMasterReference class. Provides implementation for handling the
- * master-name attribute and containment within a PageSequenceMaster
+ * master-reference attribute and containment within a PageSequenceMaster
*/
public abstract class PageMasterReference extends FObj
implements SubSequenceSpecifier {
private String _masterName;
private PageSequenceMaster _pageSequenceMaster;
- public PageMasterReference(FObj parent) {
+ public PageMasterReference(FONode parent) {
super(parent);
this.name = getElementName();
}
public void handleAttrs(Attributes attlist) throws FOPException {
super.handleAttrs(attlist);
- if (getProperty("master-name") != null) {
- setMasterName(getProperty("master-name").getString());
+ if (getProperty("master-reference") != null) {
+ setMasterName(getProperty("master-reference").getString());
}
validateParent(parent);
}
/**
- * Returns the "master-name" attribute of this page master reference
+ * Returns the "master-reference" attribute of this page master reference
*/
public String getMasterName() {
return _masterName;
boolean isEmptyPage);
/**
- * Gets the formating object name for this object. Subclasses must provide this.
+ * Gets the formating object name for this object.
+ * Subclasses must provide this.
*
- * @return the element name of this reference. e.g. fo:repeatable-page-master-reference
+ * @return the element name of this reference.
+ * e.g. fo:repeatable-page-master-reference
*/
protected abstract String getElementName();
* Checks that the parent is the right element. The default implementation
* checks for fo:page-sequence-master
*/
- protected void validateParent(FObj parent) throws FOPException {
+ protected void validateParent(FONode parent) throws FOPException {
if (parent.getName().equals("fo:page-sequence-master")) {
_pageSequenceMaster = (PageSequenceMaster)parent;
if (getMasterName() == null) {
log.warn("" + getElementName()
- + " does not have a master-name and so is being ignored");
+ + " does not have a master-reference and so is being ignored");
} else {
_pageSequenceMaster.addSubsequenceSpecifier(this);
}
public abstract void reset();
-
-
-
}
private Hashtable _flowMap;
/**
- * the "master-name" attribute
+ * the "master-reference" attribute
*/
private String masterName;
private String currentPageMasterName;
- public PageSequence(FObj parent) {
+ public PageSequence(FONode parent) {
super(parent);
- this.name = "fo:page-sequence";
}
public void handleAttrs(Attributes attlist) throws FOPException {
}
}
- masterName = this.properties.get("master-name").getString();
+ masterName = this.properties.get("master-reference").getString();
// get the 'format' properties
this.pageNumberGenerator =
SimplePageMaster simpleMaster =
this.layoutMasterSet.getSimplePageMaster(pageSequenceName);
if (simpleMaster == null) {
- throw new FOPException("'master-name' for 'fo:page-sequence'"
+ throw new FOPException("'master-reference' for 'fo:page-sequence'"
+ "matches no 'simple-page-master' or 'page-sequence-master'");
}
currentPageMasterName = pageSequenceName;
// references to page-masters. So the methods use the former
// terminology ('sub-sequence-specifiers', or SSS),
// but the actual FO's are MasterReferences.
- public PageSequenceMaster(FObj parent) {
+ public PageSequenceMaster(FONode parent) {
super(parent);
- this.name = "fo:page-sequence-master";
}
public void handleAttrs(Attributes attlist) throws FOPException {
// FOP
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.apps.FOPException;
import org.apache.fop.layout.RegionArea;
private SimplePageMaster _layoutMaster;
private String _regionName;
- protected Region(FObj parent) {
+ protected Region(FONode parent) {
super(parent);
this.name = getElementName();
}
private int precedence;
- public RegionAfter(FObj parent) {
+ public RegionAfter(FONode parent) {
super(parent);
}
private int precedence;
- public RegionBefore(FObj parent) {
+ public RegionBefore(FONode parent) {
super(parent);
}
// FOP
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.properties.Overflow;
import org.apache.fop.datatypes.ColorType;
ColorType backgroundColor;
- public RegionBody(FObj parent) {
+ public RegionBody(FONode parent) {
super(parent);
}
public static final String REGION_CLASS = "end";
- public RegionEnd(FObj parent) {
+ public RegionEnd(FONode parent) {
super(parent);
}
public static final String REGION_CLASS = "start";
- public RegionStart(FObj parent) {
+ public RegionStart(FONode parent) {
super(parent);
}
private Vector conditionalPageMasterRefs;
- public RepeatablePageMasterAlternatives(FObj parent) {
+ public RepeatablePageMasterAlternatives(FONode parent) {
super(parent);
- this.name = "fo:repeatable-page-master-alternatives";
}
public void handleAttrs(Attributes attlist) throws FOPException {
private int maximumRepeats;
private int numberConsumed = 0;
- public RepeatablePageMasterReference(FObj parent) {
+ public RepeatablePageMasterReference(FONode parent) {
super(parent);
}
*/
private int runningPageNumberCounter = 0;
- public Root(FObj parent) {
+ public Root(FONode parent) {
super(parent);
// this.properties.get("media-usage");
this.runningPageNumberCounter = count;
}
- /**
- * @deprecated handled by addChild now
- */
- public void addPageSequence(PageSequence pageSequence) {
- this.pageSequences.addElement(pageSequence);
- }
-
public int getPageSequenceCount() {
return pageSequences.size();
}
boolean afterPrecedence;
int afterHeight;
- public SimplePageMaster(FObj parent) {
+ public SimplePageMaster(FONode parent) {
super(parent);
- this.name = "fo:simple-page-master";
}
public void handleAttrs(Attributes attlist) throws FOPException {
private int state;
- public SinglePageMasterReference(FObj parent) {
+ public SinglePageMasterReference(FONode parent) {
super(parent);
this.state = FIRST;
}
package org.apache.fop.fonts;
import java.io.*;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.ArrayList;
import org.apache.fop.messaging.MessageHandler;
/**
* Create the glyf table and fill in loca table
*/
private void createGlyf(FontFileReader in,
- Hashtable glyphs) throws IOException {
+ HashMap glyphs) throws IOException {
TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf");
int size = 0;
int start = 0;
pad4();
start = currentPos;
- for (Enumeration e = glyphs.keys(); e.hasMoreElements(); ) {
+ for (Iterator e = glyphs.keySet().iterator(); e.hasNext(); ) {
int glyphLength = 0;
- Integer origIndex = (Integer)e.nextElement();
+ Integer origIndex = (Integer)e.next();
Integer subsetIndex = (Integer)glyphs.get(origIndex);
int nextOffset = 0;
* metric (key) to the subset metric (value)
*/
private void createHmtx(FontFileReader in,
- Hashtable glyphs) throws IOException {
+ HashMap glyphs) throws IOException {
TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("hmtx");
int longHorMetricSize = glyphs.size() * 2;
if (entry != null) {
pad4();
int offset = (int)entry.offset;
- for (Enumeration e = glyphs.keys(); e.hasMoreElements(); ) {
- Integer origIndex = (Integer)e.nextElement();
+ for (Iterator e = glyphs.keySet().iterator(); e.hasNext(); ) {
+ Integer origIndex = (Integer)e.next();
Integer subsetIndex = (Integer)glyphs.get(origIndex);
writeUShort(currentPos + subsetIndex.intValue() * 4,
}
/**
- * Returns a Vector containing the glyph itself plus all glyphs
+ * Returns a List containing the glyph itself plus all glyphs
* that this composite glyph uses
*/
- private Vector getIncludedGlyphs(FontFileReader in, int glyphOffset,
+ private ArrayList getIncludedGlyphs(FontFileReader in, int glyphOffset,
Integer glyphIdx) throws IOException {
- Vector ret = new Vector();
- ret.addElement(glyphIdx);
+ ArrayList ret = new ArrayList();
+ ret.add(glyphIdx);
int offset = glyphOffset + (int)mtx_tab[glyphIdx.intValue()].offset
+ 10;
Integer compositeIdx = null;
while (moreComposites) {
flags = in.readTTFUShort(offset);
compositeIdx = new Integer(in.readTTFUShort(offset + 2));
- ret.addElement(compositeIdx);
+ ret.add(compositeIdx);
offset += 4;
if ((flags & 1) > 0) {
* Rewrite all compositepointers in glyphindex glyphIdx
*
*/
- private void remapComposite(FontFileReader in, Hashtable glyphs,
+ private void remapComposite(FontFileReader in, HashMap glyphs,
int glyphOffset,
Integer glyphIdx) throws IOException {
int offset = glyphOffset + (int)mtx_tab[glyphIdx.intValue()].offset
* mapping
*/
private void scanGlyphs(FontFileReader in,
- Hashtable glyphs) throws IOException {
+ HashMap glyphs) throws IOException {
TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf");
- Hashtable newComposites = null;
- Hashtable allComposites = new Hashtable();
+ HashMap newComposites = null;
+ HashMap allComposites = new HashMap();
int newIndex = glyphs.size();
if (entry != null) {
while (newComposites == null || newComposites.size() > 0) {
// Inefficient to iterate through all glyphs
- newComposites = new Hashtable();
+ newComposites = new HashMap();
- for (Enumeration e = glyphs.keys(); e.hasMoreElements(); ) {
- Integer origIndex = (Integer)e.nextElement();
+ for (Iterator e = glyphs.keySet().iterator(); e.hasNext(); ) {
+ Integer origIndex = (Integer)e.next();
if (in.readTTFShort(entry.offset
+ mtx_tab[origIndex.intValue()].offset) < 0) {
// origIndex is a composite glyph
allComposites.put(origIndex, glyphs.get(origIndex));
- Vector composites =
+ ArrayList composites =
getIncludedGlyphs(in, (int)entry.offset,
origIndex);
// Iterate through all composites pointed to
// by this composite and check if they exists
// in the glyphs map, add them if not.
- for (Enumeration cps = composites.elements();
- cps.hasMoreElements(); ) {
+ for (Iterator cps = composites.iterator();
+ cps.hasNext(); ) {
- Integer cIdx = (Integer)cps.nextElement();
+ Integer cIdx = (Integer)cps.next();
if (glyphs.get(cIdx) == null
&& newComposites.get(cIdx) == null) {
newComposites.put(cIdx,
}
// Add composites to glyphs
- for (Enumeration m = newComposites.keys();
- m.hasMoreElements(); ) {
- Integer im = (Integer)m.nextElement();
+ for (Iterator m = newComposites.keySet().iterator();
+ m.hasNext(); ) {
+ Integer im = (Integer)m.next();
glyphs.put(im, newComposites.get(im));
}
}
// Iterate through all composites to remap their composite index
- for (Enumeration ce = allComposites.keys();
- ce.hasMoreElements(); ) {
+ for (Iterator ce = allComposites.keySet().iterator();
+ ce.hasNext(); ) {
remapComposite(in, glyphs, (int)entry.offset,
- (Integer)ce.nextElement());
+ (Integer)ce.next());
}
} else {
*/
public byte[] readFont(FontFileReader in, String name,
- Hashtable glyphs) throws IOException {
+ HashMap glyphs) throws IOException {
/*
* Check if TrueType collection, and that the name
try {
absoluteURL = new URL(href);
} catch (MalformedURLException mue) {
- // if the href contains onl a path then file is assumed
+ // if the href contains only a path then file is assumed
absoluteURL = new URL("file:" + href);
}
imgIS = absoluteURL.openStream();
xOffset = startIndent;
}
-
-
}
-
public int getStemV();
public boolean hasKerningInfo();
- public java.util.Hashtable getKerningInfo();
+ public java.util.HashMap getKerningInfo();
public boolean isEmbeddable();
public byte getSubType();
public org.apache.fop.pdf.PDFStream getFontFile(int objNum);
package org.apache.fop.layout;
-import java.util.Hashtable;
+import java.util.HashMap;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.properties.FontVariant;
private FontMetric _metric;
- private static Hashtable EMPTY_HASHTABLE = new Hashtable();
+ private static HashMap EMPTY_HASHTABLE = new HashMap();
public FontState(FontInfo fontInfo, String fontFamily, String fontStyle,
return _metric.getXHeight(_fontSize) / 1000;
}
- public Hashtable getKerning() {
+ public HashMap getKerning() {
if (_metric instanceof FontDescriptor) {
- Hashtable ret = ((FontDescriptor)_metric).getKerningInfo();
+ HashMap ret = ((FontDescriptor)_metric).getKerningInfo();
if (ret != null)
return ret;
}
package org.apache.fop.layout.hyphenation;
import java.io.*;
-import java.util.Vector;
-import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.HashMap;
/**
* This tree structure stores the hyphenation patterns in an efficient
/**
* This map stores hyphenation exceptions
*/
- protected Hashtable stoplist;
+ protected HashMap stoplist;
/**
* This map stores the character classes
private transient TernaryTree ivalues;
public HyphenationTree() {
- stoplist = new Hashtable(23); // usually a small table
+ stoplist = new HashMap(23); // usually a small table
classmap = new TernaryTree();
vspace = new ByteVector();
vspace.alloc(1); // this reserves index 0, which we don't use
String sw = new String(word, 1, len);
if (stoplist.containsKey(sw)) {
// assume only simple hyphens (Hyphen.pre="-", Hyphen.post = Hyphen.no = null)
- Vector hw = (Vector)stoplist.get(sw);
+ ArrayList hw = (ArrayList)stoplist.get(sw);
int j = 0;
for (i = 0; i < hw.size(); i++) {
- Object o = hw.elementAt(i);
+ Object o = hw.get(i);
if (o instanceof String) {
j += ((String)o).length();
if (j >= remainCharCount && j < (len - pushCharCount))
* @param hyphenatedword a vector of alternating strings and
* {@link Hyphen hyphen} objects.
*/
- public void addException(String word, Vector hyphenatedword) {
+ public void addException(String word, ArrayList hyphenatedword) {
stoplist.put(word, hyphenatedword);
}
package org.apache.fop.layout.hyphenation;
-import java.util.Vector;
+import java.util.ArrayList;
/**
* This interface is used to connect the XML pattern file parser to
* A hyphenatedword is a vector of alternating String's and
* {@link Hyphen Hyphen} instances
*/
- public void addException(String word, Vector hyphenatedword);
+ public void addException(String word, ArrayList hyphenatedword);
/**
* Add hyphenation patterns.
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
-import java.util.Vector;
+import java.util.ArrayList;
import java.net.URL;
/**
int currElement;
PatternConsumer consumer;
StringBuffer token;
- Vector exception;
+ ArrayList exception;
char hyphenChar;
String errMsg;
return pat.toString();
}
- protected Vector normalizeException(Vector ex) {
- Vector res = new Vector();
+ protected ArrayList normalizeException(ArrayList ex) {
+ ArrayList res = new ArrayList();
for (int i = 0; i < ex.size(); i++) {
- Object item = ex.elementAt(i);
+ Object item = ex.get(i);
if (item instanceof String) {
String str = (String)item;
StringBuffer buf = new StringBuffer();
if (c != hyphenChar)
buf.append(c);
else {
- res.addElement(buf.toString());
+ res.add(buf.toString());
buf.setLength(0);
char[] h = new char[1];
h[0] = hyphenChar;
// we use here hyphenChar which is not necessarily
// the one to be printed
- res.addElement(new Hyphen(new String(h), null, null));
+ res.add(new Hyphen(new String(h), null, null));
}
}
if (buf.length() > 0)
- res.addElement(buf.toString());
+ res.add(buf.toString());
} else
- res.addElement(item);
+ res.add(item);
}
return res;
}
- protected String getExceptionWord(Vector ex) {
+ protected String getExceptionWord(ArrayList ex) {
StringBuffer res = new StringBuffer();
for (int i = 0; i < ex.size(); i++) {
- Object item = ex.elementAt(i);
+ Object item = ex.get(i);
if (item instanceof String)
res.append((String)item);
else {
currElement = ELEM_PATTERNS;
else if (local.equals("exceptions")) {
currElement = ELEM_EXCEPTIONS;
- exception = new Vector();
+ exception = new ArrayList();
} else if (local.equals("hyphen")) {
if (token.length() > 0) {
- exception.addElement(token.toString());
+ exception.add(token.toString());
}
- exception.addElement(new Hyphen(attrs.getValue("pre"),
+ exception.add(new Hyphen(attrs.getValue("pre"),
attrs.getValue("no"),
attrs.getValue("post")));
currElement = ELEM_HYPHEN;
consumer.addClass(word);
break;
case ELEM_EXCEPTIONS:
- exception.addElement(word);
+ exception.add(word);
exception = normalizeException(exception);
consumer.addException(getExceptionWord(exception),
- (Vector)exception.clone());
+ (ArrayList)exception.clone());
break;
case ELEM_PATTERNS:
consumer.addPattern(getPattern(word),
consumer.addClass(word);
break;
case ELEM_EXCEPTIONS:
- exception.addElement(word);
+ exception.add(word);
exception = normalizeException(exception);
consumer.addException(getExceptionWord(exception),
- (Vector)exception.clone());
- exception.removeAllElements();
+ (ArrayList)exception.clone());
+ exception.clear();
break;
case ELEM_PATTERNS:
consumer.addPattern(getPattern(word),
System.out.println("class: " + c);
}
- public void addException(String w, Vector e) {
+ public void addException(String w, ArrayList e) {
System.out.println("exception: " + w + " : " + e.toString());
}
}
public static String doubleOut(double doubleDown, int dec) {
-
StringBuffer p = new StringBuffer();
if (doubleDown < 0) {
doubleDown = -doubleDown;
// Java
import java.io.PrintWriter;
import org.apache.fop.messaging.MessageHandler;
-import java.util.Vector;
+import java.util.ArrayList;
/**
* class representing a /Pages object.
/**
* the /Page objects
*/
- protected Vector kids = new Vector();
+ protected ArrayList kids = new ArrayList();
/**
* the number of /Page objects
* @param page the PDFPage to add.
*/
public void addPage(PDFPage page) {
- this.kids.addElement(page.referencePDF());
+ this.kids.add(page.referencePDF());
page.setParent(this);
this.incrementCount();
}
+ " obj\n<< /Type /Pages\n/Count "
+ this.getCount() + "\n/Kids [");
for (int i = 0; i < kids.size(); i++) {
- p = p.append(kids.elementAt(i) + " ");
+ p = p.append(kids.get(i) + " ");
}
p = p.append("] >>\nendobj\n");
return p.toString().getBytes();
import java.util.ArrayList;
import java.util.HashMap;
+import java.awt.Color;
+import java.awt.Paint;
+
/**
* This keeps information about the current state when writing to pdf.
* It allows for creating new graphics states with the q operator.
public class PDFState {
private final static String COLOR = "color";
private final static String BACKCOLOR = "backcolor";
- private final static String PATTERN = "pattern";
- private final static String BACKPATTERN = "backpattern";
+ private final static String PAINT = "paint";
+ private final static String BACKPAINT = "backpaint";
private final static String LINECAP = "lineCap";
private final static String LINEJOIN = "lineJoin";
private final static String LINEWIDTH = "lineWidth";
private final static String FONTNAME = "fontName";
private final static String CLIP = "clip";
- PDFColor color = new PDFColor(0, 0, 0);
- PDFColor backcolor = new PDFColor(255, 255, 255);
- PDFPattern pattern = null;
- PDFPattern backPattern = null;
+ Color color = Color.black;
+ Color backcolor = Color.white;
+ Paint paint = null;
+ Paint backPaint = null;
int lineCap = 0;
int lineJoin = 0;
float lineWidth = 1;
// this call should be used when the q operator is used
// so that the state is known when popped
public void push() {
- HashMap changedMap = new HashMap();
+ HashMap saveMap = new HashMap();
+ saveMap.put(COLOR, color);
+ saveMap.put(BACKCOLOR, backcolor);
+ saveMap.put(PAINT, paint);
+ saveMap.put(BACKPAINT, backPaint);
+ saveMap.put(LINECAP, new Integer(lineCap));
+ saveMap.put(LINEJOIN, new Integer(lineJoin));
+ saveMap.put(LINEWIDTH, new Float(lineWidth));
+ saveMap.put(MITERLIMIT, new Float(miterLimit));
+ saveMap.put(TEXT, new Boolean(text));
+ saveMap.put(DASHOFFSET, new Integer(dashOffset));
+ saveMap.put(DASHARRAY, dashArray);
+ saveMap.put(TRANSFORM, transform);
+ saveMap.put(FONTSIZE, new Float(fontSize));
+ saveMap.put(FONTNAME, fontName);
+ saveMap.put(CLIP, clip);
+ stateStack.add(saveMap);
}
public void pop() {
if (getStackLevel() > 0) {
+ HashMap saveMap = (HashMap)stateStack.get(stateStack.size() - 1);
stateStack.remove(stateStack.size() - 1);
+ color = (Color)saveMap.get(COLOR);
+ backcolor = (Color)saveMap.get(BACKCOLOR);
+ paint = (Paint)saveMap.get(PAINT);
+ backPaint = (Paint)saveMap.get(BACKPAINT);
+ lineCap = ((Integer)saveMap.get(LINECAP)).intValue();
+ lineJoin = ((Integer)saveMap.get(LINEJOIN)).intValue();
+ lineWidth = ((Float)saveMap.get(LINEWIDTH)).floatValue();
+ miterLimit = ((Float)saveMap.get(MITERLIMIT)).floatValue();
+ text = ((Boolean)saveMap.get(TEXT)).booleanValue();
+ dashOffset = ((Integer)saveMap.get(DASHOFFSET)).intValue();
+ dashArray = (int[])saveMap.get(DASHARRAY);
+ transform = (double[])saveMap.get(TRANSFORM);
+ fontSize = ((Float)saveMap.get(FONTSIZE)).floatValue();
+ fontName = (String)saveMap.get(FONTNAME);
+ clip = (Shape)saveMap.get(CLIP);
}
}
return false;
}
+ public boolean setColor(Color col) {
+ if(!col.equals(color)) {
+ color = col;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean setBackColor(Color col) {
+ if(!col.equals(backcolor)) {
+ backcolor = col;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean setPaint(Paint p) {
+ if(paint == null) {
+ if(p != null) {
+ paint = p;
+ return true;
+ }
+ } else if(!paint.equals(p)) {
+ paint = p;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean checkClip(Shape cl) {
+ if(clip == null) {
+ if(cl != null) {
+ return true;
+ }
+ } else if(!clip.equals(cl)) {
+ return true;
+ }
+ return false;
+ }
+
+ public void setClip(Shape cl) {
+ clip = cl;
+ }
+
+ public boolean checkTransform(double[] vals) {
+ for(int count = 0; count < transform.length; count++) {
+ if(transform[count] != vals[count]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void setTransform(double[] vals) {
+ transform = vals;
+ }
}
package org.apache.fop.render.awt;
// FOP
-import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.layout.FontDescriptor;
import org.apache.fop.layout.FontState;
* Since FontState and FontInfo multiply all factors by
* size, we assume a "standard" font of FONT_SIZE.
*/
-
public class AWTFontMetrics {
/**
// FOP
import org.apache.fop.render.pdf.fonts.*;
-import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.layout.FontDescriptor;
import org.apache.fop.pdf.PDFDocument;
* @param fontInfo the font info object to set up
*/
public static void setup(FontInfo fontInfo) {
- MessageHandler.logln("setting up fonts");
fontInfo.addMetrics("F1", new Helvetica());
fontInfo.addMetrics("F2", new HelveticaOblique());
}
}
} catch (Exception ex) {
- MessageHandler.error("Failed to read font metrics file "
- + configFontInfo.getMetricsFile()
- + " : " + ex.getMessage());
+ //MessageHandler.error("Failed to read font metrics file "
+ // + configFontInfo.getMetricsFile()
+ // + " : " + ex.getMessage());
}
}
}
import org.apache.fop.layout.FontDescriptor;
import org.apache.fop.pdf.PDFStream;
import org.apache.fop.messaging.MessageHandler;
-import java.util.Hashtable;
+import java.util.HashMap;
import org.apache.fop.render.pdf.FontReader;
return realFontDescriptor.hasKerningInfo();
}
- public Hashtable getKerningInfo(){
+ public HashMap getKerningInfo(){
load();
return realFontDescriptor.getKerningInfo();
}
import java.io.FileInputStream;
import java.io.File;
import java.io.BufferedInputStream;
-import java.util.Hashtable;
+import java.util.HashMap;
/**
* Generic MultiByte (CID) font
public int defaultWidth = 0;
public byte cidType = PDFCIDFont.CID_TYPE2;
- public Hashtable kerning = new Hashtable();
+ public HashMap kerning = new HashMap();
public boolean useKerning = true;
private String namePrefix = null; // Quasi unique prefix
private static int uniqueCounter = 1;
/**
* usedGlyphs contains orginal, new glyph index
*/
- private Hashtable usedGlyphs = new Hashtable();
+ private HashMap usedGlyphs = new HashMap();
/**
* usedGlyphsIndex contains new glyph, original index
*/
- private Hashtable usedGlyphsIndex = new Hashtable();
+ private HashMap usedGlyphsIndex = new HashMap();
int usedGlyphsCount = 0;
public MultiByteFont() {
return (useKerning & kerning.isEmpty());
}
- public final java.util.Hashtable getKerningInfo() {
+ public final java.util.HashMap getKerningInfo() {
if (useKerning)
return kerning;
else
- return new Hashtable();
+ return new HashMap();
}
public byte getSubType() {
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
-import java.util.Hashtable;
+import java.util.HashMap;
/**
* Generic SingleByte font
public int italicAngle = 0;
public int missingWidth = 0;
- public Hashtable kerning = new Hashtable();
+ public HashMap kerning = new HashMap();
public boolean useKerning = true;
public int width[] = null;
return (useKerning & kerning.isEmpty());
}
- public final java.util.Hashtable getKerningInfo() {
+ public final java.util.HashMap getKerningInfo() {
if (useKerning)
return kerning;
else
- return new Hashtable();
+ return new HashMap();
}
public byte getSubType() {
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
+
+ //
//userAgent.addExtensionHandler();
XMLHandler handler = new XMLXMLHandler();
userAgent.setDefaultXMLHandler(mimeType, handler);
/**
* Create a new PDFDocumentGraphics2D.
- * This is used to create a new pdf document of the given height
- * and width.
+ * This is used to create a new pdf document, the height,
+ * width and output stream can be setup later.
+ * For use by the transcoder which needs font information
+ * for the bridge before the document size is known.
* The resulting document is written to the stream after rendering.
*
* @param textAsShapes set this to true so that text will be rendered
* using curves and not the font.
- * @param stream the stream that the final document should be written to.
- * @param width the width of the document
- * @param height the height of the document
*/
- public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
- int width, int height) {
+ PDFDocumentGraphics2D(boolean textAsShapes) {
super(textAsShapes);
-
- if (!textAsShapes) {
+
+ if(!textAsShapes) {
fontInfo = new FontInfo();
FontSetup.setup(fontInfo);
try {
"normal", 12, 0);
} catch (FOPException e) {}
}
+
standalone = true;
- this.stream = stream;
this.pdfDoc = new PDFDocument();
this.pdfDoc.setProducer("FOP SVG Renderer");
pdfStream = this.pdfDoc.makeStream();
- this.width = width;
- this.height = height;
+
+ graphicsState = new PDFState();
currentFontName = "";
currentFontSize = 0;
currentYPosition = 0;
currentXPosition = 0;
+ }
+ void setupDocument(OutputStream stream, int width, int height) {
+ this.width = width;
+ this.height = height;
+ this.stream = stream;
currentStream.write("1 0 0 -1 0 " + height + " cm\n");
+ }
+ /**
+ * Create a new PDFDocumentGraphics2D.
+ * This is used to create a new pdf document of the given height
+ * and width.
+ * The resulting document is written to the stream after rendering.
+ *
+ * @param textAsShapes set this to true so that text will be rendered
+ * using curves and not the font.
+ * @param stream the stream that the final document should be written to.
+ * @param width the width of the document
+ * @param height the height of the document
+ */
+ public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
+ int width, int height) {
+ this(textAsShapes);
+ setupDocument(stream, width, height);
}
public FontState getFontState() {
*/
public void setBackgroundColor(Color col) {
Color c = col;
- currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
+ PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue());
currentStream.write("q\n");
currentStream.write(currentColour.getColorSpaceOut(true));
import java.util.Map;
import java.util.ArrayList;
-import java.util.Hashtable;
+import java.util.HashMap;
/**
- * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
- * simple help to programmers to get started with their own
- * implementation of <tt>Graphics2D</tt>.
- * <tt>DefaultGraphics2D</tt> implements all the abstract methods
- * is <tt>AbstractGraphics2D</tt> and makes it easy to start
- * implementing a <tt>Graphic2D</tt> piece-meal.
+ * PDF Graphics 2D.
+ * Used for drawing into a pdf document as if it is a graphics object.
+ * This takes a pdf document and draws into it.
*
* @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
* @version $Id$
*/
protected PDFDocument pdfDoc;
+ /**
+ * the current state of the pdf graphics
+ */
+ PDFState graphicsState;
+
/**
* the current annotation list to add annotations to
*/
*/
protected int currentXPosition = 0;
- /**
- * the current colour for use in svg
- */
- PDFColor currentColour = new PDFColor(0, 0, 0);
-
/**
* Create a new PDFGraphics2D with the given pdf document info.
* This is used to create a Graphics object for use inside an already
fontState = fs;
}
- public PDFGraphics2D(boolean textAsShapes) {
+ protected PDFGraphics2D(boolean textAsShapes) {
super(textAsShapes);
}
fontState = null;
currentStream = null;
currentFontName = null;
- currentColour = null;
}
/**
return;
}
- currentStream.write("q\n");
+ AffineTransform trans = getTransform();
+ double[] tranvals = new double[6];
+ trans.getMatrix(tranvals);
+
Shape imclip = getClip();
- writeClip(imclip);
+ boolean newClip = graphicsState.checkClip(imclip);
+ boolean newTransform = graphicsState.checkTransform(tranvals);
+
+ if(newClip || newTransform) {
+ currentStream.write("q\n");
+ graphicsState.push();
+ if(newClip) {
+ writeClip(imclip);
+ }
+ if(newTransform) {
+ currentStream.write(PDFNumber.doubleOut(tranvals[0], 5) + " "
+ + PDFNumber.doubleOut(tranvals[1], 5) + " "
+ + PDFNumber.doubleOut(tranvals[2], 5) + " "
+ + PDFNumber.doubleOut(tranvals[3], 5) + " "
+ + PDFNumber.doubleOut(tranvals[4], 5) + " "
+ + PDFNumber.doubleOut(tranvals[5], 5) + " cm\n");
+ }
+ }
applyColor(c, false);
applyPaint(getPaint(), false);
applyStroke(getStroke());
- AffineTransform trans = getTransform();
- double[] tranvals = new double[6];
- trans.getMatrix(tranvals);
- currentStream.write(PDFNumber.doubleOut(tranvals[0]) + " "
- + PDFNumber.doubleOut(tranvals[1]) + " "
- + PDFNumber.doubleOut(tranvals[2]) + " "
- + PDFNumber.doubleOut(tranvals[3]) + " "
- + PDFNumber.doubleOut(tranvals[4]) + " "
- + PDFNumber.doubleOut(tranvals[5]) + " cm\n");
-
PathIterator iter = s.getPathIterator(new AffineTransform());
while (!iter.isDone()) {
double vals[] = new double[6];
int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " "
- + PDFNumber.doubleOut(vals[2]) + " "
- + PDFNumber.doubleOut(vals[3]) + " "
- + PDFNumber.doubleOut(vals[4]) + " "
- + PDFNumber.doubleOut(vals[5]) + " c\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " "
+ + PDFNumber.doubleOut(vals[2], 5) + " "
+ + PDFNumber.doubleOut(vals[3], 5) + " "
+ + PDFNumber.doubleOut(vals[4], 5) + " "
+ + PDFNumber.doubleOut(vals[5], 5) + " c\n");
break;
case PathIterator.SEG_LINETO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " l\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " l\n");
break;
case PathIterator.SEG_MOVETO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " m\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " m\n");
break;
case PathIterator.SEG_QUADTO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " "
- + PDFNumber.doubleOut(vals[2]) + " "
- + PDFNumber.doubleOut(vals[3]) + " y\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " "
+ + PDFNumber.doubleOut(vals[2], 5) + " "
+ + PDFNumber.doubleOut(vals[3], 5) + " y\n");
break;
case PathIterator.SEG_CLOSE:
currentStream.write("h\n");
iter.next();
}
doDrawing(false, true, false);
- currentStream.write("Q\n");
+ if(newClip || newTransform) {
+ currentStream.write("Q\n");
+ graphicsState.pop();
+ }
}
protected void writeClip(Shape s) {
Color c = col;
if (c.getColorSpace().getType()
== java.awt.color.ColorSpace.TYPE_RGB) {
- currentColour = new PDFColor(c.getRed(), c.getGreen(),
+ PDFColor currentColour = new PDFColor(c.getRed(), c.getGreen(),
c.getBlue());
currentStream.write(currentColour.getColorSpaceOut(fill));
} else if (c.getColorSpace().getType()
// convert the float elements to doubles for pdf
cmyk[i] = cComps[i];
}
- currentColour = new PDFColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
+ PDFColor currentColour = new PDFColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
currentStream.write(currentColour.getColorSpaceOut(fill));
} else if (c.getColorSpace().getType()
== java.awt.color.ColorSpace.TYPE_2CLR) {
for (int i = 0; i < 1; i++) {
blackMagenta[i] = cComps[i];
}
- // currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]);
- currentStream.write(currentColour.getColorSpaceOut(fill));
+ //PDFColor currentColour = new PDFColor(blackMagenta[0], blackMagenta[1]);
+ //currentStream.write(currentColour.getColorSpaceOut(fill));
} else {
System.err.println("Color Space not supported by PDFGraphics2D");
}
currentStream.write("BT\n");
- Hashtable kerning = null;
+ HashMap kerning = null;
boolean kerningAvailable = false;
kerning = fontState.getKerning();
}
private void addKerning(StringWriter buf, Integer ch1, Integer ch2,
- Hashtable kerning, String startText,
+ HashMap kerning, String startText,
String endText) {
- Hashtable kernPair = (Hashtable)kerning.get(ch1);
+ HashMap kernPair = (HashMap)kerning.get(ch1);
if (kernPair != null) {
Integer width = (Integer)kernPair.get(ch2);
return;
}
}
- currentStream.write("q\n");
Shape imclip = getClip();
- writeClip(imclip);
+ boolean newState = graphicsState.checkClip(imclip);
+
+ if(newState) {
+ currentStream.write("q\n");
+ graphicsState.push();
+ writeClip(imclip);
+ graphicsState.setClip(imclip);
+ }
c = getColor();
- applyColor(c, true);
+ if(graphicsState.setColor(c)) {
+ applyColor(c, true);
+ }
c = getBackground();
- applyColor(c, false);
+ if(graphicsState.setBackColor(c)) {
+ applyColor(c, false);
+ }
- applyPaint(getPaint(), true);
+ Paint paint = getPaint();
+ if(graphicsState.setPaint(paint)) {
+ applyPaint(paint, true);
+ }
PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " "
- + PDFNumber.doubleOut(vals[2]) + " "
- + PDFNumber.doubleOut(vals[3]) + " "
- + PDFNumber.doubleOut(vals[4]) + " "
- + PDFNumber.doubleOut(vals[5]) + " c\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " "
+ + PDFNumber.doubleOut(vals[2], 5) + " "
+ + PDFNumber.doubleOut(vals[3], 5) + " "
+ + PDFNumber.doubleOut(vals[4], 5) + " "
+ + PDFNumber.doubleOut(vals[5], 5) + " c\n");
break;
case PathIterator.SEG_LINETO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " l\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " l\n");
break;
case PathIterator.SEG_MOVETO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " m\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " m\n");
break;
case PathIterator.SEG_QUADTO:
- currentStream.write(PDFNumber.doubleOut(vals[0]) + " "
- + PDFNumber.doubleOut(vals[1]) + " "
- + PDFNumber.doubleOut(vals[2]) + " "
- + PDFNumber.doubleOut(vals[3]) + " y\n");
+ currentStream.write(PDFNumber.doubleOut(vals[0], 5) + " "
+ + PDFNumber.doubleOut(vals[1], 5) + " "
+ + PDFNumber.doubleOut(vals[2], 5) + " "
+ + PDFNumber.doubleOut(vals[3], 5) + " y\n");
break;
case PathIterator.SEG_CLOSE:
currentStream.write("h\n");
}
doDrawing(true, false,
iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
- currentStream.write("Q\n");
+ if(newState) {
+ currentStream.write("Q\n");
+ graphicsState.pop();
+ }
}
protected void doDrawing(boolean fill, boolean stroke, boolean nonzero) {
--- /dev/null
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.svg;
+
+import org.apache.batik.gvt.TextNode;
+import org.apache.batik.bridge.*;
+
+import org.apache.batik.css.CSSOMReadOnlyStyleDeclaration;
+import org.apache.batik.gvt.CompositeGraphicsNode;
+import org.apache.batik.gvt.GraphicsNode;
+
+import org.apache.fop.layout.FontState;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.batik.gvt.GraphicsNode;
+
+/**
+ * Bridge class for the <text> element.
+ * This bridge will use the direct text painter if the text
+ * for the element is simple.
+ *
+ * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
+ */
+public class PDFTextElementBridge extends SVGTextElementBridge {
+ private PDFTextPainter pdfTextPainter;
+
+ /**
+ * Constructs a new bridge for the <text> element.
+ */
+ public PDFTextElementBridge(FontState fs) {
+ pdfTextPainter = new PDFTextPainter(fs);
+ }
+
+ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
+ GraphicsNode node = super.createGraphicsNode(ctx, e);
+ if(isSimple(ctx, e, node)) {
+ ((TextNode)node).setTextPainter(getTextPainter());
+ }
+ return node;
+ }
+
+ private PDFTextPainter getTextPainter() {
+ return pdfTextPainter;
+ }
+
+ /**
+ * Check if text element contains simple text.
+ * This checks the children of the text element to determine
+ * if the text is simple. The text is simple if it can be rendered
+ * with basic text drawing algorithms. This means there are no
+ * alternate characters, the font is known and there are no effects
+ * applied to the text.
+ */
+ private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) {
+ CSSOMReadOnlyStyleDeclaration cssDecl
+ = CSSUtilities.getComputedStyle(element);
+ UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, element);
+
+ // Font size, in user space units.
+ float fs = TextUtilities.convertFontSize(element, ctx, cssDecl, uctx);
+ if(((int)fs) != fs) {
+ return false;
+ }
+
+ Element nodeElement;
+ for (Node n = element.getFirstChild();
+ n != null;
+ n = n.getNextSibling()) {
+
+ switch (n.getNodeType()) {
+ case Node.ELEMENT_NODE:
+
+ nodeElement = (Element)n;
+
+ if (n.getLocalName().equals(SVG_TSPAN_TAG)
+ || n.getLocalName().equals(SVG_ALT_GLYPH_TAG)) {
+ return false;
+ } else if (n.getLocalName().equals(SVG_TEXT_PATH_TAG)) {
+ return false;
+ } else if (n.getLocalName().equals(SVG_TREF_TAG)) {
+ return false;
+ }
+ break;
+ case Node.TEXT_NODE:
+ case Node.CDATA_SECTION_NODE:
+ }
+ }
+
+ if(CSSUtilities.convertFilter(element, node, ctx) != null) {
+ return false;
+ }
+
+ return true;
+ }
+}
String name = fam.getFamilyName();
if (fi.hasFont(name, weight, style)) {
try {
- int fsize = (int)size.floatValue();
+ int fsize = (int)(size.floatValue() * 1000);
fontState = new FontState(fontState.getFontInfo(),
name, style, weight,
- fsize * 1000, 0);
+ fsize, 0);
} catch (org.apache.fop.apps.FOPException fope) {
fope.printStackTrace();
}
}
if (!found) {
try {
- int fsize = (int)size.floatValue();
+ int fsize = (int)(size.floatValue() * 1000);
fontState = new FontState(fontState.getFontInfo(), "any",
- style, weight, fsize * 1000, 0);
+ style, weight, fsize, 0);
} catch (org.apache.fop.apps.FOPException fope) {
fope.printStackTrace();
}
}
public Shape getDecoratedShape(TextNode node) {
- System.out.println("PDFText getDecoratedShape");
+ //System.out.println("PDFText getDecoratedShape");
return new Rectangle(1, 1);
}
public Rectangle2D getBounds(TextNode node) {
- System.out.println("PDFText getBounds");
- return null;
+ //System.out.println("PDFText getBounds");
+ Rectangle2D bounds = new Rectangle2D.Float(0, 0, 100, 12);
+ return bounds;
}
public Rectangle2D getDecoratedBounds(TextNode node) {
svgCtx.setPixelToMM(userAgent.getPixelToMM());
((SVGOMDocument)document).setSVGContext(svgCtx);
- boolean stroke = true;
+ /*boolean stroke = true;
if (hints.containsKey(KEY_STROKE_TEXT)) {
stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
- }
+ }*/
+ PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(false);
// build the GVT tree
GVTBuilder builder = new GVTBuilder();
TextPainter textPainter = null;
textPainter = new StrokingTextPainter();
ctx.setTextPainter(textPainter);
-
+
+ PDFTextElementBridge pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontState());
+ ctx.putBridge(pdfTextElementBridge);
+
PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0);
pdfAElementBridge.setCurrentTransform(currentTransform);
int w = (int)width;
int h = (int)height;
- PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(stroke,
- output.getOutputStream(), w, h);
+ graphics.setupDocument(output.getOutputStream(), w, h);
graphics.setSVGDimension(docWidth, docHeight);
currentTransform.setTransform(1, 0, 0, -1, 0, height);
- if (!stroke) {
+ /*if (!stroke) {
textPainter = new PDFTextPainter(graphics.getFontState());
ctx.setTextPainter(textPainter);
- }
+ }*/
if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
import org.apache.fop.layout.FontState;
import org.apache.fop.layout.Area;
-import java.util.*;
+//import java.util.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.*;
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- public SVGElement(FObj parent) {
+ public SVGElement(FONode parent) {
super(parent);
}
throw new FOPException("SVG not in fo:instream-foreign-object");
}
- if (this.marker == START) {
this.fs = area.getFontState();
- this.marker = 0;
- }
-
final Element svgRoot = element;
/* create an SVG area */
/* if width and height are zero, get the bounds of the content. */
package org.apache.fop.svg;
-import java.util.Enumeration;
import java.util.HashMap;
-import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.apps.Driver;
foObjs = new HashMap();
foObjs.put("svg", new SE());
- foObjs.put("<default>", new SVGMaker());
+ foObjs.put(DEFAULT, new SVGMaker());
}
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
}
class SVGMaker extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new SVGObj(parent);
}
}
class SE extends ElementMapping.Maker {
- public FObj make(FObj parent) {
+ public FONode make(FONode parent) {
return new SVGElement(parent);
}
}
package org.apache.fop.svg;
import org.apache.fop.fo.*;
-import org.apache.fop.layout.Area;
-import org.apache.fop.layout.FontState;
-import org.apache.fop.apps.FOPException;
-
-import org.w3c.dom.Element;
public class SVGObj extends XMLObj {
/**
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
- public SVGObj(FObj parent) {
+ public SVGObj(FONode parent) {
super(parent);
}
public void openLink(SVGAElement elt) {
}
-
public Point getClientAreaLocationOnScreen() {
return new Point(0, 0);
}
public void handleElement(Element elt, Object data) {}
-
}
if (csize < values.length) {
System.out.println("Cache size too small");
- System.exit(0);
}