From df1aab82cfb90510c5108cb87e03623aa1c77be2 Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Tue, 20 May 2008 16:02:09 +0000 Subject: Broke out data members from ResourceInfo and created ResourceLevel class Added MappingOptionTriplet and corresponding setMappingOption() triplet setter Correctly furnished (AFAICT) IncludeObject with ObjectClassificationTriplet MappingOptionTriplet MeasurementUnits and ObjectAreaSize FullyQualifiedNameTriplet now correctly encodes its name dependant upon its format Added resolution settings to MeasurementUnitsTriplet Added Overlay enclosure when fo:block has background color git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@658303 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/afp/AFPRenderer.java | 27 ++-- .../org/apache/fop/render/afp/DataObjectInfo.java | 38 ++--- .../org/apache/fop/render/afp/ImageObjectInfo.java | 1 + .../org/apache/fop/render/afp/ResourceInfo.java | 130 +++-------------- .../org/apache/fop/render/afp/ResourceLevel.java | 160 +++++++++++++++++++++ .../apache/fop/render/afp/modca/AFPConstants.java | 5 + .../apache/fop/render/afp/modca/AFPDataStream.java | 97 +++++++------ .../fop/render/afp/modca/AbstractPageObject.java | 2 +- .../AbstractResourceEnvironmentGroupContainer.java | 12 +- .../afp/modca/AbstractResourceGroupContainer.java | 6 +- .../afp/modca/AbstractStructuredAFPObject.java | 17 ++- .../fop/render/afp/modca/DataObjectAccessor.java | 5 + .../apache/fop/render/afp/modca/ImageSegment.java | 2 +- .../apache/fop/render/afp/modca/IncludeObject.java | 61 ++++---- .../fop/render/afp/modca/MapDataResource.java | 12 +- .../fop/render/afp/modca/MapPageOverlay.java | 4 +- .../fop/render/afp/modca/ObjectContainer.java | 14 ++ .../apache/fop/render/afp/modca/PageObject.java | 110 +++++++------- .../render/afp/modca/ResourceEnvironmentGroup.java | 16 +-- .../apache/fop/render/afp/modca/ResourceGroup.java | 35 +++-- .../fop/render/afp/modca/ResourceObject.java | 56 ++++---- .../modca/triplets/FullyQualifiedNameTriplet.java | 10 +- .../afp/modca/triplets/MappingOptionTriplet.java | 68 +++++++++ .../modca/triplets/MeasurementUnitsTriplet.java | 9 +- 24 files changed, 556 insertions(+), 341 deletions(-) create mode 100644 src/java/org/apache/fop/render/afp/ResourceLevel.java create mode 100644 src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java (limited to 'src') diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 90f07cb8b..fbcd368fd 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -513,18 +513,20 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { int res = getResolution(); final int rotation = 0; getAFPDataStream().startOverlay(x, y, w, h, res, res, rotation); +// Color col = back.getColor(); +// getAFPDataStream().createShading(x, y, w, h, col); } } - /** - * {@inheritDoc} - */ +// /** +// * {@inheritDoc} +// */ protected void renderBlock(Block block) { - // new block so start page segment - getAFPDataStream().startPageSegment(); +// // new block so start page segment +//// getAFPDataStream().startPageSegment(); super.renderBlock(block); getAFPDataStream().endOverlay(); - getAFPDataStream().endPageSegment(); +//// getAFPDataStream().endPageSegment(); } /** @@ -763,13 +765,12 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { * {@inheritDoc} */ public void fillRect(float x, float y, float width, float height) { - /* - * getAFPDataStream().createShading( pts2units(x), pts2units(y), - * pts2units(width), pts2units(height), currentColor); - */ - getAFPDataStream().createLine(pts2units(x), pts2units(y), - pts2units(x + width), pts2units(y), pts2units(height), + getAFPDataStream().createShading( + pts2units(x), pts2units(y), pts2units(width), pts2units(height), currentColor); +// getAFPDataStream().createLine(pts2units(x), pts2units(y), +// pts2units(x + width), pts2units(y), pts2units(height), +// currentColor); } /** @@ -921,7 +922,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { int x = origin.x + posInt.x; int y = origin.y + posInt.y; - String name = (String) getPageSegments().get(uri); + String name = (String)getPageSegments().get(uri); if (name != null) { getAFPDataStream().createIncludePageSegment(name, mpts2units(x), mpts2units(y)); diff --git a/src/java/org/apache/fop/render/afp/DataObjectInfo.java b/src/java/org/apache/fop/render/afp/DataObjectInfo.java index e56e6338c..00044da96 100644 --- a/src/java/org/apache/fop/render/afp/DataObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/DataObjectInfo.java @@ -56,6 +56,12 @@ public class DataObjectInfo { /** resource info */ private ResourceInfo resourceInfo = DEFAULT_RESOURCE_INFO; + /** + * Default constructor + */ + public DataObjectInfo() { + } + /** * Sets the data object uri * @param uri the data object uri @@ -111,12 +117,6 @@ public class DataObjectInfo { protected void setHeightRes(int heightRes) { this.heightRes = heightRes; } - - /** - * Default constructor - */ - public DataObjectInfo() { - } /** * @return the uri of this data object @@ -226,16 +226,19 @@ public class DataObjectInfo { } QName resourceLevelKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_LEVEL); if (foreignAttributes.containsKey(resourceLevelKey)) { - String level = (String)foreignAttributes.get(resourceLevelKey); - if (resourceInfo.setLevel(level)) { - if (resourceInfo.isExternal()) { + String level = (String)foreignAttributes.get(resourceLevelKey); + ResourceLevel resourceLevel = null; + try { + resourceLevel = ResourceLevel.valueOf(level); + resourceInfo.setLevel(resourceLevel); + if (resourceLevel.isExternal()) { QName resourceGroupFileKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_GROUP_FILE); String resourceExternalDest = (String)foreignAttributes.get(resourceGroupFileKey); if (resourceExternalDest == null) { String msg = RESOURCE_GROUP_FILE + " not specified"; - log.warn(msg); + log.error(msg); throw new UnsupportedOperationException(msg); } File resourceExternalGroupFile = new File(resourceExternalDest); @@ -245,25 +248,26 @@ public class DataObjectInfo { security.checkWrite(resourceExternalGroupFile.getPath()); } } catch (SecurityException ex) { - log.warn("unable to gain write access to external resource file: " + log.error("unable to gain write access to external resource file: " + resourceExternalDest); } - + try { boolean exists = resourceExternalGroupFile.exists(); if (exists) { log.warn("overwritting external resource file: " + resourceExternalDest); } - resourceInfo.setExternalResourceGroupFile(resourceExternalGroupFile); + resourceLevel.setExternalResourceGroupFile(resourceExternalGroupFile); } catch (SecurityException ex) { - log.warn("unable to gain read access to external resource file: " + log.error("unable to gain read access to external resource file: " + resourceExternalDest); } } - } else { - String msg = RESOURCE_LEVEL + " is null or not valid"; - log.warn(msg); + } catch (IllegalArgumentException e) { + // default to print-file resource level if invalid resource level provided + resourceLevel = new ResourceLevel(ResourceLevel.PRINT_FILE); + log.error(e.getMessage() + ", defaulting to '" + resourceLevel + "' level"); } } } diff --git a/src/java/org/apache/fop/render/afp/ImageObjectInfo.java b/src/java/org/apache/fop/render/afp/ImageObjectInfo.java index 16f9d1103..cf5e7f951 100644 --- a/src/java/org/apache/fop/render/afp/ImageObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/ImageObjectInfo.java @@ -35,6 +35,7 @@ public class ImageObjectInfo extends DataObjectInfo { * Default constructor */ public ImageObjectInfo() { + super(); } /** diff --git a/src/java/org/apache/fop/render/afp/ResourceInfo.java b/src/java/org/apache/fop/render/afp/ResourceInfo.java index 86add31d2..3c95b2f65 100644 --- a/src/java/org/apache/fop/render/afp/ResourceInfo.java +++ b/src/java/org/apache/fop/render/afp/ResourceInfo.java @@ -19,124 +19,21 @@ package org.apache.fop.render.afp; -import java.io.File; - /** * The level at which a resource is to reside in the AFP output */ public class ResourceInfo { - private static final String LEVEL_EXTERNAL = "external"; - - private static final String LEVEL_PRINT_FILE = "print-file"; - - private static final String LEVEL_DOCUMENT = "document"; - - private static final String LEVEL_PAGE_GROUP = "page-group"; - - private static final String LEVEL_PAGE = "page"; - + /** * the reference name of this resource */ private String name = null; - + /** - * where the resource will reside in the AFP output + * the resource level (default to print-file) */ - private String level = LEVEL_PAGE; // default is page level + private ResourceLevel level = new ResourceLevel(ResourceLevel.PRINT_FILE); - /** - * the external resource group file - */ - private File externalResourceGroupFile = null; - - /** - * @return true if this is a page level resource group - */ - public boolean isPage() { - return level.equals(LEVEL_PAGE); - } - - /** - * @return true if this is a page group level resource group - */ - public boolean isPageGroup() { - return level.equals(LEVEL_PAGE_GROUP); - } - - /** - * @return true if this is a document level resource group - */ - public boolean isDocument() { - return level.equals(LEVEL_DOCUMENT); - } - - /** - * @return true if this is an external level resource group - */ - public boolean isExternal() { - return level.equals(LEVEL_EXTERNAL); - } - - /** - * @return true if this is a print-file level resource group - */ - public boolean isPrintFile() { - return level.equals(LEVEL_PRINT_FILE); - } - - private boolean isValid(String lvl) { - return lvl.equals(LEVEL_EXTERNAL) - || lvl.equals(LEVEL_PRINT_FILE) - || lvl.equals(LEVEL_DOCUMENT) - || lvl.equals(LEVEL_PAGE_GROUP) - || lvl.equals(LEVEL_PAGE); - } - - /** - * Sets the resource placement level within the AFP output - * @param lvl the resource level (page, page-group, document, print-file or external) - * @return true if the resource level was successfully set - */ - public boolean setLevel(String lvl) { - if (lvl != null && isValid(lvl)) { - this.level = lvl; - return true; - } - return false; - } - - /** - * @return the external resource group file of this resource - */ - public File getExternalResourceGroupFile() { - return this.externalResourceGroupFile; - } - - /** - * @return the destination file path of the external resource group file - */ - public String getExternalResourceGroupDest() { - if (externalResourceGroupFile != null) { - return externalResourceGroupFile.getAbsolutePath(); - } - return null; - } - - /** - * @return true if this resource has a defined external resource group file destination - */ - public boolean hasExternalResourceGroupFile() { - return getExternalResourceGroupFile() != null; - } - - /** - * Sets the external destination of the resource - * @param file the external resource group file - */ - public void setExternalResourceGroupFile(File file) { - this.externalResourceGroupFile = file; - } /** * Sets the resource reference name @@ -157,8 +54,21 @@ public class ResourceInfo { * {@inheritDoc} */ public String toString() { - return "ResourceInfo(name=" + name + ", level=" + level - + (isExternal() ? ", externalResourceGroupFile=" + externalResourceGroupFile : "") - + ")"; + return "ResourceInfo(" + (name != null ? "name=" + name : "" ) + ", level=" + level + ")"; + } + + /** + * @return the resource level + */ + public ResourceLevel getLevel() { + return this.level; + } + + /** + * Sets the resource level + * @param resourceLevel the resource level + */ + public void setLevel(ResourceLevel resourceLevel) { + this.level = resourceLevel; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ResourceLevel.java b/src/java/org/apache/fop/render/afp/ResourceLevel.java new file mode 100644 index 000000000..37a8e6dce --- /dev/null +++ b/src/java/org/apache/fop/render/afp/ResourceLevel.java @@ -0,0 +1,160 @@ +/* + * 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; + +import java.io.File; + +/** + * A resource level + */ +public class ResourceLevel { + /** page level **/ + public static final int PAGE = 0; + + /** page group level **/ + public static final int PAGE_GROUP = 1; + + /** document level **/ + public static final int DOCUMENT = 2; + + /** print file level **/ + public static final int PRINT_FILE = 3; + + /** external level **/ + public static final int EXTERNAL = 4; + + private static final String NAME_PAGE = "page"; + private static final String NAME_PAGE_GROUP = "page-group"; + private static final String NAME_DOCUMENT = "document"; + private static final String NAME_PRINT_FILE = "print-file"; + private static final String NAME_EXTERNAL = "external"; + + private static final String[] NAMES + = new String[] {NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL}; + + /** + * where the resource will reside in the AFP output + */ + private int level = PRINT_FILE; // default is print-file level + + /** + * the external resource group file + */ + private File externalResourceGroupFile = null; + + /** + * Sets the resource placement level within the AFP output + * @param lvl the resource level (page, page-group, document, print-file or external) + * @return true if the resource level was successfully set + */ + public static ResourceLevel valueOf(String lvl) { + ResourceLevel level = null; + for (int i = 0; i < NAMES.length; i++) { + if (NAMES[i].equals(lvl)) { + level = new ResourceLevel(i); + break; + } + } + if (lvl == null) { + throw new IllegalArgumentException("Unknown resource level '" + lvl + "'"); + } + return level; + } + + /** + * Main constructor + * @param level the resource level + */ + public ResourceLevel(int level) { + this.level = level; + } + + /** + * @return true if this is a page level resource group + */ + public boolean isPage() { + return level == PAGE; + } + + /** + * @return true if this is a page group level resource group + */ + public boolean isPageGroup() { + return level == PAGE_GROUP; + } + + /** + * @return true if this is a document level resource group + */ + public boolean isDocument() { + return level == DOCUMENT; + } + + /** + * @return true if this is an external level resource group + */ + public boolean isExternal() { + return level == EXTERNAL; + } + + /** + * @return true if this is a print-file level resource group + */ + public boolean isPrintFile() { + return level == PRINT_FILE; + } + + /** + * @return the external resource group file of this resource + */ + public File getExternalResourceGroupFile() { + return this.externalResourceGroupFile; + } + + /** + * @return the destination file path of the external resource group file + */ + public String getExternalResourceGroupFilePath() { + if (externalResourceGroupFile != null) { + return externalResourceGroupFile.getAbsolutePath(); + } + return null; + } + + /** + * Sets the external destination of the resource + * @param file the external resource group file + */ + public void setExternalResourceGroupFile(File file) { + this.externalResourceGroupFile = file; + } + + /** + * @return true if this resource has a defined external resource group file destination + */ + public boolean hasExternalResourceGroupFile() { + return getExternalResourceGroupFile() != null; + } + + /** {@inheritDoc} */ + public String toString() { + return NAMES[level] + (isExternal() ? ", file=" + externalResourceGroupFile : ""); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/AFPConstants.java b/src/java/org/apache/fop/render/afp/modca/AFPConstants.java index 73c39f2f0..e2e2a8bbe 100644 --- a/src/java/org/apache/fop/render/afp/modca/AFPConstants.java +++ b/src/java/org/apache/fop/render/afp/modca/AFPConstants.java @@ -34,4 +34,9 @@ public interface AFPConstants { * The encoding to use to convert to ASCII */ String ASCII_ENCODING = "Cp1252"; + + /** + * The encoding to use to convert to US ASCII (7 bit) + */ + String US_ASCII_ENCODING = "US-ASCII"; } diff --git a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java index ace60e331..fdb0e5cc3 100644 --- a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java +++ b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.render.afp.AFPFontAttributes; import org.apache.fop.render.afp.DataObjectInfo; import org.apache.fop.render.afp.ResourceInfo; +import org.apache.fop.render.afp.ResourceLevel; import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.render.afp.tools.StringUtils; @@ -170,7 +171,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { /** * @return the current page */ - private AbstractPageObject getCurrentPage() { + protected AbstractPageObject getCurrentPage() { return this.currentPage; } @@ -225,14 +226,16 @@ public class AFPDataStream extends AbstractResourceGroupContainer { endPageGroup(); } - // Write out any external resource groups - getExternalResourceGroupManager().writeExternalResources(); - - // Write out any print-file level resources - if (hasResources()) { - getResourceGroup().write(this.outputStream); + if (interchangeSet.supportsLevel2()) { + // Write out any external resource groups + getExternalResourceGroupManager().writeExternalResources(); + + // Write out any print-file level resources + if (hasResources()) { + getResourceGroup().write(this.outputStream); + } } - + // Write out document if (document != null) { document.endDocument(); @@ -303,7 +306,14 @@ public class AFPDataStream extends AbstractResourceGroupContainer { this.currentOverlay = new Overlay(overlayName, width, height, widthRes, heightRes, overlayRotation); - getResourceGroup().addObject(currentOverlay); + if (interchangeSet.supportsLevel2()) { + ResourceObject resourceObject = new ResourceObject(overlayName); + resourceObject.setDataObject(currentOverlay); + getResourceGroup().addObject(resourceObject); + } +// currentPageGroup.getResourceEnvironmentGroup().addObject(currentOverlay); +// currentPageObject.getActiveEnvironmentGroup().createOverlay(overlayName); + currentPageObject.createIncludePageOverlay(overlayName, x, y, 0); currentPage = currentOverlay; setOffsets(0, 0, 0); @@ -462,13 +472,14 @@ public class AFPDataStream extends AbstractResourceGroupContainer { dataObjectInfo.setObjectType(objectType); ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - + ResourceLevel resourceLevel = resourceInfo.getLevel(); + // is MO:DCA-L available? if (interchangeSet.supportsLevel2()) { // can this data object use the include object (IOB) referencing // mechanism? if (objectType.canBeIncluded()) { - ResourceGroup resourceGroup = getResourceGroup(resourceInfo); + ResourceGroup resourceGroup = getResourceGroup(resourceLevel); IncludeObject includeObject = resourceGroup.createObject(dataObjectInfo); // add include to current page @@ -479,7 +490,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { + "' cannot be referenced with an include so it will be embedded directly"); } } else { - if (resourceInfo.isExternal()) { + if (resourceLevel.isExternal()) { log.warn( interchangeSet + ": not available, object " + getName() + " will reside inline"); } @@ -776,23 +787,23 @@ public class AFPDataStream extends AbstractResourceGroupContainer { /** * Returns the resource group for a given resource into * - * @param resourceInfo + * @param level * resource info * @return a resource group container for the given resource info */ - private ResourceGroup getResourceGroup(ResourceInfo resourceInfo) { + private ResourceGroup getResourceGroup(ResourceLevel level) { ResourceGroup resourceGroup = null; - if (resourceInfo.isPrintFile()) { + if (level.isPrintFile()) { resourceGroup = getResourceGroup(); - } else if (resourceInfo.isDocument()) { + } else if (level.isDocument()) { resourceGroup = getDocument().getResourceGroup(); - } else if (resourceInfo.isPageGroup()) { + } else if (level.isPageGroup()) { resourceGroup = getCurrentPageGroup().getResourceGroup(); - } else if (resourceInfo.isPage()) { + } else if (level.isPage()) { resourceGroup = currentPageObject.getResourceGroup(); - } else if (resourceInfo.isExternal()) { + } else if (level.isExternal()) { resourceGroup = getExternalResourceGroupManager() - .getExternalResourceGroup(resourceInfo); + .getExternalResourceGroup(level); } return resourceGroup; } @@ -889,28 +900,28 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } /** - * Returns the corresponding resource group for the given resource info + * Returns the corresponding resource group for the given resource level * - * @param resourceInfo - * resource info - * @return the corresponding resource group for the given resource info + * @param level + * the resource level + * @return the corresponding resource group for the given resource level */ - private ResourceGroup getExternalResourceGroup(ResourceInfo resourceInfo) { + private ResourceGroup getExternalResourceGroup(ResourceLevel level) { ResourceGroup resourceGroup; - // this resource info does not have a an external resource group + // this resource info does not have an external resource group // file definition - if (!resourceInfo.hasExternalResourceGroupFile()) { + if (!level.hasExternalResourceGroupFile()) { if (defaultResourceGroupFile != null) { // fallback to default resource group file - resourceInfo.setExternalResourceGroupFile(defaultResourceGroupFile); - resourceGroup = getExternalResourceGroup(resourceInfo); + level.setExternalResourceGroupFile(defaultResourceGroupFile); + resourceGroup = getExternalResourceGroup(level); } else { // use print-file level resource group in the absence // of an external resource group file definition resourceGroup = container.getResourceGroup(); } } else { - File resourceGroupFile = resourceInfo + File resourceGroupFile = level .getExternalResourceGroupFile(); resourceGroup = (ResourceGroup)getExternalResourceGroups().get(resourceGroupFile); if (resourceGroup == null) { @@ -930,19 +941,19 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } } - /** - * Starts a new page segment. - */ - public void startPageSegment() { - currentPageObject.startPageSegment(); - } - - /** - * Ends the current page segment. - */ - public void endPageSegment() { - currentPageObject.endPageSegment(); - } +// /** +// * Starts a new page segment. +// */ +// public void startPageSegment() { +// currentPageObject.startPageSegment(); +// } +// +// /** +// * Ends the current page segment. +// */ +// public void endPageSegment() { +// currentPageObject.endPageSegment(); +// } /** * Sets the MO:DCA interchange set to use diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java index e1035a6c6..065886a49 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -355,7 +355,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); - if (this instanceof PageObject) { + if (this instanceof PageObject || this instanceof Overlay) { getActiveEnvironmentGroup().write(os); } writeObjects(this.includePageSegments, os); diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java index 9449108eb..4a5785981 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java @@ -81,18 +81,10 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * @return the resource environment group */ - private ResourceEnvironmentGroup getResourceEnvironmentGroup() { + protected ResourceEnvironmentGroup getResourceEnvironmentGroup() { if (resourceEnvironmentGroup == null) { this.resourceEnvironmentGroup = new ResourceEnvironmentGroup(); } return this.resourceEnvironmentGroup; - } - - /** - * Adds a resource mapping to this resource environment group - * @param obj a resource to be referenced in this resource environment group - */ - protected void addResource(AbstractStructuredAFPObject obj) { - getResourceEnvironmentGroup().addObject(obj); - } + } } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java index 1bdf7d8bd..5df2ed3e8 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java @@ -169,8 +169,8 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject private static final String GRAPHIC_NAME_PREFIX = "GRA"; // not currently used/implemented - private static final String BARCODE_NAME_PREFIX = "BAR"; - private static final String OTHER_NAME_PREFIX = "OTH"; +// private static final String BARCODE_NAME_PREFIX = "BAR"; +// private static final String OTHER_NAME_PREFIX = "OTH"; /** * Helper method to create an image on the current container and to return @@ -248,9 +248,9 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject * {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); if (resourceGroup != null) { resourceGroup.write(os); } + super.writeContent(os); } } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java index 1573ea1a4..1a23511f5 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.List; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; @@ -232,7 +233,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** - * Specifies the extent of an object area in the X and Y directions + * Sets the extent of an object area in the X and Y directions * @param x the x direction extent * @param y the y direction extent */ @@ -242,11 +243,21 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the measurement units used to specify the units of measure + * @param xRes units per base on the x-axis + * @param yRes units per base on the y-axis */ - public void setMeasurementUnits() { - addTriplet(new MeasurementUnitsTriplet()); + public void setMeasurementUnits(int xRes, int yRes) { + addTriplet(new MeasurementUnitsTriplet(xRes, xRes)); } + /** + * Sets the mapping option + * @param optionValue the mapping option value + */ + public void setMappingOption(byte optionValue) { + addTriplet(new MappingOptionTriplet(optionValue)); + } + /** * Sets a comment on this resource * @param comment a comment string diff --git a/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java b/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java index f8a779707..b1d8aeb2a 100644 --- a/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java +++ b/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java @@ -41,4 +41,9 @@ public interface DataObjectAccessor extends Writable { * @param dataObjectInfo the data object info */ void setDataObjectInfo(DataObjectInfo dataObjectInfo); + + /** + * @return the data object accessor name + */ + String getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageSegment.java b/src/java/org/apache/fop/render/afp/modca/ImageSegment.java index e579052b0..813dffed2 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageSegment.java @@ -36,7 +36,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Default name for the object environment group */ - private static final String DEFAULT_NAME = "IS01"; + private static final String DEFAULT_NAME = "IS000001"; /** * The ImageContent for the image segment diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java index 1817bc8cc..1b1b6c1ed 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -74,27 +76,27 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA /** * The orientation on the include object */ - private int orientation = -1; + private int orientation = 0; /** * The X-axis origin of the object area */ - private int xOffset = -1; + private int xOffset = 0; /** * The Y-axis origin of the object area */ - private int yOffset = -1; + private int yOffset = 0; /** * The X-axis origin defined in the object */ - private int xContentOffset = -1; + private int xContentOffset = 0; /** * The Y-axis origin defined in the object */ - private int yContentOffset = -1; + private int yContentOffset = 0; /** * the referenced data object @@ -115,7 +117,6 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA this.dataObjectAccessor = dataObjectAccessor; AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); - // Strip any object container if (dataObject instanceof ObjectContainer) { ObjectContainer objectContainer = (ObjectContainer)dataObject; @@ -129,30 +130,28 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA this.dataObjectType = TYPE_PAGE_SEGMENT; } else { this.dataObjectType = TYPE_OTHER; - DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); - Registry registry = Registry.getInstance(); - Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - // When other type must set object classification - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); } + + DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); + + setObjectArea(dataObjectInfo.getX(), dataObjectInfo.getY()); + + super.setFullyQualifiedName( + FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, + FullyQualifiedNameTriplet.FORMAT_CHARSTR, + dataObjectInfo.getUri()); + + Registry registry = Registry.getInstance(); + Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); + super.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + + super.setMeasurementUnits(dataObjectInfo.getWidthRes(), dataObjectInfo.getHeightRes()); -// ResourceInfo resourceInfo = dataObjectAccessor.getDataObjectInfo().getResourceInfo(); -// // Set data object reference triplet -// if (resourceInfo != null && resourceInfo.isExternal()) { -// String dest = resourceInfo.getExternalResourceGroupDest(); -// super.setFullyQualifiedName( -// FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF, -// FullyQualifiedNameTriplet.FORMAT_URL, dest); -// } else { -// super.setFullyQualifiedName( -// FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF, -// FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObject.getName()); -// } + super.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); - // Set measurement units triplet - setMeasurementUnits(); + super.setObjectAreaSize(dataObjectInfo.getWidth(), dataObjectInfo.getHeight()); } /** @@ -241,7 +240,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA data[18] = dataObjectType; //XoaOset (object area) - if (xOffset > 0) { + if (xOffset >= -1) { byte[] x = BinaryUtils.convert(xOffset, 3); data[19] = x[0]; data[20] = x[1]; @@ -253,7 +252,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } // YoaOset (object area) - if (yOffset > 0) { + if (yOffset > -1) { byte[] y = BinaryUtils.convert(yOffset, 3); data[22] = y[0]; data[23] = y[1]; @@ -298,7 +297,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } // XocaOset (object content) - if (xContentOffset > 0) { + if (xContentOffset > -1) { byte[] y = BinaryUtils.convert(xContentOffset, 3); data[29] = y[0]; data[30] = y[1]; @@ -310,7 +309,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } // YocaOset (object content) - if (yContentOffset > 0) { + if (yContentOffset > -1) { byte[] y = BinaryUtils.convert(yContentOffset, 3); data[32] = y[0]; data[33] = y[1]; diff --git a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java index 3c9794e7d..9b1abe06c 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java +++ b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java @@ -22,12 +22,11 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -//import org.apache.fop.render.afp.ResourceLevel; import org.apache.fop.render.afp.DataObjectInfo; import org.apache.fop.render.afp.ResourceInfo; +import org.apache.fop.render.afp.ResourceLevel; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; -import org.apache.fop.render.afp.modca.triplets.StrucFlgs; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -48,12 +47,13 @@ public class MapDataResource extends AbstractStructuredAFPObject { AbstractNamedAFPObject namedDataObject = dataObjectAccessor.getDataObject(); DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - if (resourceInfo.isExternal()) { - String dest = resourceInfo.getExternalResourceGroupDest(); - if (dest != null) { + ResourceLevel resourceLevel = resourceInfo.getLevel(); + if (resourceLevel.isExternal()) { + String url = resourceLevel.getExternalResourceGroupFilePath(); + if (url != null) { super.setFullyQualifiedName( FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF, - FullyQualifiedNameTriplet.FORMAT_URL, dest); + FullyQualifiedNameTriplet.FORMAT_CHARSTR, url); } } else { String fqName = namedDataObject.getFullyQualifiedName(); diff --git a/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java b/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java index 02237ca90..67dcaa74f 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java +++ b/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java @@ -33,6 +33,8 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ public class MapPageOverlay extends AbstractAFPObject { + private static final int MAX_SIZE = 253; + /** * The collection of overlays (maximum of 254 stored as byte[]) */ @@ -59,7 +61,7 @@ public class MapPageOverlay extends AbstractAFPObject { * @throws MaximumSizeExceededException if the maximum size is reached */ public void addOverlay(String name) throws MaximumSizeExceededException { - if (getOverlays().size() > 253) { + if (getOverlays().size() > MAX_SIZE) { throw new MaximumSizeExceededException(); } if (name.length() != 8) { diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java index ebc402954..2e06c1b2c 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -32,6 +33,8 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjectAccessor { + private static final String DEFAULT_NAME = "OC000001"; + /** * the data object */ @@ -47,6 +50,13 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec */ private DataObjectInfo dataObjectInfo; + /** + * Default constructor + */ + public ObjectContainer() { + super(DEFAULT_NAME); + } + /** * Main constructor * @param name the name of this object container @@ -92,6 +102,10 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec } else { log.warn("no object type for " + dataObjectInfo.getUri()); } + super.setFullyQualifiedName( + FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, + FullyQualifiedNameTriplet.FORMAT_CHARSTR, + dataObjectInfo.getUri()); } /** diff --git a/src/java/org/apache/fop/render/afp/modca/PageObject.java b/src/java/org/apache/fop/render/afp/modca/PageObject.java index 1d9dc6985..1db9c4c41 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PageObject.java @@ -46,15 +46,15 @@ import org.apache.fop.render.afp.tools.StringUtils; */ public class PageObject extends AbstractResourceGroupContainer { - /** - * The page segment count - */ - private int pageSegmentCount = 0; - - /** - * The current page segment - */ - private PageSegment currentPageSegment = null; +// /** +// * The page segment count +// */ +// private int pageSegmentCount = 0; +// +// /** +// * The current page segment +// */ +// private PageSegment currentPageSegment = null; /** * Construct a new page object for the specified name argument, the page @@ -91,56 +91,58 @@ public class PageObject extends AbstractResourceGroupContainer { * the orientation required for the overlay */ public void createIncludePageOverlay(String name, int x, int y, int orientation) { - addObject(new IncludePageOverlay(name, x, y, orientation)); + getActiveEnvironmentGroup().createOverlay(name); + IncludePageOverlay ipo = new IncludePageOverlay(name, x, y, orientation); + addObject(ipo); } - /** - * @return a new page segment object - */ - private PageSegment createPageSegment() { - String name = PAGE_SEGMENT_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++pageSegmentCount), '0', 5); - PageSegment pageSegment = new PageSegment(name); - return pageSegment; - } - - /** - * @return the current page segment - */ - private PageSegment getCurrentPageSegment() { - if (currentPageSegment == null) { - this.currentPageSegment = createPageSegment(); - super.addObject(currentPageSegment); - } - return this.currentPageSegment; - } +// /** +// * @return a new page segment object +// */ +// private PageSegment createPageSegment() { +// String name = PAGE_SEGMENT_NAME_PREFIX +// + StringUtils.lpad(String.valueOf(++pageSegmentCount), '0', 5); +// PageSegment pageSegment = new PageSegment(name); +// return pageSegment; +// } - private static final String PAGE_SEGMENT_NAME_PREFIX = "PSG"; +// /** +// * @return the current page segment +// */ +// private PageSegment getCurrentPageSegment() { +// if (currentPageSegment == null) { +// this.currentPageSegment = createPageSegment(); +// super.addObject(currentPageSegment); +// } +// return this.currentPageSegment; +// } +// +// private static final String PAGE_SEGMENT_NAME_PREFIX = "PSG"; - /** - * Starts a new page segment and makes it current. - */ - public void startPageSegment() { - getCurrentPageSegment(); - } - - /** - * Ends the current page segment. - */ - public void endPageSegment() { - this.currentPageSegment = null; - } +// /** +// * Starts a new page segment and makes it current. +// */ +// public void startPageSegment() { +// getCurrentPageSegment(); +// } +// +// /** +// * Ends the current page segment. +// */ +// public void endPageSegment() { +// this.currentPageSegment = null; +// } - /** - * {@inheritDoc} - */ - protected void addObject(AbstractAFPObject obj) { - if (currentPageSegment != null) { - getCurrentPageSegment().addObject(obj); - } else { - super.addObject(obj); - } - } +// /** +// * {@inheritDoc} +// */ +// protected void addObject(AbstractAFPObject obj) { +//// if (currentPageSegment != null) { +//// getCurrentPageSegment().addObject(obj); +//// } else { +// super.addObject(obj); +//// } +// } /** * This method will create shading on the page using the specified diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java index aff5cc6eb..219dfd8cb 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java @@ -91,15 +91,15 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup { super(name); } - /** - * Adds an AFP object mapping reference to this resource environment group - * @param obj the object to add - */ - public void addObject(AbstractStructuredAFPObject obj) { - // TODO: AC - fix +// /** +// * Adds an AFP object mapping reference to this resource environment group +// * @param obj the object to add +// */ +// public void addObject(AbstractStructuredAFPObject obj) { // getMapDataResources().add(new MapDataResource(obj)); - getPreprocessPresentationObjects().add(new PreprocessPresentationObject(obj)); - } +// createOverlay(obj.get); +// getPreprocessPresentationObjects().add(new PreprocessPresentationObject(obj)); +// } /** * Returns an indication if the resource environment group is complete diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java index f8c9d5fc0..cd369b876 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java @@ -28,6 +28,8 @@ import java.util.Map; import org.apache.fop.render.afp.DataObjectInfo; import org.apache.fop.render.afp.ImageObjectInfo; import org.apache.fop.render.afp.ResourceInfo; +import org.apache.fop.render.afp.ResourceLevel; +import org.apache.fop.render.afp.tools.StringUtils; /** * A Resource Group contains a set of overlays. @@ -72,6 +74,14 @@ public final class ResourceGroup extends AbstractNamedAFPObject { return this.container; } + private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; + + private ObjectContainer createObjectContainer() { + String name = OBJECT_CONTAINER_NAME_PREFIX + + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 6); + return new ObjectContainer(name); + } + /** * Creates a data object in this resource group * @param dataObjectInfo the data object info @@ -81,6 +91,7 @@ public final class ResourceGroup extends AbstractNamedAFPObject { DataObjectAccessor dataObjectAccessor = (DataObjectAccessor)getResourceMap().get(dataObjectInfo.getUri()); ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + ResourceLevel resourceLevel = resourceInfo.getLevel(); AbstractDataObject dataObj; if (dataObjectAccessor == null) { if (dataObjectInfo instanceof ImageObjectInfo) { @@ -94,27 +105,31 @@ public final class ResourceGroup extends AbstractNamedAFPObject { dataObjectInfo.getWidthRes(), dataObjectInfo.getHeightRes(), dataObjectInfo.getRotation()); + ObjectContainer objectContainer = null; String resourceName = resourceInfo.getName(); - ObjectContainer objectContainer = new ObjectContainer(resourceName); + if (resourceName != null) { + objectContainer = new ObjectContainer(resourceName); + } else { + objectContainer = createObjectContainer(); + resourceName = objectContainer.getName(); + } objectContainer.setDataObject(dataObj); objectContainer.setDataObjectInfo(dataObjectInfo); // When externally located, wrap the object container in a resource object - if (resourceInfo.isExternal()) { + if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { ResourceObject resourceObject = new ResourceObject(resourceName); resourceObject.setDataObject(objectContainer); + resourceObject.setDataObjectInfo(dataObjectInfo); dataObjectAccessor = resourceObject; } else { // Access data object through container dataObjectAccessor = objectContainer; } - dataObjectAccessor.setDataObjectInfo(dataObjectInfo); // Add to resource map getResourceMap().put(dataObjectInfo.getUri(), dataObjectAccessor); } - // Return include object - AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); - String name = dataObject.getName(); + String name = dataObjectAccessor.getName(); IncludeObject includeObj = new IncludeObject(name, dataObjectAccessor); return includeObj; } @@ -126,13 +141,15 @@ public final class ResourceGroup extends AbstractNamedAFPObject { */ private boolean isValidObjectType(AbstractNamedAFPObject namedObj) { return (namedObj instanceof Overlay + || namedObj instanceof ResourceObject || namedObj instanceof PageSegment - // || namedObj instanceof FormMap - // || namedObj instanceof BarcodeObject || namedObj instanceof GraphicsObject || namedObj instanceof ImageObject || namedObj instanceof ObjectContainer - || namedObj instanceof Document); + || namedObj instanceof Document + // || namedObj instanceof FormMap + // || namedObj instanceof BarcodeObject + ); } /** * Adds a named object to this resource group diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java index 58c61fc58..e0ba1b4b7 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.modca.triplets.Triplet; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -54,10 +55,37 @@ public class ResourceObject extends AbstractPreparedAFPObject implements DataObj /** * Sets the data object referenced by this resource object - * @param namedObject the named data object + * @param obj the named data object */ - public void setDataObject(AbstractNamedAFPObject namedObject) { - this.namedObject = namedObject; + public void setDataObject(AbstractNamedAFPObject obj) { + this.namedObject = obj; + + String fqn = obj.getFullyQualifiedName(); + if (fqn != null) { + super.setFullyQualifiedName( + FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, + FullyQualifiedNameTriplet.FORMAT_CHARSTR, + fqn); + } + + byte type; + if (obj instanceof ObjectContainer) { + type = ResourceObjectTypeTriplet.OBJECT_CONTAINER; + } else if (obj instanceof ImageObject) { + type = ResourceObjectTypeTriplet.IMAGE_OBJECT; + } else if (obj instanceof GraphicsObject) { + type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT; + } else if (obj instanceof Document) { + type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT; + } else if (obj instanceof PageSegment) { + type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT; + } else if (obj instanceof Overlay) { + type = ResourceObjectTypeTriplet.OVERLAY_OBJECT; + } else { + throw new UnsupportedOperationException( + "Unsupported resource object type " + obj); + } + getTriplets().add(new ResourceObjectTypeTriplet(type)); } /** @@ -80,34 +108,12 @@ public class ResourceObject extends AbstractPreparedAFPObject implements DataObj public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { this.dataObjectInfo = dataObjectInfo; - byte type; if (namedObject instanceof ObjectContainer) { - type = ResourceObjectTypeTriplet.OBJECT_CONTAINER; - -// ObjectContainer objectContainer = (ObjectContainer)namedObject; -// DataObjectInfo dataObjectInfo = objectContainer.getDataObjectInfo(); Registry.ObjectType objectType = dataObjectInfo.getObjectType(); super.setObjectClassification( ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, objectType); - - } else if (namedObject instanceof ImageObject) { - type = ResourceObjectTypeTriplet.IMAGE_OBJECT; - } else if (namedObject instanceof GraphicsObject) { - type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT; - } else if (namedObject instanceof Document) { - type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT; - } else if (namedObject instanceof PageSegment) { - type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT; - } else if (namedObject instanceof Overlay) { - type = ResourceObjectTypeTriplet.OVERLAY_OBJECT; - } else { - throw new UnsupportedOperationException( - "Unsupported resource object type " + namedObject); } - - getTriplets().add(new ResourceObjectTypeTriplet(type)); - } /** diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java index 2be37b818..705a8d41d 100644 --- a/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java +++ b/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java @@ -160,13 +160,17 @@ public class FullyQualifiedNameTriplet extends Triplet { super(FULLY_QUALIFIED_NAME); this.fqName = fqName; - + byte[] fqNameBytes; + String encoding = AFPConstants.EBCIDIC_ENCODING; + if (format == FORMAT_URL) { + encoding = AFPConstants.US_ASCII_ENCODING; + } try { - fqNameBytes = fqName.getBytes(AFPConstants.ASCII_ENCODING); + fqNameBytes = fqName.getBytes(encoding); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( - AFPConstants.ASCII_ENCODING + " encoding failed"); + encoding + " encoding failed"); } byte[] data = new byte[2 + fqNameBytes.length]; diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java new file mode 100644 index 000000000..daebb6183 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java @@ -0,0 +1,68 @@ +/* + * 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.modca.triplets; + +/** + * Specifies the mapping of data object presentation space to object area + */ +public class MappingOptionTriplet extends Triplet { + /** + * the data object is placed in the upper left corner, all data must be presented + * within the object area extents + */ + public static final byte POSITION = 0x00; + + /** + * the data object is placed in the upper left corner, all data that falls within + * the object area extents will be presented but data that falls outside will not be presented + */ + public static final byte POSITION_AND_TRIM = 0x10; + + /** + * the data object is centred and symmetrically scaled up or down + * while preserving aspect ratio + */ + public static final byte SCALE_TO_FIT = 0x20; + + /** + * the data object is centred, all data that falls within the object area extents + * will be presented but data that falls outside will not be presented + */ + public static final byte CENTER_AND_TRIM = 0x30; + +// public static final byte MIGRATION_MAPPING_1 = 0x41; +// public static final byte MIGRATION_MAPPING_2 = 0x42; +// public static final byte MIGRATION_MAPPING_3 = 0x50; + + /** the data object is centred, aspect ratio is not always preserved */ + public static final byte SCALE_TO_FILL = 0x60; + + /** used to map ip3i print data objects */ + public static final byte UP3I_PRINT_DATA = 0x70; + + /** + * Main constructor + * + * @param mapValue the mapping option to use + */ + public MappingOptionTriplet(byte mapValue) { + super(Triplet.MAPPING_OPTION, mapValue); + } +} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java index 7350db27f..71da6e059 100644 --- a/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java +++ b/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java @@ -32,12 +32,15 @@ public class MeasurementUnitsTriplet extends Triplet { /** * Main constructor + * + * @param xRes units per base on the x-axis + * @param yRes units per base on the y-axis */ - public MeasurementUnitsTriplet() { + public MeasurementUnitsTriplet(int xRes, int yRes) { super(MEASUREMENT_UNITS); //TODO: units correct? - byte[] xUnits = BinaryUtils.convert(1, 2); - byte[] yUnits = BinaryUtils.convert(1, 2); + byte[] xUnits = BinaryUtils.convert(xRes * 10, 2); + byte[] yUnits = BinaryUtils.convert(yRes * 10, 2); byte[] data = new byte[] { TEN_INCHES, // XoaBase TEN_INCHES, // YoaBase -- cgit v1.2.3