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.

AbstractDataObject.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.AFPDataObjectInfo;
  22. import org.apache.fop.afp.AFPObjectAreaInfo;
  23. import org.apache.fop.afp.AFPResourceInfo;
  24. import org.apache.fop.afp.AFPResourceLevel;
  25. import org.apache.fop.afp.Completable;
  26. import org.apache.fop.afp.Factory;
  27. import org.apache.fop.afp.Startable;
  28. /**
  29. * Abstract base class used by the ImageObject and GraphicsObject which both
  30. * have define an ObjectEnvironmentGroup
  31. */
  32. public abstract class AbstractDataObject extends AbstractNamedAFPObject implements Startable, Completable {
  33. /** the object environment group */
  34. protected ObjectEnvironmentGroup objectEnvironmentGroup = null;
  35. /** the object factory */
  36. protected final Factory factory;
  37. /** the completion status of this object */
  38. private boolean complete;
  39. /** the starting status of this object */
  40. private boolean started;
  41. /**
  42. * Named constructor
  43. *
  44. * @param factory the object factory
  45. * @param name data object name
  46. */
  47. public AbstractDataObject(Factory factory, String name) {
  48. super(name);
  49. this.factory = factory;
  50. }
  51. /**
  52. * Sets the object view port (area position and size).
  53. *
  54. * @param dataObjectInfo
  55. * the object area info
  56. */
  57. public void setViewport(AFPDataObjectInfo dataObjectInfo) {
  58. AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
  59. // object area descriptor
  60. int width = objectAreaInfo.getWidth();
  61. int height = objectAreaInfo.getHeight();
  62. int widthRes = objectAreaInfo.getWidthRes();
  63. int heightRes = objectAreaInfo.getHeightRes();
  64. ObjectAreaDescriptor objectAreaDescriptor
  65. = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes);
  66. getObjectEnvironmentGroup().setObjectAreaDescriptor(objectAreaDescriptor);
  67. // object area position
  68. AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
  69. AFPResourceLevel resourceLevel = resourceInfo.getLevel();
  70. ObjectAreaPosition objectAreaPosition = null;
  71. if (resourceLevel.isInline()) {
  72. int x = objectAreaInfo.getX();
  73. int y = objectAreaInfo.getY();
  74. int rotation = objectAreaInfo.getRotation();
  75. objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation);
  76. } else {
  77. // positional values are specified in the oaOffset of the include object
  78. objectAreaPosition = factory.createObjectAreaPosition(0, 0, 0);
  79. }
  80. getObjectEnvironmentGroup().setObjectAreaPosition(objectAreaPosition);
  81. }
  82. /**
  83. * Gets the ObjectEnvironmentGroup
  84. *
  85. * @return the object environment group
  86. */
  87. public ObjectEnvironmentGroup getObjectEnvironmentGroup() {
  88. if (objectEnvironmentGroup == null) {
  89. this.objectEnvironmentGroup = factory.createObjectEnvironmentGroup();
  90. }
  91. return objectEnvironmentGroup;
  92. }
  93. /** {@inheritDoc} */
  94. protected void writeStart(OutputStream os) throws IOException {
  95. setStarted(true);
  96. }
  97. /** {@inheritDoc} */
  98. protected void writeContent(OutputStream os) throws IOException {
  99. writeTriplets(os);
  100. if (objectEnvironmentGroup != null) {
  101. objectEnvironmentGroup.writeToStream(os);
  102. }
  103. }
  104. /** {@inheritDoc} */
  105. public void setStarted(boolean started) {
  106. this.started = started;
  107. }
  108. /** {@inheritDoc} */
  109. public boolean isStarted() {
  110. return this.started;
  111. }
  112. /** {@inheritDoc} */
  113. public void setComplete(boolean complete) {
  114. this.complete = complete;
  115. }
  116. /** {@inheritDoc} */
  117. public boolean isComplete() {
  118. return this.complete;
  119. }
  120. }