* This class cannot be instantiated directly. It can be constructed from a
* TeXFormula using the {@link TeXFormula#createTeXIcon(int,float)} method.
- *
+ *
* @author Kurt Vermeulen
*/
public class TeXIcon implements Icon {
-
+
+ private static final Color defaultColor = new Color(0, 0, 0);
+
public static float defaultSize = -1;
public static float magFactor = 0;
private Box box;
-
+
private final float size;
-
+
private Insets insets = new Insets(0, 0, 0, 0);
- private Color fg = new Color(0, 0, 0);
+ private Color fg = null;
public boolean isColored = false;
-
+
/**
* Creates a new icon that will paint the given formula box in the given point size.
- *
- * @param b the formula box to be painted
+ *
+ * @param b the formula box to be painted
* @param size the point size
*/
protected TeXIcon(Box b, float size) {
- this(b, size, false);
+ this(b, size, false);
}
protected TeXIcon(Box b, float size, boolean trueValues) {
- box = b;
-
- if (defaultSize != -1) {
- size = defaultSize;
- }
-
- if (magFactor != 0) {
- this.size = size * Math.abs(magFactor);
- } else {
- this.size = size;
- }
-
- /* I add this little value because it seems that tftopl calculates badly
- the height and the depth of certains characters.
- */
- if (!trueValues) {
- insets.top += (int)(0.18f * size);
- insets.bottom += (int)(0.18f * size);
- }
+ box = b;
+
+ if (defaultSize != -1) {
+ size = defaultSize;
+ }
+
+ if (magFactor != 0) {
+ this.size = size * Math.abs(magFactor);
+ } else {
+ this.size = size;
+ }
+
+ /* I add this little value because it seems that tftopl calculates badly
+ the height and the depth of certains characters.
+ */
+ if (!trueValues) {
+ insets.top += (int)(0.18f * size);
+ insets.bottom += (int)(0.18f * size);
+ }
}
public void setForeground(Color fg) {
- this.fg = fg != null ? fg : new Color(0, 0, 0);
+ this.fg = fg;
}
-
+
/**
* Get the insets of the TeXIcon.
- *
- * @return the insets
+ *
+ * @return the insets
*/
public Insets getInsets() {
- return insets;
+ return insets;
}
-
+
/**
* Set the insets of the TeXIcon.
- *
+ *
* @param insets the insets
* @param trueValues true to force the true values
*/
public void setInsets(Insets insets, boolean trueValues) {
- this.insets = insets;
- if (!trueValues) {
- this.insets.top += (int)(0.18f * size);
- this.insets.bottom += (int)(0.18f * size);
- }
+ this.insets = insets;
+ if (!trueValues) {
+ this.insets.top += (int)(0.18f * size);
+ this.insets.bottom += (int)(0.18f * size);
+ }
}
/**
* Set the insets of the TeXIcon.
- *
+ *
* @param insets the insets
*/
public void setInsets(Insets insets) {
- setInsets(insets, false);
+ setInsets(insets, false);
}
-
+
/**
* Change the width of the TeXIcon. The new width must be greater than the current
* width, otherwise the icon will remain unchanged. The formula will be aligned to the
- * left ({@linkplain TeXConstants#ALIGN_LEFT}), to the right
- * ({@linkplain TeXConstants#ALIGN_RIGHT}) or will be centered
+ * left ({@linkplain TeXConstants#ALIGN_LEFT}), to the right
+ * ({@linkplain TeXConstants#ALIGN_RIGHT}) or will be centered
* in the middle ({@linkplain TeXConstants#ALIGN_CENTER}).
- *
+ *
* @param width the new width of the TeXIcon
* @param alignment a horizontal alignment constant: LEFT, RIGHT or CENTER
*/
public void setIconWidth(int width, int alignment) {
- float diff = width - getIconWidth();
- if (diff > 0)
- box = new HorizontalBox(box, box.getWidth() + diff, alignment);
+ float diff = width - getIconWidth();
+ if (diff > 0)
+ box = new HorizontalBox(box, box.getWidth() + diff, alignment);
}
-
+
/**
* Change the height of the TeXIcon. The new height must be greater than the current
- * height, otherwise the icon will remain unchanged. The formula will be aligned on top
- * (TeXConstants.TOP), at the bottom (TeXConstants.BOTTOM) or will be centered
+ * height, otherwise the icon will remain unchanged. The formula will be aligned on top
+ * (TeXConstants.TOP), at the bottom (TeXConstants.BOTTOM) or will be centered
* in the middle (TeXConstants.CENTER).
- *
+ *
* @param height the new height of the TeXIcon
* @param alignment a vertical alignment constant: TOP, BOTTOM or CENTER
*/
public void setIconHeight(int height, int alignment) {
- float diff = height - getIconHeight();
- if (diff > 0)
- box = new VerticalBox(box, diff, alignment);
+ float diff = height - getIconHeight();
+ if (diff > 0)
+ box = new VerticalBox(box, diff, alignment);
}
-
+
/**
* Get the total height of the TeXIcon. This also includes the insets.
*/
public int getIconHeight() {
- return ((int) ((box.getHeight()) * size + 0.99 + insets.top)) + ((int) ((box.getDepth()) * size + 0.99 + insets.bottom));
+ return ((int) ((box.getHeight()) * size + 0.99 + insets.top)) + ((int) ((box.getDepth()) * size + 0.99 + insets.bottom));
}
/**
* Get the total height of the TeXIcon. This also includes the insets.
*/
public int getIconDepth() {
- return (int) (box.getDepth() * size + 0.99 + insets.bottom);
+ return (int) (box.getDepth() * size + 0.99 + insets.bottom);
}
-
+
/**
* Get the total width of the TeXIcon. This also includes the insets.
*/
-
+
public int getIconWidth() {
- return (int) (box.getWidth() * size + 0.99 + insets.left + insets.right);
+ return (int) (box.getWidth() * size + 0.99 + insets.left + insets.right);
}
public float getTrueIconHeight() {
- return (box.getHeight() + box.getDepth()) * size;
+ return (box.getHeight() + box.getDepth()) * size;
}
/**
* Get the total height of the TeXIcon. This also includes the insets.
*/
public float getTrueIconDepth() {
- return box.getDepth() * size;
+ return box.getDepth() * size;
}
-
+
/**
* Get the total width of the TeXIcon. This also includes the insets.
*/
-
+
public float getTrueIconWidth() {
- return box.getWidth() * size;
+ return box.getWidth() * size;
}
-
+
public float getBaseLine() {
- return (float)( (box.getHeight() * size + 0.99 + insets.top) /
- ((box.getHeight() + box.getDepth()) * size + 0.99 + insets.top + insets.bottom));
+ return (float)( (box.getHeight() * size + 0.99 + insets.top) /
+ ((box.getHeight() + box.getDepth()) * size + 0.99 + insets.top + insets.bottom));
}
-
+
+ public Box getBox() {
+ return box;
+ }
+
/**
- * Paint the {@link TeXFormula} that created this icon.
+ * Paint the {@link TeXFormula} that created this icon.
*/
public void paintIcon(Component c, Graphics g, int x, int y) {
- Graphics2D g2 = (Graphics2D) g;
- // copy graphics settings
- RenderingHints oldHints = g2.getRenderingHints();
- AffineTransform oldAt = g2.getTransform();
- Color oldColor = g2.getColor();
-
- // new settings
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY);
- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-
- g2.scale(size, size); // the point size
- if (fg != null) {
- g2.setColor(fg);
- } else {
- g2.setColor(c != null ? c.getForeground() : fg); // foreground will be used as default painting color
- }
-
- // draw formula box
- box.draw(g2, (x + insets.left) / size, (y + insets.top) / size+ box.getHeight());
-
- // restore graphics settings
- g2.setRenderingHints(oldHints);
- g2.setTransform(oldAt);
- g2.setColor(oldColor);
+ Graphics2D g2 = (Graphics2D) g;
+ // copy graphics settings
+ RenderingHints oldHints = g2.getRenderingHints();
+ AffineTransform oldAt = g2.getTransform();
+ Color oldColor = g2.getColor();
+
+ // new settings
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+ g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+ g2.scale(size, size); // the point size
+ if (fg != null) {
+ g2.setColor(fg);
+ } else if (c != null) {
+ g2.setColor(c.getForeground()); // foreground will be used as default painting color
+ } else {
+ g2.setColor(defaultColor);
+ }
+
+ // draw formula box
+ box.draw(g2, (x + insets.left) / size, (y + insets.top) / size+ box.getHeight());
+
+ // restore graphics settings
+ g2.setRenderingHints(oldHints);
+ g2.setTransform(oldAt);
+ g2.setColor(oldColor);
}
}
diff -Nru libjlatexmath-java-0.9.6/src/org/scilab/forge/jlatexmath/TeXParser.java libjlatexmath-java-0.9.7/src/org/scilab/forge/jlatexmath/TeXParser.java
--- libjlatexmath-java-0.9.6/src/org/scilab/forge/jlatexmath/TeXParser.java 2011-05-08 11:52:42.000000000 +0000
+++ libjlatexmath-java-0.9.7/src/org/scilab/forge/jlatexmath/TeXParser.java 2011-12-08 17:11:16.000000000 +0000
@@ -53,6 +53,7 @@
private boolean arrayMode;
private boolean ignoreWhiteSpace = true;
private boolean isPartial;
+ private boolean autoNumberBreaking;
// the escape character
private static final char ESCAPE = '\\';
@@ -63,6 +64,7 @@
private static final char L_BRACK = '[';
private static final char R_BRACK = ']';
private static final char DOLLAR = '$';
+ private static final char DQUOTE = '\"';
// Percent char for comments
private static final char PERCENT = '%';
@@ -161,10 +163,10 @@
this.parseString = new StringBuffer(parseString);
this.len = parseString.length();
this.pos = 0;
- if (firstpass)
+ if (firstpass) {
firstpass();
- }
- else {
+ }
+ } else {
this.parseString = null;
this.pos = 0;
this.len = 0;
@@ -648,7 +650,7 @@
pos++;
}
- formula.add(new MathAtom(new TeXFormula(isPartial, getDollarGroup(DOLLAR), false).root, style));
+ formula.add(new MathAtom(new TeXFormula(this, getDollarGroup(DOLLAR), false).root, style));
if (doubleDollar) {
if (parseString.charAt(pos) == DOLLAR) {
pos++;
@@ -660,10 +662,11 @@
Atom at = processEscape();
formula.add(at);
if (arrayMode && at instanceof HlineAtom) {
- ((ArrayOfAtoms)formula).addRow();
+ ((ArrayOfAtoms) formula).addRow();
}
- if (insertion)
+ if (insertion) {
insertion = false;
+ }
break;
case L_GROUP :
Atom atom = getArgument();
@@ -676,8 +679,7 @@
group--;
pos++;
if (group == -1)
- throw new ParseException("Found a closing '" + R_GROUP
- + "' without an opening '" + L_GROUP + "'!");
+ throw new ParseException("Found a closing '" + R_GROUP + "' without an opening '" + L_GROUP + "'!");
return;
case SUPER_SCRIPT :
case SUB_SCRIPT :
@@ -705,6 +707,16 @@
}
pos++;
break;
+ case DQUOTE :
+ if (ignoreWhiteSpace) {
+ formula.add(new CumulativeScriptsAtom(getLastAtom(), null, SymbolAtom.get("prime")));
+ formula.add(new CumulativeScriptsAtom(getLastAtom(), null, SymbolAtom.get("prime")));
+ } else {
+ formula.add(convertCharacter(PRIME, true));
+ formula.add(convertCharacter(PRIME, true));
+ }
+ pos++;
+ break;
default :
formula.add(convertCharacter(ch, false));
pos++;
@@ -953,8 +965,8 @@
}
Atom at = convertCharacter(ch, true);
- pos++;
- return at;
+ pos++;
+ return at;
}
public String getOverArgument() throws ParseException {
@@ -1015,6 +1027,23 @@
return str;
}
+ public float[] getLength() throws ParseException {
+ if (pos == len)
+ return null;
+
+ int ogroup = 1, spos;
+ char ch = '\0';
+
+ skipWhiteSpace();
+ spos = pos;
+ while (pos < len && ch != ' ') {
+ ch = parseString.charAt(pos++);
+ }
+ skipWhiteSpace();
+
+ return SpaceAtom.getLength(parseString.substring(spos, pos - 1));
+ }
+
/** Convert a character in the corresponding atom in using the file TeXFormulaSettings.xml for non-alphanumeric characters
* @param c the character to be converted
* @return the corresponding atom
@@ -1039,10 +1068,10 @@
String symbolName = TeXFormula.symbolMappings[c];
if (symbolName == null && (TeXFormula.symbolFormulaMappings == null || TeXFormula.symbolFormulaMappings[c] == null)) {
TeXFormula.FontInfos fontInfos = TeXFormula.externalFontMap.get(block);
- if (fontInfos != null) {
- if (oneChar) {
- return new JavaFontRenderingAtom(Character.toString(c), fontInfos);
- }
+ if (fontInfos != null) {
+ if (oneChar) {
+ return new JavaFontRenderingAtom(Character.toString(c), fontInfos);
+ }
int start = pos++;
int end = len - 1;
while (pos < len) {
@@ -1083,11 +1112,11 @@
}
} else {
// alphanumeric character
- TeXFormula.FontInfos fontInfos = TeXFormula.externalFontMap.get(Character.UnicodeBlock.BASIC_LATIN);
- if (fontInfos != null) {
- if (oneChar) {
- return new JavaFontRenderingAtom(Character.toString(c), fontInfos);
- }
+ TeXFormula.FontInfos fontInfos = TeXFormula.externalFontMap.get(Character.UnicodeBlock.BASIC_LATIN);
+ if (fontInfos != null) {
+ if (oneChar) {
+ return new JavaFontRenderingAtom(Character.toString(c), fontInfos);
+ }
int start = pos++;
int end = len - 1;
while (pos < len) {
@@ -1222,12 +1251,15 @@
args[i] = "" + parseString.charAt(pos);
pos++;
}
- else
+ else {
args[i] = getCommandWithArgs(getCommand());
+ }
}
}
- skipWhiteSpace();
+ if (ignoreWhiteSpace) {
+ skipWhiteSpace();
+ }
}
return args;
}
diff -Nru libjlatexmath-java-0.9.6/src/org/scilab/forge/jlatexmath/VerticalBox.java libjlatexmath-java-0.9.7/src/org/scilab/forge/jlatexmath/VerticalBox.java
--- libjlatexmath-java-0.9.6/src/org/scilab/forge/jlatexmath/VerticalBox.java 2011-05-06 11:52:26.000000000 +0000
+++ libjlatexmath-java-0.9.7/src/org/scilab/forge/jlatexmath/VerticalBox.java 2011-11-22 17:18:16.000000000 +0000
@@ -69,6 +69,13 @@
depth += b.height + b.depth;
recalculateWidth(b);
}
+
+ public final void add(Box b, float interline) {
+ if (children.size() == 1) {
+ add(new StrutBox(0, interline, 0, 0));
+ }
+ add(b);
+ }
private void recalculateWidth(Box b) {
leftMostPos = Math.min(leftMostPos, b.shift);
diff -Nru libjlatexmath-java-0.9.6/version.xml libjlatexmath-java-0.9.7/version.xml
--- libjlatexmath-java-0.9.6/version.xml 2011-05-08 13:51:20.000000000 +0000
+++ libjlatexmath-java-0.9.7/version.xml 2011-11-22 17:18:16.000000000 +0000
@@ -1,5 +1,5 @@