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.

IFRendererTestCase.java 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.intermediate;
  19. import java.io.ByteArrayInputStream;
  20. import java.io.ByteArrayOutputStream;
  21. import java.io.File;
  22. import java.io.InputStream;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import javax.xml.transform.Result;
  26. import javax.xml.transform.Source;
  27. import javax.xml.transform.Transformer;
  28. import javax.xml.transform.TransformerException;
  29. import javax.xml.transform.TransformerFactory;
  30. import javax.xml.transform.sax.SAXResult;
  31. import javax.xml.transform.stream.StreamSource;
  32. import org.junit.Assert;
  33. import org.junit.Test;
  34. import org.apache.fop.apps.FOPException;
  35. import org.apache.fop.apps.FOUserAgent;
  36. import org.apache.fop.apps.Fop;
  37. import org.apache.fop.apps.FopFactory;
  38. import org.apache.fop.apps.FopFactoryBuilder;
  39. import org.apache.fop.area.inline.WordArea;
  40. public class IFRendererTestCase {
  41. private List<WordArea> wordAreas = new ArrayList<WordArea>();
  42. private void foToOutput(InputStream fo) throws FOPException, TransformerException {
  43. FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI());
  44. fopFactoryBuilder.setAccessibility(true);
  45. FopFactory fopFactory = fopFactoryBuilder.build();
  46. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  47. IFRenderer ifRenderer = new IFRenderer(userAgent) {
  48. protected void renderWord(WordArea word) {
  49. wordAreas.add(word);
  50. super.renderWord(word);
  51. }
  52. };
  53. userAgent.setRendererOverride(ifRenderer);
  54. Fop fop = fopFactory.newFop("application/pdf", userAgent, new ByteArrayOutputStream());
  55. Transformer transformer = TransformerFactory.newInstance().newTransformer();
  56. Source src = new StreamSource(fo);
  57. Result res = new SAXResult(fop.getDefaultHandler());
  58. transformer.transform(src, res);
  59. }
  60. @Test
  61. public void testWordSpace() throws FOPException, TransformerException {
  62. String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
  63. + " <fo:layout-master-set>\n"
  64. + " <fo:simple-page-master master-name=\"simple\" page-height=\"27.9cm\" page-width=\"21.6cm\">\n"
  65. + " <fo:region-body />\n"
  66. + " </fo:simple-page-master>\n"
  67. + " </fo:layout-master-set>\n"
  68. + " <fo:page-sequence master-reference=\"simple\">\n"
  69. + " <fo:flow flow-name=\"xsl-region-body\">\n"
  70. + " <fo:block>test test</fo:block>\n"
  71. + " </fo:flow>\n"
  72. + " </fo:page-sequence>\n"
  73. + "</fo:root>";
  74. foToOutput(new ByteArrayInputStream(fo.getBytes()));
  75. Assert.assertTrue(wordAreas.get(0).isNextIsSpace());
  76. Assert.assertFalse(wordAreas.get(1).isNextIsSpace());
  77. }
  78. }