You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PreprocessPresentationObject.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
  22. import org.apache.fop.afp.util.BinaryUtils;
  23. /**
  24. * The Preprocess Presentation Object structured field specifies presentation
  25. * parameters for a data object that has been mapped as a resource.
  26. */
  27. public class PreprocessPresentationObject extends AbstractTripletStructuredObject {
  28. private static final byte TYPE_OTHER = (byte)0x92;
  29. private static final byte TYPE_OVERLAY = (byte)0xDF;
  30. private static final byte TYPE_IMAGE = (byte)0xFB;
  31. private byte objType = TYPE_OTHER;
  32. private byte objOrent; // object always processed at 0 degree orientation
  33. private int objXOffset = -1;
  34. private int objYOffset = -1;
  35. /**
  36. * Main constructor
  37. *
  38. * @param prePresObj the presentation object to be preprocessed
  39. */
  40. public PreprocessPresentationObject(AbstractTripletStructuredObject prePresObj) {
  41. if (prePresObj instanceof ImageObject || prePresObj instanceof Overlay) {
  42. if (prePresObj instanceof ImageObject) {
  43. this.objType = TYPE_IMAGE;
  44. } else {
  45. this.objType = TYPE_OVERLAY;
  46. }
  47. setFullyQualifiedName(
  48. FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
  49. FullyQualifiedNameTriplet.FORMAT_CHARSTR,
  50. prePresObj.getFullyQualifiedName());
  51. } else {
  52. this.objType = TYPE_OTHER;
  53. }
  54. }
  55. /** 0 degrees orientation */
  56. public static final byte ORIENTATION_ZERO_DEGREES = 1;
  57. /** 90 degrees orientation */
  58. public static final byte ORIENTATION_90_DEGREES = 2;
  59. /** 180 degrees orientation */
  60. public static final byte ORIENTATION_180_DEGREES = 4;
  61. /** 270 degrees orientation */
  62. public static final byte ORIENTATION_270_DEGREES = 8;
  63. /**
  64. * Sets the object orientations relative to media leading edge
  65. *
  66. * @param orientation the object orientations relative to media leading edge
  67. */
  68. public void setOrientation(byte orientation) {
  69. objOrent = orientation;
  70. }
  71. /**
  72. * Sets the X axis origin for object content
  73. *
  74. * @param xOffset the X axis origin for object content
  75. */
  76. public void setXOffset(int xOffset) {
  77. this.objXOffset = xOffset;
  78. }
  79. /**
  80. * Sets the Y axis origin for object content
  81. *
  82. * @param yOffset the Y axis origin for object content
  83. */
  84. public void setYOffset(int yOffset) {
  85. this.objYOffset = yOffset;
  86. }
  87. /** {@inheritDoc} */
  88. public void writeStart(OutputStream os) throws IOException {
  89. super.writeStart(os);
  90. byte[] data = new byte[9];
  91. copySF(data, Type.PROCESS, Category.DATA_RESOURCE);
  92. byte[] l = BinaryUtils.convert(19 + getTripletDataLength(), 2);
  93. data[1] = l[0]; // Length byte 1
  94. data[2] = l[1]; // Length byte 1
  95. os.write(data);
  96. }
  97. /** {@inheritDoc} */
  98. public void writeContent(OutputStream os) throws IOException {
  99. byte[] data = new byte[12];
  100. byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2);
  101. data[0] = l[0]; // RGLength
  102. data[1] = l[1]; // RGLength
  103. data[2] = objType; // ObjType
  104. data[3] = 0x00; // Reserved
  105. data[4] = 0x00; // Reserved
  106. data[5] = objOrent; // ObjOrent
  107. if (objXOffset > 0) {
  108. byte[] xOff = BinaryUtils.convert(objYOffset, 3);
  109. data[6] = xOff[0]; // XocaOset (not specified)
  110. data[7] = xOff[1]; // XocaOset
  111. data[8] = xOff[2]; // XocaOset
  112. } else {
  113. data[6] = (byte)0xFF; // XocaOset (not specified)
  114. data[7] = (byte)0xFF; // XocaOset
  115. data[8] = (byte)0xFF; // XocaOset
  116. }
  117. if (objYOffset > 0) {
  118. byte[] yOff = BinaryUtils.convert(objYOffset, 3);
  119. data[9] = yOff[0]; // YocaOset (not specified)
  120. data[10] = yOff[1]; // YocaOset
  121. data[11] = yOff[2]; // YocaOset
  122. } else {
  123. data[9] = (byte)0xFF; // YocaOset (not specified)
  124. data[10] = (byte)0xFF; // YocaOset
  125. data[11] = (byte)0xFF; // YocaOset
  126. }
  127. os.write(data);
  128. writeTriplets(os);
  129. }
  130. }