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.

XMLRenderer.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * Copyright 1999-2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.xml;
  18. // Java
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.Iterator;
  24. import java.awt.geom.Rectangle2D;
  25. import javax.xml.transform.TransformerConfigurationException;
  26. import javax.xml.transform.sax.SAXTransformerFactory;
  27. import javax.xml.transform.sax.TransformerHandler;
  28. import javax.xml.transform.stream.StreamResult;
  29. import org.apache.avalon.framework.configuration.Configuration;
  30. import org.apache.avalon.framework.configuration.ConfigurationException;
  31. import org.w3c.dom.Document;
  32. import org.xml.sax.Attributes;
  33. import org.xml.sax.SAXException;
  34. import org.xml.sax.helpers.AttributesImpl;
  35. // FOP
  36. import org.apache.fop.render.PrintRenderer;
  37. import org.apache.fop.render.Renderer;
  38. import org.apache.fop.render.RendererContext;
  39. import org.apache.fop.render.XMLHandler;
  40. import org.apache.fop.apps.FOUserAgent;
  41. import org.apache.fop.apps.FOPException;
  42. import org.apache.fop.apps.MimeConstants;
  43. import org.apache.fop.area.Area;
  44. import org.apache.fop.area.BeforeFloat;
  45. import org.apache.fop.area.Block;
  46. import org.apache.fop.area.BlockViewport;
  47. import org.apache.fop.area.BodyRegion;
  48. import org.apache.fop.area.CTM;
  49. import org.apache.fop.area.NormalFlow;
  50. import org.apache.fop.area.Footnote;
  51. import org.apache.fop.area.LineArea;
  52. import org.apache.fop.area.MainReference;
  53. import org.apache.fop.area.PageViewport;
  54. import org.apache.fop.area.RegionReference;
  55. import org.apache.fop.area.RegionViewport;
  56. import org.apache.fop.area.Span;
  57. import org.apache.fop.area.Trait;
  58. import org.apache.fop.area.Trait.Background;
  59. import org.apache.fop.area.inline.Container;
  60. import org.apache.fop.area.inline.ForeignObject;
  61. import org.apache.fop.area.inline.Image;
  62. import org.apache.fop.area.inline.InlineArea;
  63. import org.apache.fop.area.inline.InlineBlockParent;
  64. import org.apache.fop.area.inline.InlineParent;
  65. import org.apache.fop.area.inline.Leader;
  66. import org.apache.fop.area.inline.Space;
  67. import org.apache.fop.area.inline.Viewport;
  68. import org.apache.fop.area.inline.TextArea;
  69. import org.apache.fop.area.inline.SpaceArea;
  70. import org.apache.fop.area.inline.WordArea;
  71. import org.apache.fop.fo.Constants;
  72. import org.apache.fop.fonts.FontInfo;
  73. import org.apache.fop.fonts.FontSetup;
  74. import org.apache.fop.fonts.FontTriplet;
  75. /**
  76. * Renderer that renders areas to XML for debugging purposes.
  77. * This creates an xml that contains the information of the area
  78. * tree. It does not output any state or derived information.
  79. * The output can be used to build a new area tree (@see AreaTreeBuilder)
  80. * which can be rendered to any renderer.
  81. */
  82. public class XMLRenderer extends PrintRenderer {
  83. /** XML MIME type */
  84. public static final String XML_MIME_TYPE = MimeConstants.MIME_FOP_AREA_TREE;
  85. /** Main namespace in use. */
  86. public static final String NS = "";
  87. /** CDATA type */
  88. public static final String CDATA = "CDATA";
  89. /** An empty Attributes object used when no attributes are needed. */
  90. public static final Attributes EMPTY_ATTS = new AttributesImpl();
  91. private boolean startedSequence = false;
  92. private RendererContext context;
  93. /** If not null, the XMLRenderer will mimic another renderer by using its font setup. */
  94. protected Renderer mimic;
  95. /** TransformerHandler that the generated XML is written to */
  96. protected TransformerHandler handler;
  97. /** AttributesImpl instance that can be used during XML generation. */
  98. protected AttributesImpl atts = new AttributesImpl();
  99. /** The OutputStream to write the generated XML to. */
  100. protected OutputStream out;
  101. /**
  102. * Creates a new XML renderer.
  103. */
  104. public XMLRenderer() {
  105. context = new RendererContext(this, XML_MIME_TYPE);
  106. }
  107. /**
  108. * Configure the XML renderer.
  109. * Get the configuration to be used for fonts etc.
  110. * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
  111. */
  112. public void configure(Configuration cfg) throws ConfigurationException {
  113. super.configure(cfg);
  114. //Font configuration
  115. List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
  116. if (this.fontList == null) {
  117. this.fontList = cfgFonts;
  118. } else {
  119. this.fontList.addAll(cfgFonts);
  120. }
  121. }
  122. /**
  123. * @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
  124. */
  125. public void setUserAgent(FOUserAgent agent) {
  126. super.setUserAgent(agent);
  127. XMLHandler xmlHandler = new XMLXMLHandler();
  128. userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
  129. }
  130. /**
  131. * Call this method to make the XMLRenderer mimic a different renderer by using its font
  132. * setup. This is useful when working with the intermediate format parser.
  133. * @param renderer the renderer to mimic
  134. */
  135. public void mimicRenderer(Renderer renderer) {
  136. this.mimic = renderer;
  137. }
  138. /** @see org.apache.fop.render.PrintRenderer#setupFontInfo(org.apache.fop.fonts.FontInfo) */
  139. public void setupFontInfo(FontInfo inFontInfo) {
  140. if (mimic != null) {
  141. mimic.setupFontInfo(inFontInfo);
  142. } else {
  143. super.setupFontInfo(inFontInfo);
  144. }
  145. }
  146. /**
  147. * Sets an outside TransformerHandler to use instead of the default one
  148. * create in this class in startRenderer().
  149. * @param handler Overriding TransformerHandler
  150. */
  151. public void setTransformerHandler(TransformerHandler handler) {
  152. this.handler = handler;
  153. }
  154. private boolean isCoarseXml() {
  155. return ((Boolean)
  156. userAgent.getRendererOptions().get("fineDetail")).booleanValue();
  157. }
  158. /**
  159. * Handles SAXExceptions.
  160. * @param saxe the SAXException to handle
  161. */
  162. protected void handleSAXException(SAXException saxe) {
  163. throw new RuntimeException(saxe.getMessage());
  164. }
  165. /**
  166. * Writes a comment to the generated XML.
  167. * @param comment the comment
  168. */
  169. protected void comment(String comment) {
  170. try {
  171. handler.comment(comment.toCharArray(), 0, comment.length());
  172. } catch (SAXException saxe) {
  173. handleSAXException(saxe);
  174. }
  175. }
  176. /**
  177. * Starts a new element (without attributes).
  178. * @param tagName tag name of the element
  179. */
  180. protected void startElement(String tagName) {
  181. startElement(tagName, EMPTY_ATTS);
  182. }
  183. /**
  184. * Starts a new element.
  185. * @param tagName tag name of the element
  186. * @param atts attributes to add
  187. */
  188. protected void startElement(String tagName, Attributes atts) {
  189. try {
  190. handler.startElement(NS, tagName, tagName, atts);
  191. } catch (SAXException saxe) {
  192. handleSAXException(saxe);
  193. }
  194. }
  195. /**
  196. * Ends an element.
  197. * @param tagName tag name of the element
  198. */
  199. protected void endElement(String tagName) {
  200. try {
  201. handler.endElement(NS, tagName, tagName);
  202. } catch (SAXException saxe) {
  203. handleSAXException(saxe);
  204. }
  205. }
  206. /**
  207. * Sends plain text to the XML
  208. * @param text the text
  209. */
  210. protected void characters(String text) {
  211. try {
  212. char[] ca = text.toCharArray();
  213. handler.characters(ca, 0, ca.length);
  214. } catch (SAXException saxe) {
  215. handleSAXException(saxe);
  216. }
  217. }
  218. /**
  219. * Adds a new attribute to the protected member variable "atts".
  220. * @param name name of the attribute
  221. * @param value value of the attribute
  222. */
  223. protected void addAttribute(String name, String value) {
  224. atts.addAttribute(NS, name, name, CDATA, value);
  225. }
  226. /**
  227. * Adds a new attribute to the protected member variable "atts".
  228. * @param name name of the attribute
  229. * @param value value of the attribute
  230. */
  231. protected void addAttribute(String name, int value) {
  232. addAttribute(name, Integer.toString(value));
  233. }
  234. /**
  235. * Adds a new attribute to the protected member variable "atts".
  236. * @param name name of the attribute
  237. * @param rect a Rectangle2D to format and use as attribute value
  238. */
  239. protected void addAttribute(String name, Rectangle2D rect) {
  240. addAttribute(name, createString(rect));
  241. }
  242. /**
  243. * Adds the general Area attributes.
  244. * @param area Area to extract attributes from
  245. */
  246. protected void addAreaAttributes(Area area) {
  247. addAttribute("ipd", area.getIPD());
  248. addAttribute("bpd", area.getBPD());
  249. if (area.getIPD() != 0) {
  250. addAttribute("ipda", area.getAllocIPD());
  251. }
  252. if (area.getBPD() != 0) {
  253. addAttribute("bpda", area.getAllocBPD());
  254. }
  255. addAttribute("bap", area.getBorderAndPaddingWidthStart() + " "
  256. + area.getBorderAndPaddingWidthEnd() + " "
  257. + area.getBorderAndPaddingWidthBefore() + " "
  258. + area.getBorderAndPaddingWidthAfter());
  259. }
  260. /**
  261. * Adds attributes from traits of an Area.
  262. * @param area Area to extract traits from
  263. */
  264. protected void addTraitAttributes(Area area) {
  265. Map traitMap = area.getTraits();
  266. if (traitMap != null) {
  267. Iterator iter = traitMap.entrySet().iterator();
  268. while (iter.hasNext()) {
  269. Map.Entry traitEntry = (Map.Entry) iter.next();
  270. String name = Trait.getTraitName(traitEntry.getKey());
  271. Class clazz = Trait.getTraitClass(traitEntry.getKey());
  272. if ("break-before".equals(name) || "break-after".equals(name)) {
  273. continue;
  274. }
  275. Object value = traitEntry.getValue();
  276. if (Trait.getTraitName(Trait.FONT).equals(name)) {
  277. FontTriplet triplet = (FontTriplet)value;
  278. addAttribute("font-name", triplet.getName());
  279. addAttribute("font-style", triplet.getStyle());
  280. addAttribute("font-weight", triplet.getWeight());
  281. } else if (clazz.equals(Background.class)) {
  282. Background bkg = (Background)value;
  283. //TODO Remove the following line (makes changes in the test checks necessary)
  284. addAttribute(name, bkg.toString());
  285. if (bkg.getColor() != null) {
  286. addAttribute("bkg-color", bkg.getColor().toString());
  287. }
  288. if (bkg.getURL() != null) {
  289. addAttribute("bkg-img", bkg.getURL());
  290. String repString;
  291. int repeat = bkg.getRepeat();
  292. switch (repeat) {
  293. case Constants.EN_REPEAT:
  294. repString = "repeat";
  295. break;
  296. case Constants.EN_REPEATX:
  297. repString = "repeat-x";
  298. break;
  299. case Constants.EN_REPEATY:
  300. repString = "repeat-y";
  301. break;
  302. case Constants.EN_NOREPEAT:
  303. repString = "no-repeat";
  304. break;
  305. default:
  306. throw new IllegalStateException(
  307. "Illegal value for repeat encountered: " + repeat);
  308. }
  309. addAttribute("bkg-repeat", repString);
  310. addAttribute("bkg-horz-offset", bkg.getHoriz());
  311. addAttribute("bkg-vert-offset", bkg.getVertical());
  312. }
  313. } else {
  314. addAttribute(name, value.toString());
  315. }
  316. }
  317. }
  318. }
  319. private String createString(Rectangle2D rect) {
  320. return "" + (int) rect.getX() + " " + (int) rect.getY() + " "
  321. + (int) rect.getWidth() + " " + (int) rect.getHeight();
  322. }
  323. /**
  324. * @see org.apache.fop.render.Renderer#startRenderer(OutputStream)
  325. */
  326. public void startRenderer(OutputStream outputStream)
  327. throws IOException {
  328. log.debug("Rendering areas to Area Tree XML");
  329. if (this.handler == null) {
  330. SAXTransformerFactory factory
  331. = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
  332. try {
  333. this.handler = factory.newTransformerHandler();
  334. StreamResult res = new StreamResult(outputStream);
  335. handler.setResult(res);
  336. } catch (TransformerConfigurationException tce) {
  337. throw new RuntimeException(tce.getMessage());
  338. }
  339. this.out = outputStream;
  340. }
  341. try {
  342. handler.startDocument();
  343. } catch (SAXException saxe) {
  344. handleSAXException(saxe);
  345. }
  346. comment("Produced by "
  347. + (userAgent.getProducer() != null ? userAgent.getProducer() : ""));
  348. startElement("areaTree");
  349. }
  350. /**
  351. * @see org.apache.fop.render.Renderer#stopRenderer()
  352. */
  353. public void stopRenderer() throws IOException {
  354. if (startedSequence) {
  355. endElement("pageSequence");
  356. }
  357. endElement("areaTree");
  358. try {
  359. handler.endDocument();
  360. } catch (SAXException saxe) {
  361. handleSAXException(saxe);
  362. }
  363. if (this.out != null) {
  364. this.out.flush();
  365. }
  366. log.debug("Written out Area Tree XML");
  367. }
  368. /**
  369. * @see org.apache.fop.render.Renderer#renderPage(PageViewport)
  370. */
  371. public void renderPage(PageViewport page) throws IOException, FOPException {
  372. atts.clear();
  373. addAttribute("bounds", page.getViewArea());
  374. addAttribute("nr", page.getPageNumberString());
  375. startElement("pageViewport", atts);
  376. startElement("page");
  377. super.renderPage(page);
  378. endElement("page");
  379. endElement("pageViewport");
  380. }
  381. /**
  382. * @see org.apache.fop.render.Renderer#startPageSequence(LineArea)
  383. */
  384. public void startPageSequence(LineArea seqTitle) {
  385. if (startedSequence) {
  386. endElement("pageSequence");
  387. }
  388. startedSequence = true;
  389. startElement("pageSequence");
  390. if (seqTitle != null) {
  391. startElement("title");
  392. List children = seqTitle.getInlineAreas();
  393. for (int count = 0; count < children.size(); count++) {
  394. InlineArea inline = (InlineArea) children.get(count);
  395. renderInlineArea(inline);
  396. }
  397. endElement("title");
  398. }
  399. }
  400. /**
  401. * @see org.apache.fop.render.AbstractRenderer#renderRegionViewport(RegionViewport)
  402. */
  403. protected void renderRegionViewport(RegionViewport port) {
  404. if (port != null) {
  405. atts.clear();
  406. addAreaAttributes(port);
  407. addTraitAttributes(port);
  408. addAttribute("rect", port.getViewArea());
  409. if (port.isClip()) {
  410. addAttribute("clipped", "true");
  411. }
  412. startElement("regionViewport", atts);
  413. RegionReference region = port.getRegionReference();
  414. atts.clear();
  415. addAreaAttributes(region);
  416. addTraitAttributes(region);
  417. addAttribute("name", region.getRegionName());
  418. addAttribute("ctm", region.getCTM().toString());
  419. if (region.getRegionClass() == FO_REGION_BEFORE) {
  420. startElement("regionBefore", atts);
  421. renderRegion(region);
  422. endElement("regionBefore");
  423. } else if (region.getRegionClass() == FO_REGION_START) {
  424. startElement("regionStart", atts);
  425. renderRegion(region);
  426. endElement("regionStart");
  427. } else if (region.getRegionClass() == FO_REGION_BODY) {
  428. BodyRegion body = (BodyRegion)region;
  429. if (body.getColumnCount() != 1) {
  430. addAttribute("columnGap", body.getColumnGap());
  431. addAttribute("columnCount", body.getColumnCount());
  432. }
  433. startElement("regionBody", atts);
  434. renderBodyRegion(body);
  435. endElement("regionBody");
  436. } else if (region.getRegionClass() == FO_REGION_END) {
  437. startElement("regionEnd", atts);
  438. renderRegion(region);
  439. endElement("regionEnd");
  440. } else if (region.getRegionClass() == FO_REGION_AFTER) {
  441. startElement("regionAfter", atts);
  442. renderRegion(region);
  443. endElement("regionAfter");
  444. }
  445. endElement("regionViewport");
  446. }
  447. }
  448. /** @see org.apache.fop.render.AbstractRenderer */
  449. protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
  450. //only necessary for graphical output
  451. }
  452. /** @see org.apache.fop.render.AbstractRenderer#endVParea() */
  453. protected void endVParea() {
  454. //only necessary for graphical output
  455. }
  456. /**
  457. * @see org.apache.fop.render.AbstractRenderer#renderBeforeFloat(BeforeFloat)
  458. */
  459. protected void renderBeforeFloat(BeforeFloat bf) {
  460. startElement("beforeFloat");
  461. super.renderBeforeFloat(bf);
  462. endElement("beforeFloat");
  463. }
  464. /**
  465. * @see org.apache.fop.render.AbstractRenderer#renderFootnote(Footnote)
  466. */
  467. protected void renderFootnote(Footnote footnote) {
  468. startElement("footnote");
  469. super.renderFootnote(footnote);
  470. endElement("footnote");
  471. }
  472. /**
  473. * @see org.apache.fop.render.AbstractRenderer#renderMainReference(MainReference)
  474. */
  475. protected void renderMainReference(MainReference mr) {
  476. atts.clear();
  477. addAreaAttributes(mr);
  478. addTraitAttributes(mr);
  479. if (mr.getColumnCount() != 1) {
  480. addAttribute("columnGap", mr.getColumnGap());
  481. }
  482. startElement("mainReference", atts);
  483. Span span = null;
  484. List spans = mr.getSpans();
  485. for (int count = 0; count < spans.size(); count++) {
  486. span = (Span) spans.get(count);
  487. atts.clear();
  488. if (span.getColumnCount() != 1) {
  489. addAttribute("columnCount", span.getColumnCount());
  490. }
  491. addAreaAttributes(span);
  492. addTraitAttributes(span);
  493. startElement("span", atts);
  494. for (int c = 0; c < span.getColumnCount(); c++) {
  495. NormalFlow flow = (NormalFlow) span.getNormalFlow(c);
  496. renderFlow(flow);
  497. }
  498. endElement("span");
  499. }
  500. endElement("mainReference");
  501. }
  502. /**
  503. * @see org.apache.fop.render.AbstractRenderer#renderFlow(NormalFlow)
  504. */
  505. protected void renderFlow(NormalFlow flow) {
  506. // the normal flow reference area contains stacked blocks
  507. atts.clear();
  508. addAreaAttributes(flow);
  509. addTraitAttributes(flow);
  510. startElement("flow", atts);
  511. super.renderFlow(flow);
  512. endElement("flow");
  513. }
  514. /**
  515. * @see org.apache.fop.render.AbstractRenderer#renderBlock(Block)
  516. */
  517. protected void renderBlock(Block block) {
  518. atts.clear();
  519. addAreaAttributes(block);
  520. addTraitAttributes(block);
  521. int positioning = block.getPositioning();
  522. if (block instanceof BlockViewport) {
  523. BlockViewport bvp = (BlockViewport)block;
  524. boolean abspos = false;
  525. if (bvp.getPositioning() == Block.ABSOLUTE
  526. || bvp.getPositioning() == Block.FIXED) {
  527. abspos = true;
  528. }
  529. if (abspos) {
  530. addAttribute("left-position", bvp.getXOffset());
  531. addAttribute("top-position", bvp.getYOffset());
  532. }
  533. addAttribute("ctm", bvp.getCTM().toString());
  534. if (bvp.getClip()) {
  535. addAttribute("clipped", "true");
  536. }
  537. } else {
  538. if (block.getXOffset() != 0) {
  539. addAttribute("left-offset", block.getXOffset());
  540. }
  541. if (block.getYOffset() != 0) {
  542. addAttribute("top-offset", block.getYOffset());
  543. }
  544. }
  545. switch (positioning) {
  546. case Block.RELATIVE:
  547. addAttribute("positioning", "relative");
  548. break;
  549. case Block.ABSOLUTE:
  550. addAttribute("positioning", "absolute");
  551. break;
  552. case Block.FIXED:
  553. addAttribute("positioning", "fixed");
  554. break;
  555. default: //nop
  556. }
  557. startElement("block", atts);
  558. super.renderBlock(block);
  559. endElement("block");
  560. }
  561. /**
  562. * @see org.apache.fop.render.AbstractRenderer#renderLineArea(LineArea)
  563. */
  564. protected void renderLineArea(LineArea line) {
  565. atts.clear();
  566. addAreaAttributes(line);
  567. addTraitAttributes(line);
  568. if (line.getStartIndent() != 0) {
  569. addAttribute("start-indent", line.getStartIndent());
  570. }
  571. startElement("lineArea", atts);
  572. super.renderLineArea(line);
  573. endElement("lineArea");
  574. }
  575. /**
  576. * @see org.apache.fop.render.AbstractRenderer#renderViewport(Viewport)
  577. */
  578. protected void renderViewport(Viewport viewport) {
  579. atts.clear();
  580. addAreaAttributes(viewport);
  581. addTraitAttributes(viewport);
  582. addAttribute("offset", viewport.getOffset());
  583. addAttribute("pos", viewport.getContentPosition());
  584. if (viewport.getClip()) {
  585. addAttribute("clip", Boolean.toString(viewport.getClip()));
  586. }
  587. startElement("viewport", atts);
  588. super.renderViewport(viewport);
  589. endElement("viewport");
  590. }
  591. /**
  592. * @see org.apache.fop.render.AbstractRenderer
  593. */
  594. public void renderImage(Image image, Rectangle2D pos) {
  595. atts.clear();
  596. addAreaAttributes(image);
  597. addTraitAttributes(image);
  598. addAttribute("url", image.getURL());
  599. //addAttribute("pos", pos);
  600. startElement("image", atts);
  601. endElement("image");
  602. }
  603. /**
  604. * @see org.apache.fop.render.AbstractRenderer#renderContainer(Container)
  605. */
  606. public void renderContainer(Container cont) {
  607. startElement("container");
  608. super.renderContainer(cont);
  609. endElement("container");
  610. }
  611. /**
  612. * Renders an fo:foreing-object.
  613. * @param fo the foreign object
  614. * @param pos the position of the foreign object
  615. * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D)
  616. */
  617. public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
  618. atts.clear();
  619. addAreaAttributes(fo);
  620. addTraitAttributes(fo);
  621. String ns = fo.getNameSpace();
  622. addAttribute("ns", ns);
  623. startElement("foreignObject", atts);
  624. Document doc = fo.getDocument();
  625. context.setProperty(XMLXMLHandler.HANDLER, handler);
  626. renderXML(context, doc, ns);
  627. endElement("foreignObject");
  628. }
  629. /**
  630. * @see org.apache.fop.render.AbstractRenderer#renderCharacter(Character)
  631. */
  632. protected void renderCharacter(org.apache.fop.area.inline.Character ch) {
  633. atts.clear();
  634. addAreaAttributes(ch);
  635. addTraitAttributes(ch);
  636. addAttribute("offset", ch.getOffset());
  637. addAttribute("baseline", ch.getBaselineOffset());
  638. startElement("char", atts);
  639. characters(ch.getChar());
  640. endElement("char");
  641. }
  642. /**
  643. * @see org.apache.fop.render.AbstractRenderer#renderInlineSpace(Space)
  644. */
  645. protected void renderInlineSpace(Space space) {
  646. atts.clear();
  647. addAreaAttributes(space);
  648. addTraitAttributes(space);
  649. addAttribute("offset", space.getOffset());
  650. startElement("space", atts);
  651. endElement("space");
  652. }
  653. /**
  654. * @see org.apache.fop.render.AbstractRenderer#renderText(TextArea)
  655. */
  656. protected void renderText(TextArea text) {
  657. atts.clear();
  658. if (text.getTextWordSpaceAdjust() != 0) {
  659. addAttribute("twsadjust", text.getTextWordSpaceAdjust());
  660. }
  661. if (text.getTextLetterSpaceAdjust() != 0) {
  662. addAttribute("tlsadjust", text.getTextLetterSpaceAdjust());
  663. }
  664. addAttribute("offset", text.getOffset());
  665. addAttribute("baseline", text.getBaselineOffset());
  666. addAreaAttributes(text);
  667. addTraitAttributes(text);
  668. startElement("text", atts);
  669. super.renderText(text);
  670. endElement("text");
  671. }
  672. /**
  673. * @see org.apache.fop.render.AbstractRenderer#renderWord(WordArea)
  674. */
  675. protected void renderWord(WordArea word) {
  676. atts.clear();
  677. addAttribute("offset", word.getOffset());
  678. startElement("word", atts);
  679. characters(word.getWord());
  680. endElement("word");
  681. super.renderWord(word);
  682. }
  683. /**
  684. * @see org.apache.fop.render.AbstractRenderer#renderSpace(SpaceArea)
  685. */
  686. protected void renderSpace(SpaceArea space) {
  687. atts.clear();
  688. addAttribute("offset", space.getOffset());
  689. startElement("space", atts);
  690. characters(space.getSpace());
  691. endElement("space");
  692. super.renderSpace(space);
  693. }
  694. /**
  695. * @see org.apache.fop.render.AbstractRenderer#renderInlineParent(InlineParent)
  696. */
  697. protected void renderInlineParent(InlineParent ip) {
  698. atts.clear();
  699. addAreaAttributes(ip);
  700. addTraitAttributes(ip);
  701. addAttribute("offset", ip.getOffset());
  702. startElement("inlineparent", atts);
  703. super.renderInlineParent(ip);
  704. endElement("inlineparent");
  705. }
  706. /**
  707. * @see org.apache.fop.render.AbstractRenderer#renderInlineBlockParent(InlineBlockParent)
  708. */
  709. protected void renderInlineBlockParent(InlineBlockParent ibp) {
  710. atts.clear();
  711. addAreaAttributes(ibp);
  712. addTraitAttributes(ibp);
  713. addAttribute("offset", ibp.getOffset());
  714. startElement("inlineblockparent", atts);
  715. super.renderInlineBlockParent(ibp);
  716. endElement("inlineblockparent");
  717. }
  718. /**
  719. * @see org.apache.fop.render.AbstractRenderer#renderLeader(Leader)
  720. */
  721. protected void renderLeader(Leader area) {
  722. atts.clear();
  723. addAreaAttributes(area);
  724. addTraitAttributes(area);
  725. addAttribute("offset", area.getOffset());
  726. addAttribute("ruleStyle", area.getRuleStyleAsString());
  727. addAttribute("ruleThickness", area.getRuleThickness());
  728. startElement("leader", atts);
  729. endElement("leader");
  730. super.renderLeader(area);
  731. }
  732. /** @see org.apache.fop.render.AbstractRenderer#getMimeType() */
  733. public String getMimeType() {
  734. return XML_MIME_TYPE;
  735. }
  736. }