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.

PSDocumentHandler.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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.ps;
  19. import java.awt.Dimension;
  20. import java.awt.geom.Dimension2D;
  21. import java.awt.geom.Rectangle2D;
  22. import java.io.BufferedInputStream;
  23. import java.io.BufferedOutputStream;
  24. import java.io.IOException;
  25. import java.io.InputStream;
  26. import java.io.OutputStream;
  27. import java.net.URI;
  28. import java.util.ArrayList;
  29. import java.util.Collection;
  30. import java.util.List;
  31. import java.util.Map;
  32. import javax.xml.transform.Source;
  33. import org.apache.commons.io.IOUtils;
  34. import org.apache.commons.logging.Log;
  35. import org.apache.commons.logging.LogFactory;
  36. import org.apache.xmlgraphics.java2d.Dimension2DDouble;
  37. import org.apache.xmlgraphics.ps.DSCConstants;
  38. import org.apache.xmlgraphics.ps.PSDictionary;
  39. import org.apache.xmlgraphics.ps.PSDictionaryFormatException;
  40. import org.apache.xmlgraphics.ps.PSGenerator;
  41. import org.apache.xmlgraphics.ps.PSPageDeviceDictionary;
  42. import org.apache.xmlgraphics.ps.PSProcSets;
  43. import org.apache.xmlgraphics.ps.PSResource;
  44. import org.apache.xmlgraphics.ps.dsc.DSCException;
  45. import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
  46. import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
  47. import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
  48. import org.apache.fop.apps.MimeConstants;
  49. import org.apache.fop.apps.io.TempResourceURIGenerator;
  50. import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
  51. import org.apache.fop.render.intermediate.IFContext;
  52. import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
  53. import org.apache.fop.render.intermediate.IFException;
  54. import org.apache.fop.render.intermediate.IFPainter;
  55. import org.apache.fop.render.ps.PSRendererConfig.PSRendererConfigParser;
  56. import org.apache.fop.render.ps.extensions.PSCommentAfter;
  57. import org.apache.fop.render.ps.extensions.PSCommentBefore;
  58. import org.apache.fop.render.ps.extensions.PSPageTrailerCodeBefore;
  59. import org.apache.fop.render.ps.extensions.PSSetPageDevice;
  60. import org.apache.fop.render.ps.extensions.PSSetupCode;
  61. /**
  62. * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
  63. * that produces PostScript.
  64. */
  65. public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
  66. /** logging instance */
  67. private static Log log = LogFactory.getLog(PSDocumentHandler.class);
  68. /**
  69. * Utility class which enables all sorts of features that are not directly connected to the
  70. * normal rendering process.
  71. */
  72. protected PSRenderingUtil psUtil;
  73. /** The PostScript generator used to output the PostScript */
  74. protected PSGenerator gen;
  75. /** the temporary file in case of two-pass processing */
  76. private URI tempURI;
  77. private static final TempResourceURIGenerator TEMP_URI_GENERATOR
  78. = new TempResourceURIGenerator("ps-optimize");
  79. private int currentPageNumber = 0;
  80. private PageDefinition currentPageDefinition;
  81. /** Is used to determine the document's bounding box */
  82. private Rectangle2D documentBoundingBox;
  83. /** Used to temporarily store PSSetupCode instance until they can be written. */
  84. private List setupCodeList;
  85. /** This is a cache of PSResource instances of all fonts defined */
  86. private FontResourceCache fontResources;
  87. /** This is a map of PSResource instances of all forms (key: uri) */
  88. private Map formResources;
  89. /** encapsulation of dictionary used in setpagedevice instruction **/
  90. private PSPageDeviceDictionary pageDeviceDictionary;
  91. /** This is a collection holding all document header comments */
  92. private Collection[] comments = new Collection[4];
  93. private static final int COMMENT_DOCUMENT_HEADER = 0;
  94. private static final int COMMENT_DOCUMENT_TRAILER = 1;
  95. private static final int COMMENT_PAGE_TRAILER = 2;
  96. private static final int PAGE_TRAILER_CODE_BEFORE = 3;
  97. /**
  98. * Default constructor.
  99. */
  100. public PSDocumentHandler(IFContext context) {
  101. super(context);
  102. this.psUtil = new PSRenderingUtil(context.getUserAgent());
  103. }
  104. /** {@inheritDoc} */
  105. public boolean supportsPagesOutOfOrder() {
  106. return false;
  107. }
  108. /** {@inheritDoc} */
  109. public String getMimeType() {
  110. return MimeConstants.MIME_POSTSCRIPT;
  111. }
  112. /** {@inheritDoc} */
  113. public IFDocumentHandlerConfigurator getConfigurator() {
  114. return new PSRendererConfigurator(getUserAgent(), new PSRendererConfigParser());
  115. }
  116. PSRenderingUtil getPSUtil() {
  117. return this.psUtil;
  118. }
  119. /** {@inheritDoc} */
  120. public void startDocument() throws IFException {
  121. super.startDocument();
  122. this.fontResources = new FontResourceCache(getFontInfo());
  123. try {
  124. final OutputStream out;
  125. if (psUtil.isOptimizeResources()) {
  126. tempURI = TEMP_URI_GENERATOR.generate();
  127. out = new BufferedOutputStream(getUserAgent().getResourceResolver().getOutputStream(tempURI));
  128. } else {
  129. out = this.outputStream;
  130. }
  131. //Setup for PostScript generation
  132. this.gen = new PSGenerator(out) {
  133. /** Need to subclass PSGenerator to have better URI resolution */
  134. public Source resolveURI(String uri) {
  135. return getUserAgent().resolveURI(uri);
  136. }
  137. };
  138. this.gen.setPSLevel(psUtil.getLanguageLevel());
  139. this.currentPageNumber = 0;
  140. this.documentBoundingBox = new Rectangle2D.Double();
  141. //Initial default page device dictionary settings
  142. this.pageDeviceDictionary = new PSPageDeviceDictionary();
  143. pageDeviceDictionary.setFlushOnRetrieval(!psUtil.isDSCComplianceEnabled());
  144. pageDeviceDictionary.put("/ImagingBBox", "null");
  145. } catch (IOException e) {
  146. throw new IFException("I/O error in startDocument()", e);
  147. }
  148. }
  149. private void writeHeader() throws IOException {
  150. //PostScript Header
  151. gen.writeln(DSCConstants.PS_ADOBE_30);
  152. gen.writeDSCComment(DSCConstants.CREATOR, new String[] {getUserAgent().getProducer()});
  153. gen.writeDSCComment(DSCConstants.CREATION_DATE, new Object[] {new java.util.Date()});
  154. gen.writeDSCComment(DSCConstants.LANGUAGE_LEVEL, new Integer(gen.getPSLevel()));
  155. gen.writeDSCComment(DSCConstants.PAGES, new Object[] {DSCConstants.ATEND});
  156. gen.writeDSCComment(DSCConstants.BBOX, DSCConstants.ATEND);
  157. gen.writeDSCComment(DSCConstants.HIRES_BBOX, DSCConstants.ATEND);
  158. gen.writeDSCComment(DSCConstants.DOCUMENT_SUPPLIED_RESOURCES,
  159. new Object[] {DSCConstants.ATEND});
  160. writeExtensions(COMMENT_DOCUMENT_HEADER);
  161. gen.writeDSCComment(DSCConstants.END_COMMENTS);
  162. //Defaults
  163. gen.writeDSCComment(DSCConstants.BEGIN_DEFAULTS);
  164. gen.writeDSCComment(DSCConstants.END_DEFAULTS);
  165. //Prolog and Setup written right before the first page-sequence, see startPageSequence()
  166. //Do this only once, as soon as we have all the content for the Setup section!
  167. //Prolog
  168. gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
  169. PSProcSets.writeStdProcSet(gen);
  170. PSProcSets.writeEPSProcSet(gen);
  171. FOPProcSet.INSTANCE.writeTo(gen);
  172. gen.writeDSCComment(DSCConstants.END_PROLOG);
  173. //Setup
  174. gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
  175. PSRenderingUtil.writeSetupCodeList(gen, setupCodeList, "SetupCode");
  176. if (!psUtil.isOptimizeResources()) {
  177. this.fontResources.addAll(PSFontUtils.writeFontDict(gen, fontInfo));
  178. } else {
  179. gen.commentln("%FOPFontSetup"); //Place-holder, will be replaced in the second pass
  180. }
  181. gen.writeDSCComment(DSCConstants.END_SETUP);
  182. }
  183. /** {@inheritDoc} */
  184. public void endDocumentHeader() throws IFException {
  185. try {
  186. writeHeader();
  187. } catch (IOException ioe) {
  188. throw new IFException("I/O error writing the PostScript header", ioe);
  189. }
  190. }
  191. /** {@inheritDoc} */
  192. public void endDocument() throws IFException {
  193. try {
  194. //Write trailer
  195. gen.writeDSCComment(DSCConstants.TRAILER);
  196. writeExtensions(COMMENT_DOCUMENT_TRAILER);
  197. gen.writeDSCComment(DSCConstants.PAGES, new Integer(this.currentPageNumber));
  198. new DSCCommentBoundingBox(this.documentBoundingBox).generate(gen);
  199. new DSCCommentHiResBoundingBox(this.documentBoundingBox).generate(gen);
  200. gen.getResourceTracker().writeResources(false, gen);
  201. gen.writeDSCComment(DSCConstants.EOF);
  202. gen.flush();
  203. log.debug("Rendering to PostScript complete.");
  204. if (psUtil.isOptimizeResources()) {
  205. IOUtils.closeQuietly(gen.getOutputStream());
  206. rewritePostScriptFile();
  207. }
  208. if (pageDeviceDictionary != null) {
  209. pageDeviceDictionary.clear();
  210. }
  211. } catch (IOException ioe) {
  212. throw new IFException("I/O error in endDocument()", ioe);
  213. }
  214. super.endDocument();
  215. }
  216. /**
  217. * Used for two-pass production. This will rewrite the PostScript file from the temporary
  218. * file while adding all needed resources.
  219. * @throws IOException In case of an I/O error.
  220. */
  221. private void rewritePostScriptFile() throws IOException {
  222. log.debug("Processing PostScript resources...");
  223. long startTime = System.currentTimeMillis();
  224. ResourceTracker resTracker = gen.getResourceTracker();
  225. InputStream in = new BufferedInputStream(getUserAgent().getResourceResolver().getResource(tempURI));
  226. try {
  227. try {
  228. ResourceHandler handler = new ResourceHandler(getUserAgent(), this.fontInfo,
  229. resTracker, this.formResources);
  230. handler.process(in, this.outputStream,
  231. this.currentPageNumber, this.documentBoundingBox);
  232. this.outputStream.flush();
  233. } catch (DSCException e) {
  234. throw new RuntimeException(e.getMessage());
  235. }
  236. } finally {
  237. IOUtils.closeQuietly(in);
  238. }
  239. if (log.isDebugEnabled()) {
  240. long duration = System.currentTimeMillis() - startTime;
  241. log.debug("Resource Processing complete in " + duration + " ms.");
  242. }
  243. }
  244. /** {@inheritDoc} */
  245. public void startPageSequence(String id) throws IFException {
  246. //nop
  247. }
  248. /** {@inheritDoc} */
  249. public void endPageSequence() throws IFException {
  250. //nop
  251. }
  252. /** {@inheritDoc} */
  253. public void startPage(int index, String name, String pageMasterName, Dimension size)
  254. throws IFException {
  255. try {
  256. if (this.currentPageNumber == 0) {
  257. //writeHeader();
  258. }
  259. this.currentPageNumber++;
  260. gen.getResourceTracker().notifyStartNewPage();
  261. gen.getResourceTracker().notifyResourceUsageOnPage(PSProcSets.STD_PROCSET);
  262. gen.writeDSCComment(DSCConstants.PAGE, new Object[]
  263. {name,
  264. new Integer(this.currentPageNumber)});
  265. double pageWidth = size.width / 1000.0;
  266. double pageHeight = size.height / 1000.0;
  267. boolean rotate = false;
  268. List pageSizes = new java.util.ArrayList();
  269. if (this.psUtil.isAutoRotateLandscape() && (pageHeight < pageWidth)) {
  270. rotate = true;
  271. pageSizes.add(new Long(Math.round(pageHeight)));
  272. pageSizes.add(new Long(Math.round(pageWidth)));
  273. } else {
  274. pageSizes.add(new Long(Math.round(pageWidth)));
  275. pageSizes.add(new Long(Math.round(pageHeight)));
  276. }
  277. pageDeviceDictionary.put("/PageSize", pageSizes);
  278. this.currentPageDefinition = new PageDefinition(
  279. new Dimension2DDouble(pageWidth, pageHeight), rotate);
  280. //TODO Handle extension attachments for the page!!!!!!!
  281. /*
  282. if (page.hasExtensionAttachments()) {
  283. for (Iterator iter = page.getExtensionAttachments().iterator();
  284. iter.hasNext();) {
  285. ExtensionAttachment attachment = (ExtensionAttachment) iter.next();
  286. if (attachment instanceof PSSetPageDevice) {*/
  287. /**
  288. * Extract all PSSetPageDevice instances from the
  289. * attachment list on the s-p-m and add all
  290. * dictionary entries to our internal representation
  291. * of the the page device dictionary.
  292. *//*
  293. PSSetPageDevice setPageDevice = (PSSetPageDevice)attachment;
  294. String content = setPageDevice.getContent();
  295. if (content != null) {
  296. try {
  297. pageDeviceDictionary.putAll(PSDictionary.valueOf(content));
  298. } catch (PSDictionaryFormatException e) {
  299. PSEventProducer eventProducer = PSEventProducer.Provider.get(
  300. getUserAgent().getEventBroadcaster());
  301. eventProducer.postscriptDictionaryParseError(this, content, e);
  302. }
  303. }
  304. }
  305. }
  306. }*/
  307. final Integer zero = new Integer(0);
  308. Rectangle2D pageBoundingBox = new Rectangle2D.Double();
  309. if (rotate) {
  310. pageBoundingBox.setRect(0, 0, pageHeight, pageWidth);
  311. gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[] {
  312. zero, zero, new Long(Math.round(pageHeight)),
  313. new Long(Math.round(pageWidth)) });
  314. gen.writeDSCComment(DSCConstants.PAGE_HIRES_BBOX, new Object[] {
  315. zero, zero, new Double(pageHeight),
  316. new Double(pageWidth) });
  317. gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Landscape");
  318. } else {
  319. pageBoundingBox.setRect(0, 0, pageWidth, pageHeight);
  320. gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[] {
  321. zero, zero, new Long(Math.round(pageWidth)),
  322. new Long(Math.round(pageHeight)) });
  323. gen.writeDSCComment(DSCConstants.PAGE_HIRES_BBOX, new Object[] {
  324. zero, zero, new Double(pageWidth),
  325. new Double(pageHeight) });
  326. if (psUtil.isAutoRotateLandscape()) {
  327. gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION,
  328. "Portrait");
  329. }
  330. }
  331. this.documentBoundingBox.add(pageBoundingBox);
  332. gen.writeDSCComment(DSCConstants.PAGE_RESOURCES,
  333. new Object[] {DSCConstants.ATEND});
  334. gen.commentln("%FOPSimplePageMaster: " + pageMasterName);
  335. } catch (IOException ioe) {
  336. throw new IFException("I/O error in startPage()", ioe);
  337. }
  338. }
  339. /** {@inheritDoc} */
  340. public void startPageHeader() throws IFException {
  341. super.startPageHeader();
  342. try {
  343. gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
  344. } catch (IOException ioe) {
  345. throw new IFException("I/O error in startPageHeader()", ioe);
  346. }
  347. }
  348. /** {@inheritDoc} */
  349. public void endPageHeader() throws IFException {
  350. try {
  351. // Write any unwritten changes to page device dictionary
  352. if (!pageDeviceDictionary.isEmpty()) {
  353. String content = pageDeviceDictionary.getContent();
  354. if (psUtil.isSafeSetPageDevice()) {
  355. content += " SSPD";
  356. } else {
  357. content += " setpagedevice";
  358. }
  359. PSRenderingUtil.writeEnclosedExtensionAttachment(gen, new PSSetPageDevice(content));
  360. }
  361. double pageHeight = this.currentPageDefinition.dimensions.getHeight();
  362. if (this.currentPageDefinition.rotate) {
  363. gen.writeln(gen.formatDouble(pageHeight) + " 0 translate");
  364. gen.writeln("90 rotate");
  365. }
  366. gen.concatMatrix(1, 0, 0, -1, 0, pageHeight);
  367. gen.writeDSCComment(DSCConstants.END_PAGE_SETUP);
  368. } catch (IOException ioe) {
  369. throw new IFException("I/O error in endPageHeader()", ioe);
  370. }
  371. super.endPageHeader();
  372. }
  373. private void writeExtensions(int which) throws IOException {
  374. Collection extensions = comments[which];
  375. if (extensions != null) {
  376. PSRenderingUtil.writeEnclosedExtensionAttachments(gen, extensions);
  377. extensions.clear();
  378. }
  379. }
  380. /** {@inheritDoc} */
  381. public IFPainter startPageContent() throws IFException {
  382. return new PSPainter(this);
  383. }
  384. /** {@inheritDoc} */
  385. public void endPageContent() throws IFException {
  386. try {
  387. gen.showPage();
  388. } catch (IOException ioe) {
  389. throw new IFException("I/O error in endPageContent()", ioe);
  390. }
  391. }
  392. /** {@inheritDoc} */
  393. public void startPageTrailer() throws IFException {
  394. try {
  395. writeExtensions(PAGE_TRAILER_CODE_BEFORE);
  396. super.startPageTrailer();
  397. gen.writeDSCComment(DSCConstants.PAGE_TRAILER);
  398. } catch (IOException ioe) {
  399. throw new IFException("I/O error in startPageTrailer()", ioe);
  400. }
  401. }
  402. /** {@inheritDoc} */
  403. public void endPageTrailer() throws IFException {
  404. try {
  405. writeExtensions(COMMENT_PAGE_TRAILER);
  406. } catch (IOException ioe) {
  407. throw new IFException("I/O error in endPageTrailer()", ioe);
  408. }
  409. super.endPageTrailer();
  410. }
  411. /** {@inheritDoc} */
  412. public void endPage() throws IFException {
  413. try {
  414. gen.getResourceTracker().writeResources(true, gen);
  415. } catch (IOException ioe) {
  416. throw new IFException("I/O error in endPage()", ioe);
  417. }
  418. this.currentPageDefinition = null;
  419. }
  420. private boolean inPage() {
  421. return this.currentPageDefinition != null;
  422. }
  423. /** {@inheritDoc} */
  424. public void handleExtensionObject(Object extension) throws IFException {
  425. try {
  426. if (extension instanceof PSSetupCode) {
  427. if (inPage()) {
  428. PSRenderingUtil.writeEnclosedExtensionAttachment(gen, (PSSetupCode)extension);
  429. } else {
  430. //A special collection for setup code as it's put in a different place
  431. //than the "before comments".
  432. if (setupCodeList == null) {
  433. setupCodeList = new java.util.ArrayList();
  434. }
  435. if (!setupCodeList.contains(extension)) {
  436. setupCodeList.add(extension);
  437. }
  438. }
  439. } else if (extension instanceof PSSetPageDevice) {
  440. /**
  441. * Extract all PSSetPageDevice instances from the
  442. * attachment list on the s-p-m and add all dictionary
  443. * entries to our internal representation of the the
  444. * page device dictionary.
  445. */
  446. PSSetPageDevice setPageDevice = (PSSetPageDevice)extension;
  447. String content = setPageDevice.getContent();
  448. if (content != null) {
  449. try {
  450. this.pageDeviceDictionary.putAll(PSDictionary.valueOf(content));
  451. } catch (PSDictionaryFormatException e) {
  452. PSEventProducer eventProducer = PSEventProducer.Provider.get(
  453. getUserAgent().getEventBroadcaster());
  454. eventProducer.postscriptDictionaryParseError(this, content, e);
  455. }
  456. }
  457. } else if (extension instanceof PSCommentBefore) {
  458. if (inPage()) {
  459. PSRenderingUtil.writeEnclosedExtensionAttachment(
  460. gen, (PSCommentBefore)extension);
  461. } else {
  462. if (comments[COMMENT_DOCUMENT_HEADER] == null) {
  463. comments[COMMENT_DOCUMENT_HEADER] = new java.util.ArrayList();
  464. }
  465. comments[COMMENT_DOCUMENT_HEADER].add(extension);
  466. }
  467. } else if (extension instanceof PSCommentAfter) {
  468. int targetCollection = (inPage() ? COMMENT_PAGE_TRAILER : COMMENT_DOCUMENT_TRAILER);
  469. if (comments[targetCollection] == null) {
  470. comments[targetCollection] = new java.util.ArrayList();
  471. }
  472. comments[targetCollection].add(extension);
  473. } else if (extension instanceof PSPageTrailerCodeBefore) {
  474. if (comments[PAGE_TRAILER_CODE_BEFORE] == null) {
  475. comments[PAGE_TRAILER_CODE_BEFORE] = new ArrayList();
  476. }
  477. comments[PAGE_TRAILER_CODE_BEFORE].add(extension);
  478. }
  479. } catch (IOException ioe) {
  480. throw new IFException("I/O error in handleExtensionObject()", ioe);
  481. }
  482. }
  483. /**
  484. * Returns the PSResource for the given font key.
  485. * @param key the font key ("F*")
  486. * @return the matching PSResource
  487. */
  488. protected PSResource getPSResourceForFontKey(String key) {
  489. return this.fontResources.getPSResourceForFontKey(key);
  490. }
  491. /**
  492. * Returns a PSResource instance representing a image as a PostScript form.
  493. * @param uri the image URI
  494. * @return a PSResource instance
  495. */
  496. protected PSResource getFormForImage(String uri) {
  497. if (uri == null || "".equals(uri)) {
  498. throw new IllegalArgumentException("uri must not be empty or null");
  499. }
  500. if (this.formResources == null) {
  501. this.formResources = new java.util.HashMap();
  502. }
  503. PSResource form = (PSResource)this.formResources.get(uri);
  504. if (form == null) {
  505. form = new PSImageFormResource(this.formResources.size() + 1, uri);
  506. this.formResources.put(uri, form);
  507. }
  508. return form;
  509. }
  510. private static final class PageDefinition {
  511. private Dimension2D dimensions;
  512. private boolean rotate;
  513. private PageDefinition(Dimension2D dimensions, boolean rotate) {
  514. this.dimensions = dimensions;
  515. this.rotate = rotate;
  516. }
  517. }
  518. }