public class OfficeMath extends CompositeNode
OfficeMath instances and some other nodes.
To learn more, visit the Working with OfficeMath documentation article.
Remarks:
In this version of Aspose.Words, OfficeMath nodes do not provide public methods and properties to create or modify a OfficeMath object. In this version you are not able to instantiate N:Aspose.Words.Math nodes or modify existing except deleting them.
OfficeMath can only be a child of Paragraph.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
int |
acceptEnd(DocumentVisitor visitor)
Accepts a visitor for visiting the end of the office math.
|
int |
acceptStart(DocumentVisitor visitor)
Accepts a visitor for visiting the start of the office math.
|
void |
clearRunAttrs() |
java.lang.Object |
fetchInheritedRunAttr(int fontAttr) |
java.lang.Object |
getDirectRunAttr(int key) |
java.lang.Object |
getDirectRunAttr(int key,
int revisionsView) |
int |
getDisplayType()
Gets/sets Office Math display format type which represents whether an equation is displayed inline with the text or displayed on its own line.
|
DocumentBase |
getDocument_IInline() |
int |
getJustification()
Gets/sets Office Math justification.
|
int |
getMathObjectType()
Gets type
getMathObjectType() of this Office Math object. |
OfficeMathRenderer |
getMathRenderer()
Creates and returns an object that can be used to render this equation into an image.
|
int |
getNodeType()
Returns
NodeType.OFFICE_MATH. |
Paragraph |
getParentParagraph_IInline() |
Paragraph |
getParentParagraph()
Retrieves the parent
Paragraph of this node. |
void |
removeMoveRevisions() |
void |
removeRunAttr(int key) |
void |
setDisplayType(int value)
Gets/sets Office Math display format type which represents whether an equation is displayed inline with the text or displayed on its own line.
|
void |
setJustification(int value)
Gets/sets Office Math justification.
|
void |
setRunAttr(int fontAttr,
java.lang.Object value) |
acceptChildren, acceptCore, appendChild, coreRemoveSelfOnly, getChild, getChildNodes, getContainer, getCount, getCurrentNode, getFirstChild, getLastChild, getNextMatchingNode, getText, hasChildNodes, indexOf, insertAfter, insertBefore, isComposite, iterator, prependChild, removeAllChildren, removeChild, removeSmartTags, selectNodes, selectSingleNodedeepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.
For more info see the Visitor design pattern.
Calls DocumentVisitor.visitOfficeMathStart(com.aspose.words.OfficeMath), then calls Node.accept(com.aspose.words.DocumentVisitor) for all child nodes of the Office Math and calls DocumentVisitor.visitOfficeMathEnd(com.aspose.words.OfficeMath) at the end.
Examples:
Shows how to print the node structure of every office math node in a document.
public void officeMathToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
OfficeMathStructurePrinter visitor = new OfficeMathStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered OfficeMath nodes and their children.
/// </summary>
public static class OfficeMathStructurePrinter extends DocumentVisitor {
public OfficeMathStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideOfficeMath = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideOfficeMath) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when an OfficeMath node is encountered in the document.
/// </summary>
public int visitOfficeMathStart(final OfficeMath officeMath) {
indentAndAppendLine("[OfficeMath start] Math object type: " + officeMath.getMathObjectType());
mDocTraversalDepth++;
mVisitorIsInsideOfficeMath = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of an OfficeMath node have been visited.
/// </summary>
public int visitOfficeMathEnd(final OfficeMath officeMath) {
mDocTraversalDepth--;
indentAndAppendLine("[OfficeMath end]");
mVisitorIsInsideOfficeMath = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideOfficeMath;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
accept in class Nodevisitor - The visitor that will visit the nodes.DocumentVisitor stopped the operation before visiting all nodes.java.lang.Exceptionpublic OfficeMathRenderer getMathRenderer() throws java.lang.Exception
Remarks:
This method just invokes the OfficeMathRenderer constructor and passes this object as a parameter.
Examples:
Shows how to render an Office Math object into an image file in the local file system.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath math = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// Create an "ImageSaveOptions" object to pass to the node renderer's "Save" method to modify
// how it renders the OfficeMath node into an image.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
// Set the "Scale" property to 5 to render the object to five times its original size.
saveOptions.setScale(5f);
math.getMathRenderer().save(getArtifactsDir() + "Shape.RenderOfficeMath.png", saveOptions);
java.lang.Exceptionpublic int acceptStart(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to print the node structure of every office math node in a document.
public void officeMathToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
OfficeMathStructurePrinter visitor = new OfficeMathStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered OfficeMath nodes and their children.
/// </summary>
public static class OfficeMathStructurePrinter extends DocumentVisitor {
public OfficeMathStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideOfficeMath = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideOfficeMath) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when an OfficeMath node is encountered in the document.
/// </summary>
public int visitOfficeMathStart(final OfficeMath officeMath) {
indentAndAppendLine("[OfficeMath start] Math object type: " + officeMath.getMathObjectType());
mDocTraversalDepth++;
mVisitorIsInsideOfficeMath = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of an OfficeMath node have been visited.
/// </summary>
public int visitOfficeMathEnd(final OfficeMath officeMath) {
mDocTraversalDepth--;
indentAndAppendLine("[OfficeMath end]");
mVisitorIsInsideOfficeMath = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideOfficeMath;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
acceptStart in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic int acceptEnd(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to print the node structure of every office math node in a document.
public void officeMathToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
OfficeMathStructurePrinter visitor = new OfficeMathStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered OfficeMath nodes and their children.
/// </summary>
public static class OfficeMathStructurePrinter extends DocumentVisitor {
public OfficeMathStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideOfficeMath = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideOfficeMath) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when an OfficeMath node is encountered in the document.
/// </summary>
public int visitOfficeMathStart(final OfficeMath officeMath) {
indentAndAppendLine("[OfficeMath start] Math object type: " + officeMath.getMathObjectType());
mDocTraversalDepth++;
mVisitorIsInsideOfficeMath = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of an OfficeMath node have been visited.
/// </summary>
public int visitOfficeMathEnd(final OfficeMath officeMath) {
mDocTraversalDepth--;
indentAndAppendLine("[OfficeMath end]");
mVisitorIsInsideOfficeMath = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideOfficeMath;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
acceptEnd in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic java.lang.Object getDirectRunAttr(int key)
public java.lang.Object getDirectRunAttr(int key,
int revisionsView)
public java.lang.Object fetchInheritedRunAttr(int fontAttr)
public void setRunAttr(int fontAttr,
java.lang.Object value)
public void removeRunAttr(int key)
public void clearRunAttrs()
public int getNodeType()
NodeType.OFFICE_MATH.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
getNodeType in class NodeNodeType.OFFICE_MATH. The returned value is one of NodeType constants.public Paragraph getParentParagraph()
Paragraph of this node.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
Paragraph value.public Paragraph getParentParagraph_IInline()
public DocumentBase getDocument_IInline()
public int getMathObjectType()
getMathObjectType() of this Office Math object.
Examples:
Shows how to print the node structure of every office math node in a document.
public void officeMathToText() throws Exception {
Document doc = new Document(getMyDir() + "DocumentVisitor-compatible features.docx");
OfficeMathStructurePrinter visitor = new OfficeMathStructurePrinter();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc.accept(visitor);
System.out.println(visitor.getText());
}
/// <summary>
/// Traverses a node's non-binary tree of child nodes.
/// Creates a map in the form of a string of all encountered OfficeMath nodes and their children.
/// </summary>
public static class OfficeMathStructurePrinter extends DocumentVisitor {
public OfficeMathStructurePrinter() {
mBuilder = new StringBuilder();
mVisitorIsInsideOfficeMath = false;
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public String getText() {
return mBuilder.toString();
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
public int visitRun(final Run run) {
if (mVisitorIsInsideOfficeMath) {
indentAndAppendLine("[Run] \"" + run.getText() + "\"");
}
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when an OfficeMath node is encountered in the document.
/// </summary>
public int visitOfficeMathStart(final OfficeMath officeMath) {
indentAndAppendLine("[OfficeMath start] Math object type: " + officeMath.getMathObjectType());
mDocTraversalDepth++;
mVisitorIsInsideOfficeMath = true;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called after all the child nodes of an OfficeMath node have been visited.
/// </summary>
public int visitOfficeMathEnd(final OfficeMath officeMath) {
mDocTraversalDepth--;
indentAndAppendLine("[OfficeMath end]");
mVisitorIsInsideOfficeMath = false;
return VisitorAction.CONTINUE;
}
/// <summary>
/// Append a line to the StringBuilder and indent it depending on how deep the visitor is into the document tree.
/// </summary>
/// <param name="text"></param>
private void indentAndAppendLine(final String text) {
for (int i = 0; i < mDocTraversalDepth; i++) {
mBuilder.append("| ");
}
mBuilder.append(text + "\r\n");
}
private boolean mVisitorIsInsideOfficeMath;
private int mDocTraversalDepth;
private final StringBuilder mBuilder;
}
getMathObjectType() of this Office Math object. The returned value is one of MathObjectType constants.public int getJustification()
Remarks:
Justification cannot be set to the Office Math with display format type OfficeMathDisplayType.INLINE.
Inline justification cannot be set to the Office Math with display format type OfficeMathDisplayType.DISPLAY.
Corresponding getDisplayType() / setDisplayType(int) has to be set before setting Office Math justification.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
int value. The returned value is one of OfficeMathJustification constants.public void setJustification(int value)
Remarks:
Justification cannot be set to the Office Math with display format type OfficeMathDisplayType.INLINE.
Inline justification cannot be set to the Office Math with display format type OfficeMathDisplayType.DISPLAY.
Corresponding getDisplayType() / setDisplayType(int) has to be set before setting Office Math justification.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
value - The corresponding int value. The value must be one of OfficeMathJustification constants.public int getDisplayType()
Remarks:
Display format type has effect for top level Office Math only.
Returned display format type is always OfficeMathDisplayType.INLINE for nested Office Math.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
int value. The returned value is one of OfficeMathDisplayType constants.public void setDisplayType(int value)
Remarks:
Display format type has effect for top level Office Math only.
Returned display format type is always OfficeMathDisplayType.INLINE for nested Office Math.
Examples:
Shows how to set office math display formatting.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath officeMath = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// OfficeMath nodes that are children of other OfficeMath nodes are always inline.
// The node we are working with is the base node to change its location and display type.
Assert.assertEquals(MathObjectType.O_MATH_PARA, officeMath.getMathObjectType());
Assert.assertEquals(NodeType.OFFICE_MATH, officeMath.getNodeType());
Assert.assertEquals(officeMath.getParentNode(), officeMath.getParentParagraph());
// Change the location and display type of the OfficeMath node.
officeMath.setDisplayType(OfficeMathDisplayType.DISPLAY);
officeMath.setJustification(OfficeMathJustification.LEFT);
doc.save(getArtifactsDir() + "Shape.OfficeMath.docx");
value - The corresponding int value. The value must be one of OfficeMathDisplayType constants.public void removeMoveRevisions()