package org.apache.fop.afp.modca;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.fop.afp.Factory;
+import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
+import org.apache.fop.afp.util.BinaryUtils;
/**
* The document is the highest level of the MO:DCA data-stream document
*/
public final class Document extends AbstractResourceEnvironmentGroupContainer {
+ private static final int CODE_PAGE = 500;
+
/**
* Constructor for the document object.
*
/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
- byte[] data = new byte[17];
- copySF(data, Type.BEGIN, Category.DOCUMENT);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] startData = new byte[17];
+ copySF(startData, Type.BEGIN, Category.DOCUMENT);
+ baos.write(startData);
+ baos.write(0x00);
+ baos.write(0x06); // Total length of triplets (6)
+ /*
+ The triplet below was created following the
+ Mixed Object Document Content Architecture (MO:DCA) Reference
+ */
+ // X'01 triplet
+ baos.write(0x06); //triplet length
+ baos.write(FullyQualifiedNameTriplet.CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER);
+ baos.write(0xFF); //part 1 of GCSGID
+ baos.write(0xFF); //part 2 of GCSGID
+ baos.write(BinaryUtils.convert(CODE_PAGE, 2)); //CPGID
+
+ byte[] data = baos.toByteArray();
+ // Set the total record length
+ byte[] rl1 = BinaryUtils.convert(data.length - 1, 2);
+ data[1] = rl1[0];
+ data[2] = rl1[1];
+
os.write(data);
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import org.apache.fop.afp.fonts.CharacterSet;
import org.apache.fop.afp.fonts.CharacterSetBuilder;
import org.apache.fop.afp.modca.InterchangeSet;
import org.apache.fop.afp.modca.InvokeMediumMap;
import org.apache.fop.afp.modca.PageGroup;
+import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
+import org.apache.fop.afp.util.BinaryUtils;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.util.CharUtilities;
ds.endDocument();
ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
data.skip(21);
+ data.skip(8);
Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
}
ds.endDocument();
ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
data.skip(21);
+ data.skip(8);
Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
}
+
+ @Test
+ public void testMandatoryTripletIsAddedToAFP() throws Exception {
+ ds = new DataStream(new Factory(), paintState, outStream);
+ ds.startDocument();
+ ds.startPageGroup();
+ ds.startPage(1, 1, 0, 1, 1);
+ ds.endPage();
+ ds.endPageGroup();
+ ds.endDocument();
+ ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
+ data.skip(17); //skipping the begin document data
+ Assert.assertEquals("Separation byte", 0x00, (byte) data.read());
+ Assert.assertEquals("Sum of the length of triplets", 0x06, (byte) data.read());
+ Assert.assertEquals("Length of the current triplet", 0x06, (byte) data.read());
+ Assert.assertEquals("Byte code of the mandatory triplet",
+ FullyQualifiedNameTriplet.CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER,
+ (byte) data.read());
+ Assert.assertEquals("Part 1 of the 0xFFFF byte. Sets the character set to All",
+ -1, (byte) data.read());
+ Assert.assertEquals("Part 2 of the 0xFFFF byte. Sets the character set to All",
+ -1, (byte) data.read()); //the 0xFF byte is converted to -1
+ Assert.assertEquals("Part 1 of the default code page id",
+ BinaryUtils.convert(500, 2)[0], (byte) data.read());
+ Assert.assertEquals("Part 2 of the default code page id",
+ BinaryUtils.convert(500, 2)[1], (byte) data.read());
+ }
}
public void testPresentationText() throws Exception {
List<String> strings = new ArrayList<String>();
strings.add("test");
- Assert.assertEquals(writeText(strings), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(writeText(strings), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "DESCRIPTOR PAGE\n"
for (int i = 0; i < 5000; i++) {
strings.add("test");
}
- Assert.assertEquals(writeText(strings), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(writeText(strings), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "DESCRIPTOR PAGE\n"
for (int i = 0; i < 5000; i++) {
strings.add("tes");
}
- Assert.assertEquals(writeText(strings), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(writeText(strings), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "DESCRIPTOR PAGE\n"
InputStream bis = new ByteArrayInputStream(os.toByteArray());
StringBuilder sb = new StringBuilder();
new AFPParser(false).read(bis, sb);
- Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "DESCRIPTOR PAGE\n"
InputStream bis = new ByteArrayInputStream(os.toByteArray());
StringBuilder sb = new StringBuilder();
new AFPParser(false).read(bis, sb);
- Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "DESCRIPTOR PAGE\n"
InputStream bis = new ByteArrayInputStream(os.toByteArray());
StringBuilder sb = new StringBuilder();
new AFPParser(false).read(bis, sb);
- Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "MAP CODED_FONT Triplets: "
format += "END OBJECT_CONTAINER OC000001\n"
+ "END NAME_RESOURCE RES00001\n"
+ "END RESOURCE_GROUP RG000001\n"
- + "BEGIN DOCUMENT DOC00001\n"
+ + "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE_GROUP PGP00001\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
public class PageOverlayTestCase {
@Test
public void testPageOverlay() throws Exception {
- Assert.assertEquals(getPageOverlay(), "BEGIN DOCUMENT DOC00001\n"
+ Assert.assertEquals(getPageOverlay(), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE_GROUP PGP00001\n"
+ "END PAGE_GROUP PGP00001\n"
+ "BEGIN PAGE PGN00001\n"