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.

ObjectAreaSizeTriplet.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.triplets;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.util.BinaryUtils;
  22. /**
  23. * The Object Area Size triplet is used to specify the extent of an object area
  24. * in the X and Y directions
  25. */
  26. public class ObjectAreaSizeTriplet extends AbstractTriplet {
  27. private final int x;
  28. private final int y;
  29. private final byte type;
  30. /**
  31. * Main constructor
  32. *
  33. * @param x the object area extent for the X axis
  34. * @param y the object area extent for the Y axis
  35. * @param type the object area size type
  36. */
  37. public ObjectAreaSizeTriplet(int x, int y, byte type) {
  38. super(AbstractTriplet.OBJECT_AREA_SIZE);
  39. this.x = x;
  40. this.y = y;
  41. this.type = type;
  42. }
  43. /**
  44. * Main constructor
  45. *
  46. * @param x the object area extent for the X axis
  47. * @param y the object area extent for the Y axis
  48. */
  49. public ObjectAreaSizeTriplet(int x, int y) {
  50. this(x, y, (byte)0x02);
  51. }
  52. /** {@inheritDoc} */
  53. public int getDataLength() {
  54. return 9;
  55. }
  56. /** {@inheritDoc} */
  57. public void writeToStream(OutputStream os) throws IOException {
  58. byte[] data = getData();
  59. data[2] = type; // SizeType
  60. byte[] xOASize = BinaryUtils.convert(x, 3);
  61. data[3] = xOASize[0]; // XoaSize - Object area extent for X axis
  62. data[4] = xOASize[1];
  63. data[5] = xOASize[2];
  64. byte[] yOASize = BinaryUtils.convert(y, 3);
  65. data[6] = yOASize[0]; // YoaSize - Object area extent for Y axis
  66. data[7] = yOASize[1];
  67. data[8] = yOASize[2];
  68. os.write(data);
  69. }
  70. }