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.

Factory.java 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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.OutputStream;
  20. import org.apache.commons.logging.Log;
  21. import org.apache.commons.logging.LogFactory;
  22. import org.apache.fop.render.afp.goca.GraphicsData;
  23. import org.apache.fop.render.afp.ioca.ImageContent;
  24. import org.apache.fop.render.afp.ioca.ImageRasterData;
  25. import org.apache.fop.render.afp.ioca.ImageSegment;
  26. import org.apache.fop.render.afp.tools.StringUtils;
  27. /**
  28. * Creator of MO:DCA data objects (mostly)
  29. */
  30. public class Factory {
  31. /** Static logging instance */
  32. private static final Log log = LogFactory.getLog(Factory.class);
  33. private static final String OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX = "OEG";
  34. private static final String ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX = "AEG";
  35. private static final String IMAGE_NAME_PREFIX = "IMG";
  36. private static final String GRAPHIC_NAME_PREFIX = "GRA";
  37. private static final String BARCODE_NAME_PREFIX = "BAR";
  38. // private static final String OTHER_NAME_PREFIX = "OTH";
  39. private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC";
  40. private static final String RESOURCE_NAME_PREFIX = "RES";
  41. private static final String RESOURCE_GROUP_NAME_PREFIX = "RG";
  42. private static final String PAGE_GROUP_NAME_PREFIX = "PGP";
  43. private static final String PAGE_NAME_PREFIX = "PGN";
  44. private static final String OVERLAY_NAME_PREFIX = "OVL";
  45. private static final String PRESENTATION_TEXT_NAME_PREFIX = "PT";
  46. private static final String DOCUMENT_NAME_PREFIX = "DOC";
  47. private static final String IM_IMAGE_NAME_PREFIX = "IMIMG";
  48. private static final String IMAGE_SEGMENT_NAME_PREFIX = "IS";
  49. /** the page group count */
  50. private int pageGroupCount = 0;
  51. /** the page count */
  52. private int pageCount = 0;
  53. /** the image count */
  54. private int imageCount = 0;
  55. /** the im image count */
  56. private int imImageCount = 0;
  57. /** the image segment count */
  58. private int imageSegmentCount = 0;
  59. /** the graphic count */
  60. private int graphicCount = 0;
  61. /** the object container count */
  62. private int objectContainerCount = 0;
  63. /** the resource count */
  64. private int resourceCount = 0;
  65. /** the resource group count */
  66. private int resourceGroupCount = 0;
  67. /** the overlay count */
  68. private int overlayCount = 0;
  69. /** the presentation text object count */
  70. private int textObjectCount = 0;
  71. /** the active environment group count */
  72. private int activeEnvironmentGroupCount = 0;
  73. /** the document count */
  74. private int documentCount = 0;
  75. /** the object environment group count */
  76. private int objectEnvironmentGroupCount = 0;
  77. /**
  78. * Main constructor
  79. */
  80. public Factory() {
  81. }
  82. /**
  83. * Creates a new IOCA {@link ImageObject}
  84. *
  85. * @return a new {@link ImageObject}
  86. */
  87. public ImageObject createImageObject() {
  88. String name = IMAGE_NAME_PREFIX
  89. + StringUtils.lpad(String.valueOf(++imageCount), '0', 5);
  90. ImageObject imageObject = new ImageObject(this, name);
  91. return imageObject;
  92. }
  93. /**
  94. * Creates an IOCA {@link IMImageObject}
  95. *
  96. * @return a new {@link IMImageObject}
  97. */
  98. public IMImageObject createIMImageObject() {
  99. String name = IM_IMAGE_NAME_PREFIX
  100. + StringUtils.lpad(String.valueOf(++imImageCount), '0', 3);
  101. IMImageObject imImageObject = new IMImageObject(name);
  102. return imImageObject;
  103. }
  104. /**
  105. * Creates a new GOCA {@link GraphicsObject}
  106. *
  107. * @return a new {@link GraphicsObject}
  108. */
  109. public GraphicsObject createGraphic() {
  110. String name = GRAPHIC_NAME_PREFIX
  111. + StringUtils.lpad(String.valueOf(++graphicCount), '0', 5);
  112. GraphicsObject graphicsObj = new GraphicsObject(this, name);
  113. return graphicsObj;
  114. }
  115. /**
  116. * Creates a new MO:DCA {@link ObjectContainer}
  117. *
  118. * @return a new {@link ObjectContainer}
  119. */
  120. public ObjectContainer createObjectContainer() {
  121. String name = OBJECT_CONTAINER_NAME_PREFIX
  122. + StringUtils.lpad(String.valueOf(++objectContainerCount), '0', 6);
  123. return new ObjectContainer(this, name);
  124. }
  125. /**
  126. * Creates a new MO:DCA {@link ResourceObject}
  127. *
  128. * @param resourceName the resource object name
  129. * @return a new {@link ResourceObject}
  130. */
  131. public ResourceObject createResource(String resourceName) {
  132. return new ResourceObject(resourceName);
  133. }
  134. /**
  135. * Creates a new MO:DCA {@link ResourceObject}
  136. *
  137. * @return a new {@link ResourceObject}
  138. */
  139. public ResourceObject createResource() {
  140. String name = RESOURCE_NAME_PREFIX
  141. + StringUtils.lpad(String.valueOf(++resourceCount), '0', 5);
  142. return createResource(name);
  143. }
  144. /**
  145. * Creates a new MO:DCA {@link PageGroup}
  146. *
  147. * @return a new {@link PageGroup}
  148. */
  149. public PageGroup createPageGroup() {
  150. String name = PAGE_GROUP_NAME_PREFIX
  151. + StringUtils.lpad(String.valueOf(++pageGroupCount), '0', 5);
  152. return new PageGroup(this, name);
  153. }
  154. /**
  155. * Creates a new MO:DCA {@link ActiveEnvironmentGroup}
  156. *
  157. * @param width the page width
  158. * @param height the page height
  159. * @param widthRes the page width resolution
  160. * @param heightRes the page height resolution
  161. * @return a new {@link ActiveEnvironmentGroup}
  162. */
  163. public ActiveEnvironmentGroup createActiveEnvironmentGroup(
  164. int width, int height, int widthRes, int heightRes) {
  165. String name = ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX
  166. + StringUtils.lpad(String.valueOf(++activeEnvironmentGroupCount ), '0', 5);
  167. return new ActiveEnvironmentGroup(this, name, width, height, widthRes, heightRes);
  168. }
  169. /**
  170. * Creates a new MO:DCA {@link ResourceGroup}
  171. *
  172. * @return a new {@link ResourceGroup}
  173. */
  174. public ResourceGroup createResourceGroup() {
  175. String name = RESOURCE_GROUP_NAME_PREFIX
  176. + StringUtils.lpad(String.valueOf(++resourceGroupCount), '0', 6);
  177. return new ResourceGroup(name);
  178. }
  179. /**
  180. * Creates a new MO:DCA {@link StreamedResourceGroup}
  181. *
  182. * @param os the outputstream of the streamed resource group
  183. * @return a new {@link StreamedResourceGroup}
  184. */
  185. public StreamedResourceGroup createStreamedResourceGroup(OutputStream os) {
  186. String name = RESOURCE_GROUP_NAME_PREFIX
  187. + StringUtils.lpad(String.valueOf(++resourceGroupCount), '0', 6);
  188. return new StreamedResourceGroup(name, os);
  189. }
  190. /**
  191. * Creates a new MO:DCA {@link PageObject}.
  192. *
  193. * @param pageWidth
  194. * the width of the page
  195. * @param pageHeight
  196. * the height of the page
  197. * @param pageRotation
  198. * the rotation of the page
  199. * @param pageWidthRes
  200. * the width resolution of the page
  201. * @param pageHeightRes
  202. * the height resolution of the page
  203. *
  204. * @return a new {@link PageObject}
  205. */
  206. public PageObject createPage(int pageWidth, int pageHeight, int pageRotation,
  207. int pageWidthRes, int pageHeightRes) {
  208. String pageName = PAGE_NAME_PREFIX
  209. + StringUtils.lpad(String.valueOf(++pageCount), '0', 5);
  210. return new PageObject(this, pageName, pageWidth, pageHeight,
  211. pageRotation, pageWidthRes, pageHeightRes);
  212. }
  213. /**
  214. * Creates a new MO:DCA {@link PresentationTextObject}.
  215. *
  216. * @return a new {@link PresentationTextObject}
  217. */
  218. public PresentationTextObject createPresentationTextObject() {
  219. String textObjectName = PRESENTATION_TEXT_NAME_PREFIX
  220. + StringUtils.lpad(String.valueOf(++textObjectCount), '0', 6);
  221. return new PresentationTextObject(textObjectName);
  222. }
  223. /**
  224. * Creates a new MO:DCA {@link Overlay}.
  225. *
  226. * @param width
  227. * the width of the overlay
  228. * @param height
  229. * the height of the overlay
  230. * @param widthRes
  231. * the width resolution of the overlay
  232. * @param heightRes
  233. * the height resolution of the overlay
  234. * @param overlayRotation
  235. * the rotation of the overlay
  236. *
  237. * @return a new {@link Overlay}.
  238. */
  239. public Overlay createOverlay(int width, int height,
  240. int widthRes, int heightRes, int overlayRotation) {
  241. String overlayName = OVERLAY_NAME_PREFIX
  242. + StringUtils.lpad(String.valueOf(++overlayCount), '0', 5);
  243. Overlay overlay = new Overlay(this, overlayName, width, height,
  244. overlayRotation, widthRes, heightRes);
  245. return overlay;
  246. }
  247. /**
  248. * Creates a MO:DCA {@link Document}
  249. *
  250. * @return a new {@link Document}
  251. */
  252. public Document createDocument() {
  253. String documentName = DOCUMENT_NAME_PREFIX
  254. + StringUtils.lpad(String.valueOf(++documentCount), '0', 5);
  255. Document document = new Document(this, documentName);
  256. return document;
  257. }
  258. /**
  259. * Creates a MO:DCA {@link MapCodedFont}
  260. *
  261. * @return a new {@link MapCodedFont}
  262. */
  263. public MapCodedFont createMapCodedFont() {
  264. MapCodedFont mapCodedFont = new MapCodedFont();
  265. return mapCodedFont;
  266. }
  267. /**
  268. * Creates a MO:DCA {@link IncludePageSegment}
  269. *
  270. * @param name the page segment name
  271. * @param x the x coordinate
  272. * @param y the y coordinate
  273. *
  274. * @return a new {@link IncludePageSegment}
  275. */
  276. public IncludePageSegment createIncludePageSegment(String name, int x, int y) {
  277. IncludePageSegment includePageSegment = new IncludePageSegment(name, x, y);
  278. return includePageSegment;
  279. }
  280. /**
  281. * Creates a MO:DCA {@link IncludeObject}
  282. *
  283. * @param name the name of this include object
  284. * @return a new {@link IncludeObject}
  285. */
  286. public IncludeObject createInclude(String name) {
  287. IncludeObject includeObject = new IncludeObject(name);
  288. return includeObject;
  289. }
  290. /**
  291. * Creates a MO:DCA {@link TagLogicalElement}
  292. *
  293. * @param name name of the element
  294. * @param value value of the element
  295. * @return a new {@link TagLogicalElement}
  296. */
  297. public TagLogicalElement createTagLogicalElement(String name, String value) {
  298. TagLogicalElement tle = new TagLogicalElement(name, value);
  299. return tle;
  300. }
  301. /**
  302. * Creates an {@link DataStream}
  303. *
  304. * @param outputStream an outputstream to write to
  305. * @return a new {@link DataStream}
  306. */
  307. public DataStream createDataStream(OutputStream outputStream) {
  308. DataStream dataStream = new DataStream(this, outputStream);
  309. return dataStream;
  310. }
  311. /**
  312. * Creates a new MO:DCA {@link PageDescriptor}
  313. *
  314. * @param width the page width.
  315. * @param height the page height.
  316. * @param widthRes the page width resolution.
  317. * @param heightRes the page height resolution.
  318. * @return a new {@link PageDescriptor}
  319. */
  320. public PageDescriptor createPageDescriptor(int width, int height, int widthRes, int heightRes) {
  321. PageDescriptor pageDescriptor = new PageDescriptor(width, height, widthRes, heightRes);
  322. return pageDescriptor;
  323. }
  324. /**
  325. * Returns a new MO:DCA {@link ObjectEnvironmentGroup}
  326. *
  327. * @return a new {@link ObjectEnvironmentGroup}
  328. */
  329. public ObjectEnvironmentGroup createObjectEnvironmentGroup() {
  330. String oegName = OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX
  331. + StringUtils.lpad(String.valueOf(++objectEnvironmentGroupCount), '0', 5);
  332. ObjectEnvironmentGroup objectEnvironmentGroup = new ObjectEnvironmentGroup(this, oegName);
  333. return objectEnvironmentGroup;
  334. }
  335. /**
  336. * Creates a new GOCA {@link GraphicsData}
  337. *
  338. * @return a new {@link GraphicsData}
  339. */
  340. public GraphicsData createGraphicsData() {
  341. GraphicsData graphicsData = new GraphicsData();
  342. return graphicsData;
  343. }
  344. /**
  345. * Creates a new {@link ObjectAreaDescriptor}
  346. *
  347. * @param width the object width.
  348. * @param height the object height.
  349. * @param widthRes the object width resolution.
  350. * @param heightRes the object height resolution.
  351. * @return a new {@link ObjectAreaDescriptor}
  352. */
  353. public ObjectAreaDescriptor createObjectAreaDescriptor(
  354. int width, int height, int widthRes, int heightRes) {
  355. ObjectAreaDescriptor objectAreaDescriptor
  356. = new ObjectAreaDescriptor(width, height, widthRes, heightRes);
  357. return objectAreaDescriptor;
  358. }
  359. /**
  360. * Creates a new {@link ObjectAreaPosition}
  361. *
  362. * @param x The x coordinate.
  363. * @param y The y coordinate.
  364. * @param rotation The coordinate system rotation (must be 0, 90, 180, 270).
  365. * @return a new {@link ObjectAreaPosition}
  366. */
  367. public ObjectAreaPosition createObjectAreaPosition(int x, int y,
  368. int rotation) {
  369. ObjectAreaPosition objectAreaPosition = new ObjectAreaPosition(
  370. x, y, rotation);
  371. return objectAreaPosition;
  372. }
  373. /**
  374. * Creates a new {@link ImageDataDescriptor}
  375. *
  376. * @param width the image width
  377. * @param height the image height
  378. * @param widthRes the x resolution of the image
  379. * @param heightRes the y resolution of the image
  380. * @return a new {@link ImageDataDescriptor}
  381. */
  382. public ImageDataDescriptor createImageDataDescriptor(
  383. int width, int height, int widthRes, int heightRes) {
  384. ImageDataDescriptor imageDataDescriptor = new ImageDataDescriptor(
  385. width, height, widthRes, heightRes);
  386. return imageDataDescriptor;
  387. }
  388. /**
  389. * Creates a new GOCA {@link GraphicsDataDescriptor}
  390. *
  391. * @param xlwind the left edge of the graphics window
  392. * @param xrwind the right edge of the graphics window
  393. * @param ybwind the top edge of the graphics window
  394. * @param ytwind the bottom edge of the graphics window
  395. * @param widthRes the x resolution of the graphics window
  396. * @param heightRes the y resolution of the graphics window
  397. * @return a new {@link GraphicsDataDescriptor}
  398. */
  399. public GraphicsDataDescriptor createGraphicsDataDescriptor(
  400. int xlwind, int xrwind, int ybwind, int ytwind, int widthRes, int heightRes) {
  401. GraphicsDataDescriptor graphicsDataDescriptor = new GraphicsDataDescriptor(
  402. xlwind, xrwind, ybwind, ytwind, widthRes, heightRes);
  403. return graphicsDataDescriptor;
  404. }
  405. /**
  406. * Creates a new MO:DCA {@link ContainerDataDescriptor}
  407. *
  408. * @param dataWidth the container data width
  409. * @param dataHeight the container data height
  410. * @param widthRes the container data width resolution
  411. * @param heightRes the container data height resolution
  412. * @return a new {@link ContainerDataDescriptor}
  413. */
  414. public ContainerDataDescriptor createContainerDataDescriptor(
  415. int dataWidth, int dataHeight, int widthRes, int heightRes) {
  416. ContainerDataDescriptor containerDataDescriptor
  417. = new ContainerDataDescriptor(dataWidth, dataHeight, widthRes, heightRes);
  418. return containerDataDescriptor;
  419. }
  420. /**
  421. * Creates a new MO:DCA {@link MapContainerData}
  422. *
  423. * @param optionValue the option value
  424. * @return a new {@link MapContainerData}
  425. */
  426. public MapContainerData createMapContainerData(byte optionValue) {
  427. MapContainerData mapContainerData = new MapContainerData(optionValue);
  428. return mapContainerData;
  429. }
  430. /**
  431. * Creates a new MO:DCA {@link MapDataResource}
  432. *
  433. * @return a new {@link MapDataResource}
  434. */
  435. public MapDataResource createMapDataResource() {
  436. MapDataResource mapDataResource = new MapDataResource();
  437. return mapDataResource;
  438. }
  439. /**
  440. * Creates a new MO:DCA {@link PresentationEnvironmentControl}
  441. *
  442. * @return a new {@link PresentationEnvironmentControl}
  443. */
  444. public PresentationEnvironmentControl createPresentationEnvironmentControl() {
  445. PresentationEnvironmentControl presentationEnvironmentControl
  446. = new PresentationEnvironmentControl();
  447. return presentationEnvironmentControl;
  448. }
  449. /**
  450. * Creates a new MO:DCA {@link InvokeMediumMap}
  451. *
  452. * @param name the object name
  453. * @return a new {@link InvokeMediumMap}
  454. */
  455. public InvokeMediumMap createInvokeMediumMap(String name) {
  456. InvokeMediumMap invokeMediumMap = new InvokeMediumMap(name);
  457. return invokeMediumMap;
  458. }
  459. /**
  460. * Creates a new MO:DCA {@link ResourceEnvironmentGroup}
  461. *
  462. * @return a new {@link ResourceEnvironmentGroup}
  463. */
  464. public ResourceEnvironmentGroup createResourceEnvironmentGroup() {
  465. ResourceEnvironmentGroup resourceEnvironmentGroup = new ResourceEnvironmentGroup();
  466. return resourceEnvironmentGroup;
  467. }
  468. /**
  469. * Creates a new IOCA {@link ImageSegment}
  470. *
  471. * @return a new {@link ImageSegment}
  472. */
  473. public ImageSegment createImageSegment() {
  474. String name = IMAGE_SEGMENT_NAME_PREFIX
  475. + StringUtils.lpad(String.valueOf(++imageSegmentCount), '0', 2);
  476. ImageSegment imageSegment = new ImageSegment(this, name);
  477. return imageSegment;
  478. }
  479. /**
  480. * Creates an new IOCA {@link ImageContent}
  481. *
  482. * @return an {@link ImageContent}
  483. */
  484. public ImageContent createImageContent() {
  485. ImageContent imageContent = new ImageContent();
  486. return imageContent;
  487. }
  488. /**
  489. * Creates a new IOCA {@link ImageRasterData}
  490. *
  491. * @param rasterData raster data
  492. * @return a new {@link ImageRasterData}
  493. */
  494. public ImageRasterData createImageRasterData(byte[] rasterData) {
  495. ImageRasterData imageRasterData = new ImageRasterData(rasterData);
  496. return imageRasterData;
  497. }
  498. }