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.

RTFHandler.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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.rtf;
  52. // Java
  53. import java.io.IOException;
  54. import java.io.OutputStream;
  55. import java.io.OutputStreamWriter;
  56. import org.apache.avalon.framework.logger.ConsoleLogger;
  57. import org.apache.avalon.framework.logger.Logger;
  58. import org.apache.fop.apps.FOPException;
  59. import org.apache.fop.datatypes.ColorType;
  60. import org.apache.fop.fo.FOInputHandler;
  61. import org.apache.fop.fo.flow.Block;
  62. import org.apache.fop.fo.flow.ExternalGraphic;
  63. import org.apache.fop.fo.flow.Inline;
  64. import org.apache.fop.fo.flow.InstreamForeignObject;
  65. import org.apache.fop.fo.flow.Leader;
  66. import org.apache.fop.fo.flow.ListBlock;
  67. import org.apache.fop.fo.flow.ListItem;
  68. import org.apache.fop.fo.flow.PageNumber;
  69. import org.apache.fop.fo.flow.Table;
  70. import org.apache.fop.fo.flow.TableColumn;
  71. import org.apache.fop.fo.flow.TableBody;
  72. import org.apache.fop.fo.flow.TableCell;
  73. import org.apache.fop.fo.flow.TableRow;
  74. import org.apache.fop.fo.pagination.Flow;
  75. import org.apache.fop.fo.pagination.PageSequence;
  76. import org.apache.fop.fo.pagination.SimplePageMaster;
  77. import org.apache.fop.fo.properties.Constants;
  78. import org.apache.fop.fo.Property;
  79. import org.apache.fop.fo.PropertyList;
  80. import org.apache.fop.apps.Document;
  81. import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer;
  82. import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfBeforeContainer;
  83. import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfPageNumberContainer;
  84. import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfParagraphContainer;
  85. import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTextrunContainer;
  86. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAfter;
  87. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
  88. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfBefore;
  89. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
  90. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
  91. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement;
  92. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile;
  93. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFontManager;
  94. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
  95. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
  96. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
  97. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun;
  98. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
  99. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
  100. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
  101. import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTableContainer;
  102. import org.xml.sax.SAXException;
  103. /**
  104. * RTF Handler: generates RTF output using the structure events from
  105. * the FO Tree sent to this structure handler.
  106. *
  107. * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
  108. * @author Trembicki-Guy, Ed <GuyE@DNB.com>
  109. * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
  110. * @author Peter Herweg <pherweg@web.de>
  111. */
  112. public class RTFHandler extends FOInputHandler {
  113. private RtfFile rtfFile;
  114. private final OutputStream os;
  115. private final Logger log = new ConsoleLogger();
  116. private RtfSection sect;
  117. private RtfDocumentArea docArea;
  118. private RtfParagraph para;
  119. private boolean warned = false;
  120. private boolean bPrevHeaderSpecified = false;//true, if there has been a
  121. //header in any page-sequence
  122. private boolean bPrevFooterSpecified = false;//true, if there has been a
  123. //footer in any page-sequence
  124. private boolean bHeaderSpecified = false; //true, if there is a header
  125. //in current page-sequence
  126. private boolean bFooterSpecified = false; //true, if there is a footer
  127. //in current page-sequence
  128. private BuilderContext builderContext = new BuilderContext(null);
  129. private static final String ALPHA_WARNING = "WARNING: RTF renderer is "
  130. + "veryveryalpha at this time, see class org.apache.fop.rtf.renderer.RTFHandler";
  131. /**
  132. * Creates a new RTF structure handler.
  133. * @param doc the Document for which this RTFHandler is processing
  134. * @param os OutputStream to write to
  135. */
  136. public RTFHandler(Document doc, OutputStream os) {
  137. super(doc);
  138. this.os = os;
  139. // use pdf fonts for now, this is only for resolving names
  140. org.apache.fop.render.pdf.FontSetup.setup(doc, null);
  141. log.warn(ALPHA_WARNING);
  142. }
  143. /**
  144. * @see org.apache.fop.fo.FOInputHandler#startDocument()
  145. */
  146. public void startDocument() throws SAXException {
  147. // TODO sections should be created
  148. try {
  149. rtfFile = new RtfFile(new OutputStreamWriter(os));
  150. docArea = rtfFile.startDocumentArea();
  151. } catch (IOException ioe) {
  152. // TODO could we throw Exception in all FOInputHandler events?
  153. throw new SAXException(ioe);
  154. }
  155. }
  156. /**
  157. * @see org.apache.fop.fo.FOInputHandler#endDocument()
  158. */
  159. public void endDocument() throws SAXException {
  160. try {
  161. rtfFile.flush();
  162. } catch (IOException ioe) {
  163. // TODO could we throw Exception in all FOInputHandler events?
  164. throw new SAXException(ioe);
  165. }
  166. }
  167. /**
  168. * @see org.apache.fop.fo.FOInputHandler
  169. */
  170. public void startPageSequence(PageSequence pageSeq) {
  171. try {
  172. sect = docArea.newSection();
  173. //read page size and margins, if specified
  174. Property prop;
  175. if((prop=pageSeq.properties.get("master-reference"))!=null) {
  176. String reference=prop.getString();
  177. SimplePageMaster pagemaster=
  178. pageSeq.getLayoutMasterSet().getSimplePageMaster(reference);
  179. //only simple-page-master supported, so pagemaster may be null
  180. if(pagemaster!=null) {
  181. sect.getRtfAttributes().set(
  182. PageAttributesConverter.convertPageAttributes(
  183. pagemaster.properties,null));
  184. }
  185. }
  186. builderContext.pushContainer(sect);
  187. bHeaderSpecified = false;
  188. bFooterSpecified = false;
  189. } catch (IOException ioe) {
  190. // TODO could we throw Exception in all FOInputHandler events?
  191. log.error("startPageSequence: " + ioe.getMessage());
  192. //TODO throw new FOPException(ioe);
  193. }
  194. }
  195. /**
  196. * @see org.apache.fop.fo.FOInputHandler#endPageSequence(PageSequence)
  197. */
  198. public void endPageSequence(PageSequence pageSeq) throws FOPException {
  199. builderContext.popContainer();
  200. }
  201. /**
  202. * @see org.apache.fop.fo.FOInputHandler#startFlow(Flow)
  203. */
  204. public void startFlow(Flow fl) {
  205. try {
  206. if (fl.getFlowName().equals("xsl-region-body")) {
  207. // if there is no header in current page-sequence but there has been
  208. // a header in a previous page-sequence, insert an empty header.
  209. if (bPrevHeaderSpecified && !bHeaderSpecified) {
  210. RtfAttributes attr = new RtfAttributes();
  211. attr.set(RtfBefore.HEADER);
  212. final IRtfBeforeContainer contBefore =
  213. (IRtfBeforeContainer)builderContext.getContainer
  214. (IRtfBeforeContainer.class, true, this);
  215. contBefore.newBefore(attr);
  216. }
  217. // if there is no footer in current page-sequence but there has been
  218. // a footer in a previous page-sequence, insert an empty footer.
  219. if (bPrevFooterSpecified && !bFooterSpecified) {
  220. RtfAttributes attr = new RtfAttributes();
  221. attr.set(RtfAfter.FOOTER);
  222. final IRtfAfterContainer contAfter =
  223. (IRtfAfterContainer)builderContext.getContainer
  224. (IRtfAfterContainer.class, true, this);
  225. contAfter.newAfter(attr);
  226. }
  227. // print ALPHA_WARNING
  228. if (!warned) {
  229. sect.newParagraph().newText(ALPHA_WARNING);
  230. warned = true;
  231. }
  232. } else if (fl.getFlowName().equals("xsl-region-before")) {
  233. bHeaderSpecified = true;
  234. bPrevHeaderSpecified = true;
  235. final IRtfBeforeContainer c =
  236. (IRtfBeforeContainer)builderContext.getContainer(IRtfBeforeContainer.class,
  237. true, this);
  238. RtfAttributes beforeAttributes = ((RtfElement)c).getRtfAttributes();
  239. if (beforeAttributes == null) {
  240. beforeAttributes = new RtfAttributes();
  241. }
  242. beforeAttributes.set(RtfBefore.HEADER);
  243. RtfBefore before = c.newBefore(beforeAttributes);
  244. builderContext.pushContainer(before);
  245. } else if (fl.getFlowName().equals("xsl-region-after")) {
  246. bFooterSpecified = true;
  247. bPrevFooterSpecified = true;
  248. final IRtfAfterContainer c =
  249. (IRtfAfterContainer)builderContext.getContainer(IRtfAfterContainer.class,
  250. true, this);
  251. RtfAttributes afterAttributes = ((RtfElement)c).getRtfAttributes();
  252. if (afterAttributes == null) {
  253. afterAttributes = new RtfAttributes();
  254. }
  255. afterAttributes.set(RtfAfter.FOOTER);
  256. RtfAfter after = c.newAfter(afterAttributes);
  257. builderContext.pushContainer(after);
  258. }
  259. } catch (IOException ioe) {
  260. log.error("startFlow: " + ioe.getMessage());
  261. throw new Error(ioe.getMessage());
  262. } catch (Exception e) {
  263. log.error("startFlow: " + e.getMessage());
  264. throw new Error(e.getMessage());
  265. }
  266. }
  267. /**
  268. * @see org.apache.fop.fo.FOInputHandler#endFlow(Flow)
  269. */
  270. public void endFlow(Flow fl) {
  271. try {
  272. if (fl.getFlowName().equals("xsl-region-body")) {
  273. //just do nothing
  274. } else if (fl.getFlowName().equals("xsl-region-before")) {
  275. builderContext.popContainer();
  276. } else if (fl.getFlowName().equals("xsl-region-after")) {
  277. builderContext.popContainer();
  278. }
  279. } catch (Exception e) {
  280. log.error("endFlow: " + e.getMessage());
  281. throw new Error(e.getMessage());
  282. }
  283. }
  284. /**
  285. * @see org.apache.fop.fo.FOInputHandler#startBlock(Block)
  286. */
  287. public void startBlock(Block bl) {
  288. try {
  289. RtfAttributes rtfAttr =
  290. TextAttributesConverter.convertAttributes(bl.properties, null);
  291. IRtfTextrunContainer container =
  292. (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
  293. true,this);
  294. RtfTextrun textrun=container.getTextrun();
  295. textrun.addParagraphBreak();
  296. textrun.pushAttributes(rtfAttr);
  297. } catch (IOException ioe) {
  298. // TODO could we throw Exception in all FOInputHandler events?
  299. log.error("startBlock: " + ioe.getMessage());
  300. throw new Error("IOException: " + ioe);
  301. } catch (Exception e) {
  302. log.error("startBlock: " + e.getMessage());
  303. throw new Error("Exception: " + e);
  304. }
  305. }
  306. /**
  307. * @see org.apache.fop.fo.FOInputHandler#endBlock(Block)
  308. */
  309. public void endBlock(Block bl) {
  310. try {
  311. IRtfTextrunContainer container =
  312. (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
  313. true,this);
  314. RtfTextrun textrun=container.getTextrun();
  315. textrun.addParagraphBreak();
  316. textrun.popAttributes();
  317. } catch (IOException ioe) {
  318. log.error("startBlock:" + ioe.getMessage());
  319. throw new Error(ioe.getMessage());
  320. } catch (Exception e) {
  321. log.error("startBlock:" + e.getMessage());
  322. throw new Error(e.getMessage());
  323. }
  324. }
  325. /**
  326. * @see org.apache.fop.fo.FOInputHandler#startTable(Table)
  327. */
  328. public void startTable(Table tbl) {
  329. // create an RtfTable in the current table container
  330. TableContext tableContext = new TableContext(builderContext);
  331. RtfAttributes atts = new RtfAttributes();
  332. try {
  333. final IRtfTableContainer tc =
  334. (IRtfTableContainer)builderContext.getContainer(IRtfTableContainer.class,
  335. true, null);
  336. builderContext.pushContainer(tc.newTable(atts, tableContext));
  337. } catch (Exception e) {
  338. log.error("startTable:" + e.getMessage());
  339. throw new Error(e.getMessage());
  340. }
  341. builderContext.pushTableContext(tableContext);
  342. }
  343. /**
  344. * @see org.apache.fop.fo.FOInputHandler#endTable(Table)
  345. */
  346. public void endTable(Table tbl) {
  347. builderContext.popTableContext();
  348. builderContext.popContainer();
  349. }
  350. /**
  351. *
  352. * @param tc TableColumn that is starting;
  353. */
  354. public void startColumn(TableColumn tc) {
  355. try {
  356. Integer iWidth = new Integer(tc.getColumnWidth() / 1000);
  357. builderContext.getTableContext().setNextColumnWidth(iWidth.toString() + "pt");
  358. builderContext.getTableContext().setNextColumnRowSpanning(new Integer(0), null);
  359. } catch (Exception e) {
  360. log.error("startColumn: " + e.getMessage());
  361. throw new Error(e.getMessage());
  362. }
  363. }
  364. /**
  365. *
  366. * @param tc TableColumn that is ending;
  367. */
  368. public void endColumn(TableColumn tc) {
  369. }
  370. /**
  371. * @see org.apache.fop.fo.FOInputHandler#startHeader(TableBody)
  372. */
  373. public void startHeader(TableBody th) {
  374. }
  375. /**
  376. * @see org.apache.fop.fo.FOInputHandler#endHeader(TableBody)
  377. */
  378. public void endHeader(TableBody th) {
  379. }
  380. /**
  381. * @see org.apache.fop.fo.FOInputHandler#startFooter(TableBody)
  382. */
  383. public void startFooter(TableBody tf) {
  384. }
  385. /**
  386. * @see org.apache.fop.fo.FOInputHandler#endFooter(TableBody)
  387. */
  388. public void endFooter(TableBody tf) {
  389. }
  390. /**
  391. *
  392. * @param inl Inline that is starting.
  393. */
  394. public void startInline(Inline inl){
  395. try {
  396. RtfAttributes rtfAttr =
  397. TextAttributesConverter.convertCharacterAttributes(inl.properties, null);
  398. IRtfTextrunContainer container =
  399. (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
  400. true,this);
  401. RtfTextrun textrun=container.getTextrun();
  402. textrun.pushAttributes(rtfAttr);
  403. } catch (IOException ioe) {
  404. log.error("startInline:" + ioe.getMessage());
  405. throw new Error(ioe.getMessage());
  406. } catch (FOPException fe) {
  407. log.error("startInline:" + fe.getMessage());
  408. throw new Error(fe.getMessage());
  409. } catch (Exception e) {
  410. log.error("startInline:" + e.getMessage());
  411. throw new Error(e.getMessage());
  412. }
  413. }
  414. /**
  415. *
  416. * @param inl Inline that is ending.
  417. */
  418. public void endInline(Inline inl){
  419. try {
  420. IRtfTextrunContainer container =
  421. (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
  422. true,this);
  423. RtfTextrun textrun=container.getTextrun();
  424. textrun.popAttributes();
  425. } catch (IOException ioe) {
  426. log.error("startInline:" + ioe.getMessage());
  427. throw new Error(ioe.getMessage());
  428. } catch (Exception e) {
  429. log.error("startInline:" + e.getMessage());
  430. throw new Error(e.getMessage());
  431. }
  432. }
  433. /**
  434. * @see org.apache.fop.fo.FOInputHandler#startBody(TableBody)
  435. */
  436. public void startBody(TableBody tb) {
  437. try {
  438. RtfAttributes atts = TableAttributesConverter.convertRowAttributes (tb.properties,
  439. null, null);
  440. RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this);
  441. tbl.setHeaderAttribs(atts);
  442. } catch (Exception e) {
  443. log.error("startBody: " + e.getMessage());
  444. throw new Error(e.getMessage());
  445. }
  446. }
  447. /**
  448. * @see org.apache.fop.fo.FOInputHandler#endBody(TableBody)
  449. */
  450. public void endBody(TableBody tb) {
  451. try {
  452. RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this);
  453. tbl.setHeaderAttribs(null);
  454. } catch (Exception e) {
  455. log.error("endBody: " + e.getMessage());
  456. throw new Error(e.getMessage());
  457. }
  458. }
  459. /**
  460. * @see org.apache.fop.fo.FOInputHandler#startRow(TableRow)
  461. */
  462. public void startRow(TableRow tr) {
  463. try {
  464. // create an RtfTableRow in the current RtfTable
  465. final RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class,
  466. true, null);
  467. RtfAttributes tblAttribs = tbl.getRtfAttributes();
  468. RtfAttributes tblRowAttribs = new RtfAttributes();
  469. RtfAttributes atts = TableAttributesConverter.convertRowAttributes(tr.properties,
  470. null, tbl.getHeaderAttribs());
  471. builderContext.pushContainer(tbl.newTableRow(atts));
  472. // reset column iteration index to correctly access column widths
  473. builderContext.getTableContext().selectFirstColumn();
  474. } catch (Exception e) {
  475. log.error("startRow: " + e.getMessage());
  476. throw new Error(e.getMessage());
  477. }
  478. }
  479. /**
  480. * @see org.apache.fop.fo.FOInputHandler#endRow(TableRow)
  481. */
  482. public void endRow(TableRow tr) {
  483. builderContext.popContainer();
  484. builderContext.getTableContext().decreaseRowSpannings();
  485. }
  486. /**
  487. * @see org.apache.fop.fo.FOInputHandler#startCell(TableCell)
  488. */
  489. public void startCell(TableCell tc) {
  490. try {
  491. TableContext tctx = builderContext.getTableContext();
  492. final RtfTableRow row = (RtfTableRow)builderContext.getContainer(RtfTableRow.class,
  493. true, null);
  494. //while the current column is in row-spanning, act as if
  495. //a vertical merged cell would have been specified.
  496. while (tctx.getNumberOfColumns() > tctx.getColumnIndex()
  497. && tctx.getColumnRowSpanningNumber().intValue() > 0) {
  498. row.newTableCellMergedVertically((int)tctx.getColumnWidth(),
  499. tctx.getColumnRowSpanningAttrs());
  500. tctx.selectNextColumn();
  501. }
  502. //get the width of the currently started cell
  503. float width = tctx.getColumnWidth();
  504. // create an RtfTableCell in the current RtfTableRow
  505. RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc.properties,
  506. null);
  507. RtfTableCell cell = row.newTableCell((int)width, atts);
  508. //process number-rows-spanned attribute
  509. Property p = null;
  510. if ((p = tc.properties.get("number-rows-spanned")) != null && false) {
  511. // Start vertical merge
  512. cell.setVMerge(RtfTableCell.MERGE_START);
  513. // set the number of rows spanned
  514. tctx.setCurrentColumnRowSpanning(new Integer(p.getNumber().intValue()),
  515. cell.getRtfAttributes());
  516. } else {
  517. tctx.setCurrentColumnRowSpanning(new Integer(1), null);
  518. }
  519. builderContext.pushContainer(cell);
  520. } catch (Exception e) {
  521. log.error("startCell: " + e.getMessage());
  522. throw new Error(e.getMessage());
  523. }
  524. }
  525. /**
  526. * @see org.apache.fop.fo.FOInputHandler#endCell(TableCell)
  527. */
  528. public void endCell(TableCell tc) {
  529. builderContext.popContainer();
  530. builderContext.getTableContext().selectNextColumn();
  531. }
  532. // Lists
  533. /**
  534. * @see org.apache.fop.fo.FOInputHandler#startList(ListBlock)
  535. */
  536. public void startList(ListBlock lb) {
  537. }
  538. /**
  539. * @see org.apache.fop.fo.FOInputHandler#endList(ListBlock)
  540. */
  541. public void endList(ListBlock lb) {
  542. }
  543. /**
  544. * @see org.apache.fop.fo.FOInputHandler#startListItem(ListItem)
  545. */
  546. public void startListItem(ListItem li) {
  547. }
  548. /**
  549. * @see org.apache.fop.fo.FOInputHandler#endListItem(ListItem)
  550. */
  551. public void endListItem(ListItem li) {
  552. }
  553. /**
  554. * @see org.apache.fop.fo.FOInputHandler#startListLabel()
  555. */
  556. public void startListLabel() {
  557. }
  558. /**
  559. * @see org.apache.fop.fo.FOInputHandler#endListLabel()
  560. */
  561. public void endListLabel() {
  562. }
  563. /**
  564. * @see org.apache.fop.fo.FOInputHandler#startListBody()
  565. */
  566. public void startListBody() {
  567. }
  568. /**
  569. * @see org.apache.fop.fo.FOInputHandler#endListBody()
  570. */
  571. public void endListBody() {
  572. }
  573. // Static Regions
  574. /**
  575. * @see org.apache.fop.fo.FOInputHandler#startStatic()
  576. */
  577. public void startStatic() {
  578. }
  579. /**
  580. * @see org.apache.fop.fo.FOInputHandler#endStatic()
  581. */
  582. public void endStatic() {
  583. }
  584. /**
  585. * @see org.apache.fop.fo.FOInputHandler#startMarkup()
  586. */
  587. public void startMarkup() {
  588. }
  589. /**
  590. * @see org.apache.fop.fo.FOInputHandler#endMarkup()
  591. */
  592. public void endMarkup() {
  593. }
  594. /**
  595. * @see org.apache.fop.fo.FOInputHandler#startLink()
  596. */
  597. public void startLink() {
  598. }
  599. /**
  600. * @see org.apache.fop.fo.FOInputHandler#endLink()
  601. */
  602. public void endLink() {
  603. }
  604. /**
  605. * @see org.apache.fop.fo.FOInputHandler#image(ExternalGraphic)
  606. */
  607. public void image(ExternalGraphic eg) {
  608. }
  609. /**
  610. * @see org.apache.fop.fo.FOInputHandler#pageRef()
  611. */
  612. public void pageRef() {
  613. }
  614. /**
  615. * @see org.apache.fop.fo.FOInputHandler#foreignObject(InstreamForeignObject)
  616. */
  617. public void foreignObject(InstreamForeignObject ifo) {
  618. }
  619. /**
  620. * @see org.apache.fop.fo.FOInputHandler#footnote()
  621. */
  622. public void footnote() {
  623. }
  624. /**
  625. * @see org.apache.fop.fo.FOInputHandler#leader(Leader)
  626. */
  627. public void leader(Leader l) {
  628. }
  629. /**
  630. * @see org.apache.fop.fo.FOInputHandler#characters(char[], int, int)
  631. */
  632. public void characters(char data[], int start, int length) {
  633. try {
  634. IRtfTextrunContainer container =
  635. (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
  636. true,this);
  637. RtfTextrun textrun=container.getTextrun();
  638. textrun.addString(new String(data, start, length));
  639. } catch (IOException ioe) {
  640. // FIXME could we throw Exception in all FOInputHandler events?
  641. log.error("characters: " + ioe.getMessage());
  642. throw new Error(ioe.getMessage());
  643. } catch (Exception e) {
  644. log.error("characters:" + e.getMessage());
  645. throw new Error(e.getMessage());
  646. }
  647. }
  648. /**
  649. *
  650. * @param pagenum PageNumber that is starting.
  651. */
  652. public void startPageNumber(PageNumber pagenum) {
  653. try {
  654. RtfAttributes rtfAttr =
  655. TextAttributesConverter.convertCharacterAttributes(pagenum.properties, null);
  656. IRtfTextrunContainer container =
  657. (IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
  658. true,this);
  659. RtfTextrun textrun=container.getTextrun();
  660. textrun.addPageNumber(rtfAttr);
  661. } catch (IOException ioe) {
  662. log.error("startPageNumber:" + ioe.getMessage());
  663. throw new Error(ioe.getMessage());
  664. } catch (Exception e) {
  665. log.error("startPageNumber: " + e.getMessage());
  666. throw new Error(e.getMessage());
  667. }
  668. }
  669. /**
  670. *
  671. * @param pagenum PageNumber that is ending.
  672. */
  673. public void endPageNumber(PageNumber pagenum) {
  674. }
  675. }