Skip to content

Commit f28e8a4

Browse files
updated for Table tags structure, #28
1 parent 8197eb5 commit f28e8a4

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

fop-core/src/main/java/org/apache/fop/pdf/PDFStructElem.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import java.util.*;
2727

2828
import org.apache.fop.accessibility.StructureTreeElement;
29+
import org.apache.fop.fo.extensions.InternalElementMapping;
2930
import org.apache.fop.pdf.StandardStructureAttributes.Table;
3031
import org.apache.fop.util.LanguageTags;
32+
import org.xml.sax.Attributes;
3133

3234
/**
3335
* Class representing a PDF Structure Element.
@@ -255,22 +257,29 @@ protected boolean attachKids() {
255257
return kidsAttached;
256258
}
257259

258-
public void setTableAttributeColSpan(int colSpan) {
259-
setTableAttributeRowColumnSpan("ColSpan", colSpan);
260+
public void setTableAttributeColSpan(int colSpan, Attributes attributes) {
261+
setTableAttributeRowColumnSpan("ColSpan", colSpan, attributes);
260262
}
261263

262-
public void setTableAttributeRowSpan(int rowSpan) {
263-
setTableAttributeRowColumnSpan("RowSpan", rowSpan);
264+
public void setTableAttributeRowSpan(int rowSpan, Attributes attributes) {
265+
setTableAttributeRowColumnSpan("RowSpan", rowSpan, attributes);
264266
}
265267

266-
private void setTableAttributeRowColumnSpan(String typeSpan, int span) {
268+
private void setTableAttributeRowColumnSpan(String typeSpan, int span, Attributes attributes) {
267269
PDFDictionary attribute = new PDFDictionary();
268270
attribute.put("O", Table.NAME);
269271
attribute.put(typeSpan, span);
270-
if (attributes == null) {
271-
attributes = new ArrayList<PDFDictionary>(attribute.entries.size());
272+
String scopeAttribute = attributes.getValue(InternalElementMapping.URI,
273+
InternalElementMapping.SCOPE);
274+
Table.Scope scope = (scopeAttribute == null)
275+
? Table.Scope.COLUMN
276+
: Table.Scope.valueOf(scopeAttribute.toUpperCase(Locale.ENGLISH));
277+
attribute.put("Scope", scope.getName());
278+
279+
if (this.attributes == null) {
280+
this.attributes = new ArrayList<PDFDictionary>(attribute.entries.size());
272281
}
273-
attributes.add(attribute);
282+
this.attributes.add(attribute);
274283
}
275284

276285
public List<PDFObject> getKids() {
@@ -281,7 +290,7 @@ public int output(OutputStream stream) throws IOException {
281290
if (getDocument() != null && getDocument().getProfile().getPDFUAMode().isEnabled()) {
282291
if (entries.containsKey("Alt") && "".equals(get("Alt"))) {
283292
put("Alt", "No alternate text specified");
284-
} else if (kids != null) {
293+
} else if (kids != null && structureType != null) {
285294
for (PDFObject kid : kids) {
286295
if (kid instanceof PDFStructElem && isBSLE(((PDFStructElem) kid))) {
287296
structureType = StandardStructureTypes.Grouping.DIV;

fop-core/src/main/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
package org.apache.fop.render.pdf;
2121

22-
import java.util.LinkedList;
23-
import java.util.Locale;
24-
import java.util.Map;
22+
import java.util.*;
2523

2624
import javax.xml.XMLConstants;
2725

26+
import org.apache.fop.pdf.*;
2827
import org.xml.sax.Attributes;
2928
import org.xml.sax.helpers.AttributesImpl;
3029

@@ -34,16 +33,9 @@
3433
import org.apache.fop.fo.extensions.ExtensionElementMapping;
3534
import org.apache.fop.fo.extensions.InternalElementMapping;
3635
import org.apache.fop.fo.pagination.Flow;
37-
import org.apache.fop.pdf.PDFFactory;
38-
import org.apache.fop.pdf.PDFParentTree;
39-
import org.apache.fop.pdf.PDFStructElem;
40-
import org.apache.fop.pdf.PDFStructTreeRoot;
4136
import org.apache.fop.pdf.StandardStructureAttributes.Table.Scope;
42-
import org.apache.fop.pdf.StandardStructureTypes;
4337
import org.apache.fop.pdf.StandardStructureTypes.Grouping;
4438
import org.apache.fop.pdf.StandardStructureTypes.Table;
45-
import org.apache.fop.pdf.StructureHierarchyMember;
46-
import org.apache.fop.pdf.StructureType;
4739
import org.apache.fop.util.LanguageTags;
4840
import org.apache.fop.util.XMLUtil;
4941

@@ -314,11 +306,11 @@ protected void registerStructureElement(PDFStructElem structureElement, PDFFacto
314306
protected void setAttributes(PDFStructElem structElem, Attributes attributes) {
315307
String columnSpan = attributes.getValue("number-columns-spanned");
316308
if (columnSpan != null) {
317-
structElem.setTableAttributeColSpan(Integer.parseInt(columnSpan));
309+
structElem.setTableAttributeColSpan(Integer.parseInt(columnSpan), attributes);
318310
}
319311
String rowSpan = attributes.getValue("number-rows-spanned");
320312
if (rowSpan != null) {
321-
structElem.setTableAttributeRowSpan(Integer.parseInt(rowSpan));
313+
structElem.setTableAttributeRowSpan(Integer.parseInt(rowSpan), attributes);
322314
}
323315
}
324316

0 commit comments

Comments
 (0)