aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2012-07-24 16:39:04 +0000
committerVincent Hennebert <vhennebert@apache.org>2012-07-24 16:39:04 +0000
commit6c6183d35af7ed373ac3c9613ea4e35e77ae3afc (patch)
treebd5bd0569162b8b4deef8230e3dd4888e6cfcc7d /src/java/org/apache
parent22d7da60355a19d132deb696dcdc45d8ae1f5f2d (diff)
downloadxmlgraphics-fop-6c6183d35af7ed373ac3c9613ea4e35e77ae3afc.tar.gz
xmlgraphics-fop-6c6183d35af7ed373ac3c9613ea4e35e77ae3afc.zip
Bugzilla #53596: When PDF accessibility is enabled, the structure tree must contain information about the number of columns or rows spanned by a table cell.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1365162 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java13
-rw-r--r--src/java/org/apache/fop/pdf/PDFArray.java9
-rw-r--r--src/java/org/apache/fop/pdf/PDFStructElem.java34
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java12
4 files changed, 63 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java b/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java
index 51f7f2bed..7e3ed0591 100644
--- a/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java
+++ b/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java
@@ -221,14 +221,17 @@ class StructureTreeEventTrigger extends FOEventHandler {
@Override
public void startCell(TableCell tc) {
AttributesImpl attributes = new AttributesImpl();
- int colSpan = tc.getNumberColumnsSpanned();
- if (colSpan > 1) {
- addNoNamespaceAttribute(attributes, "number-columns-spanned",
- Integer.toString(colSpan));
- }
+ addSpanAttribute(attributes, "number-columns-spanned", tc.getNumberColumnsSpanned());
+ addSpanAttribute(attributes, "number-rows-spanned", tc.getNumberRowsSpanned());
startElement(tc, attributes);
}
+ private void addSpanAttribute(AttributesImpl attributes, String attributeName, int span) {
+ if (span > 1) {
+ addNoNamespaceAttribute(attributes, attributeName, Integer.toString(span));
+ }
+ }
+
@Override
public void endCell(TableCell tc) {
endElement(tc);
diff --git a/src/java/org/apache/fop/pdf/PDFArray.java b/src/java/org/apache/fop/pdf/PDFArray.java
index 131830328..78f5d080b 100644
--- a/src/java/org/apache/fop/pdf/PDFArray.java
+++ b/src/java/org/apache/fop/pdf/PDFArray.java
@@ -100,6 +100,15 @@ public class PDFArray extends PDFObject {
}
/**
+ * Creates an array object made of the given elements.
+ *
+ * @param elements the array content
+ */
+ public PDFArray(List<?> elements) {
+ this(null, elements);
+ }
+
+ /**
* Create the array object
* @param parent the array's parent if any
* @param values the actual array wrapped by this object
diff --git a/src/java/org/apache/fop/pdf/PDFStructElem.java b/src/java/org/apache/fop/pdf/PDFStructElem.java
index 8030e53db..2a756fe9b 100644
--- a/src/java/org/apache/fop/pdf/PDFStructElem.java
+++ b/src/java/org/apache/fop/pdf/PDFStructElem.java
@@ -33,6 +33,8 @@ import org.apache.fop.util.LanguageTags;
*/
public class PDFStructElem extends PDFDictionary implements StructureTreeElement, CompressedObject {
+ private static final PDFName TABLE = new PDFName("Table");
+
private PDFStructElem parentElement;
/**
@@ -40,6 +42,8 @@ public class PDFStructElem extends PDFDictionary implements StructureTreeElement
*/
protected List<PDFObject> kids;
+ private List<PDFDictionary> attributes;
+
/**
* Creates a new structure element.
*
@@ -143,9 +147,21 @@ public class PDFStructElem extends PDFDictionary implements StructureTreeElement
@Override
protected void writeDictionary(OutputStream out, StringBuilder textBuffer) throws IOException {
attachKids();
+ attachAttributes();
super.writeDictionary(out, textBuffer);
}
+ private void attachAttributes() {
+ if (attributes != null) {
+ if (attributes.size() == 1) {
+ put("A", attributes.get(0));
+ } else {
+ PDFArray array = new PDFArray(attributes);
+ put("A", array);
+ }
+ }
+ }
+
/**
* Attaches all valid kids to the kids array.
*
@@ -175,6 +191,24 @@ public class PDFStructElem extends PDFDictionary implements StructureTreeElement
return kidsAttached;
}
+ public void setTableAttributeColSpan(int colSpan) {
+ setTableAttributeRowColumnSpan("ColSpan", colSpan);
+ }
+
+ public void setTableAttributeRowSpan(int rowSpan) {
+ setTableAttributeRowColumnSpan("RowSpan", rowSpan);
+ }
+
+ private void setTableAttributeRowColumnSpan(String typeSpan, int span) {
+ PDFDictionary attribute = new PDFDictionary();
+ attribute.put("O", TABLE);
+ attribute.put(typeSpan, span);
+ if (attributes == null) {
+ attributes = new ArrayList<PDFDictionary>(2);
+ }
+ attributes.add(attribute);
+ }
+
/**
* Class representing a placeholder for a PDF Structure Element.
*/
diff --git a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java
index 3839d47bc..0f8e74515 100644
--- a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java
+++ b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java
@@ -90,11 +90,23 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler {
PDFStructElem parent = ancestors.getFirst();
String role = attributes.getValue("role");
PDFStructElem structElem = createStructureElement(name, parent, role);
+ setSpanAttributes(structElem, attributes);
parent.addKid(structElem);
ancestors.addFirst(structElem);
return structElem;
}
+ private void setSpanAttributes(PDFStructElem structElem, Attributes attributes) {
+ String columnSpan = attributes.getValue("number-columns-spanned");
+ if (columnSpan != null) {
+ structElem.setTableAttributeColSpan(Integer.parseInt(columnSpan));
+ }
+ String rowSpan = attributes.getValue("number-rows-spanned");
+ if (rowSpan != null) {
+ structElem.setTableAttributeRowSpan(Integer.parseInt(rowSpan));
+ }
+ }
+
public void endNode(String name) {
removeFirstAncestor();
}