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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 = 0; // 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. public static final byte ORIENTATION_ZERO_DEGREES = 1;
  56. public static final byte ORIENTATION_90_DEGREES = 2;
  57. public static final byte ORIENTATION_180_DEGREES = 4;
  58. public static final byte ORIENTATION_270_DEGREES = 8;
  59. /**
  60. * Sets the object orientations relative to media leading edge
  61. *
  62. * @param orientation the object orientations relative to media leading edge
  63. */
  64. public void setOrientation(byte orientation) {
  65. objOrent = orientation;
  66. }
  67. /**
  68. * Sets the X axis origin for object content
  69. *
  70. * @param xOffset the X axis origin for object content
  71. */
  72. public void setXOffset(int xOffset) {
  73. this.objXOffset = xOffset;
  74. }
  75. /**
  76. * Sets the Y axis origin for object content
  77. *
  78. * @param yOffset the Y axis origin for object content
  79. */
  80. public void setYOffset(int yOffset) {
  81. this.objYOffset = yOffset;
  82. }
  83. /** {@inheritDoc} */
  84. public void writeStart(OutputStream os) throws IOException {
  85. super.writeStart(os);
  86. byte[] data = new byte[9];
  87. copySF(data, Type.PROCESS, Category.DATA_RESOURCE);
  88. byte[] l = BinaryUtils.convert(19 + getTripletDataLength(), 2);
  89. data[1] = l[0]; // Length byte 1
  90. data[2] = l[1]; // Length byte 1
  91. os.write(data);
  92. }
  93. /** {@inheritDoc} */
  94. public void writeContent(OutputStream os) throws IOException {
  95. byte[] data = new byte[12];
  96. byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2);
  97. data[0] = l[0]; // RGLength
  98. data[1] = l[1]; // RGLength
  99. data[2] = objType; // ObjType
  100. data[3] = 0x00; // Reserved
  101. data[4] = 0x00; // Reserved
  102. data[5] = objOrent; // ObjOrent
  103. if (objXOffset > 0) {
  104. byte[] xOff = BinaryUtils.convert(objYOffset, 3);
  105. data[6] = xOff[0]; // XocaOset (not specified)
  106. data[7] = xOff[1]; // XocaOset
  107. data[8] = xOff[2]; // XocaOset
  108. } else {
  109. data[6] = (byte)0xFF; // XocaOset (not specified)
  110. data[7] = (byte)0xFF; // XocaOset
  111. data[8] = (byte)0xFF; // XocaOset
  112. }
  113. if (objYOffset > 0) {
  114. byte[] yOff = BinaryUtils.convert(objYOffset, 3);
  115. data[9] = yOff[0]; // YocaOset (not specified)
  116. data[10] = yOff[1]; // YocaOset
  117. data[11] = yOff[2]; // YocaOset
  118. } else {
  119. data[9] = (byte)0xFF; // YocaOset (not specified)
  120. data[10] = (byte)0xFF; // YocaOset
  121. data[11] = (byte)0xFF; // YocaOset
  122. }
  123. os.write(data);
  124. writeTriplets(os);
  125. }
  126. }