diff options
author | Peter Hancock <phancock@apache.org> | 2011-07-27 12:50:12 +0000 |
---|---|---|
committer | Peter Hancock <phancock@apache.org> | 2011-07-27 12:50:12 +0000 |
commit | eee73c4deda72cc6610e7fc78e54301b5e968a4b (patch) | |
tree | 24f4f7e1b47bed35f04ce78d7a65fdc039fbeaac /test/java/org/apache/fop | |
parent | 24158d577f1512d4c765c73829c96197154d1e2a (diff) | |
download | xmlgraphics-fop-eee73c4deda72cc6610e7fc78e54301b5e968a4b.tar.gz xmlgraphics-fop-eee73c4deda72cc6610e7fc78e54301b5e968a4b.zip |
Fixed a bug in AFP where the object area axes of an Include Object was incorrectly set when rotated by 180
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1151452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop')
7 files changed, 697 insertions, 2 deletions
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index d6a6f8367..01e3a365e 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -28,7 +28,6 @@ import org.apache.fop.fonts.DejaVuLGCSerifTest; import org.apache.fop.image.loader.batik.ImageLoaderTestCase; import org.apache.fop.image.loader.batik.ImagePreloaderTestCase; import org.apache.fop.intermediate.IFMimickingTestCase; -import org.apache.fop.render.afp.AFPTestSuite; import org.apache.fop.render.extensions.prepress.PageBoundariesTest; import org.apache.fop.render.extensions.prepress.PageScaleTest; import org.apache.fop.render.pdf.PDFAConformanceTestCase; @@ -53,13 +52,14 @@ public class StandardTestSuite { //$JUnit-BEGIN$ suite.addTest(BasicDriverTestSuite.suite()); suite.addTest(UtilityCodeTestSuite.suite()); + suite.addTest(org.apache.fop.afp.AFPTestSuite.suite()); suite.addTest(new TestSuite(PDFAConformanceTestCase.class)); suite.addTest(new TestSuite(PDFEncodingTestCase.class)); suite.addTest(new TestSuite(PDFCMapTestCase.class)); suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class)); suite.addTest(new TestSuite(DejaVuLGCSerifTest.class)); suite.addTest(new TestSuite(MODCAParserTestCase.class)); - suite.addTest(AFPTestSuite.suite()); + suite.addTest(org.apache.fop.render.afp.AFPTestSuite.suite()); suite.addTest(PSTestSuite.suite()); suite.addTest(RichTextFormatTestSuite.suite()); suite.addTest(new TestSuite(ImageLoaderTestCase.class)); diff --git a/test/java/org/apache/fop/afp/AFPTestSuite.java b/test/java/org/apache/fop/afp/AFPTestSuite.java new file mode 100644 index 000000000..c32eab6ea --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPTestSuite.java @@ -0,0 +1,44 @@ +/* + * 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; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.fop.afp.modca.AbstractStructuredObjectTestCase; +import org.apache.fop.afp.modca.AbstractTripletStructuredObjectTestCase; +import org.apache.fop.afp.modca.IncludeObjectTestCase; + +/** + * Test suite for FOP's AFP classes. + */ +public class AFPTestSuite { + /** + * Builds the test suite + * @return the test suite + */ + public static Test suite() { + TestSuite suite = new TestSuite("Test suite for FOP's AFP classes"); + //$JUnit-BEGIN$ + suite.addTest(new TestSuite(IncludeObjectTestCase.class)); + //$JUnit-END$ + return suite; + } +} diff --git a/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTestCase.java new file mode 100644 index 000000000..815939da4 --- /dev/null +++ b/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTestCase.java @@ -0,0 +1,245 @@ +/* + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.fop.afp.Streamable; + +/** + * Tests the {@link AbstractAFPObject} class. + */ +public abstract class AbstractAFPObjectTestCase<S extends AbstractAFPObject> + extends TestCase { + + private S sut; + + protected final S getSut() { + return sut; + } + + protected final void setSut(S sut) { + if ( this.sut == null) { + this.sut = sut; + } + } + + + private byte[] header = new byte[] { + 0x5A, // Structured field identifier + 0x00, // Length byte 1 + 0x10, // Length byte 2 + 0x00, // Structured field id byte 1 + 0x00, // Structured field id byte 2 + 0x00, // Structured field id byte 3 + 0x00, // Flags + 0x00, // Reserved + 0x00 // Reserved + }; + + + public void testCopySFStatic() { + byte[] actual = new byte[9]; + Arrays.fill(actual, (byte)-1); + + S.copySF(actual, (byte)0, (byte)0, (byte)0); + + assertTrue(Arrays.equals(actual, header)); + + byte[] expected2 = new byte[9]; + System.arraycopy(header, 0, expected2, 0, header.length); + + final byte clazz = (byte) 0x01; + final byte type = (byte) 0x02; + final byte catagory = (byte) 0x03; + expected2[3] = clazz; + expected2[4] = type; + expected2[5] = catagory; + + AbstractAFPObject.copySF(actual, clazz, type, catagory); + + assertTrue(Arrays.equals(actual, expected2)); + } + + public void testCopySF() { + byte[] expected = new byte[9]; + S.copySF(expected, (byte) 0xD3, (byte)0, (byte)0); + + byte[] actual = new byte[9]; + Arrays.fill(actual, (byte)-1); + + getSut().copySF(actual, (byte)0, (byte)0); + + assertTrue(Arrays.equals(actual, expected)); + + byte[] expected2 = new byte[9]; + System.arraycopy(expected, 0, expected2, 0, expected.length); + + final byte type = (byte)1; + final byte catagory = (byte)2; + expected2[4] = type; + expected2[5] = catagory; + + getSut().copySF(actual, type, catagory); + + assertTrue(Arrays.equals(actual, expected2)); + } + + /** + * + */ + public void testwriteObjects() { + final byte[][] expected = {{(byte)0, (byte)1}, {(byte)2, (byte)3}, {(byte)4, (byte)5}}; + + List<Streamable> objects = new ArrayList<Streamable>() { + { + add(StreamableObject.instance(expected[0])); + add(StreamableObject.instance(expected[1])); + add(StreamableObject.instance(expected[2])); + } }; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + try { + getSut().writeObjects(objects, baos); + } catch (IOException e) { + fail(); + } + + byte[] actual = baos.toByteArray(); + + int index = 0; + for (int i = 0; i < expected.length; i++) { + for (int j = 0; j < expected[i].length; j++) { + assertTrue("" + index, actual[index] == expected[i][j]); + index++; + } + } + } + + /** + * + */ + public void testTruncate() { + String expected = "abc"; + assertTrue(AbstractAFPObject.truncate(expected, 4) == expected); + assertTrue(AbstractAFPObject.truncate(expected, 3) == expected); + assertEquals(AbstractAFPObject.truncate(expected + "d", 3), expected); + assertEquals(AbstractAFPObject.truncate(expected, 0), ""); + try { + assertTrue(AbstractAFPObject.truncate(null, 4) == null); + fail(); + } catch (NullPointerException e) { + // PASS + } + } + + /** + * + */ + public void testWriteChunksToStream() throws IOException { + final byte[] data = new byte[256]; + int counter = 0; + for (int i = 0; i < data.length; i++) { + data[i] = (byte) counter++; + } + + byte[] header = new byte[9]; + // Test when chunk size % data.length == 0 + testWithGivenChunkSize(data, header, 16); + + // test when chunk size % data.length != 0 + testWithGivenChunkSize(data, header, 10); + + // test with an odd number... + testWithGivenChunkSize(data, header, 13); + } + + private void testWithGivenChunkSize(byte[] data, byte[] header, int chunkSize) + throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + S.writeChunksToStream(data, header, 0, chunkSize, baos); + byte[] testData = baos.toByteArray(); + + int numberOfFullDataChunks = data.length / chunkSize; + int lastChunkSize = data.length % chunkSize; + int lengthOfTestData = numberOfFullDataChunks * (chunkSize + header.length); + lengthOfTestData += lastChunkSize == 0 ? 0 : header.length + lastChunkSize; + + putLengthInHeader(header, chunkSize); + + assertEquals(lengthOfTestData, testData.length); + int testIndex = 0; + int expectedIndex = 0; + for (int i = 0; i < numberOfFullDataChunks; i++) { + checkHeaderAndData(header, data, testData, expectedIndex, testIndex, chunkSize); + expectedIndex += chunkSize + header.length; + testIndex += chunkSize; + } + + putLengthInHeader(header, lastChunkSize); + // check last chunk + if (lastChunkSize != 0) { + checkHeaderAndData(header, data, testData, expectedIndex, testIndex, lastChunkSize); + } + } + + private void putLengthInHeader(byte[] header, int chunkSize) { + header[0] = 0; + header[1] = (byte) (chunkSize + header.length); + } + + private void checkHeaderAndData(byte[] header, byte[] data, byte[] testData, int expectedIndex, + int testIndex, int chunkSize) { + for (int i = 0; i < header.length; i++) { + assertEquals(testData[expectedIndex++], header[i]); + } + for (int i = 0; i < chunkSize; i++) { + assertEquals(testData[expectedIndex++], data[i + testIndex]); + } + } + + /** + * + */ + private static class StreamableObject implements Streamable { + private byte[] bytes; + + StreamableObject(byte[] bytes) { + this.bytes = new byte[bytes.length]; + System.arraycopy(bytes, 0, this.bytes, 0, bytes.length); + } + + private static Streamable instance(byte[] bytes) { + return new StreamableObject(bytes); + } + + public void writeToStream(OutputStream os) throws IOException { + os.write(bytes); + } + } +} diff --git a/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTestCase.java new file mode 100644 index 000000000..975c26994 --- /dev/null +++ b/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTestCase.java @@ -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.afp.modca; + +import java.util.Arrays; + +/** + * Tests the {@linkplain AbstractAFPObject} class. + */ +public abstract class AbstractNamedAFPObjectTestCase<S extends AbstractNamedAFPObject> + extends AbstractAFPObjectTestCase<S> { + + public void testCopySF() { + + final S sut = getSut(); + + byte[] expected = new byte[17]; + S.copySF(expected, (byte) 0xD3, (byte)0, (byte)0); + + byte[] nameData = sut.getNameBytes(); + System.arraycopy(nameData, 0, expected, 9, nameData.length); + + byte[] actual = new byte[17]; + Arrays.fill(actual, (byte)-1); + + getSut().copySF(actual, (byte)0, (byte)0); + + assertTrue(Arrays.equals(actual, expected)); + + byte[] expected2 = new byte[17]; + System.arraycopy(expected, 0, expected2, 0, expected.length); + System.arraycopy(nameData, 0, expected, 9, nameData.length); + + final byte type = (byte)1; + final byte catagory = (byte)2; + expected2[4] = type; + expected2[5] = catagory; + + getSut().copySF(actual, type, catagory); + + assertTrue(Arrays.equals(actual, expected2)); + } +} diff --git a/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTestCase.java new file mode 100644 index 000000000..e5bf70c7a --- /dev/null +++ b/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTestCase.java @@ -0,0 +1,63 @@ +/* + * 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; + +public abstract class AbstractStructuredObjectTestCase<S extends AbstractStructuredObject> extends AbstractAFPObjectTestCase<S> { + + /** + * Test writeStart() - test that the contract is maintained with + * {@link AbstractStructuredObject}. + * + * @throws IOException + */ + public void testwriteStart() throws IOException { + } + + /** + * Test writeEnd() - test that the contract is maintained with {@link AbstractStructuredObject}. + * + * @throws IOException + */ + public void testWriteEnd() throws IOException { + } + + /** + * Test writeContent() - test that the contract is maintained with + * {@link AbstractStructuredObject}. + * + * @throws IOException + */ + public void testWriteContent() throws IOException { + } + + /** + * Test writeToStream() - test that the contract is maintained with + * {@link AbstractStructuredObject}. + * + * @throws IOException + */ + public void testWriteToStream() throws IOException { + testwriteStart(); + testWriteEnd(); + testWriteContent(); + } +} diff --git a/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTestCase.java new file mode 100644 index 000000000..ebb0f42e9 --- /dev/null +++ b/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTestCase.java @@ -0,0 +1,154 @@ +/* + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.apache.fop.afp.modca.triplets.AbstractTriplet; +import org.apache.fop.afp.modca.triplets.AttributeQualifierTriplet; +import org.apache.fop.afp.modca.triplets.CommentTriplet; +import org.apache.fop.afp.modca.triplets.ObjectAreaSizeTriplet; +import org.apache.fop.afp.modca.triplets.Triplet; + +/** + * Test {@link AbstractTripletStructuredObject} + */ +public abstract class AbstractTripletStructuredObjectTestCase<S extends AbstractTripletStructuredObject> + extends AbstractStructuredObjectTestCase<AbstractTripletStructuredObject> { + + private static final List<AbstractTriplet> TRIPLETS; + + static { + List<AbstractTriplet> triplets = new ArrayList<AbstractTriplet>(); + + triplets.add(new CommentTriplet((byte) 0x01, "test comment")); + + triplets.add(new AttributeQualifierTriplet(1, 1)); + + triplets.add(new ObjectAreaSizeTriplet(10, 20)); + + TRIPLETS = Collections.unmodifiableList(triplets); + } + + private AbstractTripletStructuredObject emptyStructuredObject + = new AbstractTripletStructuredObject() { }; + + @Override + public void setUp() throws Exception { + super.setUp(); + + AbstractTripletStructuredObject sut = getSut(); + + for (AbstractTriplet triplet : TRIPLETS) { + sut.addTriplet(triplet); + } + } + + + /** + * Test getTripletLength() - ensure a sum of all enclosing object lengths is returned. + */ + public void testGetTripletLength() { + + int dataLength = 0; + for (Triplet t : TRIPLETS) { + dataLength += t.getDataLength(); + } + assertEquals(dataLength, getSut().getTripletDataLength()); + assertEquals(0, emptyStructuredObject.getTripletDataLength()); + } + + /** + * Test hasTriplets() + */ + public void testHasTriplets() { + assertTrue(getSut().hasTriplets()); + assertFalse(emptyStructuredObject.hasTriplets()); + } + + /** + * Test writeTriplets() - Ensure the triplets are written properly. + * + * @throws IOException - + */ + public void testWriteObjects() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (AbstractTriplet triplet : TRIPLETS) { + triplet.writeToStream(baos); + } + byte[] expected = baos.toByteArray(); + baos.reset(); + getSut().writeTriplets(baos); + assertTrue(Arrays.equals(expected, baos.toByteArray())); + + baos.reset(); + // Ensure it doesn't die if no data has been added + emptyStructuredObject.writeTriplets(baos); + byte[] emptyArray = baos.toByteArray(); + assertTrue(Arrays.equals(emptyArray, new byte[0])); + } + + /** + * Test hasTriplet() - ensure both positive and negative values are returned. + */ + public void testHasTriplet() { + for (AbstractTriplet triplet : TRIPLETS) { + assertTrue(getSut().hasTriplet(triplet.getId())); + assertFalse(emptyStructuredObject.hasTriplet(triplet.getId())); + } + CommentTriplet notInSystem = new CommentTriplet((byte) 0x30, "This should return false"); + assertFalse(getSut().hasTriplet(notInSystem.getId())); + } + + /** + * Test addTriplet() - mostly tested above, but check boundary cases + */ + public void testAddTriplet() { + // ensure null doesn't kill it... not sure what else to test + getSut().addTriplet(null); + } + + /** + * Test addTriplets() - ensure all triplets are added. + */ + public void testAddTriplets() { + // Tested on empty object + List<AbstractTriplet> expectedList = TRIPLETS; + emptyStructuredObject.addTriplets(expectedList); + // checks equals() on each member of both lists + assertEquals(expectedList, emptyStructuredObject.getTriplets()); + + // Add a list to an already populated list + getSut().addTriplets(expectedList); + + List<AbstractTriplet> newExpected = new ArrayList<AbstractTriplet>(expectedList); + newExpected.addAll(expectedList); + assertEquals(newExpected, getSut().getTriplets()); + + // Ensure null doesn't throw exception + emptyStructuredObject.addTriplets(null); + } + +}
\ No newline at end of file diff --git a/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java b/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java new file mode 100644 index 000000000..5e28f00bd --- /dev/null +++ b/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java @@ -0,0 +1,129 @@ +/* + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; + +import org.apache.fop.afp.util.BinaryUtils; + +/** + * Test {@link IncludeObject} + */ +public class IncludeObjectTestCase extends AbstractNamedAFPObjectTestCase<IncludeObject> { + + @Override + public void setUp() throws Exception { + setSut(new IncludeObject("8__chars")); + super.setUp(); + } + + /** + * Test writeToStream() + * @throws IOException - + */ + public void testWriteToStream() throws IOException { + final IncludeObject sut = getSut(); + + byte[] expected = defaultIncludeObjectBytes(sut.getTripletDataLength(), sut.getNameBytes()); + + testWriteToStreamHelper(sut, expected); + } + + /** + * Test writeToStream() - the orientation of the referenced object is a right- + * handed with a 180 x-axis + * @throws IOException - + */ + public void testWriteToStreamForOrientation() throws IOException { + final IncludeObject sut = getSut(); + + byte[] expected = defaultIncludeObjectBytes(sut.getTripletDataLength(), sut.getNameBytes()); + + expected[25] = (byte)0x5A; + expected[26] = (byte)0x00; + expected[27] = (byte)0x87; + expected[28] = (byte)0x00; + + sut.setObjectAreaOrientation(180); + + testWriteToStreamHelper(sut, expected); + } + + private void testWriteToStreamHelper(IncludeObject sut, byte[] expected) throws IOException { + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + sut.writeToStream(baos); + + byte[] actual = baos.toByteArray(); + + assertTrue(Arrays.equals(actual, expected)); + } + + private byte[] defaultIncludeObjectBytes(int tripletDataLength, byte[] nameData) { + + byte[] expected = new byte[36]; + + byte[] header = new byte[] { + 0x5A, // Structured field identifier + 0x00, // Length byte 1 + 0x10, // Length byte 2 + (byte)0xD3, // Structured field id byte 1 + (byte)0xAF, // Structured field id byte 2 - type 'input' + (byte)0xC3, // Structured field id byte 3 - category 'data resource' + 0x00, // Flags + 0x00, // Reserved + 0x00, // Reserved + }; + + System.arraycopy(header, 0, expected, 0, header.length); + + byte[] lengthBytes = BinaryUtils.convert(35 + tripletDataLength, 2); //Ignore first byte + expected[1] = lengthBytes[0]; + expected[2] = lengthBytes[1]; + + System.arraycopy(nameData, 0, expected, 9, nameData.length); + + expected[18] = (byte)0x92; // object type 'other' + + expected[27] = (byte)0x2D; // orientation of the reference object + writeOsetTo(expected, 29, -1); // the X-axis origin defined in the object + writeOsetTo(expected, 32, -1); // the Y-axis origin defined in the object + + expected[35] = 0x01; // Page or overlay coordinate system + + return expected; + } + + private static void writeOsetTo(byte[] out, int offset, int oset) { + if (oset > -1) { + byte[] y = BinaryUtils.convert(oset, 3); + out[offset] = y[0]; + out[offset + 1] = y[1]; + out[offset + 2] = y[2]; + } else { + out[offset] = (byte)0xFF; + out[offset + 1] = (byte)0xFF; + out[offset + 2] = (byte)0xFF; + } + } +}
\ No newline at end of file |