diff options
Diffstat (limited to 'src/java/org/apache/fop/afp/modca')
12 files changed, 314 insertions, 54 deletions
diff --git a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java index 4a13b4a55..fcab3cb4a 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java @@ -90,6 +90,8 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject implemen // positional values are specified in the oaOffset of the include object objectAreaPosition = factory.createObjectAreaPosition(0, 0, 0); } + objectAreaPosition.setReferenceCoordinateSystem( + ObjectAreaPosition.REFCSYS_PAGE_SEGMENT_RELATIVE); getObjectEnvironmentGroup().setObjectAreaPosition(objectAreaPosition); } diff --git a/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java index a58bba1f0..4ba9abff8 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java @@ -5,9 +5,9 @@ * 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. @@ -29,14 +29,15 @@ import java.util.List; */ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { - /** - * The collection of MapPageOverlay objects - */ + /** the collection of MapDataResource objects */ + protected final List mapDataResources = null; + + /** the collection of MapPageOverlay objects */ protected List mapPageOverlays = null; /** * Main constructor - * + * * @param name the object name */ public AbstractEnvironmentGroup(String name) { @@ -53,7 +54,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Actually creates the MPO object. * Also creates the supporting object (an IPO) - * + * * @param name the name of the overlay to be used */ public void createOverlay(String name) { @@ -80,12 +81,16 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Getter method for the most recent MapPageOverlay added to the * Active Environment Group (returns null if no MapPageOverlay exist) - * + * * @return the most recent Map Coded Font */ private MapPageOverlay getCurrentMapPageOverlay() { - if (mapPageOverlays != null && mapPageOverlays.size() > 0) { - return (MapPageOverlay) mapPageOverlays.get(mapPageOverlays.size() - 1); + return (MapPageOverlay)getLastElement(this.mapPageOverlays); + } + + protected Object getLastElement(List list) { + if (list != null && list.size() > 0) { + return list.get(list.size() - 1); } else { return null; } @@ -94,8 +99,5 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); - if (mapPageOverlays != null) { - writeObjects(mapPageOverlays, os); - } } } diff --git a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java index 60dea2dde..c043faf2e 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java @@ -248,9 +248,14 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject implemen * @param y * the y coordinate of the page segment. */ - public void createIncludePageSegment(String name, int x, int y) { + public void createIncludePageSegment(String name, int x, int y, boolean hard) { IncludePageSegment ips = factory.createIncludePageSegment(name, x, y); addObject(ips); + if (hard) { + //For performance reasons, page segments can be turned into hard page segments + //using the Map Page Segment (MPS) structured field. + getActiveEnvironmentGroup().addMapPageSegment(name); + } } /** diff --git a/src/java/org/apache/fop/afp/modca/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ActiveEnvironmentGroup.java index ddc986be3..ecdfa0157 100644 --- a/src/java/org/apache/fop/afp/modca/ActiveEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/ActiveEnvironmentGroup.java @@ -45,8 +45,8 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { private final List/*<MapCodedFonts>*/ mapCodedFonts = new java.util.ArrayList/*<MapCodedFonts>*/(); - /** the collection of MapDataResource objects */ - private final List mapDataResources = null; + /** the collection of MapPageSegments objects */ + private List mapPageSegments = null; /** the Object Area Descriptor for the active environment group */ private ObjectAreaDescriptor objectAreaDescriptor = null; @@ -132,6 +132,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { writeObjects(mapCodedFonts, os); writeObjects(mapDataResources, os); writeObjects(mapPageOverlays, os); + writeObjects(mapPageSegments, os); if (pageDescriptor != null) { pageDescriptor.writeToStream(os); @@ -204,18 +205,29 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { } } -// private List getMapDataResources() { -// if (mapDataResources == null) { -// mapDataResources = new java.util.ArrayList(); -// } -// return mapDataResources; -//} - -// /** -// * Method to create a map data resource object -// * @param dataObjectAccessor a data object accessor -// */ -// protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { -// getMapDataResources().add(new MapDataResource(dataObjectAccessor)); -// } + public void addMapPageSegment(String name) { + try { + needMapPageSegment().addPageSegment(name); + } catch (MaximumSizeExceededException e) { + //Should not happen, handled internally + throw new IllegalStateException("Internal error: " + e.getMessage()); + } + } + + private MapPageSegment getCurrentMapPageSegment() { + return (MapPageSegment)getLastElement(this.mapPageSegments); + } + + private MapPageSegment needMapPageSegment() { + if (this.mapPageSegments == null) { + this.mapPageSegments = new java.util.ArrayList(); + } + MapPageSegment seg = getCurrentMapPageSegment(); + if (seg == null || seg.isFull()) { + seg = new MapPageSegment(); + this.mapPageSegments.add(seg); + } + return seg; + } + }
\ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java b/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java index 07976e18a..0a7b665d7 100644 --- a/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java +++ b/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java @@ -29,6 +29,11 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class ImageDataDescriptor extends AbstractDescriptor { + public static final byte FUNCTION_SET_FS10 = 0x0A; + public static final byte FUNCTION_SET_FS11 = 0x0B; + + private byte functionSet = FUNCTION_SET_FS11; // FCNSET = IOCA FS 11 + /** * Constructor for a ImageDataDescriptor for the specified * resolution, width and height. @@ -42,6 +47,14 @@ public class ImageDataDescriptor extends AbstractDescriptor { super(width, height, widthRes, heightRes); } + /** + * Sets the IOCA function set to be used. + * @param functionSet the function set (0x0A for FS 10, 0x0B for FS 11, etc.) + */ + public void setFunctionSet(byte functionSet) { + this.functionSet = functionSet; + } + /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[22]; @@ -68,10 +81,11 @@ public class ImageDataDescriptor extends AbstractDescriptor { data[16] = h[0]; data[17] = h[1]; + //IOCA Function Set Field data[18] = (byte)0xF7; // ID = Set IOCA Function Set data[19] = 0x02; // Length data[20] = 0x01; // Category = Function set identifier - data[21] = 0x0B; // FCNSET = IOCA FS 11 + data[21] = functionSet; os.write(data); } diff --git a/src/java/org/apache/fop/afp/modca/ImageObject.java b/src/java/org/apache/fop/afp/modca/ImageObject.java index b11d478cc..bbbc25bea 100644 --- a/src/java/org/apache/fop/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/afp/modca/ImageObject.java @@ -28,13 +28,14 @@ import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.afp.AFPImageObjectInfo; import org.apache.fop.afp.Factory; import org.apache.fop.afp.ioca.ImageSegment; +import org.apache.fop.afp.modca.triplets.MappingOptionTriplet; /** * An IOCA Image Data Object */ public class ImageObject extends AbstractDataObject { - private static final int MAX_DATA_LEN = 32759; + private static final int MAX_DATA_LEN = 8192; /** the image segment */ private ImageSegment imageSegment = null; @@ -73,7 +74,12 @@ public class ImageObject extends AbstractDataObject { int dataHeightRes = imageObjectInfo.getDataWidthRes(); ImageDataDescriptor imageDataDescriptor = factory.createImageDataDescriptor(dataWidth, dataHeight, dataWidthRes, dataHeightRes); + if (imageObjectInfo.getBitsPerPixel() == 1) { + imageDataDescriptor.setFunctionSet(ImageDataDescriptor.FUNCTION_SET_FS10); + } getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor); + getObjectEnvironmentGroup().setMapImageObject( + new MapImageObject(MappingOptionTriplet.SCALE_TO_FILL)); getImageSegment().setImageSize(dataWidth, dataHeight, dataWidthRes, dataHeightRes); } diff --git a/src/java/org/apache/fop/afp/modca/MapImageObject.java b/src/java/org/apache/fop/afp/modca/MapImageObject.java new file mode 100644 index 000000000..b1e258bb0 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MapImageObject.java @@ -0,0 +1,58 @@ +/* + * 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.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.triplets.MappingOptionTriplet; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The Map Image Object (MIO) structured field specifies how an image data object is + * mapped into its object area. + */ +public class MapImageObject extends AbstractTripletStructuredObject { + + /** + * Constructor for the Map Image Object. + * @param mappingOption the mapping option (see {@link MappingOptionTriplet}.*) + */ + public MapImageObject(byte mappingOption) { + addTriplet(new MappingOptionTriplet(mappingOption)); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[11]; + copySF(data, Type.MAP, Category.IMAGE); + int tripletLen = getTripletDataLength(); + + byte[] len = BinaryUtils.convert(10 + tripletLen, 2); + data[1] = len[0]; + data[2] = len[1]; + + len = BinaryUtils.convert(2 + tripletLen, 2); + data[9] = len[0]; + data[10] = len[1]; + os.write(data); + writeTriplets(os); + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/MapPageSegment.java b/src/java/org/apache/fop/afp/modca/MapPageSegment.java new file mode 100644 index 000000000..e2afd0257 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MapPageSegment.java @@ -0,0 +1,134 @@ +/* + * 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.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Iterator; +import java.util.Set; + +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The Map Page Segment structured field identifies page segments that are required to present + * a page on a physical medium. + */ +public class MapPageSegment extends AbstractAFPObject { + + private static final int MAX_SIZE = 127; + + /** + * The collection of page segments (maximum of 127 stored as String) + */ + private Set pageSegments = null; + + /** + * Constructor for the Map Page Overlay + */ + public MapPageSegment() { + } + + private Set getPageSegments() { + if (pageSegments == null) { + this.pageSegments = new java.util.HashSet(); + } + return this.pageSegments; + } + + /** + * Add a page segment to to the map page segment object. + * @param name the name of the page segment. + * @throws MaximumSizeExceededException if the maximum size is reached + */ + public void addPageSegment(String name) throws MaximumSizeExceededException { + if (getPageSegments().size() > MAX_SIZE) { + throw new MaximumSizeExceededException(); + } + if (name.length() > 8) { + throw new IllegalArgumentException("The name of page segment " + name + + " must not be longer than 8 characters"); + } + if (log.isDebugEnabled()) { + log.debug("addPageSegment():: adding page segment " + name); + } + getPageSegments().add(name); + } + + /** + * Indicates whether this object already contains the maximum number of + * page segments. + * @return true if the object is full + */ + public boolean isFull() { + return this.pageSegments.size() >= MAX_SIZE; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + int count = getPageSegments().size(); + byte groupLength = 0x0C; + int groupsLength = count * groupLength; + + byte[] data = new byte[groupsLength + 12 + 1]; + + data[0] = 0x5A; + + // Set the total record length + byte[] rl1 = BinaryUtils.convert(data.length - 1, 2); //Ignore the + // first byte in + // the length + data[1] = rl1[0]; + data[2] = rl1[1]; + + // Structured field ID for a MPS + data[3] = (byte) 0xD3; + data[4] = Type.MIGRATION; + data[5] = Category.PAGE_SEGMENT; + + data[6] = 0x00; // Flags + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + data[9] = groupLength; + data[10] = 0x00; // Reserved + data[11] = 0x00; // Reserved + data[12] = 0x00; // Reserved + + int pos = 13; + + Iterator iter = this.pageSegments.iterator(); + while (iter.hasNext()) { + pos += 4; + + String name = (String)iter.next(); + try { + byte[] nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); + System.arraycopy(nameBytes, 0, data, pos, nameBytes.length); + } catch (UnsupportedEncodingException usee) { + log.error("UnsupportedEncodingException translating the name " + + name); + } + pos += 8; + } + os.write(data); + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java index 25323b864..6ab2ea734 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java +++ b/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java @@ -25,7 +25,6 @@ import java.io.OutputStream; import org.apache.fop.afp.modca.triplets.DescriptorPositionTriplet; import org.apache.fop.afp.modca.triplets.MeasurementUnitsTriplet; import org.apache.fop.afp.modca.triplets.ObjectAreaSizeTriplet; -import org.apache.fop.afp.modca.triplets.PresentationSpaceResetMixingTriplet; import org.apache.fop.afp.util.BinaryUtils; /** @@ -57,8 +56,10 @@ public class ObjectAreaDescriptor extends AbstractDescriptor { addTriplet(new DescriptorPositionTriplet(OBJECT_AREA_POSITION_ID)); addTriplet(new MeasurementUnitsTriplet(widthRes, heightRes)); addTriplet(new ObjectAreaSizeTriplet(width, height)); + /* not allowed in Presentation Interchange Set 1 addTriplet(new PresentationSpaceResetMixingTriplet( PresentationSpaceResetMixingTriplet.NOT_RESET)); + */ int tripletDataLength = getTripletDataLength(); byte[] len = BinaryUtils.convert(data.length + tripletDataLength - 1, 2); diff --git a/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java b/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java index 3929c1196..d40454998 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java +++ b/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java @@ -31,11 +31,20 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class ObjectAreaPosition extends AbstractAFPObject { + /** + * Object areas will be positioned with respect to a point that is define by the + * Include Page Segment (IPS) structured field. + */ + public static final byte REFCSYS_PAGE_SEGMENT_RELATIVE = 0x00; + /** Object areas will be positioned with respect to the standard origin */ + public static final byte REFCSYS_PAGE_RELATIVE = 0x01; + private final int x; private final int y; private final int rotation; private int xOffset; private int yOffset; + private byte refCSys = 0x01; //Page or overlay coordinate system /** * Construct an object area position for the specified object y, y position. @@ -45,9 +54,30 @@ public class ObjectAreaPosition extends AbstractAFPObject { * @param rotation The coordinate system rotation (must be 0, 90, 180, 270). */ public ObjectAreaPosition(int x, int y, int rotation) { + this(x, y, rotation, REFCSYS_PAGE_RELATIVE); + } + + /** + * Construct an object area position for the specified object y, y position. + * + * @param x The x coordinate. + * @param y The y coordinate. + * @param rotation The coordinate system rotation (must be 0, 90, 180, 270). + * @param refCSys the reference coordinate system (normally 0x01) + */ + public ObjectAreaPosition(int x, int y, int rotation, byte refCSys) { this.x = x; this.y = y; this.rotation = rotation; + setReferenceCoordinateSystem(refCSys); + } + + /** + * Sets the reference coordinate system. + * @param refCSys the reference coordinate system (normally 0x01) + */ + public void setReferenceCoordinateSystem(byte refCSys) { + this.refCSys = refCSys; } /** {@inheritDoc} */ @@ -94,7 +124,7 @@ public class ObjectAreaPosition extends AbstractAFPObject { data[30] = 0x2D; // YocaOrent data[31] = 0x00; - data[32] = 0x01; // RefCSys + data[32] = this.refCSys; // RefCSys os.write(data); } diff --git a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java index bc0cc5a63..359f68602 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java @@ -46,6 +46,9 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** the ObjectAreaPosition for the object environment group */ private ObjectAreaPosition objectAreaPosition; + /** the MapImageObject for the object environment group (optional) */ + private MapImageObject mapImageObject; + /** the DataDescriptor for the object environment group */ private AbstractDescriptor dataDescriptor; @@ -83,6 +86,15 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { this.objectAreaPosition = objectAreaPosition; } + /** + * Sets the Map Image Object (MIO). + * + * @param mapImageObject the MIO structured field + */ + public void setMapImageObject(MapImageObject mapImageObject) { + this.mapImageObject = mapImageObject; + } + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; @@ -115,6 +127,10 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { objectAreaPosition.writeToStream(os); } + if (mapImageObject != null) { + mapImageObject.writeToStream(os); + } + if (mapContainerData != null) { mapContainerData.writeToStream(os); } diff --git a/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java index 2e4f57314..9a898ef4d 100644 --- a/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java @@ -34,12 +34,6 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup implement /** default name for the resource group */ private static final String DEFAULT_NAME = "REG00001"; - /** the maps data resources contained in this resource environment group */ - private List/*<MapDataResource>*/ mapDataResources = null; - - /** the maps page overlays contained in this resource environment group */ - private List mapPageOverlays = null; - /** the pre-process presentation objects contained in this resource environment group */ private List/*<PreprocessPresentationObject>*/ preProcessPresentationObjects = null; @@ -53,20 +47,6 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup implement this(DEFAULT_NAME); } - private List/*<MapDataResource>*/ getMapDataResources() { - if (mapDataResources == null) { - this.mapDataResources = new java.util.ArrayList/*<MapDataResource>*/(); - } - return this.mapDataResources; - } - - private List getMapPageOverlays() { - if (mapPageOverlays == null) { - this.mapPageOverlays = new java.util.ArrayList(); - } - return this.mapPageOverlays; - } - private List/*<PreprocessPresentationObject>*/ getPreprocessPresentationObjects() { if (preProcessPresentationObjects == null) { this.preProcessPresentationObjects |