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.

GraphicsDataDescriptor.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.util.BinaryUtils;
  22. /**
  23. * GOCA Graphics Data Descriptor
  24. */
  25. public class GraphicsDataDescriptor extends AbstractDescriptor {
  26. private final int xlwind;
  27. private final int xrwind;
  28. private final int ybwind;
  29. private final int ytwind;
  30. /**
  31. * Main constructor
  32. *
  33. * @param xlwind
  34. * the left edge of the graphics window
  35. * @param xrwind
  36. * the right edge of the graphics window
  37. * @param ybwind
  38. * the top edge of the graphics window
  39. * @param ytwind
  40. * the bottom edge of the graphics window
  41. * @param widthRes
  42. * the width resolution of the graphics window
  43. * @param heightRes
  44. * the height resolution of the graphics window
  45. */
  46. public GraphicsDataDescriptor(int xlwind, int xrwind, int ybwind,
  47. int ytwind, int widthRes, int heightRes) {
  48. this.xlwind = xlwind;
  49. this.xrwind = xrwind;
  50. this.ybwind = ybwind;
  51. this.ytwind = ytwind;
  52. super.widthRes = widthRes;
  53. super.heightRes = heightRes;
  54. }
  55. /** {@inheritDoc} */
  56. public void writeToStream(OutputStream os) throws IOException {
  57. byte[] headerData = new byte[9];
  58. copySF(headerData, Type.DESCRIPTOR, Category.GRAPHICS);
  59. byte[] drawingOrderSubsetData = getDrawingOrderSubset();
  60. byte[] windowSpecificationData = getWindowSpecification();
  61. byte[] len = BinaryUtils.convert(headerData.length
  62. + drawingOrderSubsetData.length
  63. + windowSpecificationData.length - 1, 2);
  64. headerData[1] = len[0];
  65. headerData[2] = len[1];
  66. os.write(headerData);
  67. os.write(drawingOrderSubsetData);
  68. os.write(windowSpecificationData);
  69. }
  70. /**
  71. * Returns the drawing order subset data
  72. *
  73. * @return the drawing order subset data
  74. */
  75. private byte[] getDrawingOrderSubset() {
  76. final byte[] data = new byte[] {
  77. // Drawing order subset
  78. (byte) 0xF7,
  79. 7, // LENGTH
  80. (byte) 0xB0, // drawing order subset
  81. 0x00, // reserved (must be zero)
  82. 0x00, // reserved (must be zero)
  83. 0x02, // SUBLEV
  84. 0x00, // VERSION 0
  85. 0x01, // LENGTH (of following field)
  86. 0x00 // GEOM
  87. };
  88. return data;
  89. }
  90. private static final int ABS = 2;
  91. private static final int IMGRES = 8;
  92. /**
  93. * Returns the window specification data
  94. *
  95. * @return the window specification data
  96. */
  97. private byte[] getWindowSpecification() {
  98. byte[] xlcoord = BinaryUtils.convert(xlwind, 2);
  99. byte[] xrcoord = BinaryUtils.convert(xrwind, 2);
  100. byte[] xbcoord = BinaryUtils.convert(ybwind, 2);
  101. byte[] ytcoord = BinaryUtils.convert(ytwind, 2);
  102. byte[] xResol = BinaryUtils.convert(widthRes * 10, 2);
  103. byte[] yResol = BinaryUtils.convert(heightRes * 10, 2);
  104. byte[] imxyres = xResol;
  105. // Window specification
  106. final byte[] data = new byte[] {
  107. (byte) 0xF6,
  108. 18, // LENGTH
  109. (ABS + IMGRES), // FLAGS (ABS)
  110. 0x00, // reserved (must be zero)
  111. 0x00, // CFORMAT (coordinate format - 16bit high byte first signed)
  112. 0x00, // UBASE (unit base - ten inches)
  113. xResol[0], // XRESOL
  114. xResol[1],
  115. yResol[0], // YRESOL
  116. yResol[1],
  117. imxyres[0], // IMXYRES (Number of image points per ten inches
  118. imxyres[1], // in X and Y directions)
  119. xlcoord[0], // XLWIND
  120. xlcoord[1],
  121. xrcoord[0], // XRWIND
  122. xrcoord[1],
  123. xbcoord[0], // YBWIND
  124. xbcoord[1],
  125. ytcoord[0], // YTWIND
  126. ytcoord[1]
  127. };
  128. return data;
  129. }
  130. }