public class MathObjectType
extends java.lang.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;
}
| Modifier and Type | Field and Description |
|---|---|
static int |
ACCENT
Accent function, consisting of a base and a combining diacritical mark.
|
static int |
ARGUMENT
Argument object.
|
static 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 int |
BAR
Bar function, consisting of a base argument and an overbar or underbar.
|
static int |
BORDER_BOX
Border Box object, consisting of a border drawn around an instance of mathematical text (such as a formula or equation)
|
static int |
BOX
Box object, which is used to group components of an equation or other instance of mathematical text.
|
static int |
DEGREE
Degree in the mathematical radical.
|
static int |
DELIMITER
Delimiter object, consisting of opening and closing delimiters (such as parentheses, braces, brackets, and vertical bars), and an element contained inside.
|
static int |
DENOMINATOR
Denominator of a fraction object.
|
static int |
FRACTION
Fraction object, consisting of a numerator and denominator separated by a fraction bar.
|
static int |
FUNCTION
Function-Apply object, which consists of a function name and an argument element acted upon.
|
static int |
FUNCTION_NAME
Name of the function.
|
static int |
GROUP_CHARACTER
Group-Character object, consisting of a character drawn above or below text, often with the purpose of visually grouping items
|
static int |
length |
static int |
LIMIT
Lower limit of the
LOWER_LIMIT object and the upper limit of the UPPER_LIMIT function. |
static int |
LOWER_LIMIT
Lower-Limit object, consisting of text on the baseline and reduced-size text immediately below it.
|
static int |
MATRIX
Matrix object, consisting of one or more elements laid out in one or more rows and one or more columns.
|
static int |
MATRIX_ROW
Single row of the matrix.
|
static int |
N_ARY
N-ary object, consisting of an n-ary object, a base (or operand), and optional upper and lower limits.
|
static int |
NUMERATOR
Numerator of the Fraction object.
|
static int |
O_MATH
Instance of mathematical text.
|
static int |
O_MATH_PARA
Math paragraph, or display math zone, that contains one or more
O_MATH elements that are in display mode. |
static int |
PHANTOM
Phantom object.
|
static 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 int |
RADICAL
Radical object, consisting of a radical, a base element, and an optional degree .
|
static 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 int |
SUBSCRIPT
Subscript object, which consists of a base element and a reduced-size script placed below and to the right.
|
static int |
SUBSCRIPT_PART
Subscript of the object that can have subscript part.
|
static int |
SUPERCRIPT
Superscript object, which consists of a base element and a reduced-size script placed above and to the right.
|
static int |
SUPERSCRIPT_PART
Superscript of the superscript object.
|
static int |
UPPER_LIMIT
Upper-Limit object, consisting of text on the baseline and reduced-size text immediately above it.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String mathObjectTypeName) |
static java.lang.String |
getName(int mathObjectType) |
static int[] |
getValues() |
static java.lang.String |
toString(int mathObjectType) |
public static int O_MATH
public static int O_MATH_PARA
O_MATH elements that are in display mode.public static int ACCENT
public static int BAR
public static int BORDER_BOX
public static int BOX
public static int DELIMITER
public static int DEGREE
public static int ARGUMENT
public static int ARRAY
public static int FRACTION
public static int DENOMINATOR
public static int NUMERATOR
public static int FUNCTION
public static int FUNCTION_NAME
public static int GROUP_CHARACTER
public static int LIMIT
LOWER_LIMIT object and the upper limit of the UPPER_LIMIT function.public static int LOWER_LIMIT
public static int UPPER_LIMIT
public static int MATRIX
public static int MATRIX_ROW
public static int N_ARY
public static int PHANTOM
public static int RADICAL
public static int SUBSCRIPT_PART
public static int SUPERSCRIPT_PART
public static int PRE_SUB_SUPERSCRIPT
public static int SUBSCRIPT
public static int SUB_SUPERSCRIPT
public static int SUPERCRIPT
public static int length