|
22 | 22 | import java.io.ByteArrayOutputStream; |
23 | 23 | import java.io.File; |
24 | 24 | import java.util.Collection; |
| 25 | +import java.util.List; |
25 | 26 |
|
26 | 27 | import javax.xml.transform.Result; |
27 | 28 | import javax.xml.transform.Source; |
|
30 | 31 | import javax.xml.transform.sax.SAXResult; |
31 | 32 | import javax.xml.transform.stream.StreamSource; |
32 | 33 |
|
33 | | -import org.junit.Assert; |
34 | 34 | import org.junit.Test; |
| 35 | +import org.xml.sax.helpers.AttributesImpl; |
| 36 | +import static org.junit.Assert.assertEquals; |
35 | 37 |
|
36 | 38 | import org.apache.fop.apps.FOUserAgent; |
37 | 39 | import org.apache.fop.apps.Fop; |
38 | 40 | import org.apache.fop.apps.FopFactory; |
39 | 41 | import org.apache.fop.pdf.PDFLinearizationTestCase; |
| 42 | +import org.apache.fop.pdf.PDFStructElem; |
| 43 | +import org.apache.fop.pdf.StandardStructureTypes; |
40 | 44 |
|
41 | 45 | public class PDFStructureTreeTestCase { |
42 | 46 | @Test |
@@ -65,16 +69,107 @@ public void testStaticRegionPerPage() throws Exception { |
65 | 69 | for (StringBuilder sb : objs) { |
66 | 70 | String obj = sb.toString(); |
67 | 71 | if (obj.contains("/Type /MCR")) { |
68 | | - Assert.assertEquals(obj, obj.split("/Pg ").length, 2); |
| 72 | + assertEquals(obj, obj.split("/Pg ").length, 2); |
69 | 73 | count++; |
70 | 74 | } |
71 | 75 | } |
72 | | - Assert.assertEquals(count, 4); |
| 76 | + assertEquals(count, 4); |
73 | 77 | } |
74 | 78 |
|
75 | | - private ByteArrayOutputStream foToOutput(String fo) throws Exception { |
| 79 | + @Test |
| 80 | + public void testTableHeaderDuplicatedIfStaticRegionsPerPageTrue() throws Exception { |
| 81 | + List<PDFStructElem> elems = getPDFStructElems("<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" " |
| 82 | + + "font-family=\"arial\" font-size=\"16pt\" xml:lang=\"en\">\n" |
| 83 | + + " <fo:layout-master-set>\n" |
| 84 | + + " <fo:simple-page-master master-name=\"A5-Page\" page-width=\"148mm\" page-height=\"210mm\">\n" |
| 85 | + + " <fo:region-body background-color=\"#efefef\" margin=\"10mm\"/>\n" |
| 86 | + + " </fo:simple-page-master>\n" |
| 87 | + + " <fo:page-sequence-master master-name=\"A5\">\n" |
| 88 | + + " <fo:repeatable-page-master-alternatives>\n" |
| 89 | + + " <fo:conditional-page-master-reference master-reference=\"A5-Page\"/>\n" |
| 90 | + + " </fo:repeatable-page-master-alternatives>\n" |
| 91 | + + " </fo:page-sequence-master>\n" |
| 92 | + + " </fo:layout-master-set>\n" |
| 93 | + + " <fo:page-sequence master-reference=\"A5\">\n" |
| 94 | + + " <fo:flow flow-name=\"xsl-region-body\">\n" |
| 95 | + + " <fo:block>\n" |
| 96 | + + " <fo:block padding-bottom=\"160mm\">Table overflow</fo:block>\n" |
| 97 | + + " <fo:table table-layout=\"fixed\" width=\"100%\">\n" |
| 98 | + + " <fo:table-header>\n" |
| 99 | + + " <fo:table-row>\n" |
| 100 | + + " <fo:table-cell number-columns-spanned=\"2\">\n" |
| 101 | + + " <fo:block font-weight=\"bold\" font-style=\"italic\" text-align=\"left\" " |
| 102 | + + "text-align-last=\"center\"> Table Title </fo:block>\n" |
| 103 | + + " </fo:table-cell>\n" |
| 104 | + + " </fo:table-row>\n" |
| 105 | + + " </fo:table-header>\n" |
| 106 | + + " <fo:table-body>\n" |
| 107 | + + " <fo:table-row>\n" |
| 108 | + + " <fo:table-cell>\n" |
| 109 | + + " <fo:block>Row 1 Column A</fo:block>\n" |
| 110 | + + " </fo:table-cell>\n" |
| 111 | + + " <fo:table-cell>\n" |
| 112 | + + " <fo:block>Row 1 Column B</fo:block>\n" |
| 113 | + + " </fo:table-cell>\n" |
| 114 | + + " </fo:table-row>\n" |
| 115 | + + " <fo:table-row>\n" |
| 116 | + + " <fo:table-cell>\n" |
| 117 | + + " <fo:block>Row 2 Column A</fo:block>\n" |
| 118 | + + " </fo:table-cell>\n" |
| 119 | + + " <fo:table-cell>\n" |
| 120 | + + " <fo:block>Row 2 Column B</fo:block>\n" |
| 121 | + + " </fo:table-cell>\n" |
| 122 | + + " </fo:table-row>\n" |
| 123 | + + " <fo:table-row>\n" |
| 124 | + + " <fo:table-cell>\n" |
| 125 | + + " <fo:block>Row 2 Column A</fo:block>\n" |
| 126 | + + " </fo:table-cell>\n" |
| 127 | + + " <fo:table-cell>\n" |
| 128 | + + " <fo:block>Row 2 Column B</fo:block>\n" |
| 129 | + + " </fo:table-cell>\n" |
| 130 | + + " </fo:table-row>\n" |
| 131 | + + " <fo:table-row>\n" |
| 132 | + + " <fo:table-cell>\n" |
| 133 | + + " <fo:block>Row 2 Column A</fo:block>\n" |
| 134 | + + " </fo:table-cell>\n" |
| 135 | + + " <fo:table-cell>\n" |
| 136 | + + " <fo:block>Row 2 Column B</fo:block>\n" |
| 137 | + + " </fo:table-cell>\n" |
| 138 | + + " </fo:table-row>\n" |
| 139 | + + " </fo:table-body>\n" |
| 140 | + + " </fo:table>\n" |
| 141 | + + " </fo:block>\n" |
| 142 | + + " </fo:flow>\n" |
| 143 | + + " </fo:page-sequence>\n" |
| 144 | + + "</fo:root>"); |
| 145 | + |
| 146 | + int count = 0; |
| 147 | + for (PDFStructElem elem : elems) { |
| 148 | + if (elem.getStructureType().equals(StandardStructureTypes.Table.THEAD)) { |
| 149 | + count++; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + assertEquals("The static region per page conf must apply to static regions only", 1, count); |
| 154 | + } |
| 155 | + |
| 156 | + private List<PDFStructElem> getPDFStructElems(String fo) throws Exception { |
76 | 157 | FopFactory fopFactory = getFopFactory(); |
77 | 158 | FOUserAgent userAgent = fopFactory.newFOUserAgent(); |
| 159 | + foToOutput(fo, fopFactory, userAgent); |
| 160 | + |
| 161 | + PDFStructElem block = (PDFStructElem) userAgent |
| 162 | + .getStructureTreeEventHandler().startNode("block", new AttributesImpl(), null); |
| 163 | + |
| 164 | + return block.getDocument().getStructureTreeElements(); |
| 165 | + } |
| 166 | + |
| 167 | + private ByteArrayOutputStream foToOutput(String fo) throws Exception { |
| 168 | + FopFactory fopFactory = getFopFactory(); |
| 169 | + return foToOutput(fo, fopFactory, fopFactory.newFOUserAgent()); |
| 170 | + } |
| 171 | + |
| 172 | + private ByteArrayOutputStream foToOutput(String fo, FopFactory fopFactory, FOUserAgent userAgent) throws Exception { |
78 | 173 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
79 | 174 | Fop fop = fopFactory.newFop("application/pdf", userAgent, bos); |
80 | 175 | Transformer transformer = TransformerFactory.newInstance().newTransformer(); |
|
0 commit comments