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

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