diff --git a/src/main/doctypes/simplewpml/simplewpml-base.rng b/src/main/doctypes/simplewpml/simplewpml-base.rng index 7d70bee..712edf2 100644 --- a/src/main/doctypes/simplewpml/simplewpml-base.rng +++ b/src/main/doctypes/simplewpml/simplewpml-base.rng @@ -1330,11 +1330,23 @@ - - + + + +

Specifies the alignment of the table with respect to the text margins, but not the text inside the table. The default is implementation-dependent, but 'start' is typical.

+
+ + start + center + end + +
+
+ + - + diff --git a/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java b/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java index 9fa85c1..4326f19 100644 --- a/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java +++ b/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java @@ -45,6 +45,7 @@ import org.apache.poi.xwpf.usermodel.BreakType; import org.apache.poi.xwpf.usermodel.IBodyElement; import org.apache.poi.xwpf.usermodel.ParagraphAlignment; +import org.apache.poi.xwpf.usermodel.TableRowAlign; import org.apache.poi.xwpf.usermodel.UnderlinePatterns; import org.apache.poi.xwpf.usermodel.XWPFAbstractFootnoteEndnote; import org.apache.poi.xwpf.usermodel.XWPFAbstractNum; @@ -2707,8 +2708,7 @@ private void makeTable(XWPFTable table, XmlObject xml) throws DocxGenerationExce setTableIndents(table, cursor); setTableLayout(table, cursor); - - + setTableAlign(table, cursor); String styleName = cursor.getAttributeText(DocxConstants.QNAME_STYLE_ATT); String styleId = cursor.getAttributeText(DocxConstants.QNAME_STYLEID_ATT); @@ -2854,6 +2854,26 @@ private void setTableIndents(XWPFTable table, XmlCursor cursor) { } + private void setTableAlign(XWPFTable table, XmlCursor cursor) throws DocxGenerationException { + String align = cursor.getAttributeText(DocxConstants.QNAME_ALIGN_ATT); + if (align == null) { + return; + } + + TableRowAlign alignObj; + if (align.equals("start")) { + alignObj = TableRowAlign.LEFT; + } else if (align.equals("center")) { + alignObj = TableRowAlign.CENTER; + } else if (align.equals("end")) { + alignObj = TableRowAlign.RIGHT; + } else { + throw new DocxGenerationException("Unknown value for table align: '" + + align + "'"); + } + + table.setTableAlignment(alignObj); + } /** * Sets the w:tblLayout to fixed or auto diff --git a/src/main/java/org/wordinator/xml2docx/generator/MathMLConverter.java b/src/main/java/org/wordinator/xml2docx/generator/MathMLConverter.java index 23216a8..27fdb67 100644 --- a/src/main/java/org/wordinator/xml2docx/generator/MathMLConverter.java +++ b/src/main/java/org/wordinator/xml2docx/generator/MathMLConverter.java @@ -42,7 +42,14 @@ public static void convertMath(XWPFParagraph para, XmlObject indoc) throws DocxG CTOMathPara ctOMathPara = CTOMathPara.Factory.parse(convertToOOML(indoc)); CTP ctp = para.getCTP(); - ctp.setOMathArray(ctOMathPara.getOMathArray()); + + int oMathCount = ctp.getOMathList().size(); + + // add empty OMath + ctp.addNewOMath(); + + // then overwrite that empty OMath with ours + ctp.setOMathArray(oMathCount, ctOMathPara.getOMathArray()[0]); } catch (XmlException e) { // we seem to have produced bad OOXML, but this was done by the // stylesheet the user supplied, so treating as user error diff --git a/src/test/java/org/wordinator/xml2docx/TestDocxGenerator.java b/src/test/java/org/wordinator/xml2docx/TestDocxGenerator.java index 189d052..1a61ec2 100644 --- a/src/test/java/org/wordinator/xml2docx/TestDocxGenerator.java +++ b/src/test/java/org/wordinator/xml2docx/TestDocxGenerator.java @@ -17,6 +17,7 @@ import org.apache.poi.xwpf.usermodel.BodyElementType; import org.apache.poi.xwpf.usermodel.IBodyElement; import org.apache.poi.xwpf.usermodel.IRunElement; +import org.apache.poi.xwpf.usermodel.TableRowAlign; import org.apache.poi.xwpf.usermodel.XWPFAbstractNum; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFFooter; @@ -862,6 +863,29 @@ public void testMultiSectionPageProps() throws Exception { assertEquals(BigInteger.valueOf(16838), pageSz.getH()); } + public void testTableAlign() throws Exception { + XWPFDocument doc = convert("simplewp/simplewpml-table-align.swpx", "out/table-align.docx"); + List contents = doc.getBodyElements(); + assertEquals(2, contents.size()); + + // first table + Iterator it = contents.iterator(); + IBodyElement elem = it.next(); + assertEquals(BodyElementType.TABLE, elem.getElementType()); + + XWPFTable t = (XWPFTable) elem; + TableRowAlign align = t.getTableAlignment(); + assertEquals(TableRowAlign.LEFT, align); + + // second table + elem = it.next(); + assertEquals(BodyElementType.TABLE, elem.getElementType()); + + t = (XWPFTable) elem; + align = t.getTableAlignment(); + assertEquals(TableRowAlign.CENTER, align); + } + // ===== INTERNAL UTILITIES private XWPFDocument convert(String infile, String outfile) throws Exception { diff --git a/src/test/java/org/wordinator/xml2docx/TestMathML.java b/src/test/java/org/wordinator/xml2docx/TestMathML.java index 6bb20d0..4747646 100644 --- a/src/test/java/org/wordinator/xml2docx/TestMathML.java +++ b/src/test/java/org/wordinator/xml2docx/TestMathML.java @@ -48,6 +48,26 @@ public void testEndingStep() throws Exception { assertEquals("And it is possible for inline equations to be in the middle of paragraphs.", p.getText()); } + @Test + public void testTwoMathMLInOnePara() throws Exception { + XWPFDocument doc = convert("simplewp/simplewpml-mathml-03.xml", "out/testMathML.docx"); + + // first para of text + Iterator iterator = doc.getParagraphsIterator(); + XWPFParagraph p = iterator.next(); + assertNotNull("Expected a paragraph", p); + assertEquals("When 12 test specimens of size  mm ×  mm are tested in accordance with Appendix B, the following apply:", p.getText()); + + // check the math in the para + CTP ctp = p.getCTP(); + CTOMath[] maths = ctp.getOMathArray(); + assertEquals(2, maths.length); + + // there's no point in looking into the maths to see what's there, + // since that would amount to testing the stylesheet, but the + // stylesheet is not part of the Wordinator + } + private XWPFDocument convert(String infile, String outfile) throws Exception { ClassLoader classLoader = getClass().getClassLoader(); File inFile = new File(classLoader.getResource(infile).getFile()); diff --git a/src/test/resources/simplewp/simplewpml-mathml-03.xml b/src/test/resources/simplewp/simplewpml-mathml-03.xml new file mode 100644 index 0000000..8f3c265 --- /dev/null +++ b/src/test/resources/simplewp/simplewpml-mathml-03.xml @@ -0,0 +1,50 @@ + + + + + When 12 test specimens of size + + + + + + 300 + + + + 0 + + + + + 10 + + + + + +  mm ×  + + + + + + 300 + + + + 0 + + + + + 10 + + + + + + mm are tested in accordance with + Appendix B + , the following apply: + + + diff --git a/src/test/resources/simplewp/simplewpml-table-align.swpx b/src/test/resources/simplewp/simplewpml-table-align.swpx new file mode 100644 index 0000000..307f581 --- /dev/null +++ b/src/test/resources/simplewp/simplewpml-table-align.swpx @@ -0,0 +1,40 @@ + + + + + + + + + + Left-aligned + + + + + table + + + + + + + + + + + + + Centered + + + + + table + + + + + + +