aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/afp/extensions
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-07-27 16:33:01 +0000
committerJeremias Maerki <jeremias@apache.org>2009-07-27 16:33:01 +0000
commita11874283eb80e4ce5759196bb1a751e3c93e5ac (patch)
treea45243590a2691b1341667b2f86b607e3f71ad4d /src/java/org/apache/fop/render/afp/extensions
parentc29f2ba1ecada01d680ff1ce9ce76898243681f0 (diff)
downloadxmlgraphics-fop-a11874283eb80e4ce5759196bb1a751e3c93e5ac.tar.gz
xmlgraphics-fop-a11874283eb80e4ce5759196bb1a751e3c93e5ac.zip
Added support for AFP font embedding. Note: this changes the default behaviour. Like with PDF and PS, all fonts are embedded by default unless matched in the "referenced-fonts" section in the configuration.
Added support for embedding external AFP form maps (form defs) using the afp:include-form-map extension. Fixed a small problem with AFP-related events. DefaultFOPResourceAccessor got a fallback to the user agent's base URI if no category base URI is specified. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@798207 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/afp/extensions')
-rwxr-xr-xsrc/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java12
-rw-r--r--src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java60
-rw-r--r--src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java87
-rw-r--r--src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java89
-rwxr-xr-xsrc/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java11
5 files changed, 233 insertions, 26 deletions
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java b/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
index 83615b75d..cb5478340 100755
--- a/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
@@ -42,6 +42,9 @@ public class AFPElementMapping extends ElementMapping {
/** include page segment element */
public static final String INCLUDE_PAGE_SEGMENT = "include-page-segment";
+ /** include form map element */
+ public static final String INCLUDE_FORM_MAP = "include-form-map";
+
/** NOP */
public static final String NO_OPERATION = "no-operation";
@@ -81,6 +84,9 @@ public class AFPElementMapping extends ElementMapping {
INCLUDE_PAGE_OVERLAY,
new AFPIncludePageOverlayMaker());
foObjs.put(
+ INCLUDE_FORM_MAP,
+ new AFPIncludeFormMapMaker());
+ foObjs.put(
NO_OPERATION,
new AFPNoOperationMaker());
foObjs.put(
@@ -101,6 +107,12 @@ public class AFPElementMapping extends ElementMapping {
}
}
+ static class AFPIncludeFormMapMaker extends ElementMapping.Maker {
+ public FONode make(FONode parent) {
+ return new AFPIncludeFormMapElement(parent, INCLUDE_FORM_MAP);
+ }
+ }
+
static class AFPTagLogicalElementMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new AFPPageSetupElement(parent, TAG_LOGICAL_ELEMENT);
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java b/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java
index 1a8cfdf47..c487b1825 100644
--- a/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java
@@ -19,6 +19,9 @@
package org.apache.fop.render.afp.extensions;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -48,13 +51,14 @@ public class AFPExtensionHandler extends DefaultHandler
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
boolean handled = false;
- if (AFPPageSetup.CATEGORY.equals(uri)) {
+ if (AFPExtensionAttachment.CATEGORY.equals(uri)) {
lastAttributes = attributes;
handled = true;
if (localName.equals(AFPElementMapping.NO_OPERATION)
|| localName.equals(AFPElementMapping.TAG_LOGICAL_ELEMENT)
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_OVERLAY)
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_SEGMENT)
+ || localName.equals(AFPElementMapping.INCLUDE_FORM_MAP)
|| localName.equals(AFPElementMapping.INVOKE_MEDIUM_MAP)) {
//handled in endElement
} else {
@@ -62,7 +66,7 @@ public class AFPExtensionHandler extends DefaultHandler
}
}
if (!handled) {
- if (AFPPageSetup.CATEGORY.equals(uri)) {
+ if (AFPExtensionAttachment.CATEGORY.equals(uri)) {
throw new SAXException("Unhandled element " + localName
+ " in namespace: " + uri);
} else {
@@ -74,26 +78,38 @@ public class AFPExtensionHandler extends DefaultHandler
/** {@inheritDoc} */
public void endElement(String uri, String localName, String qName) throws SAXException {
- if (AFPPageSetup.CATEGORY.equals(uri)) {
- AFPPageSetup pageSetupExtn = null;
- if (localName.equals(AFPElementMapping.INVOKE_MEDIUM_MAP)) {
- this.returnedObject = new AFPInvokeMediumMap();
- }
- else {
- pageSetupExtn = new AFPPageSetup(localName);
- this.returnedObject = pageSetupExtn;
- }
- String name = lastAttributes.getValue("name");
- if (name != null) {
- returnedObject.setName(name);
- }
- String value = lastAttributes.getValue("value");
- if (value != null && pageSetupExtn != null) {
- pageSetupExtn.setValue(value);
- }
- if (content.length() > 0 && pageSetupExtn != null) {
- pageSetupExtn.setContent(content.toString());
- content.setLength(0); //Reset text buffer (see characters())
+ if (AFPExtensionAttachment.CATEGORY.equals(uri)) {
+ if (AFPElementMapping.INCLUDE_FORM_MAP.equals(localName)) {
+ AFPIncludeFormMap formMap = new AFPIncludeFormMap();
+ String name = lastAttributes.getValue("name");
+ formMap.setName(name);
+ String src = lastAttributes.getValue("src");
+ try {
+ formMap.setSrc(new URI(src));
+ } catch (URISyntaxException e) {
+ throw new SAXException("Invalid URI: " + src, e);
+ }
+ this.returnedObject = formMap;
+ } else {
+ AFPPageSetup pageSetupExtn = null;
+ if (AFPElementMapping.INVOKE_MEDIUM_MAP.equals(localName)) {
+ this.returnedObject = new AFPInvokeMediumMap();
+ } else {
+ pageSetupExtn = new AFPPageSetup(localName);
+ this.returnedObject = pageSetupExtn;
+ }
+ String name = lastAttributes.getValue("name");
+ if (name != null) {
+ returnedObject.setName(name);
+ }
+ String value = lastAttributes.getValue("value");
+ if (value != null && pageSetupExtn != null) {
+ pageSetupExtn.setValue(value);
+ }
+ if (content.length() > 0 && pageSetupExtn != null) {
+ pageSetupExtn.setContent(content.toString());
+ content.setLength(0); //Reset text buffer (see characters())
+ }
}
}
}
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java b/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java
new file mode 100644
index 000000000..06c7cbc9d
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp.extensions;
+
+import java.net.URI;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+
+/**
+ * This extension allows to include an AFP form map resource. It is implemented as an extension
+ * attachment ({@link ExtensionAttachment}).
+ */
+public class AFPIncludeFormMap extends AFPExtensionAttachment {
+
+ private static final long serialVersionUID = 8548056652642588914L;
+
+ /** src attribute containing the URI to the form map resource */
+ protected static final String ATT_SRC = "src";
+
+ /**
+ * the URI identifying the form map resource.
+ */
+ protected URI src;
+
+ /**
+ * Default constructor.
+ */
+ public AFPIncludeFormMap() {
+ super(AFPElementMapping.INCLUDE_FORM_MAP);
+ }
+
+ /**
+ * Returns the URI of the form map.
+ * @return the form map URI
+ */
+ public URI getSrc() {
+ return this.src;
+ }
+
+ /**
+ * Sets the URI of the form map.
+ * @param value the form map URI
+ */
+ public void setSrc(URI value) {
+ this.src = value;
+ }
+
+ /** {@inheritDoc} */
+ public void toSAX(ContentHandler handler) throws SAXException {
+ AttributesImpl atts = new AttributesImpl();
+ if (name != null && name.length() > 0) {
+ atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name);
+ }
+ if (this.src != null) {
+ atts.addAttribute(null, ATT_SRC, ATT_SRC, "CDATA", this.src.toASCIIString());
+ }
+ handler.startElement(CATEGORY, elementName, elementName, atts);
+ handler.endElement(CATEGORY, elementName, elementName);
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return getClass().getName() + "(element-name=" + getElementName()
+ + " name=" + getName() + " src=" + getSrc() + ")";
+ }
+}
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java
new file mode 100644
index 000000000..719d8c765
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp.extensions;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+import org.apache.fop.fo.extensions.ExtensionObj;
+
+/**
+ * This class extends the {@link ExtensionObj} class. It represents the "include-form-map"
+ * extension in the FO tree.
+ */
+public class AFPIncludeFormMapElement extends AbstractAFPExtensionObject {
+
+ private static final String ATT_SRC = "src";
+
+ /**
+ * Constructs an AFP object (called by Maker).
+ *
+ * @param parent the parent formatting object
+ * @param name the name of the AFP element
+ */
+ public AFPIncludeFormMapElement(FONode parent, String name) {
+ super(parent, name);
+ }
+
+ private AFPIncludeFormMap getFormMapAttachment() {
+ return (AFPIncludeFormMap)getExtensionAttachment();
+ }
+
+ /** {@inheritDoc} */
+ protected void startOfNode() throws FOPException {
+ super.startOfNode();
+ if (parent.getNameId() != Constants.FO_DECLARATIONS) {
+ invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
+ "rule.childOfDeclarations");
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void processNode(String elementName, Locator locator,
+ Attributes attlist, PropertyList propertyList)
+ throws FOPException {
+ super.processNode(elementName, locator, attlist, propertyList);
+ AFPIncludeFormMap formMap = getFormMapAttachment();
+ String attr = attlist.getValue(ATT_SRC);
+ if (attr != null && attr.length() > 0) {
+ try {
+ formMap.setSrc(new URI(attr));
+ } catch (URISyntaxException e) {
+ getFOValidationEventProducer().invalidPropertyValue(this,
+ elementName, ATT_SRC, attr, null, getLocator());
+ }
+ } else {
+ missingPropertyError(ATT_SRC);
+ }
+ }
+
+ /** {@inheritDoc} */
+ protected ExtensionAttachment instantiateExtensionAttachment() {
+ return new AFPIncludeFormMap();
+ }
+}
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
index 0c6dfadc4..19f98f32a 100755
--- a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
@@ -36,6 +36,9 @@ import org.apache.fop.fo.extensions.ExtensionAttachment;
*/
public class AFPPageSetupElement extends AbstractAFPExtensionObject {
+ private static final String ATT_VALUE = "value";
+ private static final String ATT_SRC = "src";
+
/**
* Constructs an AFP object (called by Maker).
*
@@ -86,18 +89,18 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject {
super.processNode(elementName, locator, attlist, propertyList);
AFPPageSetup pageSetup = getPageSetupAttachment();
if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(elementName)) {
- String attr = attlist.getValue("src");
+ String attr = attlist.getValue(ATT_SRC);
if (attr != null && attr.length() > 0) {
pageSetup.setValue(attr);
} else {
- throw new FOPException(elementName + " must have a src attribute.");
+ missingPropertyError(ATT_SRC);
}
} else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(elementName)) {
- String attr = attlist.getValue("value");
+ String attr = attlist.getValue(ATT_VALUE);
if (attr != null && attr.length() > 0) {
pageSetup.setValue(attr);
} else {
- throw new FOPException(elementName + " must have a value attribute.");
+ missingPropertyError(ATT_VALUE);
}
}
}