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.

PSRenderer.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.render.ps;
  52. // Java
  53. import java.awt.geom.Rectangle2D;
  54. import java.io.IOException;
  55. import java.io.OutputStream;
  56. import java.util.Iterator;
  57. import java.util.List;
  58. import java.util.Map;
  59. // FOP
  60. import org.apache.fop.apps.FOPException;
  61. import org.apache.fop.area.Block;
  62. import org.apache.fop.area.BlockViewport;
  63. import org.apache.fop.area.CTM;
  64. import org.apache.fop.area.PageViewport;
  65. import org.apache.fop.area.Trait;
  66. import org.apache.fop.area.inline.ForeignObject;
  67. import org.apache.fop.area.inline.Word;
  68. import org.apache.fop.datatypes.ColorType;
  69. import org.apache.fop.fo.FOUserAgent;
  70. import org.apache.fop.fonts.Font;
  71. import org.apache.fop.layout.FontInfo;
  72. import org.apache.fop.render.AbstractRenderer;
  73. import org.apache.fop.render.RendererContext;
  74. import org.w3c.dom.Document;
  75. /**
  76. * Renderer that renders to PostScript.
  77. * <br>
  78. * This class currently generates PostScript Level 2 code. The only exception
  79. * is the FlateEncode filter which is a Level 3 feature. The filters in use
  80. * are hardcoded at the moment.
  81. * <br>
  82. * This class follows the Document Structuring Conventions (DSC) version 3.0.
  83. * If anyone modifies this renderer please make
  84. * sure to also follow the DSC to make it simpler to programmatically modify
  85. * the generated Postscript files (ex. extract pages etc.).
  86. * <br>
  87. * The PS renderer operates in millipoints as the layout engine. Since PostScript
  88. * initially uses points, scaling is applied as needed.
  89. * @todo Rebuild the PostScript renderer
  90. *
  91. * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
  92. * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
  93. * @version $Id$
  94. */
  95. public class PSRenderer extends AbstractRenderer {
  96. /** The MIME type for PostScript */
  97. public static final String MIME_TYPE = "application/postscript";
  98. /** The application producing the PostScript */
  99. protected String producer;
  100. private int currentPageNumber = 0;
  101. private boolean enableComments = true;
  102. /** The PostScript generator used to output the PostScript */
  103. protected PSGenerator gen;
  104. private boolean ioTrouble = false;
  105. private String currentFontName;
  106. private int currentFontSize;
  107. private int pageHeight;
  108. private int pageWidth;
  109. private float currRed;
  110. private float currGreen;
  111. private float currBlue;
  112. private FontInfo fontInfo;
  113. /**
  114. * Set the document's producer
  115. *
  116. * @param producer string indicating application producing the PostScript
  117. */
  118. public void setProducer(String producer) {
  119. this.producer = producer;
  120. }
  121. /**
  122. * @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
  123. */
  124. public void setUserAgent(FOUserAgent agent) {
  125. super.setUserAgent(agent);
  126. PSXMLHandler xmlHandler = new PSXMLHandler();
  127. //userAgent.setDefaultXMLHandler(MIME_TYPE, xmlHandler);
  128. String svg = "http://www.w3.org/2000/svg";
  129. userAgent.addXMLHandler(MIME_TYPE, svg, xmlHandler);
  130. }
  131. /**
  132. * Write out a command
  133. * @param cmd PostScript command
  134. */
  135. protected void writeln(String cmd) {
  136. try {
  137. gen.writeln(cmd);
  138. } catch (IOException ioe) {
  139. handleIOTrouble(ioe);
  140. }
  141. }
  142. /**
  143. * Central exception handler for I/O exceptions.
  144. * @param ioe IOException to handle
  145. */
  146. protected void handleIOTrouble(IOException ioe) {
  147. if (!ioTrouble) {
  148. getLogger().error("Error while writing to target file", ioe);
  149. ioTrouble = true;
  150. }
  151. }
  152. /**
  153. * Write out a comment
  154. * @param comment Comment to write
  155. */
  156. protected void comment(String comment) {
  157. if (this.enableComments) {
  158. writeln(comment);
  159. }
  160. }
  161. /**
  162. * Generates the PostScript code for the font dictionary.
  163. * @param fontInfo available fonts
  164. */
  165. protected void writeFontDict(FontInfo fontInfo) {
  166. writeln("%%BeginResource: procset FOPFonts");
  167. writeln("%%Title: Font setup (shortcuts) for this file");
  168. writeln("/FOPFonts 100 dict dup begin");
  169. // write("/gfF1{/Helvetica findfont} bd");
  170. // write("/gfF3{/Helvetica-Bold findfont} bd");
  171. Map fonts = fontInfo.getFonts();
  172. Iterator enum = fonts.keySet().iterator();
  173. while (enum.hasNext()) {
  174. String key = (String)enum.next();
  175. Font fm = (Font)fonts.get(key);
  176. writeln("/" + key + " /" + fm.getFontName() + " def");
  177. }
  178. writeln("end def");
  179. writeln("%%EndResource");
  180. enum = fonts.keySet().iterator();
  181. while (enum.hasNext()) {
  182. String key = (String)enum.next();
  183. Font fm = (Font)fonts.get(key);
  184. writeln("/" + fm.getFontName() + " findfont");
  185. writeln("dup length dict begin");
  186. writeln(" {1 index /FID ne {def} {pop pop} ifelse} forall");
  187. writeln(" /Encoding ISOLatin1Encoding def");
  188. writeln(" currentdict");
  189. writeln("end");
  190. writeln("/" + fm.getFontName() + " exch definefont pop");
  191. }
  192. }
  193. /**
  194. * Make sure the cursor is in the right place.
  195. */
  196. protected void movetoCurrPosition() {
  197. moveTo(this.currentIPPosition, this.currentBPPosition);
  198. }
  199. /**
  200. * Moves the cursor.
  201. * @param x X coordinate
  202. * @param y Y coordinate
  203. */
  204. protected void moveTo(int x, int y) {
  205. writeln(x + " " + y + " M");
  206. }
  207. /** Saves the graphics state of the rendering engine. */
  208. public void saveGraphicsState() {
  209. try {
  210. //delegate
  211. gen.saveGraphicsState();
  212. } catch (IOException ioe) {
  213. handleIOTrouble(ioe);
  214. }
  215. }
  216. /** Restores the last graphics state of the rendering engine. */
  217. public void restoreGraphicsState() {
  218. try {
  219. //delegate
  220. gen.restoreGraphicsState();
  221. } catch (IOException ioe) {
  222. handleIOTrouble(ioe);
  223. }
  224. }
  225. /** Indicates the beginning of a text object. */
  226. protected void beginTextObject() {
  227. writeln("BT");
  228. }
  229. /** Indicates the end of a text object. */
  230. protected void endTextObject() {
  231. writeln("ET");
  232. }
  233. /**
  234. * Concats the transformation matrix.
  235. * @param a A part
  236. * @param b B part
  237. * @param c C part
  238. * @param d D part
  239. * @param e E part
  240. * @param f F part
  241. */
  242. protected void concatMatrix(double a, double b,
  243. double c, double d,
  244. double e, double f) {
  245. try {
  246. gen.concatMatrix(a, b, c, d, e, f);
  247. } catch (IOException ioe) {
  248. handleIOTrouble(ioe);
  249. }
  250. }
  251. /**
  252. * Concats the transformations matrix.
  253. * @param matrix Matrix to use
  254. */
  255. protected void concatMatrix(double[] matrix) {
  256. try {
  257. gen.concatMatrix(matrix);
  258. } catch (IOException ioe) {
  259. handleIOTrouble(ioe);
  260. }
  261. }
  262. /**
  263. * Set up the font info
  264. *
  265. * @param fontInfo the font info object to set up
  266. */
  267. public void setupFontInfo(FontInfo fontInfo) {
  268. /* use PDF's font setup to get PDF metrics */
  269. org.apache.fop.render.pdf.FontSetup.setup(fontInfo, null);
  270. this.fontInfo = fontInfo;
  271. }
  272. /**
  273. * Draws a filled rectangle.
  274. * @param x x-coordinate
  275. * @param y y-coordinate
  276. * @param w width
  277. * @param h height
  278. * @param col color to fill with
  279. */
  280. protected void fillRect(int x, int y, int w, int h,
  281. ColorType col) {
  282. useColor(col);
  283. writeln(x + " " + y + " " + w + " " + h + " rectfill");
  284. }
  285. /**
  286. * Draws a stroked rectangle with the current stroke settings.
  287. * @param x x-coordinate
  288. * @param y y-coordinate
  289. * @param w width
  290. * @param h height
  291. */
  292. protected void drawRect(int x, int y, int w, int h) {
  293. writeln(x + " " + y + " " + w + " " + h + " rectstroke");
  294. }
  295. /**
  296. * Clip an area.
  297. * Write a clipping operation given coordinates in the current
  298. * transform.
  299. * @param x the x coordinate
  300. * @param y the y coordinate
  301. * @param width the width of the area
  302. * @param height the height of the area
  303. */
  304. protected void clip(float x, float y, float width, float height) {
  305. writeln(x + " " + y + " " + width + " " + height + " rectclip");
  306. }
  307. /**
  308. * Changes the currently used font.
  309. * @param name name of the font
  310. * @param size font size
  311. */
  312. public void useFont(String name, int size) {
  313. if ((currentFontName != name) || (currentFontSize != size)) {
  314. writeln(name + " " + size + " F");
  315. currentFontName = name;
  316. currentFontSize = size;
  317. }
  318. }
  319. private void useColor(ColorType col) {
  320. useColor(col.getRed(), col.getGreen(), col.getBlue());
  321. }
  322. private void useColor(float red, float green, float blue) {
  323. if ((red != currRed) || (green != currGreen) || (blue != currBlue)) {
  324. writeln(red + " " + green + " " + blue + " setrgbcolor");
  325. currRed = red;
  326. currGreen = green;
  327. currBlue = blue;
  328. }
  329. }
  330. /**
  331. * @see org.apache.fop.render.Renderer#startRenderer(OutputStream)
  332. */
  333. public void startRenderer(OutputStream outputStream)
  334. throws IOException {
  335. getLogger().debug("rendering areas to PostScript");
  336. //Setup for PostScript generation
  337. this.gen = new PSGenerator(outputStream);
  338. this.currentPageNumber = 0;
  339. //PostScript Header
  340. writeln(DSCConstants.PS_ADOBE_30);
  341. gen.writeDSCComment(DSCConstants.CREATOR, new String[] {"FOP " + this.producer});
  342. gen.writeDSCComment(DSCConstants.CREATION_DATE, new Object[] {new java.util.Date()});
  343. gen.writeDSCComment(DSCConstants.PAGES, new Object[] {PSGenerator.ATEND});
  344. gen.writeDSCComment(DSCConstants.END_COMMENTS);
  345. //Defaults
  346. gen.writeDSCComment(DSCConstants.BEGIN_DEFAULTS);
  347. gen.writeDSCComment(DSCConstants.END_DEFAULTS);
  348. //Prolog
  349. gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
  350. gen.writeDSCComment(DSCConstants.END_PROLOG);
  351. //Setup
  352. gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
  353. PSProcSets.writeFOPStdProcSet(gen);
  354. PSProcSets.writeFOPEPSProcSet(gen);
  355. writeFontDict(fontInfo);
  356. gen.writeDSCComment(DSCConstants.END_SETUP);
  357. }
  358. /**
  359. * @see org.apache.fop.render.Renderer#stopRenderer()
  360. */
  361. public void stopRenderer() throws IOException {
  362. gen.writeDSCComment(DSCConstants.TRAILER);
  363. gen.writeDSCComment(DSCConstants.PAGES, new Integer(this.currentPageNumber));
  364. gen.writeDSCComment(DSCConstants.EOF);
  365. gen.flush();
  366. }
  367. /**
  368. * @see org.apache.fop.render.Renderer#renderPage(PageViewport)
  369. */
  370. public void renderPage(PageViewport page)
  371. throws IOException, FOPException {
  372. getLogger().debug("renderPage(): " + page);
  373. this.currentPageNumber++;
  374. gen.writeDSCComment(DSCConstants.PAGE, new Object[]
  375. {page.getPageNumber(),
  376. new Integer(this.currentPageNumber)});
  377. final Integer zero = new Integer(0);
  378. final Long pagewidth = new Long(Math.round(page.getViewArea().getWidth() / 1000f));
  379. final Long pageheight = new Long(Math.round(page.getViewArea().getHeight() / 1000f));
  380. gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
  381. {zero, zero, pagewidth, pageheight});
  382. gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
  383. gen.writeln("FOPFonts begin");
  384. concatMatrix(1, 0, 0, -1, 0, pageheight.doubleValue());
  385. gen.writeln("0.001 0.001 scale");
  386. gen.writeDSCComment(DSCConstants.END_PAGE_SETUP);
  387. //Process page
  388. super.renderPage(page);
  389. writeln("showpage");
  390. gen.writeDSCComment(DSCConstants.PAGE_TRAILER);
  391. gen.writeDSCComment(DSCConstants.END_PAGE);
  392. }
  393. /**
  394. * Paints text.
  395. * @param rx X coordinate
  396. * @param bl Y coordinate
  397. * @param text Text to paint
  398. * @param font Font to use
  399. */
  400. protected void paintText(int rx, int bl, String text, Font font) {
  401. saveGraphicsState();
  402. writeln("1 0 0 -1 " + rx + " " + bl + " Tm");
  403. int initialSize = text.length();
  404. initialSize += initialSize / 2;
  405. StringBuffer sb = new StringBuffer(initialSize);
  406. sb.append("(");
  407. for (int i = 0; i < text.length(); i++) {
  408. final char c = text.charAt(i);
  409. final char mapped = font.mapChar(c);
  410. gen.escapeChar(mapped, sb);
  411. }
  412. sb.append(") t");
  413. writeln(sb.toString());
  414. restoreGraphicsState();
  415. }
  416. /**
  417. * @see org.apache.fop.render.Renderer#renderWord(Word)
  418. */
  419. public void renderWord(Word area) {
  420. String fontname = (String)area.getTrait(Trait.FONT_NAME);
  421. int fontsize = area.getTraitAsInteger(Trait.FONT_SIZE);
  422. // This assumes that *all* CIDFonts use a /ToUnicode mapping
  423. Font f = (Font)fontInfo.getFonts().get(fontname);
  424. //Determine position
  425. int rx = currentBlockIPPosition;
  426. int bl = currentBPPosition + area.getOffset();
  427. useFont(fontname, fontsize);
  428. paintText(rx, bl, area.getWord(), f);
  429. /*
  430. String psString = null;
  431. if (area.getFontState().getLetterSpacing() > 0) {
  432. //float f = area.getFontState().getLetterSpacing()
  433. // * 1000 / this.currentFontSize;
  434. float f = area.getFontState().getLetterSpacing();
  435. psString = (new StringBuffer().append(f).append(" 0.0 (")
  436. .append(sb.toString()).append(") A")).toString();
  437. } else {
  438. psString = (new StringBuffer("(").append(sb.toString())
  439. .append(") t")).toString();
  440. }
  441. // System.out.println("["+s+"] --> ["+sb.toString()+"]");
  442. // comment("% --- InlineArea font-weight="+fontWeight+": " + sb.toString());
  443. useFont(fs.getFontName(), fs.getFontSize());
  444. useColor(area.getRed(), area.getGreen(), area.getBlue());
  445. if (area.getUnderlined() || area.getLineThrough()
  446. || area.getOverlined())
  447. write("ULS");
  448. write(psString);
  449. if (area.getUnderlined())
  450. write("ULE");
  451. if (area.getLineThrough())
  452. write("SOE");
  453. if (area.getOverlined())
  454. write("OLE");
  455. this.currentXPosition += area.getContentWidth();
  456. */
  457. super.renderWord(area); //Updates IPD
  458. }
  459. /**
  460. * @see org.apache.fop.render.AbstractRenderer#renderBlockViewport(BlockViewport, List)
  461. */
  462. protected void renderBlockViewport(BlockViewport bv, List children) {
  463. // clip and position viewport if necessary
  464. // save positions
  465. int saveIP = currentIPPosition;
  466. int saveBP = currentBPPosition;
  467. String saveFontName = currentFontName;
  468. CTM ctm = bv.getCTM();
  469. if (bv.getPositioning() == Block.ABSOLUTE) {
  470. currentIPPosition = 0;
  471. currentBPPosition = 0;
  472. //closeText();
  473. endTextObject();
  474. if (bv.getClip()) {
  475. saveGraphicsState();
  476. int x = bv.getXOffset() + containingIPPosition;
  477. int y = bv.getYOffset() + containingBPPosition;
  478. int width = bv.getWidth();
  479. int height = bv.getHeight();
  480. clip(x, y, width, height);
  481. }
  482. CTM tempctm = new CTM(containingIPPosition, containingBPPosition);
  483. ctm = tempctm.multiply(ctm);
  484. startVParea(ctm);
  485. handleBlockTraits(bv);
  486. renderBlocks(children);
  487. endVParea();
  488. if (bv.getClip()) {
  489. restoreGraphicsState();
  490. }
  491. beginTextObject();
  492. // clip if necessary
  493. currentIPPosition = saveIP;
  494. currentBPPosition = saveBP;
  495. } else {
  496. if (ctm != null) {
  497. currentIPPosition = 0;
  498. currentBPPosition = 0;
  499. //closeText();
  500. endTextObject();
  501. double[] vals = ctm.toArray();
  502. //boolean aclock = vals[2] == 1.0;
  503. if (vals[2] == 1.0) {
  504. ctm = ctm.translate(-saveBP - bv.getHeight(), -saveIP);
  505. } else if (vals[0] == -1.0) {
  506. ctm = ctm.translate(-saveIP - bv.getWidth(), -saveBP - bv.getHeight());
  507. } else {
  508. ctm = ctm.translate(saveBP, saveIP - bv.getWidth());
  509. }
  510. }
  511. // clip if necessary
  512. if (bv.getClip()) {
  513. if (ctm == null) {
  514. //closeText();
  515. endTextObject();
  516. }
  517. saveGraphicsState();
  518. int x = bv.getXOffset();
  519. int y = bv.getYOffset();
  520. int width = bv.getWidth();
  521. int height = bv.getHeight();
  522. clip(x, y, width, height);
  523. }
  524. if (ctm != null) {
  525. startVParea(ctm);
  526. }
  527. handleBlockTraits(bv);
  528. renderBlocks(children);
  529. if (ctm != null) {
  530. endVParea();
  531. }
  532. if (bv.getClip()) {
  533. restoreGraphicsState();
  534. if (ctm == null) {
  535. beginTextObject();
  536. }
  537. }
  538. if (ctm != null) {
  539. beginTextObject();
  540. }
  541. currentIPPosition = saveIP;
  542. currentBPPosition = saveBP;
  543. currentBPPosition += (int)(bv.getHeight());
  544. }
  545. currentFontName = saveFontName;
  546. }
  547. /**
  548. * @see org.apache.fop.render.AbstractRenderer#startVParea(CTM)
  549. */
  550. protected void startVParea(CTM ctm) {
  551. // Set the given CTM in the graphics state
  552. //currentState.push();
  553. //currentState.setTransform(new AffineTransform(CTMHelper.toPDFArray(ctm)));
  554. saveGraphicsState();
  555. // multiply with current CTM
  556. //currentStream.add(CTMHelper.toPDFString(ctm) + " cm\n");
  557. final double matrix[] = ctm.toArray();
  558. concatMatrix(matrix);
  559. // Set clip?
  560. beginTextObject();
  561. }
  562. /**
  563. * @see org.apache.fop.render.AbstractRenderer#endVParea()
  564. */
  565. protected void endVParea() {
  566. endTextObject();
  567. restoreGraphicsState();
  568. //currentState.pop();
  569. }
  570. /**
  571. * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D)
  572. */
  573. public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
  574. Document doc = fo.getDocument();
  575. String ns = fo.getNameSpace();
  576. renderDocument(doc, ns, pos);
  577. }
  578. /**
  579. * Renders an XML document (SVG for example).
  580. * @param doc DOM Document containing the XML document to be rendered
  581. * @param ns Namespace for the XML document
  582. * @param pos Position for the generated graphic/image
  583. */
  584. public void renderDocument(Document doc, String ns, Rectangle2D pos) {
  585. RendererContext context;
  586. context = new RendererContext(MIME_TYPE);
  587. context.setUserAgent(userAgent);
  588. context.setProperty(PSXMLHandler.PS_GENERATOR, this.gen);
  589. context.setProperty(PSXMLHandler.PS_FONT_INFO, fontInfo);
  590. context.setProperty(PSXMLHandler.PS_WIDTH,
  591. new Integer((int) pos.getWidth()));
  592. context.setProperty(PSXMLHandler.PS_HEIGHT,
  593. new Integer((int) pos.getHeight()));
  594. context.setProperty(PSXMLHandler.PS_XPOS,
  595. new Integer(currentBlockIPPosition + (int) pos.getX()));
  596. context.setProperty(PSXMLHandler.PS_YPOS,
  597. new Integer(currentBPPosition + (int) pos.getY()));
  598. /*
  599. context.setProperty(PDFXMLHandler.PDF_DOCUMENT, pdfDoc);
  600. context.setProperty(PDFXMLHandler.OUTPUT_STREAM, ostream);
  601. context.setProperty(PDFXMLHandler.PDF_STATE, currentState);
  602. context.setProperty(PDFXMLHandler.PDF_PAGE, currentPage);
  603. context.setProperty(PDFXMLHandler.PDF_CONTEXT,
  604. currentContext == null ? currentPage: currentContext);
  605. context.setProperty(PDFXMLHandler.PDF_CONTEXT, currentContext);
  606. context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream);
  607. context.setProperty(PDFXMLHandler.PDF_XPOS,
  608. new Integer(currentBlockIPPosition + (int) pos.getX()));
  609. context.setProperty(PDFXMLHandler.PDF_YPOS,
  610. new Integer(currentBPPosition + (int) pos.getY()));
  611. context.setProperty(PDFXMLHandler.PDF_FONT_INFO, fontInfo);
  612. context.setProperty(PDFXMLHandler.PDF_FONT_NAME, currentFontName);
  613. context.setProperty(PDFXMLHandler.PDF_FONT_SIZE,
  614. new Integer(currentFontSize));
  615. context.setProperty(PDFXMLHandler.PDF_WIDTH,
  616. new Integer((int) pos.getWidth()));
  617. context.setProperty(PDFXMLHandler.PDF_HEIGHT,
  618. new Integer((int) pos.getHeight()));
  619. */
  620. userAgent.renderXML(context, doc, ns);
  621. }
  622. }