Index: src/java/org/apache/fop/render/afp/AFPRenderer.java =================================================================== --- src/java/org/apache/fop/render/afp/AFPRenderer.java (revision 527506) +++ src/java/org/apache/fop/render/afp/AFPRenderer.java (working copy) @@ -47,8 +47,8 @@ import org.apache.fop.area.RegionReference; import org.apache.fop.area.RegionViewport; import org.apache.fop.area.Trait; +import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.Leader; -import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.SpaceArea; import org.apache.fop.area.inline.TextArea; import org.apache.fop.area.inline.WordArea; @@ -69,10 +69,11 @@ import org.apache.fop.render.AbstractPathOrientedRenderer; import org.apache.fop.render.Graphics2DAdapter; import org.apache.fop.render.RendererContext; +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.afp.extensions.AFPPageSetup; +import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.fonts.AFPFontInfo; -import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.fonts.CharacterSet; import org.apache.fop.render.afp.fonts.FopCharacterSet; import org.apache.fop.render.afp.fonts.OutlineFont; @@ -143,107 +144,107 @@ /** * AFP factor for a 240 resolution = 72000/240 = 300 */ - private static final int DPI_CONVERSION_FACTOR_240 = 300; + protected static final int DPI_CONVERSION_FACTOR_240 = 300; /** * The afp data stream object responsible for generating afp data */ - private AFPDataStream _afpDataStream = null; + protected AFPDataStream _afpDataStream = null; /** * The map of afp root extensions */ - private HashMap _rootExtensionMap = null; + protected HashMap _rootExtensionMap = null; /** * The map of page segments */ - private HashMap _pageSegmentsMap = null; + protected HashMap _pageSegmentsMap = null; /** * The fonts on the current page */ - private HashMap _currentPageFonts = null; + protected HashMap _currentPageFonts = null; /** * The current color object */ - private Color _currentColor = null; + protected Color _currentColor = null; /** * The page font number counter, used to determine the next font reference */ - private int _pageFontCounter = 0; + protected int _pageFontCounter = 0; /** * The current font family */ - private String _currentFontFamily = ""; + protected String _currentFontFamily = ""; /** * The current font size */ - private int _currentFontSize = 0; + protected int _currentFontSize = 0; /** * The Options to be set on the AFPRenderer */ - private Map _afpOptions = null; + protected Map _afpOptions = null; /** * The page width */ - private int _pageWidth = 0; + protected int _pageWidth = 0; /** * The page height */ - private int _pageHeight = 0; + protected int _pageHeight = 0; /** * The current page sequence id */ - private String _pageSequenceId = null; + protected String _pageSequenceId = null; /** * The portrait rotation */ - private int _portraitRotation = 0; + protected int _portraitRotation = 0; /** * The landscape rotation */ - private int _landscapeRotation = 270; + protected int _landscapeRotation = 270; /** * The line cache, avoids drawing duplicate lines in tables. */ - private HashSet _lineCache = null; + protected HashSet _lineCache = null; /** * The current x position for line drawing */ - private float _x; + protected float _x; /** * The current y position for line drawing */ - private float _y; + protected float _y; /** * The map of saved incomplete pages */ - private Map _pages = null; + protected Map _pages = null; /** * Flag to the set the output object type for images */ - private boolean colorImages = false; + protected boolean colorImages = false; /** * Default value for image depth */ - private int bitsPerPixel = 8; + protected int bitsPerPixel = 8; /** * Constructor for AFPRenderer. @@ -1764,6 +1765,23 @@ _afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot); } } + + /** + * Render the Barcode specified in the bean to AFP(BCOCA) + * @param data the barcode data + * @param bcoca the barcode attributes + * @param x the x coordinate (in mpt) + * @param y the y coordinate (in mpt) + * @param o the orientation + */ + public void renderBarcode(String data, BarcodeSymbologies bcoca, int x, int y, int o) { + + int afpx = mpts2units(x); + int afpy = mpts2units(y); + + _afpDataStream.createBarcodeObject(data, bcoca, afpx, afpy, o); + + } } Index: src/java/org/apache/fop/render/afp/bcoca/MatrixSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/MatrixSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/MatrixSymbologies.java (revision 0) @@ -0,0 +1,35 @@ +/* + * 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.bcoca; + +/** + * Two-dimensional matrix symbologies (sometimes called area symbologies) allow + * large amounts of information to be encoded in a two-dimensional matrix. These + * symbologies are usually rectangular and require a quiet zone around all four sides; + * for example, the Data Matrix symbology requires a quiet zone at least one module wide + * around the symbol. Two-dimensional matrix symbologies use extensive data compaction + * and error correction codes, allowing large amounts of character or binary data to be + * encoded. Unlike linear bar codes, Human-Readable Interpretation (HRI) is not provided + * with the bar code symbol. + */ +public abstract class MatrixSymbologies extends BarcodeSymbologies { + + +} Index: src/java/org/apache/fop/render/afp/bcoca/PDF417.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/PDF417.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/PDF417.java (revision 0) @@ -0,0 +1,126 @@ +/* + * 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.bcoca; + +import org.apache.fop.render.afp.modca.AFPConstants; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * The attributes specific to a PDF417 barcode + */ + +public class PDF417 extends StackedSymbologies { + + /** + * Flag to indicate if barcode is truncated + */ + private boolean truncated = false; + + /** + * The error correction level + */ + private int errorCorrection = 4; + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte getBarCodeModifier() { + + if (truncated) { + return 0x01; + } else { + return 0x00; + } + + } + + /** + * @see BarcodeSymbologies#getBarCodeType() + */ + public byte getBarCodeType() { + // The code to indicate PDF417 + return 0x1E; + } + + /** + * @see BarcodeSymbologies#getDataEncoding()) + */ + public String getDataEncoding() { + return AFPConstants.ASCII_ENCODING; + } + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte[] getSpecialFunctions() { + + byte[] data = new byte[] { 0x00, BinaryUtils.convert(getColumns())[0], + (byte) 0xFF, BinaryUtils.convert(errorCorrection)[0], 0x00, + 0x00, }; + + return data; + + } + + /** + * @return the error correction level + */ + public int getErrorCorrection() { + return errorCorrection; + } + + /** + * Settter for the error correction level + * + * @param errorCorrection + */ + public void setErrorCorrection(int errorCorrection) { + if (errorCorrection < 0 || errorCorrection > 8) { + throw new IllegalArgumentException("Error correction level of " + + errorCorrection + + " is invalid, valid ranges are between 0 and 8."); + } + this.errorCorrection = errorCorrection; + } + + /** + * @return true if the barcode symbol should be truncated + */ + public boolean isTruncated() { + return truncated; + } + + /** + * Setter for the truncated flag + * + * @param truncated + */ + public void setTruncated(boolean truncated) { + this.truncated = truncated; + } + + /** + * @see BarcodeSymbologies#isHumanReadableSupported() + */ + public boolean isHumanReadableSupported() { + return false; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/Code39.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/Code39.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/Code39.java (revision 0) @@ -0,0 +1,88 @@ +/* + * 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.bcoca; + +/** + * The attributes specific to a Code39 barcode + */ +import org.apache.fop.render.afp.modca.AFPConstants; + +public class Code39 extends LinearSymbologies { + + /** + * The checksum flag + */ + private boolean checkDigitEnabled = true; + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte getBarCodeModifier() { + + if (!checkDigitEnabled) { + // Do not generate the checksum + return 0x01; + } else { + // Default is to generate the checksum + return 0x02; + } + + } + + /** + * @see BarcodeSymbologies#getBarCodeType() + */ + public byte getBarCodeType() { + // The code to indicate Code39 + return 0x01; + } + + /** + * @see BarcodeSymbologies#getDataEncoding() + */ + public String getDataEncoding() { + return AFPConstants.EBCIDIC_ENCODING; + } + + /** + * @see BarcodeSymbologies#getSpecialFunctions() + */ + public byte[] getSpecialFunctions() { + + return new byte[] {}; + + } + + /** + * @return true if the check digit should be generated + */ + public boolean isCheckDigitEnabled() { + return checkDigitEnabled; + } + + /** + * Setter to enable/disable the check digit generation + * @param enabled + */ + public void setCheckDigitEnabled(boolean enabled) { + this.checkDigitEnabled = enabled; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/LinearSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/LinearSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/LinearSymbologies.java (revision 0) @@ -0,0 +1,107 @@ +/* + * 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.bcoca; + +/** + * Linear symbologies can be either width-modulated or height-modulated. The latter is mostly used + * in postal applications. Based on the character set, the symbologies can be further divided into + * two categories of numeric or alpha-numeric. + */ +public abstract class LinearSymbologies extends BarcodeSymbologies { + + /** + * Flag to indicate if the HRI should be preseneted + */ + private boolean humanReadablePresented = true; + + /** + * Flags to indicate if the position of the HRI + */ + private boolean hriPositionBelow = false; + private boolean hriPositionAbove = false; + + /** + * Flag to indicate if the asterisk is presented + */ + private boolean asteriskPresented = false; + + /** + * @return true if the human readable text should be at the below + */ + public boolean isHRIPositionBelow() { + return hriPositionBelow; + } + + /** + * @return true if the human readable text should be at the above + */ + public boolean isHRIPositionAbove() { + return hriPositionAbove; + } + + /** + * Set to true to position above, false will position at the bottom. + * @param above + */ + public void setHRIPositionAbove(boolean above) { + hriPositionAbove = above; + hriPositionBelow = !above; + } + + /** + * Set to true to position below, false will position at the top. + * @param below + */ + public void setHRIPositionBelow(boolean below) { + hriPositionBelow = below; + hriPositionAbove = !below; + } + + /** + * @return true if the human readable text should be presented + */ + public boolean isHRIPresented() { + return humanReadablePresented; + } + + /** + * Setter for the human readable presented flag + * @param humanReadablePresented + */ + public void setHRIPresented(boolean humanReadablePresented) { + this.humanReadablePresented = humanReadablePresented; + } + + /** + * @return true if the asterisk should be presented + */ + public boolean isAsteriskPresented() { + return asteriskPresented; + } + + /** + * Setter to indicate that the asterisk should be presented + * @param asteriskPresented + */ + public void setAsteriskPresented(boolean asteriskPresented) { + this.asteriskPresented = asteriskPresented; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/StackedSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/StackedSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/StackedSymbologies.java (revision 0) @@ -0,0 +1,92 @@ +/* + * 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.bcoca; + +/** + * Two-dimensional stacked symbologies allow large amounts of information to be encoded + * by effectively stacking short one-dimensional symbols in a row/column arrangement. + * This reduces the amount of space that is typically consumed by conventional linear + * bar code symbols and allows for a large variety of rectangular bar code shapes. + */ +public abstract class StackedSymbologies extends BarcodeSymbologies { + + /** + * the element height (i.e. the height of a row) + */ + private int elementHeight; + + /** + * the height multiplier or number of rows + */ + private int heightMultiplier = 0; + + /** + * The number of columns in the barccode + */ + private int columns = 3; + + /** + * @return the height of the element or row + */ + public int getElementHeight() { + return elementHeight; + } + + /** + * Setter for the element height + * @param units + * @param uom + */ + public void setElementHeight(double units, String uom) { + elementHeight = units2afp(units, uom); + } + + /** + * @return the height multiplier (or number of rows) + */ + public int getHeightMultiplier() { + return heightMultiplier; + } + + /** + * Setter for the height multiplier, also know as the number of rows. + * @param multiplier + */ + public void setHeightMultiplier(int multiplier) { + heightMultiplier = multiplier; + } + + /** + * @return the number of columns + */ + public int getColumns() { + return columns; + } + + /** + * Setter for the number of columns + * @param columns + */ + public void setColumns(int columns) { + this.columns = columns; + } + + +} Index: src/java/org/apache/fop/render/afp/bcoca/BarcodeSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/BarcodeSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/BarcodeSymbologies.java (revision 0) @@ -0,0 +1,208 @@ +/* + * 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.bcoca; + +import org.apache.fop.util.UnitConv; + +public abstract class BarcodeSymbologies { + + /** + * AFP factor for a 1440 resolution (default used for barcodes) + */ + private static final int DPI_CONVERSION_FACTOR = 50; + + /** + * the height in afp units + */ + private int height = 0; + + /** + * the width in afp units + */ + private int width = 0; + + /** + * the xoffset in afp units + */ + private int xOffset = 0; + + /** + * the yoffset in afp units + */ + private int yOffset = 0; + + /** + * the module width in thousandths of an inch + */ + private int moduleWidth = 0; + + /** + * Flag to surpress the output of the barcode symbol + */ + private boolean symbolSupressed = false; + + /** + * @return the module width in thousandths of an inch + */ + public int getModuleWidth() { + return moduleWidth; + } + + /** + * Setter for the module width + * @param moduleWidth + */ + public void setModuleWidth(double units, String uom) { + + if ("mm".equals(uom)) { + moduleWidth = (int)Math.round((units / 25.4f) * 1000); + } else if ("in".equals(uom)) { + moduleWidth = (int)Math.round(units * 1000); + } else { + throw new UnsupportedOperationException("Cannot convert the unit of measurement " + uom + " to thousandths of an inch."); + } + + } + + /** + * @return the height in afp units + */ + public int getHeight() { + return height; + } + + /** + * Setter for the height + * @param units + * @param uom + */ + public void setHeight(int units, String uom) { + height = units2afp(units, uom); + } + + public int getWidth() { + return width; + } + + /** + * Setter for the width + * @param units + * @param uom + */ + public void setWidth(int units, String uom) { + width = units2afp(units, uom); + } + + /** + * @return the xOffset + */ + public int getXOffset() { + return xOffset; + } + + /** + * Setter for the xOffset + * @param units + * @param uom + */ + public void setXOffset(int units, String uom) { + xOffset = units2afp(units, uom); + } + + /** + * @return the yOffset + */ + public int getYOffset() { + return yOffset; + } + + /** + * Setter for the yOffset + * @param units + * @param uom + */ + public void setYOffset(int units, String uom) { + yOffset = units2afp(units, uom); + } + + /** + * Converts FOP measurement units to afp measurement units + * @param units the measurement + * @param uom the unit of measurement + */ + protected int units2afp(double units, String uom) { + + double mpt = 0; + if ("mm".equals(uom)) { + mpt = UnitConv.mm2mpt(units); + } else if ("in".equals(uom)) { + mpt = UnitConv.in2mpt(units); + } else { + throw new UnsupportedOperationException("Cannot convert the unit of measurement " + uom + " to afo units."); + } + + return (int)Math.round(mpt / DPI_CONVERSION_FACTOR); + + } + + /** + * @return the bcoca code to represent the barcode type + */ + public abstract byte getBarCodeType(); + + /** + * @return the encoding to use for the barcode + */ + public abstract String getDataEncoding(); + + /** + * @return the bcoca special function flags + */ + public abstract byte[] getSpecialFunctions(); + + /** + * @return the bcoca modifier flags + */ + public abstract byte getBarCodeModifier(); + + /** + * The mpts to units factor identified the afp units resolution. + * @return the conversion factor for mpts to afp units. + */ + public int getMpts2unitsFactor() { + return DPI_CONVERSION_FACTOR; + } + + /** + * @return true if the barcode symbol should be supressed + */ + public boolean isSymbolSupressed() { + return symbolSupressed; + } + + /** + * Setter for the symbolSupressed attribute + * @param symbolSupressed + */ + public void setSymbolSupressed(boolean symbolSupressed) { + this.symbolSupressed = symbolSupressed; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/POSTNET.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/POSTNET.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/POSTNET.java (revision 0) @@ -0,0 +1,60 @@ +/* + * 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.bcoca; + +import org.apache.fop.render.afp.modca.AFPConstants; + +/** + * The attributes specific to a POSTNET barcode + */ +public class POSTNET extends BarcodeSymbologies { + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte getBarCodeModifier() { + return 0x00; + } + + /** + * @see BarcodeSymbologies#getBarCodeType() + */ + public byte getBarCodeType() { + // The code to indicate Postnet + return 0x18; + } + + /** + * @see BarcodeSymbologies#getDataEncoding() + */ + public String getDataEncoding() { + return AFPConstants.EBCIDIC_ENCODING; + } + + /** + * @see BarcodeSymbologies#getSpecialFunctions() + */ + public byte[] getSpecialFunctions() { + + return new byte[] {}; + + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/BarcodeSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/BarcodeSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/BarcodeSymbologies.java (revision 0) @@ -0,0 +1,208 @@ +/* + * 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.bcoca; + +import org.apache.fop.util.UnitConv; + +public abstract class BarcodeSymbologies { + + /** + * AFP factor for a 1440 resolution (default used for barcodes) + */ + private static final int DPI_CONVERSION_FACTOR = 50; + + /** + * the height in afp units + */ + private int height = 0; + + /** + * the width in afp units + */ + private int width = 0; + + /** + * the xoffset in afp units + */ + private int xOffset = 0; + + /** + * the yoffset in afp units + */ + private int yOffset = 0; + + /** + * the module width in thousandths of an inch + */ + private int moduleWidth = 0; + + /** + * Flag to surpress the output of the barcode symbol + */ + private boolean symbolSupressed = false; + + /** + * @return the module width in thousandths of an inch + */ + public int getModuleWidth() { + return moduleWidth; + } + + /** + * Setter for the module width + * @param moduleWidth + */ + public void setModuleWidth(double units, String uom) { + + if ("mm".equals(uom)) { + moduleWidth = (int)Math.round((units / 25.4f) * 1000); + } else if ("in".equals(uom)) { + moduleWidth = (int)Math.round(units * 1000); + } else { + throw new UnsupportedOperationException("Cannot convert the unit of measurement " + uom + " to thousandths of an inch."); + } + + } + + /** + * @return the height in afp units + */ + public int getHeight() { + return height; + } + + /** + * Setter for the height + * @param units + * @param uom + */ + public void setHeight(int units, String uom) { + height = units2afp(units, uom); + } + + public int getWidth() { + return width; + } + + /** + * Setter for the width + * @param units + * @param uom + */ + public void setWidth(int units, String uom) { + width = units2afp(units, uom); + } + + /** + * @return the xOffset + */ + public int getXOffset() { + return xOffset; + } + + /** + * Setter for the xOffset + * @param units + * @param uom + */ + public void setXOffset(int units, String uom) { + xOffset = units2afp(units, uom); + } + + /** + * @return the yOffset + */ + public int getYOffset() { + return yOffset; + } + + /** + * Setter for the yOffset + * @param units + * @param uom + */ + public void setYOffset(int units, String uom) { + yOffset = units2afp(units, uom); + } + + /** + * Converts FOP measurement units to afp measurement units + * @param units the measurement + * @param uom the unit of measurement + */ + protected int units2afp(double units, String uom) { + + double mpt = 0; + if ("mm".equals(uom)) { + mpt = UnitConv.mm2mpt(units); + } else if ("in".equals(uom)) { + mpt = UnitConv.in2mpt(units); + } else { + throw new UnsupportedOperationException("Cannot convert the unit of measurement " + uom + " to afo units."); + } + + return (int)Math.round(mpt / DPI_CONVERSION_FACTOR); + + } + + /** + * @return the bcoca code to represent the barcode type + */ + public abstract byte getBarCodeType(); + + /** + * @return the encoding to use for the barcode + */ + public abstract String getDataEncoding(); + + /** + * @return the bcoca special function flags + */ + public abstract byte[] getSpecialFunctions(); + + /** + * @return the bcoca modifier flags + */ + public abstract byte getBarCodeModifier(); + + /** + * The mpts to units factor identified the afp units resolution. + * @return the conversion factor for mpts to afp units. + */ + public int getMpts2unitsFactor() { + return DPI_CONVERSION_FACTOR; + } + + /** + * @return true if the barcode symbol should be supressed + */ + public boolean isSymbolSupressed() { + return symbolSupressed; + } + + /** + * Setter for the symbolSupressed attribute + * @param symbolSupressed + */ + public void setSymbolSupressed(boolean symbolSupressed) { + this.symbolSupressed = symbolSupressed; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/Code39.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/Code39.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/Code39.java (revision 0) @@ -0,0 +1,88 @@ +/* + * 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.bcoca; + +/** + * The attributes specific to a Code39 barcode + */ +import org.apache.fop.render.afp.modca.AFPConstants; + +public class Code39 extends LinearSymbologies { + + /** + * The checksum flag + */ + private boolean checkDigitEnabled = true; + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte getBarCodeModifier() { + + if (!checkDigitEnabled) { + // Do not generate the checksum + return 0x01; + } else { + // Default is to generate the checksum + return 0x02; + } + + } + + /** + * @see BarcodeSymbologies#getBarCodeType() + */ + public byte getBarCodeType() { + // The code to indicate Code39 + return 0x01; + } + + /** + * @see BarcodeSymbologies#getDataEncoding() + */ + public String getDataEncoding() { + return AFPConstants.EBCIDIC_ENCODING; + } + + /** + * @see BarcodeSymbologies#getSpecialFunctions() + */ + public byte[] getSpecialFunctions() { + + return new byte[] {}; + + } + + /** + * @return true if the check digit should be generated + */ + public boolean isCheckDigitEnabled() { + return checkDigitEnabled; + } + + /** + * Setter to enable/disable the check digit generation + * @param enabled + */ + public void setCheckDigitEnabled(boolean enabled) { + this.checkDigitEnabled = enabled; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/LinearSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/LinearSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/LinearSymbologies.java (revision 0) @@ -0,0 +1,107 @@ +/* + * 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.bcoca; + +/** + * Linear symbologies can be either width-modulated or height-modulated. The latter is mostly used + * in postal applications. Based on the character set, the symbologies can be further divided into + * two categories of numeric or alpha-numeric. + */ +public abstract class LinearSymbologies extends BarcodeSymbologies { + + /** + * Flag to indicate if the HRI should be preseneted + */ + private boolean humanReadablePresented = true; + + /** + * Flags to indicate if the position of the HRI + */ + private boolean hriPositionBelow = false; + private boolean hriPositionAbove = false; + + /** + * Flag to indicate if the asterisk is presented + */ + private boolean asteriskPresented = false; + + /** + * @return true if the human readable text should be at the below + */ + public boolean isHRIPositionBelow() { + return hriPositionBelow; + } + + /** + * @return true if the human readable text should be at the above + */ + public boolean isHRIPositionAbove() { + return hriPositionAbove; + } + + /** + * Set to true to position above, false will position at the bottom. + * @param above + */ + public void setHRIPositionAbove(boolean above) { + hriPositionAbove = above; + hriPositionBelow = !above; + } + + /** + * Set to true to position below, false will position at the top. + * @param below + */ + public void setHRIPositionBelow(boolean below) { + hriPositionBelow = below; + hriPositionAbove = !below; + } + + /** + * @return true if the human readable text should be presented + */ + public boolean isHRIPresented() { + return humanReadablePresented; + } + + /** + * Setter for the human readable presented flag + * @param humanReadablePresented + */ + public void setHRIPresented(boolean humanReadablePresented) { + this.humanReadablePresented = humanReadablePresented; + } + + /** + * @return true if the asterisk should be presented + */ + public boolean isAsteriskPresented() { + return asteriskPresented; + } + + /** + * Setter to indicate that the asterisk should be presented + * @param asteriskPresented + */ + public void setAsteriskPresented(boolean asteriskPresented) { + this.asteriskPresented = asteriskPresented; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/MatrixSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/MatrixSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/MatrixSymbologies.java (revision 0) @@ -0,0 +1,35 @@ +/* + * 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.bcoca; + +/** + * Two-dimensional matrix symbologies (sometimes called area symbologies) allow + * large amounts of information to be encoded in a two-dimensional matrix. These + * symbologies are usually rectangular and require a quiet zone around all four sides; + * for example, the Data Matrix symbology requires a quiet zone at least one module wide + * around the symbol. Two-dimensional matrix symbologies use extensive data compaction + * and error correction codes, allowing large amounts of character or binary data to be + * encoded. Unlike linear bar codes, Human-Readable Interpretation (HRI) is not provided + * with the bar code symbol. + */ +public abstract class MatrixSymbologies extends BarcodeSymbologies { + + +} Index: src/java/org/apache/fop/render/afp/bcoca/PDF417.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/PDF417.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/PDF417.java (revision 0) @@ -0,0 +1,126 @@ +/* + * 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.bcoca; + +import org.apache.fop.render.afp.modca.AFPConstants; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * The attributes specific to a PDF417 barcode + */ + +public class PDF417 extends StackedSymbologies { + + /** + * Flag to indicate if barcode is truncated + */ + private boolean truncated = false; + + /** + * The error correction level + */ + private int errorCorrection = 4; + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte getBarCodeModifier() { + + if (truncated) { + return 0x01; + } else { + return 0x00; + } + + } + + /** + * @see BarcodeSymbologies#getBarCodeType() + */ + public byte getBarCodeType() { + // The code to indicate PDF417 + return 0x1E; + } + + /** + * @see BarcodeSymbologies#getDataEncoding()) + */ + public String getDataEncoding() { + return AFPConstants.ASCII_ENCODING; + } + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte[] getSpecialFunctions() { + + byte[] data = new byte[] { 0x00, BinaryUtils.convert(getColumns())[0], + (byte) 0xFF, BinaryUtils.convert(errorCorrection)[0], 0x00, + 0x00, }; + + return data; + + } + + /** + * @return the error correction level + */ + public int getErrorCorrection() { + return errorCorrection; + } + + /** + * Settter for the error correction level + * + * @param errorCorrection + */ + public void setErrorCorrection(int errorCorrection) { + if (errorCorrection < 0 || errorCorrection > 8) { + throw new IllegalArgumentException("Error correction level of " + + errorCorrection + + " is invalid, valid ranges are between 0 and 8."); + } + this.errorCorrection = errorCorrection; + } + + /** + * @return true if the barcode symbol should be truncated + */ + public boolean isTruncated() { + return truncated; + } + + /** + * Setter for the truncated flag + * + * @param truncated + */ + public void setTruncated(boolean truncated) { + this.truncated = truncated; + } + + /** + * @see BarcodeSymbologies#isHumanReadableSupported() + */ + public boolean isHumanReadableSupported() { + return false; + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/POSTNET.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/POSTNET.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/POSTNET.java (revision 0) @@ -0,0 +1,60 @@ +/* + * 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.bcoca; + +import org.apache.fop.render.afp.modca.AFPConstants; + +/** + * The attributes specific to a POSTNET barcode + */ +public class POSTNET extends BarcodeSymbologies { + + /** + * @see BarcodeSymbologies#getBarCodeModifier() + */ + public byte getBarCodeModifier() { + return 0x00; + } + + /** + * @see BarcodeSymbologies#getBarCodeType() + */ + public byte getBarCodeType() { + // The code to indicate Postnet + return 0x18; + } + + /** + * @see BarcodeSymbologies#getDataEncoding() + */ + public String getDataEncoding() { + return AFPConstants.EBCIDIC_ENCODING; + } + + /** + * @see BarcodeSymbologies#getSpecialFunctions() + */ + public byte[] getSpecialFunctions() { + + return new byte[] {}; + + } + +} Index: src/java/org/apache/fop/render/afp/bcoca/StackedSymbologies.java =================================================================== --- src/java/org/apache/fop/render/afp/bcoca/StackedSymbologies.java (revision 0) +++ src/java/org/apache/fop/render/afp/bcoca/StackedSymbologies.java (revision 0) @@ -0,0 +1,92 @@ +/* + * 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.bcoca; + +/** + * Two-dimensional stacked symbologies allow large amounts of information to be encoded + * by effectively stacking short one-dimensional symbols in a row/column arrangement. + * This reduces the amount of space that is typically consumed by conventional linear + * bar code symbols and allows for a large variety of rectangular bar code shapes. + */ +public abstract class StackedSymbologies extends BarcodeSymbologies { + + /** + * the element height (i.e. the height of a row) + */ + private int elementHeight; + + /** + * the height multiplier or number of rows + */ + private int heightMultiplier = 0; + + /** + * The number of columns in the barccode + */ + private int columns = 3; + + /** + * @return the height of the element or row + */ + public int getElementHeight() { + return elementHeight; + } + + /** + * Setter for the element height + * @param units + * @param uom + */ + public void setElementHeight(double units, String uom) { + elementHeight = units2afp(units, uom); + } + + /** + * @return the height multiplier (or number of rows) + */ + public int getHeightMultiplier() { + return heightMultiplier; + } + + /** + * Setter for the height multiplier, also know as the number of rows. + * @param multiplier + */ + public void setHeightMultiplier(int multiplier) { + heightMultiplier = multiplier; + } + + /** + * @return the number of columns + */ + public int getColumns() { + return columns; + } + + /** + * Setter for the number of columns + * @param columns + */ + public void setColumns(int columns) { + this.columns = columns; + } + + +} Index: src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java =================================================================== --- src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java (revision 527506) +++ src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java (working copy) @@ -19,7 +19,6 @@ package org.apache.fop.render.afp.extensions; -import org.apache.fop.apps.FOPException; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.StringProperty; Index: src/java/org/apache/fop/render/afp/extensions/AFPElement.java =================================================================== --- src/java/org/apache/fop/render/afp/extensions/AFPElement.java (revision 527506) +++ src/java/org/apache/fop/render/afp/extensions/AFPElement.java (working copy) @@ -22,7 +22,6 @@ import org.apache.fop.fo.Constants; import org.apache.fop.fo.FONode; import org.apache.fop.fo.ValidationException; -import org.apache.fop.fo.XMLObj; /** * This class extends the org.apache.fop.extensions.ExtensionObj class. The @@ -59,8 +58,8 @@ // || !AFPElementMapping.PAGE.equals(parent.getLocalName())) { // throw new ValidationException(getName() + " must be a child of afp:page."); //} - if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) { - throw new ValidationException(getName() + " must be a child of fo:simple-page-master."); + if (parent.getNameId() != Constants.FO_INSTREAM_FOREIGN_OBJECT) { + throw new ValidationException(getName() + " must be a child of fo:instream-foreign-object."); } } Index: src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java (working copy) @@ -20,10 +20,10 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.tools.StringUtils; @@ -409,5 +409,29 @@ public int getRotation() { return _rotation; } + + /** + * @param data + * the barcode data + * @param bean + * the attributes of the barcode + * @param dimension + * the dimension of the barcode + * @param x + * the x coordinate for the overlay + * @param y + * the y coordinate for the overlay + * @param o + * the orientation of the barcode + */ + public void createBarcode(String data, BarcodeSymbologies bcoca, int x, int y, int o) { + BarcodeObject bco = new BarcodeObject(bcoca); + bco.setBarcodeViewport(x, y, o); + BarcodeData bcd = new BarcodeData(data, bcoca); + bco.setBarCodeData(bcd); + _objects.add(bco); + + } + } \ No newline at end of file Index: src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java (working copy) @@ -20,8 +20,8 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; + import org.apache.fop.render.afp.fonts.AFPFont; /** @@ -100,7 +100,7 @@ _pageDescriptor = new PageDescriptor(width, height); // Create ObjectAreaDescriptor - _objectAreaDescriptor = new ObjectAreaDescriptor(width, height); + _objectAreaDescriptor = new ObjectAreaDescriptor(width, height, 2400); // Create PresentationTextDataDescriptor _presentationTextDataDescriptor = Index: src/java/org/apache/fop/render/afp/modca/AFPConstants.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/AFPConstants.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/AFPConstants.java (working copy) @@ -34,5 +34,15 @@ * The encoding to use to convert to ASCII */ public String ASCII_ENCODING = "Cp1252"; + + /** + * 240 DPI (i.e. 2400/10 hex value '09' '60') + */ + public String DPI_240 = "0960"; + + /** + * 1440 DPI (i.e. 14400/10 hex value '38' '40') + */ + public String DPI_1440 = "3840"; } Index: src/java/org/apache/fop/render/afp/modca/AFPDataStream.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/AFPDataStream.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/AFPDataStream.java (working copy) @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.tools.StringUtils; @@ -516,7 +517,7 @@ break; } _currentPage.createIncludePageSegment(name, xOrigin, yOrigin); - + } /** @@ -637,5 +638,59 @@ } } + + /** + * Creates an BarcodeObject (BCOCA) on the current page. + * @param data + * the barcode data + * @param bcoca + * the attributes of the barcode + * @param x + * the x coordinate for the overlay + * @param y + * the y coordinate for the overlay + * @param o + * the orientation of the barcode + */ + public void createBarcodeObject(String data, BarcodeSymbologies bcoca, int x, int y, int o) { + int xOrigin; + int yOrigin; + + int height; + int width; + + int factor = bcoca.getMpts2unitsFactor(); + if (factor == 50) { + // Convert from 1440 resolution to 240 + height = Math.round(((float)bcoca.getHeight() / 1440) * 240); + width = Math.round(((float)bcoca.getWidth() / 1440) * 240); + } else { + height = bcoca.getHeight(); + width = bcoca.getWidth(); + } + + switch (o) { + case 90: + xOrigin = x + _xOffset + height; + yOrigin = y + _yOffset; + break; + case 180: + xOrigin = x + _xOffset + width; + yOrigin = y + _yOffset + height; + break; + case 270: + xOrigin = x + _xOffset; + yOrigin = y + _yOffset + width; + break; + default: + xOrigin = x + _xOffset; + yOrigin = y + _yOffset; + break; + } + + _currentPage.createBarcode(data, bcoca, xOrigin, yOrigin, o); + + } + } Index: src/java/org/apache/fop/render/afp/modca/BarcodeData.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/BarcodeData.java (revision 0) +++ src/java/org/apache/fop/render/afp/modca/BarcodeData.java (revision 0) @@ -0,0 +1,155 @@ +/* + * 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; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; +import org.apache.fop.render.afp.bcoca.LinearSymbologies; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * The Barcode Data (BDA) structured field contains parameters to position a + * single bar code symbol within a bar code presentation space, parameters to + * specify special functions for 2D bar codes, flags to specify attributes + * specific to the symbol, and the data to be encoded. The data is encoded + * according to the parameters specified in the Bar Code Data Descriptor (BDD) + * structured field + */ +public class BarcodeData extends AbstractAFPObject { + + /** + * Dimensions of the barcode presentation space + */ + private BarcodeSymbologies _bcocaObject; + + /** + * The barcode data + */ + byte[] _barcodeData = null; + + /** + * Default constructor for the BarcodeData. + * + * @param data + * the barcode data + * @param bcoca + * the barcode attributes + */ + public BarcodeData(String data, BarcodeSymbologies bcoca) { + + _bcocaObject = bcoca; + + try { + _barcodeData = data.getBytes(_bcocaObject.getDataEncoding()); + } catch (UnsupportedEncodingException usee) { + _barcodeData = data.getBytes(); + log.warn("Constructor:: UnsupportedEncodingException translating the barcode data: " + data); + } + + } + + /** + * Accessor method to write the AFP datastream for the barcode data. + * + * @param os + * The stream to write to + * @throws java.io.IOException + */ + public void writeDataStream(OutputStream os) throws IOException { + + byte[] specialFunctions = _bcocaObject.getSpecialFunctions(); + int length = 14 + specialFunctions.length + _barcodeData.length; + byte[] data = new byte[length]; + + data[0] = 0x5A; + // Set the total record length + byte[] rl1 = BinaryUtils.convert(length - 1, 2); + data[1] = rl1[0]; + data[2] = rl1[1]; + + // Structured field the BarcodeData + data[3] = (byte) 0xD3; + data[4] = (byte) 0xEE; + data[5] = (byte) 0xEB; + + data[6] = 0x00; // Reserved + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + byte flags = (byte) 0x00; + + if (_bcocaObject instanceof LinearSymbologies) { + LinearSymbologies linearSymbologies = (LinearSymbologies) _bcocaObject; + flags = BinaryUtils.setBit(flags, 0, !linearSymbologies.isHRIPresented()); + if (linearSymbologies.isHRIPositionAbove()) { + // "10" Above + flags = BinaryUtils.setBit(flags, 1, true); + flags = BinaryUtils.setBit(flags, 2, false); + } else if (linearSymbologies.isHRIPositionBelow()) { + // "01" Below + flags = BinaryUtils.setBit(flags, 1, false); + flags = BinaryUtils.setBit(flags, 2, true); + } else { + // Use the default "00" + } + flags = BinaryUtils.setBit(flags, 3, linearSymbologies.isAsteriskPresented()); + } else { + // Asterisk not presented + flags = BinaryUtils.setBit(flags, 3, false); + } + + flags = BinaryUtils.setBit(flags, 5, _bcocaObject.isSymbolSupressed()); + data[9] = flags; + + int xOffset = _bcocaObject.getXOffset(); + int yOffset = _bcocaObject.getYOffset(); + + if (xOffset < 1) { + data[10] = 0x00; + data[11] = 0x01; + } else { + byte[] xOset = BinaryUtils.convert(xOffset, 2); + data[10] = xOset[0]; + data[11] = xOset[1]; + } + + if (yOffset < 1) { + data[12] = 0x00; + data[13] = 0x01; + } else { + byte[] yOset = BinaryUtils.convert(yOffset, 2); + data[12] = yOset[0]; + data[13] = yOset[1]; + } + + System + .arraycopy(specialFunctions, 0, data, 14, + specialFunctions.length); + System.arraycopy(_barcodeData, 0, data, 14 + specialFunctions.length, + _barcodeData.length); + + os.write(data); + + } + +} \ No newline at end of file Index: src/java/org/apache/fop/render/afp/modca/BarcodeDataDescriptor.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/BarcodeDataDescriptor.java (revision 0) +++ src/java/org/apache/fop/render/afp/modca/BarcodeDataDescriptor.java (revision 0) @@ -0,0 +1,143 @@ +/* + * 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; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; +import org.apache.fop.render.afp.bcoca.StackedSymbologies; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * The Barcode Data Descriptor (BDA) specifies the size of the bar code presentation space, + * the type of bar code to be generated, and the parameters used to generate the bar code symbols. + */ +public class BarcodeDataDescriptor implements DataDescriptor { + + /** + * The barcode attributes + */ + private BarcodeSymbologies _bcocaObject; + + /** + * Constructor for a BarcodeDataDescriptor + * @param bcoca the barcode attributes + */ + public BarcodeDataDescriptor(BarcodeSymbologies bcoca) { + + _bcocaObject = bcoca; + + } + + /** + * Accessor method to write the AFP datastream for the Image Data Descriptor + * @param os The stream to write to + * @throws java.io.IOException + */ + public void writeDataStream(OutputStream os) + throws IOException { + + byte[] unitsperbase = new byte[2]; + if (_bcocaObject.getMpts2unitsFactor() == 50) { + unitsperbase[0] = 0x38; + unitsperbase[1] = 0x40; + } else if (_bcocaObject.getMpts2unitsFactor() == 300) { + unitsperbase[0] = 0x09; + unitsperbase[1] = 0x60; + } + + byte[] bw = BinaryUtils.convert(_bcocaObject.getWidth(), 2); + byte[] bl = BinaryUtils.convert(_bcocaObject.getHeight(), 2); + + byte[] elementHeight = new byte[2]; + byte[] heightMultiplier = new byte[1]; + if (_bcocaObject instanceof StackedSymbologies) { + StackedSymbologies stackedSymbology = (StackedSymbologies) _bcocaObject; + int ehi = stackedSymbology.getElementHeight(); + if (ehi < 1) { + // Use default + elementHeight[0] = (byte)0xFF; + elementHeight[1] = (byte)0xFF; + heightMultiplier[0] = 0x01; + } else { + elementHeight = BinaryUtils.convert(ehi, 2); + heightMultiplier = BinaryUtils.convert(stackedSymbology.getHeightMultiplier(), 2); + } + } else { + elementHeight[0] = (byte)0xFF; + elementHeight[1] = (byte)0xFF; + heightMultiplier[0] = 0x01; + } + + byte[] data = new byte[] { + 0x5A, + 0x00, + 0x20, + (byte) 0xD3, + (byte) 0xA6, + (byte) 0xEB, + 0x00, // Flags + 0x00, // Reserved + 0x00, // Reserved + + 0x00, // Base units (ten inches) + 0x00, // Reserved + + unitsperbase[0], // Units per base in the X direction + unitsperbase[1], // + unitsperbase[0], // Units per base in the Y direction + unitsperbase[1], // + + bw[0], + bw[1], + bl[0], + bl[1], + + 0x00, // Reserved + 0x00, // Reserved + + _bcocaObject.getBarCodeType(), + _bcocaObject.getBarCodeModifier(), + + (byte)0xFF, // Default HRI Local Font + (byte)0x00, // Default Color + (byte)0x00, // Default Color + + BinaryUtils.convert(_bcocaObject.getModuleWidth(), 1)[0], // The module width + + elementHeight[0], // Element height + elementHeight[1], // Element height + heightMultiplier[0], // Default height multiplier + + (byte)0xFF, // Default wide to narrow ratio + (byte)0xFF, // Default wide to narrow ratio + + }; + + byte[] l = BinaryUtils.convert(data.length - 1, 2); + data[1] = l[0]; + data[2] = l[1]; + + os.write(data); + + } + +} Index: src/java/org/apache/fop/render/afp/modca/BarcodeObject.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/BarcodeObject.java (revision 0) +++ src/java/org/apache/fop/render/afp/modca/BarcodeObject.java (revision 0) @@ -0,0 +1,174 @@ +/* + * 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; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; + +/** + * Barcodes consists of patterns of bars and spaces that represent alphanumeric information. + * Characteristics of the patterns are defined by specific bar code symbologies. A bar code object + * carries the alphanumeric information that is to be presented as a bar code and the controls to + * present this information using a specific bar code symbology. The bar code data object is defined + * by the Bar Code Object Content Architecture. + */ +public class BarcodeObject extends AbstractNamedAFPObject { + + /** + * Default name for the object environment group + */ + private static final String DEFAULT_NAME = "BCO00001"; + + private BarcodeSymbologies _bcocaObject; + + /** + * The barcode object environment group + */ + private BarcodeObjectEnvironmentGroup _barCodeObjectEnvironmentGroup = null; + + /** + * The barcode object environment group + */ + private BarcodeData _barCodeData = null; + + + /** + * Constructor for the barcode object + * @param bean the barcode attributes + * @param dimension the barcode dimension + */ + public BarcodeObject(BarcodeSymbologies bcoca) { + + super(DEFAULT_NAME); + _bcocaObject = bcoca; + + } + + /** + * Sets the barcode display area position and size. + * + * @param x + * the x position of the barcode + * @param y + * the y position of the barcode + * @param r + * the rotation of the barcode + */ + public void setBarcodeViewport(int x, int y, int r) { + if (_barCodeObjectEnvironmentGroup == null) { + _barCodeObjectEnvironmentGroup = new BarcodeObjectEnvironmentGroup(_bcocaObject); + } + _barCodeObjectEnvironmentGroup.setObjectArea(x, y, r); + } + + /** + * Set the data of the barcode. + * @param data the barcode data + */ + public void setBarCodeData(BarcodeData barcodeData) { + + _barCodeData = barcodeData; + + } + + + /** + * Accessor method to write the AFP datastream for the Image Object + * @param os The stream to write to + * @throws java.io.IOException + */ + public void writeDataStream(OutputStream os) + throws IOException { + + writeStart(os); + + if (_barCodeObjectEnvironmentGroup != null) { + _barCodeObjectEnvironmentGroup.writeDataStream(os); + } + + if (_barCodeData != null) { + _barCodeData.writeDataStream(os); + } + + writeEnd(os); + + } + + /** + * Helper method to write the start of the Image Object. + * @param os The stream to write to + */ + private void writeStart(OutputStream os) + throws IOException { + + byte[] data = new byte[17]; + + data[0] = 0x5A; // Structured field identifier + data[1] = 0x00; // Length byte 1 + data[2] = 0x10; // Length byte 2 + data[3] = (byte) 0xD3; // Structured field id byte 1 + data[4] = (byte) 0xA8; // Structured field id byte 2 + data[5] = (byte) 0xEB; // Structured field id byte 3 + data[6] = 0x00; // Flags + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + for (int i = 0; i < _nameBytes.length; i++) { + + data[9 + i] = _nameBytes[i]; + + } + + os.write(data); + + } + + /** + * Helper method to write the end of the Image Object. + * @param os The stream to write to + */ + private void writeEnd(OutputStream os) + throws IOException { + + byte[] data = new byte[17]; + + data[0] = 0x5A; // Structured field identifier + data[1] = 0x00; // Length byte 1 + data[2] = 0x10; // Length byte 2 + data[3] = (byte) 0xD3; // Structured field id byte 1 + data[4] = (byte) 0xA9; // Structured field id byte 2 + data[5] = (byte) 0xEB; // Structured field id byte 3 + data[6] = 0x00; // Flags + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + for (int i = 0; i < _nameBytes.length; i++) { + + data[9 + i] = _nameBytes[i]; + + } + + os.write(data); + + } + +} Index: src/java/org/apache/fop/render/afp/modca/BarcodeObjectEnvironmentGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/BarcodeObjectEnvironmentGroup.java (revision 0) +++ src/java/org/apache/fop/render/afp/modca/BarcodeObjectEnvironmentGroup.java (revision 0) @@ -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.modca; + +import org.apache.fop.render.afp.bcoca.BarcodeSymbologies; + +/** + * A Barcode Object Environment Group (OEG) may be associated with an object and + * is contained within the object's begin-end envelope. + * + * The object environment group defines the object's origin and orientation on + * the page, and can contain font and color attribute table information. The + * scope of an object environment group is the scope of its containing object. + * + * An application that creates a data-stream document may omit some of the + * parameters normally contained in the object environment group, or it may + * specify that one or more default values are to be used. + */ +public final class BarcodeObjectEnvironmentGroup extends ObjectEnvironmentGroup { + + /** + * Default name for the object environment group + */ + protected static final String DEFAULT_NAME = "BOEG0001"; + + /** + * the barcode attributes + */ + private BarcodeSymbologies _bcocaObject; + + /** + * Constructor for the BarcodeObjectEnvironmentGroup + * + * @param bcoca + * the barcode attributes + */ + public BarcodeObjectEnvironmentGroup(BarcodeSymbologies bcoca) { + + this(DEFAULT_NAME, bcoca); + + } + + /** + * Constructor for the BarcodeObjectEnvironmentGroup, this takes a name + * parameter which must be 8 characters long. + * + * @param name + * the barcode object environment group name + * @param bcoca + * the barcode attributes + */ + public BarcodeObjectEnvironmentGroup(String name, BarcodeSymbologies bcoca) { + + super(name); + _bcocaObject = bcoca; + _dataDescriptor = new BarcodeDataDescriptor(_bcocaObject); + if (_bcocaObject.getMpts2unitsFactor() == 50) { + _unitOfMeasure = 14400; + } else if (_bcocaObject.getMpts2unitsFactor() == 300) { + _unitOfMeasure = 2400; + } + + } + + /** + * @see ObjectEnvironmentGroup#setObjectArea(int, int, int, int, int) + */ + public void setObjectArea(int x, int y, int rotation) { + super.setObjectArea(x, y, _bcocaObject.getWidth(), _bcocaObject.getHeight(), rotation); + } + +} \ No newline at end of file Index: src/java/org/apache/fop/render/afp/modca/DataDescriptor.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/DataDescriptor.java (revision 0) +++ src/java/org/apache/fop/render/afp/modca/DataDescriptor.java (revision 0) @@ -0,0 +1,29 @@ +/* + * 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; + +import java.io.IOException; +import java.io.OutputStream; + +public interface DataDescriptor { + + public void writeDataStream(OutputStream os) throws IOException; + +} Index: src/java/org/apache/fop/render/afp/modca/Document.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/Document.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/Document.java (working copy) @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Iterator; Index: src/java/org/apache/fop/render/afp/modca/EndPageGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/EndPageGroup.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/EndPageGroup.java (working copy) @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** * The End Named Page Group (ENG) structured field terminates a page group that was Index: src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java (working copy) @@ -25,7 +25,7 @@ /** */ -public class ImageDataDescriptor extends AbstractAFPObject { +public class ImageDataDescriptor extends AbstractAFPObject implements DataDescriptor { private int _xresol = 0; private int _yresol = 0; Index: src/java/org/apache/fop/render/afp/modca/ImageObject.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ImageObject.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/ImageObject.java (working copy) @@ -22,7 +22,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; + import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -33,7 +33,7 @@ /** * The object environment group */ - private ObjectEnvironmentGroup _objectEnvironmentGroup = null; + private ImageObjectEnvironmentGroup _imageObjectEnvironmentGroup = null; /** * The image segment @@ -66,10 +66,10 @@ * the rotation of the image */ public void setImageViewport(int x, int y, int w, int h, int r) { - if (_objectEnvironmentGroup == null) { - _objectEnvironmentGroup = new ObjectEnvironmentGroup(); + if (_imageObjectEnvironmentGroup == null) { + _imageObjectEnvironmentGroup = new ImageObjectEnvironmentGroup(); } - _objectEnvironmentGroup.setObjectArea(x, y, w, h, r); + _imageObjectEnvironmentGroup.setObjectArea(x, y, w, h, r); } /** @@ -80,10 +80,10 @@ * @param height the image height */ public void setImageParameters(int xresol, int yresol, int width, int height) { - if (_objectEnvironmentGroup == null) { - _objectEnvironmentGroup = new ObjectEnvironmentGroup(); + if (_imageObjectEnvironmentGroup == null) { + _imageObjectEnvironmentGroup = new ImageObjectEnvironmentGroup(); } - _objectEnvironmentGroup.setImageData(xresol, yresol, width, height); + _imageObjectEnvironmentGroup.setImageData(xresol, yresol, width, height); if (_imageSegment == null) { _imageSegment = new ImageSegment(); } @@ -146,11 +146,11 @@ } /** - * Sets the ObjectEnvironmentGroup. + * Sets the ImageObjectEnvironmentGroup. * @param objectEnvironmentGroup The objectEnvironmentGroup to set */ - public void setObjectEnvironmentGroup(ObjectEnvironmentGroup objectEnvironmentGroup) { - _objectEnvironmentGroup = objectEnvironmentGroup; + public void setObjectEnvironmentGroup(ImageObjectEnvironmentGroup imageObjectEnvironmentGroup) { + _imageObjectEnvironmentGroup = imageObjectEnvironmentGroup; } /** @@ -190,8 +190,8 @@ writeStart(os); - if (_objectEnvironmentGroup != null) { - _objectEnvironmentGroup.writeDataStream(os); + if (_imageObjectEnvironmentGroup != null) { + _imageObjectEnvironmentGroup.writeDataStream(os); } if (_imageSegment != null) { Index: src/java/org/apache/fop/render/afp/modca/ImageObjectEnvironmentGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ImageObjectEnvironmentGroup.java (revision 0) +++ src/java/org/apache/fop/render/afp/modca/ImageObjectEnvironmentGroup.java (revision 0) @@ -0,0 +1,73 @@ +/* + * 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; + + +/** + * An Image Object Environment Group (OEG) may be associated with an object and is contained + * within the object's begin-end envelope. + * + * The object environment group defines the object's origin and orientation on the page, + * and can contain font and color attribute table information. The scope of an object + * environment group is the scope of its containing object. + * + * An application that creates a data-stream document may omit some of the parameters + * normally contained in the object environment group, or it may specify that one or + * more default values are to be used. + */ +public final class ImageObjectEnvironmentGroup extends ObjectEnvironmentGroup { + + /** + * Default name for the object environment group + */ + protected static final String DEFAULT_NAME = "IOEG0001"; + + /** + * Default constructor for the ImageObjectEnvironmentGroup. + */ + public ImageObjectEnvironmentGroup() { + + this(DEFAULT_NAME); + + } + + /** + * Constructor for the ImageObjectEnvironmentGroup, this takes a + * name parameter which must be 8 characters long. + * @param name the object environment group name + */ + public ImageObjectEnvironmentGroup(String name) { + + super(name); + + } + + /** + * Set the dimensions of the image. + * @param xresol the x resolution of the image + * @param yresol the y resolution of the image + * @param width the image width + * @param height the image height + */ + public void setImageData(int xresol, int yresol, int width, int height) { + _dataDescriptor = new ImageDataDescriptor(xresol, yresol, width, height); + } + +} \ No newline at end of file Index: src/java/org/apache/fop/render/afp/modca/IMImageObject.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/IMImageObject.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/IMImageObject.java (working copy) @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** * An IM image data object specifies the contents of a raster image and Index: src/java/org/apache/fop/render/afp/modca/IncludeObject.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/IncludeObject.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/IncludeObject.java (working copy) @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; Index: src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java (working copy) @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; Index: src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java (working copy) @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; Index: src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java (working copy) @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import org.apache.fop.render.afp.tools.BinaryUtils; Index: src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java (working copy) @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.OutputStream; + import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -32,17 +33,20 @@ private int _width = 0; private int _height = 0; + private int _unitOfMeasure = 0; /** * Construct an object area descriptor for the specified object width * and object height. - * @param width The page width. - * @param height The page height. + * @param width The area width + * @param height The area height + * @param unitOfMeasure The unit of measure */ - public ObjectAreaDescriptor(int width, int height) { + public ObjectAreaDescriptor(int width, int height, int unitOfMeasure) { _width = width; _height = height; + _unitOfMeasure = unitOfMeasure; } @@ -53,6 +57,8 @@ */ public void writeDataStream(OutputStream os) throws IOException { + + byte[] uom = BinaryUtils.convert(_unitOfMeasure); byte[] data = new byte[] { 0x5A, @@ -70,11 +76,11 @@ 0x08, // Triplet length 0x4B, // tid = Measurement Units Triplet 0x00, // XaoBase = 10 inches - 0x00, // YaoBase = 10 inches - 0x09, // XaoUnits = 2400 - 0x60, // XaoUnits = - 0x09, // YaoUnits = 2400 - 0x60, // YaoUnits = + 0x00, // YaoBase = 10 inches + uom[0], // XaoUnits + uom[1], // XaoUnits + uom[0], // YaoUnits + uom[1], // YaoUnits 0x09, // Triplet length 0x4C, // tid = Object Area Size 0x02, // Size Type @@ -103,5 +109,5 @@ os.write(data); } - + } \ No newline at end of file Index: src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java (working copy) @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; /** @@ -34,14 +33,9 @@ * normally contained in the object environment group, or it may specify that one or * more default values are to be used. */ -public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { +public abstract class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** - * Default name for the object environment group - */ - private static final String DEFAULT_NAME = "OEG00001"; - - /** * The ObjectAreaDescriptor for the object environment group */ private ObjectAreaDescriptor _objectAreaDescriptor = null; @@ -52,19 +46,15 @@ private ObjectAreaPosition _objectAreaPosition = null; /** - * The ImageDataDescriptor for the object environment group + * The DataDescriptor for the object environment group */ - private ImageDataDescriptor _imageDataDescriptor = null; - + protected DataDescriptor _dataDescriptor = null; + /** - * Default constructor for the ObjectEnvironmentGroup. + * The unit of measure (default 2400) */ - public ObjectEnvironmentGroup() { + protected int _unitOfMeasure = 2400; - this(DEFAULT_NAME); - - } - /** * Constructor for the ObjectEnvironmentGroup, this takes a * name parameter which must be 8 characters long. @@ -86,23 +76,12 @@ */ public void setObjectArea(int x, int y, int width, int height, int rotation) { - _objectAreaDescriptor = new ObjectAreaDescriptor(width, height); + _objectAreaDescriptor = new ObjectAreaDescriptor(width, height, _unitOfMeasure); _objectAreaPosition = new ObjectAreaPosition(x, y, rotation); } - + /** - * Set the dimensions of the image. - * @param xresol the x resolution of the image - * @param yresol the y resolution of the image - * @param width the image width - * @param height the image height - */ - public void setImageData(int xresol, int yresol, int width, int height) { - _imageDataDescriptor = new ImageDataDescriptor(xresol, yresol, width, height); - } - - /** * Accessor method to obtain write the AFP datastream for * the object environment group. * @param os The stream to write to @@ -118,8 +97,8 @@ _objectAreaPosition.writeDataStream(os); - if (_imageDataDescriptor != null) { - _imageDataDescriptor.writeDataStream(os); + if (_dataDescriptor != null) { + _dataDescriptor.writeDataStream(os); } writeEnd(os); Index: src/java/org/apache/fop/render/afp/modca/Overlay.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/Overlay.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/Overlay.java (working copy) @@ -19,10 +19,8 @@ package org.apache.fop.render.afp.modca; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.Iterator; /** */ Index: src/java/org/apache/fop/render/afp/modca/PageGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/PageGroup.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/PageGroup.java (working copy) @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; Index: src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java (working copy) @@ -22,7 +22,6 @@ import java.awt.Color; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; /** Index: src/java/org/apache/fop/render/afp/modca/ResourceGroup.java =================================================================== --- src/java/org/apache/fop/render/afp/modca/ResourceGroup.java (revision 527506) +++ src/java/org/apache/fop/render/afp/modca/ResourceGroup.java (working copy) @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -35,7 +34,6 @@ */ private static final String DEFAULT_NAME = "RG000001"; - /** * The overlays contained in this resource group */ Index: src/java/org/apache/fop/render/afp/tools/BinaryUtils.java =================================================================== --- src/java/org/apache/fop/render/afp/tools/BinaryUtils.java (revision 527506) +++ src/java/org/apache/fop/render/afp/tools/BinaryUtils.java (working copy) @@ -128,5 +128,37 @@ shortToByteArray(value, serverValue, 0); return serverValue; } + + /** + * Returns true if the specified bit is set, + * false otherwise. Bits are numbered 0-7.

+ * + * @param b the byte value to check bits on. + * @param pos the number of the bit to check. + * @return true if the bit is set, false otherwise. + */ + public static boolean getBit(final byte b, final int pos) + { + return (b & (1 << pos)) != 0; + } + + /** + *

Sets the specified bit to 1 if value parameter is true, unsets the + * bit otherwise. Bits are numbered 0-7.

+ * + * @param b the byte value to set bits in. + * @param pos the number of the bit to set. + * @param value true if the bit should be set false otherwise. + * @return an byte with the specified bit set/unset. + **/ + public static byte setBit(final byte b, final int pos, final boolean value) + { + if (value) { + return (byte)(b | (1 << pos)); + } + return (byte)(b & ~(1 << pos)); + } + } +