Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

IncludePageOverlay.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.afp.modca;
  18. import java.io.IOException;
  19. import java.io.OutputStream;
  20. import java.io.UnsupportedEncodingException;
  21. import org.apache.fop.render.afp.tools.BinaryUtils;
  22. /**
  23. *
  24. * The Include Page Overlay structured field references an overlay resource
  25. * definition that is to be positioned on the page. A page overlay can be
  26. * referenced at any time during the page state, but not during an object state.
  27. * The overlay contains its own active environment group definition.
  28. *
  29. * Note: There is no need for the triplets, so I have ignored them.
  30. *
  31. * A real example of where this will be used is for static overlays, such as an
  32. * address on the page.
  33. *
  34. */
  35. public class IncludePageOverlay extends AbstractNamedAFPObject {
  36. /**
  37. * The x coordinate
  38. */
  39. private int _xCoor = 0;
  40. /**
  41. * The y coordinate
  42. */
  43. private int _yCoor = 0;
  44. /**
  45. * The orientation
  46. */
  47. private int _orientation = 0;
  48. /**
  49. * Constructor for the Include Page Overlay
  50. * @param overlayName Name of the page segment
  51. * @param x The x position
  52. * @param y The y position
  53. * @param orientation The orientation
  54. */
  55. public IncludePageOverlay(String overlayName, int x, int y, int orientation) {
  56. super(overlayName);
  57. _xCoor = x;
  58. _yCoor = y;
  59. setOrientation(orientation);
  60. }
  61. /**
  62. * Sets the orienation to use for the overlay.
  63. *
  64. * @param orientation
  65. * The orientation (0,90, 180, 270)
  66. */
  67. public void setOrientation(int orientation) {
  68. if (orientation == 0 || orientation == 90 || orientation == 180
  69. || orientation == 270) {
  70. _orientation = orientation;
  71. } else {
  72. throw new IllegalArgumentException(
  73. "The orientation must be one of the values 0, 90, 180, 270");
  74. }
  75. }
  76. /**
  77. * Accessor method to write the AFP datastream for the Include Page Overlay
  78. * @param os The stream to write to
  79. * @throws java.io.IOException
  80. */
  81. public void writeDataStream(OutputStream os)
  82. throws IOException {
  83. byte[] data = new byte[25]; //(9 +16)
  84. data[0] = 0x5A;
  85. // Set the total record length
  86. byte[] rl1 = BinaryUtils.convert(24, 2); //Ignore first byte
  87. data[1] = rl1[0];
  88. data[2] = rl1[1];
  89. // Structured field ID for a IPO
  90. data[3] = (byte) 0xD3;
  91. data[4] = (byte) 0xAF;
  92. data[5] = (byte) 0xD8;
  93. data[6] = 0x00; // Reserved
  94. data[7] = 0x00; // Reserved
  95. data[8] = 0x00; // Reserved
  96. for (int i = 0; i < _nameBytes.length; i++) {
  97. data[9 + i] = _nameBytes[i];
  98. }
  99. byte[] r2 = BinaryUtils.convert(_xCoor, 3);
  100. data[17] = r2[0]; // x coordinate
  101. data[18] = r2[1];
  102. data[19] = r2[2];
  103. byte[] r3 = BinaryUtils.convert(_yCoor, 3);
  104. data[20] = r3[0]; // y coordinate
  105. data[21] = r3[1];
  106. data[22] = r3[2];
  107. switch (_orientation) {
  108. case 90:
  109. data[23] = 0x2D;
  110. data[24] = 0x00;
  111. break;
  112. case 180:
  113. data[23] = 0x5A;
  114. data[24] = 0x00;
  115. break;
  116. case 270:
  117. data[23] = (byte) 0x87;
  118. data[24] = 0x00;
  119. break;
  120. default:
  121. data[23] = 0x00;
  122. data[24] = 0x00;
  123. break;
  124. }
  125. os.write(data);
  126. }
  127. }