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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.render.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.render.afp.tools.BinaryUtils;
  22. /**
  23. * GOCA Graphics Data Descriptor
  24. */
  25. public class GraphicsDataDescriptor extends AbstractAFPObject {
  26. private int xlwind;
  27. private int xrwind;
  28. private int ybwind;
  29. private int ytwind;
  30. private int xresol;
  31. private int yresol;
  32. /**
  33. * Main constructor
  34. * @param xresol the x resolution of the graphics window
  35. * @param yresol the y resolution of the graphics window
  36. * @param xlwind the left edge of the graphics window
  37. * @param xrwind the right edge of the graphics window
  38. * @param ybwind the top edge of the graphics window
  39. * @param ytwind the bottom edge of the graphics window
  40. */
  41. protected GraphicsDataDescriptor(int xresol, int yresol,
  42. int xlwind, int xrwind, int ybwind, int ytwind) {
  43. this.xresol = xresol;
  44. this.yresol = yresol;
  45. this.xlwind = xlwind;
  46. this.xrwind = xrwind;
  47. this.ybwind = ybwind;
  48. this.ytwind = ytwind;
  49. }
  50. private static final int ABS = 2;
  51. private static final int IMGRES = 8;
  52. /**
  53. * {@inheritDoc}
  54. */
  55. public void writeDataStream(OutputStream os) throws IOException {
  56. byte[] xreswind = BinaryUtils.convert(xresol * 10, 2);
  57. byte[] yreswind = BinaryUtils.convert(yresol * 10, 2);
  58. byte[] xlcoord = BinaryUtils.convert(xlwind, 2);
  59. byte[] xrcoord = BinaryUtils.convert(xrwind, 2);
  60. byte[] xbcoord = BinaryUtils.convert(ybwind, 2);
  61. byte[] ytcoord = BinaryUtils.convert(ytwind, 2);
  62. byte[] imxyres = xreswind;
  63. byte[] data = new byte[] {
  64. 0x5A,
  65. 0x00,
  66. 0x25,
  67. (byte) 0xD3,
  68. (byte) 0xA6,
  69. (byte) 0xBB,
  70. 0x00, // Flags
  71. 0x00, // Reserved
  72. 0x00, // Reserved
  73. // Drawing order subset
  74. (byte) 0xF7,
  75. 7, // LENGTH
  76. (byte) 0xB0, // drawing order subset
  77. 0x00, // reserved (must be zero)
  78. 0x00, // reserved (must be zero)
  79. 0x02, // SUBLEV
  80. 0x00, // VERSION 0
  81. 0x01, // LENGTH (of following field)
  82. 0x00, // GEOM
  83. // Window specification
  84. (byte) 0xF6,
  85. 18, // LENGTH
  86. (ABS + IMGRES), // FLAGS (ABS)
  87. 0x00, // reserved (must be zero)
  88. 0x00, // CFORMAT (coordinate format - 16bit high byte first signed)
  89. 0x00, // UBASE (unit base - ten inches)
  90. xreswind[0], // XRESOL
  91. xreswind[1],
  92. yreswind[0], // YRESOL
  93. yreswind[1],
  94. imxyres[0], // IMXYRES (Number of image points per ten inches
  95. imxyres[1], // in X and Y directions)
  96. xlcoord[0], // XLWIND
  97. xlcoord[1],
  98. xrcoord[0], // XRWIND
  99. xrcoord[1],
  100. xbcoord[0], // YBWIND
  101. xbcoord[1],
  102. ytcoord[0], // YTWIND
  103. ytcoord[1]
  104. };
  105. os.write(data);
  106. }
  107. }