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.

GraphicsChainedSegment.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.goca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.util.BinaryUtils;
  22. /**
  23. * A GOCA graphics segment
  24. */
  25. public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderContainer {
  26. /** The maximum segment data length */
  27. protected static final int MAX_DATA_LEN = 8192;
  28. private byte[] predecessorNameBytes;
  29. /**
  30. * Main constructor
  31. *
  32. * @param name
  33. * the name of this graphics segment
  34. */
  35. public GraphicsChainedSegment(String name) {
  36. super(name);
  37. }
  38. /**
  39. * Constructor
  40. *
  41. * @param name
  42. * the name of this graphics segment
  43. * @param predecessorNameBytes
  44. * the name of the predecessor in this chain
  45. */
  46. public GraphicsChainedSegment(String name, byte[] predecessorNameBytes) {
  47. super(name);
  48. this.predecessorNameBytes = predecessorNameBytes;
  49. }
  50. /** {@inheritDoc} */
  51. public int getDataLength() {
  52. return 14 + super.getDataLength();
  53. }
  54. private static final byte APPEND_NEW_SEGMENT = 0;
  55. // private static final byte PROLOG = 4;
  56. // private static final byte APPEND_TO_EXISING = 48;
  57. private static final int NAME_LENGTH = 4;
  58. /** {@inheritDoc} */
  59. protected int getNameLength() {
  60. return NAME_LENGTH;
  61. }
  62. /** {@inheritDoc} */
  63. byte getOrderCode() {
  64. return 0x70;
  65. }
  66. /** {@inheritDoc} */
  67. public void writeToStream(OutputStream os) throws IOException {
  68. byte[] data = new byte[14];
  69. data[0] = getOrderCode(); // BEGIN_SEGMENT
  70. data[1] = 0x0C; // Length of following parameters
  71. // segment name
  72. byte[] nameBytes = getNameBytes();
  73. System.arraycopy(nameBytes, 0, data, 2, NAME_LENGTH);
  74. data[6] = 0x00; // FLAG1 (ignored)
  75. data[7] = APPEND_NEW_SEGMENT;
  76. int dataLength = super.getDataLength();
  77. byte[] len = BinaryUtils.convert(dataLength, 2);
  78. data[8] = len[0]; // SEGL
  79. data[9] = len[1];
  80. // P/S NAME (predecessor name)
  81. if (predecessorNameBytes != null) {
  82. System.arraycopy(predecessorNameBytes, 0, data, 10, NAME_LENGTH);
  83. }
  84. os.write(data);
  85. writeObjects(objects, os);
  86. }
  87. /** {@inheritDoc} */
  88. public String toString() {
  89. return "GraphicsChainedSegment(name=" + super.getName() + ")";
  90. }
  91. }