public class MathObjectType
Example:
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 of 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 StringBuilder mBuilder;
}
Field Summary | ||
---|---|---|
static final int | O_MATH | |
Instance of mathematical text.
|
||
static final int | O_MATH_PARA | |
Math paragraph, or display math zone, that contains one or more |
||
static final int | ACCENT | |
Accent function, consisting of a base and a combining diacritical mark.
|
||
static final int | BAR | |
Bar function, consisting of a base argument and an overbar or underbar.
|
||
static final int | BORDER_BOX | |
Border Box object, consisting of a border drawn around an instance of mathematical text (such as a formula or equation)
|
||
static final int | BOX | |
Box object, which is used to group components of an equation or other instance of mathematical text.
|
||
static final int | DELIMITER | |
Delimiter object, consisting of opening and closing delimiters (such as parentheses,
braces, brackets, and vertical bars), and an element contained inside.
|
||
static final int | DEGREE | |
Degree in the mathematical radical.
|
||
static final int | ARGUMENT | |
Argument object. Encloses Office Math entities when they are used as arguments to other Office Math entities.
|
||
static final int | ARRAY | |
Array object, consisting of one or more equations, expressions, or other mathematical text runs
that can be vertically justified as a unit with respect to surrounding text on the line.
|
||
static final int | FRACTION | |
Fraction object, consisting of a numerator and denominator separated by a fraction bar.
|
||
static final int | DENOMINATOR | |
Denominator of a fraction object.
|
||
static final int | NUMERATOR | |
Numerator of the Fraction object.
|
||
static final int | FUNCTION | |
Function-Apply object, which consists of a function name and an argument element acted upon.
|
||
static final int | FUNCTION_NAME | |
Name of the function. For example, function names are sin and cos.
|
||
static final int | GROUP_CHARACTER | |
Group-Character object, consisting of a character drawn above or below text, often
with the purpose of visually grouping items
|
||
static final int | LIMIT | |
Lower limit of the |
||
static final int | LOWER_LIMIT | |
Lower-Limit object, consisting of text on the baseline and reduced-size text immediately below it.
|
||
static final int | UPPER_LIMIT | |
Upper-Limit object, consisting of text on the baseline and reduced-size text immediately above it.
|
||
static final int | MATRIX | |
Matrix object, consisting of one or more elements laid out in one or more rows and one or more columns.
|
||
static final int | MATRIX_ROW | |
Single row of the matrix.
|
||
static final int | N_ARY | |
N-ary object, consisting of an n-ary object, a base (or operand), and optional upper and lower limits.
|
||
static final int | PHANTOM | |
Phantom object.
|
||
static final int | RADICAL | |
Radical object, consisting of a radical, a base element, and an optional degree .
|
||
static final int | SUBSCRIPT_PART | |
Subscript of the object that can have subscript part.
|
||
static final int | SUPERSCRIPT_PART | |
Superscript of the superscript object.
|
||
static final int | PRE_SUB_SUPERSCRIPT | |
Pre-Sub-Superscript object, which consists of a base element and a subscript and superscript placed to the left of the base.
|
||
static final int | SUBSCRIPT | |
Subscript object, which consists of a base element and a reduced-size script placed below and to the right.
|
||
static final int | SUB_SUPERSCRIPT | |
Sub-superscript object, which consists of a base element, a reduced-size script placed below and to the right, and a reduced-size script placed above and to the right.
|
||
static final int | SUPERCRIPT | |
Superscript object, which consists of a base element and a reduced-size script placed above and to the right.
|
public static final int O_MATH
public static final int O_MATH_PARA
public static final int ACCENT
public static final int BAR
public static final int BORDER_BOX
public static final int BOX
public static final int DELIMITER
public static final int DEGREE
public static final int ARGUMENT
public static final int ARRAY
public static final int FRACTION
public static final int DENOMINATOR
public static final int NUMERATOR
public static final int FUNCTION
public static final int FUNCTION_NAME
public static final int GROUP_CHARACTER
public static final int LIMIT
public static final int LOWER_LIMIT
public static final int UPPER_LIMIT
public static final int MATRIX
public static final int MATRIX_ROW
public static final int N_ARY
public static final int PHANTOM
public static final int RADICAL
public static final int SUBSCRIPT_PART
public static final int SUPERSCRIPT_PART
public static final int PRE_SUB_SUPERSCRIPT
public static final int SUBSCRIPT
public static final int SUB_SUPERSCRIPT
public static final int SUPERCRIPT