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.

ActiveEnvironmentGroup.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 java.util.List;
  22. import org.apache.fop.afp.Factory;
  23. import org.apache.fop.afp.fonts.AFPFont;
  24. /**
  25. * An Active Environment Group (AEG) is associated with each page,
  26. * and is contained in the page's begin-end envelope in the data stream.
  27. * The active environment group contains layout and formatting information
  28. * that defines the measurement units and size of the page, and may contain
  29. * resource information.
  30. *
  31. * Any objects that are required for page presentation and that are to be
  32. * treated as resource objects must be mapped with a map structured field
  33. * in the AEG. The scope of an active environment group is the scope of its
  34. * containing page or overlay.
  35. *
  36. */
  37. public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup {
  38. /** The collection of MapCodedFont objects */
  39. private final List/*<MapCodedFonts>*/ mapCodedFonts
  40. = new java.util.ArrayList/*<MapCodedFonts>*/();
  41. /** the collection of MapDataResource objects */
  42. private final List mapDataResources = null;
  43. /** the Object Area Descriptor for the active environment group */
  44. private ObjectAreaDescriptor objectAreaDescriptor = null;
  45. /** the Object Area Position for the active environment group */
  46. private ObjectAreaPosition objectAreaPosition = null;
  47. /** the PresentationTextDescriptor for the active environment group */
  48. private PresentationTextDescriptor presentationTextDataDescriptor = null;
  49. /** the PageDescriptor for the active environment group */
  50. private PageDescriptor pageDescriptor = null;
  51. /** the resource manager */
  52. private final Factory factory;
  53. /**
  54. * Constructor for the ActiveEnvironmentGroup, this takes a
  55. * name parameter which must be 8 characters long.
  56. *
  57. * @param factory the object factory
  58. * @param name the active environment group name
  59. * @param width the page width
  60. * @param height the page height
  61. * @param widthRes the page width resolution
  62. * @param heightRes the page height resolution
  63. */
  64. public ActiveEnvironmentGroup(Factory factory,
  65. String name, int width, int height, int widthRes, int heightRes) {
  66. super(name);
  67. this.factory = factory;
  68. // Create PageDescriptor
  69. this.pageDescriptor
  70. = factory.createPageDescriptor(width, height, widthRes, heightRes);
  71. // Create ObjectAreaDescriptor
  72. this.objectAreaDescriptor
  73. = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes);
  74. // Create PresentationTextDataDescriptor
  75. this.presentationTextDataDescriptor
  76. = factory.createPresentationTextDataDescriptor(width, height,
  77. widthRes, heightRes);
  78. }
  79. /**
  80. * Set the position of the object area
  81. *
  82. * @param x the x offset
  83. * @param y the y offset
  84. * @param rotation the rotation
  85. */
  86. public void setObjectAreaPosition(int x, int y, int rotation) {
  87. this.objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation);
  88. }
  89. /**
  90. * Accessor method to obtain the PageDescriptor object of the
  91. * active environment group.
  92. *
  93. * @return the page descriptor object
  94. */
  95. public PageDescriptor getPageDescriptor() {
  96. return pageDescriptor;
  97. }
  98. /**
  99. * Accessor method to obtain the PresentationTextDataDescriptor object of
  100. * the active environment group.
  101. *
  102. * @return the presentation text descriptor
  103. */
  104. public PresentationTextDescriptor getPresentationTextDataDescriptor() {
  105. return presentationTextDataDescriptor;
  106. }
  107. /** {@inheritDoc} */
  108. public void writeContent(OutputStream os) throws IOException {
  109. super.writeTriplets(os);
  110. writeObjects(mapCodedFonts, os);
  111. writeObjects(mapDataResources, os);
  112. writeObjects(mapPageOverlays, os);
  113. if (pageDescriptor != null) {
  114. pageDescriptor.writeToStream(os);
  115. }
  116. if (objectAreaDescriptor != null && objectAreaPosition != null) {
  117. objectAreaDescriptor.writeToStream(os);
  118. objectAreaPosition.writeToStream(os);
  119. }
  120. if (presentationTextDataDescriptor != null) {
  121. presentationTextDataDescriptor.writeToStream(os);
  122. }
  123. }
  124. /** {@inheritDoc} */
  125. protected void writeStart(OutputStream os) throws IOException {
  126. byte[] data = new byte[17];
  127. copySF(data, Type.BEGIN, Category.ACTIVE_ENVIRONMENT_GROUP);
  128. os.write(data);
  129. }
  130. /** {@inheritDoc} */
  131. protected void writeEnd(OutputStream os) throws IOException {
  132. byte[] data = new byte[17];
  133. copySF(data, Type.END, Category.ACTIVE_ENVIRONMENT_GROUP);
  134. os.write(data);
  135. }
  136. /**
  137. * Method to create a map coded font object
  138. *
  139. * @param fontRef the font number used as the resource identifier
  140. * @param font the font
  141. * @param size the point size of the font
  142. * @param orientation the orientation of the font (e.g. 0, 90, 180, 270)
  143. */
  144. public void createFont(int fontRef, AFPFont font, int size, int orientation) {
  145. MapCodedFont mapCodedFont = getCurrentMapCodedFont();
  146. if (mapCodedFont == null) {
  147. mapCodedFont = factory.createMapCodedFont();
  148. mapCodedFonts.add(mapCodedFont);
  149. }
  150. try {
  151. mapCodedFont.addFont(fontRef, font, size, orientation);
  152. } catch (MaximumSizeExceededException msee) {
  153. mapCodedFont = factory.createMapCodedFont();
  154. mapCodedFonts.add(mapCodedFont);
  155. try {
  156. mapCodedFont.addFont(fontRef, font, size, orientation);
  157. } catch (MaximumSizeExceededException ex) {
  158. // Should never happen (but log just in case)
  159. log.error("createFont():: resulted in a MaximumSizeExceededException");
  160. }
  161. }
  162. }
  163. /**
  164. * Getter method for the most recent MapCodedFont added to the
  165. * Active Environment Group (returns null if no MapCodedFonts exist)
  166. *
  167. * @return the most recent Map Coded Font.
  168. */
  169. private MapCodedFont getCurrentMapCodedFont() {
  170. int size = mapCodedFonts.size();
  171. if (size > 0) {
  172. return (MapCodedFont)mapCodedFonts.get(size - 1);
  173. } else {
  174. return null;
  175. }
  176. }
  177. // private List getMapDataResources() {
  178. // if (mapDataResources == null) {
  179. // mapDataResources = new java.util.ArrayList();
  180. // }
  181. // return mapDataResources;
  182. //}
  183. // /**
  184. // * Method to create a map data resource object
  185. // * @param dataObjectAccessor a data object accessor
  186. // */
  187. // protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) {
  188. // getMapDataResources().add(new MapDataResource(dataObjectAccessor));
  189. // }
  190. }